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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/mystery_shopper.rb +9 -1
- data/lib/mystery_shopper/configuration.rb +10 -0
- data/lib/mystery_shopper/game.rb +64 -34
- data/lib/mystery_shopper/request/base.rb +16 -1
- data/lib/mystery_shopper/request/detail.rb +72 -5
- data/lib/mystery_shopper/response.rb +1 -1
- data/lib/mystery_shopper/version.rb +1 -1
- data/mystery_shopper.gemspec +1 -0
- metadata +17 -3
- data/lib/mystery_shopper/utils.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbffe2143bef8081c08300361ada9fcaf7d80d25f2edf183f084a9abf5c7b0dc
|
4
|
+
data.tar.gz: bb6d64ab1763a79663945200c1e69a2383e2fcc18368c703832df3abb818c072
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 430fd886c9081d2619c0ff614badc040b112fdcb03937c063d18194545d2e3bc5c3911adc1a597e629853a282bbf83d3c1cd4252305c240f4dacfd8592102568
|
7
|
+
data.tar.gz: 06dd5d286f31cfe38e392e9d50b40207af789403b251b3b047827f3bed740b4f1f384614aaef4d189d19553ffb5328bb0a9a673a8b5d51f29b1d7491a247625c
|
data/Gemfile.lock
CHANGED
data/lib/mystery_shopper.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/mystery_shopper/game.rb
CHANGED
@@ -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
|
15
|
-
@
|
11
|
+
def url
|
12
|
+
@url ||= "#{base_url}#{data.fetch('url')}"
|
16
13
|
end
|
17
14
|
|
18
|
-
def
|
19
|
-
@
|
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
|
23
|
-
@
|
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('
|
49
|
+
@release_date ||= Date.parse(data.fetch('releaseDateMask'))
|
28
50
|
end
|
29
51
|
|
30
|
-
def
|
31
|
-
@
|
52
|
+
def characters
|
53
|
+
@characters ||= data.fetch('characters')
|
32
54
|
end
|
33
55
|
|
34
|
-
def
|
35
|
-
@
|
56
|
+
def categories
|
57
|
+
@categories ||= data.fetch('categories')
|
36
58
|
end
|
37
59
|
|
38
|
-
def
|
39
|
-
@
|
60
|
+
def esrb
|
61
|
+
@esrb ||= data.fetch('esrb')
|
40
62
|
end
|
41
63
|
|
42
|
-
def
|
43
|
-
@
|
64
|
+
def esrb_descriptors
|
65
|
+
@esrb_descriptors ||= data.fetch('esrbDescriptors')
|
44
66
|
end
|
45
67
|
|
46
|
-
def
|
47
|
-
@
|
68
|
+
def virtual_console
|
69
|
+
@virtual_console ||= data.fetch('virtualConsole')
|
48
70
|
end
|
49
71
|
|
50
|
-
def
|
51
|
-
@
|
72
|
+
def general_filters
|
73
|
+
@general_filters ||= data.fetch('generalFilters')
|
52
74
|
end
|
53
75
|
|
54
|
-
def
|
55
|
-
@
|
76
|
+
def filter_shops
|
77
|
+
@filter_shops ||= data.fetch('filterShops')
|
56
78
|
end
|
57
79
|
|
58
|
-
def
|
59
|
-
@
|
80
|
+
def filter_players
|
81
|
+
@filter_players ||= data.fetch('filterPlayers')
|
60
82
|
end
|
61
83
|
|
62
|
-
def
|
63
|
-
@
|
84
|
+
def number_of_players
|
85
|
+
@number_of_players ||= data.fetch('players')
|
64
86
|
end
|
65
87
|
|
66
|
-
def
|
67
|
-
@
|
88
|
+
def featured?
|
89
|
+
@featured ||= data.fetch('featured')
|
68
90
|
end
|
69
91
|
|
70
|
-
def
|
71
|
-
@
|
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
|
75
|
-
@
|
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
|
-
@
|
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
|
-
|
17
|
+
"https://#{application_id}-dsn.algolia.net/1/indexes/*/queries"
|
16
18
|
end
|
17
19
|
|
18
|
-
def
|
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
|
-
|
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
|
data/mystery_shopper.gemspec
CHANGED
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.
|
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-
|
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
|