-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from rickpeyton/list_games_by_interface
Add a GamesList.by... interface
- Loading branch information
Showing
13 changed files
with
204 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
example_id | status | run_time | | ||
------------------------------------------------------ | ------ | --------------- | | ||
./spec/acceptance/retrieve_a_valid_record_spec.rb[1:1] | passed | 0.11786 seconds | | ||
./spec/nintendo_eshop/game_spec.rb[1:1:1] | passed | 0.00419 seconds | | ||
./spec/nintendo_eshop/game_spec.rb[1:1:2] | passed | 0.00606 seconds | | ||
./spec/nintendo_eshop/game_spec.rb[1:1:3] | passed | 0.00398 seconds | | ||
./spec/nintendo_eshop_spec.rb[1:1] | passed | 0.00083 seconds | | ||
./spec/acceptance/retrieve_a_valid_record_spec.rb[1:1] | passed | 0.14289 seconds | | ||
./spec/nintendo_eshop/game_spec.rb[1:1:1] | passed | 0.00375 seconds | | ||
./spec/nintendo_eshop/game_spec.rb[1:1:2] | passed | 0.00616 seconds | | ||
./spec/nintendo_eshop/game_spec.rb[1:1:3] | passed | 0.00564 seconds | | ||
./spec/nintendo_eshop/games_list_spec.rb[1:1] | passed | 0.00254 seconds | | ||
./spec/nintendo_eshop/games_list_spec.rb[1:2:1] | passed | 0.00393 seconds | | ||
./spec/nintendo_eshop_spec.rb[1:1] | passed | 0.00331 seconds | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
inherit_gem: | ||
ramsey_cop: | ||
- default.yml | ||
|
||
AllCops: | ||
TargetRubyVersion: 2.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
require: rubocop-performance | ||
|
||
AllCops: | ||
Exclude: | ||
- db/schema.rb | ||
- vendor/**/* | ||
TargetRubyVersion: 2.4.6 | ||
|
||
Documentation: | ||
Enabled: false | ||
|
||
Layout/AccessModifierIndentation: | ||
EnforcedStyle: outdent | ||
|
||
Metrics/AbcSize: | ||
Exclude: | ||
- spec/**/* | ||
- test/**/* | ||
|
||
Metrics/BlockLength: | ||
Exclude: | ||
- config/initializers/* | ||
- config/routes.rb | ||
- Gemfile | ||
- spec/**/* | ||
- test/**/* | ||
- "*.gemspec" | ||
- "**/*.rake" | ||
|
||
Metrics/BlockNesting: | ||
Exclude: | ||
- spec/**/* | ||
- test/**/* | ||
|
||
Metrics/CyclomaticComplexity: | ||
Exclude: | ||
- spec/**/* | ||
- test/**/* | ||
|
||
Metrics/LineLength: | ||
Max: 120 | ||
Exclude: | ||
- config/routes.rb | ||
- config/routes/* | ||
- db/migrate/* | ||
|
||
Metrics/MethodLength: | ||
Exclude: | ||
- db/migrate/* | ||
- spec/**/* | ||
- test/**/* | ||
|
||
Metrics/ModuleLength: | ||
Exclude: | ||
- spec/**/* | ||
- test/**/* | ||
|
||
Style/Alias: | ||
EnforcedStyle: prefer_alias_method | ||
|
||
Style/AndOr: | ||
EnforcedStyle: conditionals | ||
|
||
Style/DateTime: | ||
Enabled: false | ||
|
||
Style/FrozenStringLiteralComment: | ||
Enabled: false | ||
|
||
Style/Lambda: | ||
Enabled: false | ||
|
||
Style/NumericLiterals: | ||
Enabled: false | ||
|
||
Style/PercentLiteralDelimiters: | ||
PreferredDelimiters: | ||
'%i': () | ||
'%I': () | ||
'%q': () | ||
'%Q': () | ||
'%r': '{}' | ||
'%s': () | ||
'%w': () | ||
'%W': () | ||
'%x': () | ||
|
||
Style/StringLiterals: | ||
EnforcedStyle: double_quotes | ||
Enabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module NintendoEshop | ||
class GamesList < APIRequest | ||
include Enumerable | ||
|
||
attr_accessor :title | ||
attr_accessor :games | ||
|
||
RESOURCE_PATH = "/1/indexes/noa_aem_game_en_us/query".freeze | ||
|
||
def initialize(title) | ||
self.title = title | ||
end | ||
|
||
def refresh | ||
response = request(:post, to_json: body) | ||
result = response.dig(:hits) | ||
self.games = refresh_list_objects(result) | ||
self | ||
end | ||
|
||
def each | ||
games.each do |game| | ||
yield(game) | ||
end | ||
end | ||
|
||
def self.by_title(title) | ||
instance = new(title) | ||
instance.refresh | ||
end | ||
|
||
private | ||
|
||
def body | ||
{ | ||
"query": title.to_s, | ||
"restrictSearchableAttributes": [ | ||
"title" | ||
] | ||
} | ||
end | ||
|
||
def refresh_list_objects(objects) | ||
objects.map do |object| | ||
game = Game.new(object.dig(:nsuid)) | ||
game.art = object.dig(:boxArt) | ||
game.msrp = object.dig(:msrp) | ||
game.platform = object.dig(:platform) | ||
game.sale_price = object.dig(:salePrice) | ||
game.title = object.dig(:title) | ||
game.url = object.dig(:url) | ||
game | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module NintendoEshop | ||
VERSION = "0.1.0.alpha3".freeze | ||
VERSION = "0.1.0.alpha4".freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,22 @@ Gem::Specification.new do |spec| | |
spec.email = ["[email protected]"] | ||
|
||
spec.summary = "Retrieve game prices from the Nintendo eShop" | ||
spec.homepage = "https://github.com/rickpeyton/nintendo_eshop" | ||
spec.license = "MIT" | ||
spec.description = <<~DESCRIPTION | ||
When I want to check the price of a game on the Nintendo eShop I want to search Nintendo's | ||
API by external key so that I am confident I am getting the correct price. | ||
DESCRIPTION | ||
spec.homepage = "https://github.com/rickpeyton/nintendo_eshop" | ||
spec.metadata = { | ||
"changelog_uri" => "https://github.com/rickpeyton/nintendo_eshop/releases", | ||
"homepage_uri" => "https://github.com/rickpeyton/nintendo_eshop", | ||
"source_code_uri" => "https://github.com/rickpeyton/nintendo_eshop" | ||
} | ||
spec.license = "MIT" | ||
spec.required_ruby_version = ">= 2.4.6" | ||
|
||
# Specify which files should be added to the gem when it is released. | ||
# The `git ls-files -z` loads the files in the RubyGem that have been added into git. | ||
spec.files = Dir.chdir(File.expand_path(__dir__)) do | ||
spec.files = Dir.chdir(File.expand_path(__dir__)) do | ||
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } | ||
end | ||
spec.bindir = "exe" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
RSpec.describe NintendoEshop::GamesList do | ||
it "includes enumerable" do | ||
expect(NintendoEshop::GamesList).to include(Enumerable) | ||
end | ||
|
||
describe ".by_title" do | ||
it "returns a list of games" do | ||
actual = NintendoEshop::GamesList.by_title("Mario") | ||
first_game = actual.first | ||
|
||
expect(actual).to be_a(NintendoEshop::GamesList) | ||
expect(first_game.title).to eq("Dr. Mario World") | ||
end | ||
end | ||
end |