mystery_shopper 0.1.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74e03d884f08b5ef36fbdb5b3d568720d50542aac19b7e977f05e49cb39ab208
4
- data.tar.gz: a646914038071ccc4493c0437162720661063c58a1347baadd8cdde1985cb820
3
+ metadata.gz: fbffe2143bef8081c08300361ada9fcaf7d80d25f2edf183f084a9abf5c7b0dc
4
+ data.tar.gz: bb6d64ab1763a79663945200c1e69a2383e2fcc18368c703832df3abb818c072
5
5
  SHA512:
6
- metadata.gz: 591eeba1777372f7ef7d0ac215a4495b3a5fde4083940f8a5f04d3bbbbec4d30fd552803e9eb03e837b86c6b3c0f00a7b0bf55e60d9c0a22660a5b44ff4d0294
7
- data.tar.gz: df90c166f20b71b91e100df76c6f6c91f0310ac57d2707a7a1ac5735de73b8f179ce4b04a24ae47276e587fd7edf49f6e0c4af7e7618862776b6e725cd89be2a
6
+ metadata.gz: 430fd886c9081d2619c0ff614badc040b112fdcb03937c063d18194545d2e3bc5c3911adc1a597e629853a282bbf83d3c1cd4252305c240f4dacfd8592102568
7
+ data.tar.gz: 06dd5d286f31cfe38e392e9d50b40207af789403b251b3b047827f3bed740b4f1f384614aaef4d189d19553ffb5328bb0a9a673a8b5d51f29b1d7491a247625c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mystery_shopper (0.1.6)
4
+ mystery_shopper (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,8 +1,16 @@
1
1
  require 'mystery_shopper/version'
2
+ require 'mystery_shopper/configuration'
2
3
  require 'mystery_shopper/response'
3
4
  require 'mystery_shopper/request/detail'
4
5
  require 'mystery_shopper/request/price'
5
6
 
6
7
  module MysteryShopper
7
- # Nothing to see here.
8
+ class << self
9
+ attr_accessor :configuration
10
+ end
11
+
12
+ def self.configure
13
+ self.configuration ||= Configuration.new
14
+ yield(configuration)
15
+ end
8
16
  end
@@ -0,0 +1,10 @@
1
+ module MysteryShopper
2
+ class Configuration
3
+ attr_accessor :application_id, :api_key
4
+
5
+ def initialize
6
+ @application_id = nil
7
+ @api_key = nil
8
+ end
9
+ end
10
+ end
@@ -1,78 +1,104 @@
1
1
  require 'date'
2
- require 'mystery_shopper/utils'
3
2
  require 'mystery_shopper/price'
4
3
  require 'mystery_shopper/request/price'
5
4
 
6
5
  module MysteryShopper
7
6
  class Game
8
- include Utils
9
-
10
7
  def initialize(data)
11
8
  @data = data
12
9
  end
13
10
 
14
- def categories
15
- @categories ||= Array(data.dig('categories', 'category'))
11
+ def url
12
+ @url ||= "#{base_url}#{data.fetch('url')}"
16
13
  end
17
14
 
18
- def url
19
- @url ||= "https://www.nintendo.com/games/detail/#{slug}"
15
+ def title
16
+ @title ||= data.fetch('title')
17
+ end
18
+
19
+ def description
20
+ @description ||= data.fetch('description')
21
+ end
22
+
23
+ def id
24
+ @id ||= data.fetch('id')
20
25
  end
21
26
 
22
- def buy_it_now?
23
- @buy_it_now ||= to_bool(data.fetch('buyitnow'))
27
+ def nsuid
28
+ @nsuid ||= data['nsuid']
29
+ end
30
+
31
+ def slug
32
+ @slug ||= data.fetch('slug')
33
+ end
34
+
35
+ def front_box_art
36
+ @front_box_art ||= "#{base_url}#{data.fetch('boxArt')}"
37
+ end
38
+
39
+ # TODO: Figure out what the value returned here actually is.
40
+ def gallery
41
+ @gallery ||= data.fetch('gallery')
42
+ end
43
+
44
+ def platform
45
+ @platform ||= data.fetch('platform')
24
46
  end
25
47
 
26
48
  def release_date
27
- @release_date ||= Date.parse(data.fetch('release_date'))
49
+ @release_date ||= Date.parse(data.fetch('releaseDateMask'))
28
50
  end
29
51
 
30
- def digital_download?
31
- @digital_download ||= to_bool(data.fetch('digitaldownload'))
52
+ def characters
53
+ @characters ||= data.fetch('characters')
32
54
  end
33
55
 
34
- def free_to_start?
35
- @free_to_start ||= to_bool(data.fetch('free_to_start'))
56
+ def categories
57
+ @categories ||= data.fetch('categories')
36
58
  end
37
59
 
38
- def title
39
- @title ||= data.fetch('title')
60
+ def esrb
61
+ @esrb ||= data.fetch('esrb')
40
62
  end
41
63
 
42
- def slug
43
- @slug ||= data.fetch('slug')
64
+ def esrb_descriptors
65
+ @esrb_descriptors ||= data.fetch('esrbDescriptors')
44
66
  end
45
67
 
46
- def system
47
- @system ||= data.fetch('system')
68
+ def virtual_console
69
+ @virtual_console ||= data.fetch('virtualConsole')
48
70
  end
49
71
 
50
- def id
51
- @id ||= data.fetch('id')
72
+ def general_filters
73
+ @general_filters ||= data.fetch('generalFilters')
52
74
  end
53
75
 
54
- def number_of_players
55
- @number_of_players ||= data.fetch('number_of_players')
76
+ def filter_shops
77
+ @filter_shops ||= data.fetch('filterShops')
56
78
  end
57
79
 
58
- def nsuid
59
- @nsuid ||= data['nsuid']
80
+ def filter_players
81
+ @filter_players ||= data.fetch('filterPlayers')
60
82
  end
61
83
 
62
- def video_link
63
- @video_link ||= data['video_link']
84
+ def number_of_players
85
+ @number_of_players ||= data.fetch('players')
64
86
  end
65
87
 
66
- def front_box_art
67
- @front_box_art ||= data.fetch('front_box_art')
88
+ def featured?
89
+ @featured ||= data.fetch('featured')
68
90
  end
69
91
 
70
- def game_code
71
- @game_code ||= data.fetch('game_code')
92
+ def free_to_start?
93
+ @free_to_start ||= data.fetch('freeToStart')
94
+ end
95
+
96
+ def price_range
97
+ @price_range ||= data.fetch('priceRange')
72
98
  end
73
99
 
74
- def buy_online?
75
- @buy_online ||= to_bool(data.fetch('buyonline'))
100
+ def availability
101
+ @availability ||= data.fetch('availability')
76
102
  end
77
103
 
78
104
  def regular_price
@@ -104,5 +130,9 @@ module MysteryShopper
104
130
  Request::Price.new(nsuid).get.fetch('prices').first
105
131
  )
106
132
  end
133
+
134
+ def base_url
135
+ 'https://www.nintendo.com'
136
+ end
107
137
  end
108
138
  end
@@ -9,13 +9,28 @@ module MysteryShopper
9
9
  JSON.parse(Net::HTTP.get(construct_uri))
10
10
  end
11
11
 
12
+ def post
13
+ JSON.parse(Net::HTTP.new(construct_uri.host).request(construct_request).body)
14
+ end
15
+
12
16
  private
13
17
 
18
+ def construct_request
19
+ Net::HTTP::Post.new(construct_uri).tap do |request|
20
+ request.body = body.to_json
21
+ end
22
+ end
23
+
14
24
  def construct_uri
15
- URI(uri).tap do |uri|
25
+ URI.parse(uri).tap do |uri|
16
26
  uri.query = URI.encode_www_form(params)
17
27
  end
18
28
  end
29
+
30
+ def params
31
+ { 'x-algolia-application-id' => application_id,
32
+ 'x-algolia-api-key' => api_key }
33
+ end
19
34
  end
20
35
  end
21
36
  end
@@ -4,25 +4,92 @@ module MysteryShopper
4
4
  module Request
5
5
  class Detail < Base
6
6
  def initialize(**options)
7
- @options = options
7
+ @application_id = MysteryShopper.configuration.application_id
8
+ @api_key = MysteryShopper.configuration.api_key
9
+ @options = options
8
10
  end
9
11
 
10
12
  private
11
13
 
12
- attr_reader :options
14
+ attr_reader :application_id, :api_key, :options
13
15
 
14
16
  def uri
15
- 'https://www.nintendo.com/json/content/get/filter/game'
17
+ "https://#{application_id}-dsn.algolia.net/1/indexes/*/queries"
16
18
  end
17
19
 
18
- def params
20
+ def body
21
+ {
22
+ requests: [
23
+ {
24
+ indexName: sort_direction,
25
+ params: request_params
26
+ }
27
+ ]
28
+ }
29
+ end
30
+
31
+ def request_params
32
+ 'query='\
33
+ "&hitsPerPage=#{defaults[:limit]}"\
34
+ "&page=#{defaults[:page]}"\
35
+ "&facets=#{facets}"\
36
+ "&facetFilters=#{facet_filters}"
37
+ end
38
+
39
+ def facets
40
+ %w[generalFilters
41
+ platform
42
+ availability]
43
+ end
44
+
45
+ def facet_filters
46
+ [general_filters,
47
+ platform,
48
+ availability].compact
49
+ end
50
+
51
+ def general_filters
52
+ return unless defaults[:sale]
53
+
54
+ ['generalFilters:Deals']
55
+ end
56
+
57
+ # TODO: Support 3DS, Wii U, iOS, Android platforms
58
+ def platform
59
+ ['platform:Nintendo Switch']
60
+ end
61
+
62
+ def availability
63
+ defaults[:availability].map do |avail|
64
+ "availability:#{mappings.dig(:availability, avail)}"
65
+ end
66
+ end
67
+
68
+ def sort_direction
69
+ base = 'noa_aem_game_en_us'
70
+ return base if defaults[:sort] == 'featured'
71
+
72
+ [base,
73
+ defaults[:sort],
74
+ defaults[:direction]].join('_')
75
+ end
76
+
77
+ def defaults
19
78
  { limit: 50,
20
- offset: 0,
79
+ page: 0,
21
80
  availability: 'now',
22
81
  sort: 'title',
23
82
  direction: 'asc',
24
83
  system: 'switch' }.merge(options)
25
84
  end
85
+
86
+ def mappings
87
+ { availability: {
88
+ 'now' => 'Available now',
89
+ 'prepurchase' => 'Pre-purchase',
90
+ 'soon' => 'Coming soon'
91
+ } }
92
+ end
26
93
  end
27
94
  end
28
95
  end
@@ -7,7 +7,7 @@ module MysteryShopper
7
7
  end
8
8
 
9
9
  def games
10
- data.fetch('games', []).fetch('game', []).map { |game| Game.new(game) }
10
+ data.dig('results', 0, 'hits').map { |game| Game.new(game) }
11
11
  end
12
12
 
13
13
  private
@@ -1,3 +1,3 @@
1
1
  module MysteryShopper
2
- VERSION = '0.1.7'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -20,5 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.16'
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.8'
23
24
  spec.add_development_dependency 'rubocop', '~> 0.58'
24
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mystery_shopper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hunter Braun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-26 00:00:00.000000000 Z
11
+ date: 2019-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.8'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rubocop
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -71,13 +85,13 @@ files:
71
85
  - bin/console
72
86
  - bin/setup
73
87
  - lib/mystery_shopper.rb
88
+ - lib/mystery_shopper/configuration.rb
74
89
  - lib/mystery_shopper/game.rb
75
90
  - lib/mystery_shopper/price.rb
76
91
  - lib/mystery_shopper/request/base.rb
77
92
  - lib/mystery_shopper/request/detail.rb
78
93
  - lib/mystery_shopper/request/price.rb
79
94
  - lib/mystery_shopper/response.rb
80
- - lib/mystery_shopper/utils.rb
81
95
  - lib/mystery_shopper/version.rb
82
96
  - mystery_shopper.gemspec
83
97
  homepage: https://github.com/goronfreeman/mystery_shopper
@@ -1,7 +0,0 @@
1
- module MysteryShopper
2
- module Utils
3
- def to_bool(str)
4
- str == 'true'
5
- end
6
- end
7
- end