cheapshark 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/Guardfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +2 -0
- data/cheapshark.gemspec +36 -0
- data/expectations.md +49 -0
- data/lib/cheapshark.rb +95 -0
- data/lib/cheapshark/config.rb +4 -0
- data/lib/cheapshark/fetchers/alerts_fetcher.rb +0 -0
- data/lib/cheapshark/fetchers/deal_fetcher.rb +14 -0
- data/lib/cheapshark/fetchers/deals_fetcher.rb +14 -0
- data/lib/cheapshark/fetchers/fetcher.rb +25 -0
- data/lib/cheapshark/fetchers/game_fetcher.rb +14 -0
- data/lib/cheapshark/fetchers/games_fetcher.rb +14 -0
- data/lib/cheapshark/fetchers/stores_fetcher.rb +14 -0
- data/lib/cheapshark/models/alert.rb +0 -0
- data/lib/cheapshark/models/deal.rb +48 -0
- data/lib/cheapshark/models/game.rb +22 -0
- data/lib/cheapshark/models/store.rb +11 -0
- data/lib/cheapshark/version.rb +3 -0
- data/spec/cheapshark_spec.rb +130 -0
- data/spec/fetchers/deal_fetcher.rb +38 -0
- data/spec/fetchers/games_fetcher_spec.rb +49 -0
- data/spec/models/deal_spec.rb +6 -0
- data/spec/models/game_spec.rb +170 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/cheapshark_api_mock.rb +23 -0
- data/spec/support/fixtures/cheapshark_api_mock/arkham_by_id.json +29 -0
- data/spec/support/fixtures/cheapshark_api_mock/batman_games.json +1 -0
- data/spec/support/fixtures/cheapshark_api_mock/bio_inf_deal.json +28 -0
- metadata +284 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
module CheapShark
|
2
|
+
class Game
|
3
|
+
attr_reader :game_id, :steam_app_id, :cheapest, :cheapest_deal_id, :title, :thumb, :cheapest_date, :deals
|
4
|
+
|
5
|
+
def initialize(query_type, results)
|
6
|
+
case query_type
|
7
|
+
when :search
|
8
|
+
@game_id = results['gameID'].to_i
|
9
|
+
@steam_app_id = results['steamAppID'].to_i
|
10
|
+
@cheapest = results['cheapest'].to_f
|
11
|
+
@cheapest_deal_id = results['cheapestDealID']
|
12
|
+
@title = results['external']
|
13
|
+
@thumb = results['thumb']
|
14
|
+
when :by_id
|
15
|
+
@title = results['info']['title']
|
16
|
+
@cheapest = results['cheapestPriceEver']['price'].to_f
|
17
|
+
@cheapest_date = Time.at(results['cheapestPriceEver']['date'].to_i)
|
18
|
+
@deals = results['deals'].map { |deal| Deal.new :game, deal }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require_relative '../lib/cheapshark'
|
3
|
+
|
4
|
+
#TODO: ENSURE ALL OBJECTS' ATTRS ARE READABLE! Figure out how to test this.
|
5
|
+
|
6
|
+
describe CheapShark do
|
7
|
+
|
8
|
+
it 'has a method #games' do
|
9
|
+
expect(CheapShark.method_defined? :games).to eq(true)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#games' do
|
13
|
+
|
14
|
+
context 'when searching for Borderlands 2' do
|
15
|
+
before(:each) do
|
16
|
+
VCR.use_cassette 'games.title_borderlands_2.limit_1' do
|
17
|
+
@results = CheapShark.games(title: 'borderlands 2', limit: 1)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'has a method #cheapest' do
|
22
|
+
expect(@results.first.respond_to? :cheapest).to eq(true)
|
23
|
+
end
|
24
|
+
describe '#cheapest' do
|
25
|
+
it 'returns a Float' do
|
26
|
+
expect(@results.first.cheapest).to be_a(Float)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when searching for 3 games with the title "batman"' do
|
33
|
+
before(:each) do
|
34
|
+
VCR.use_cassette 'games.title_batman.limit_3' do
|
35
|
+
@results = CheapShark.games(title: 'batman', limit: 3)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns an array' do
|
40
|
+
expect(@results).to be_an(Array)
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'the array' do
|
44
|
+
|
45
|
+
it 'contains three items' do
|
46
|
+
expect(@results.size).to eq(3)
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'each item' do
|
50
|
+
|
51
|
+
it 'is a CheapShark::Game' do
|
52
|
+
@results.each do |item|
|
53
|
+
expect(item).to be_a(CheapShark::Game)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'has a method #deal' do
|
66
|
+
expect(CheapShark.method_defined? :deal).to eq(true)
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#deal' do
|
70
|
+
context 'when getting Borderlands 2\'s deal ID' do
|
71
|
+
before(:each) do
|
72
|
+
VCR.use_cassette 'deal.id_DCqsq6_unescape' do
|
73
|
+
@results = CheapShark.deal(id: 'DCqsq6Hnmtzu2UVkBpD133kL1pG93Ovz4%2BEjTuJAx9c%3D')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'has a method store_id' do
|
78
|
+
expect(@results.respond_to? :store_id).to eq(true)
|
79
|
+
end
|
80
|
+
describe '#store_id' do
|
81
|
+
it 'returns an Integer' do
|
82
|
+
expect(@results.store_id).to be_an(Integer)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'has a method sale_price' do
|
87
|
+
expect(@results.respond_to? :store_id).to eq(true)
|
88
|
+
end
|
89
|
+
describe '#sale_price' do
|
90
|
+
it 'returns a Float' do
|
91
|
+
expect(@results.sale_price).to be_an(Float)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'has a method retail_price' do
|
96
|
+
expect(@results.respond_to? :store_id).to eq(true)
|
97
|
+
end
|
98
|
+
describe '#retail_price' do
|
99
|
+
it 'returns a Float' do
|
100
|
+
expect(@results.retail_price).to be_an(Float)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#stores' do
|
107
|
+
context 'when getting all stores' do
|
108
|
+
before(:each) do
|
109
|
+
VCR.use_cassette 'stores_array' do
|
110
|
+
@results = CheapShark.stores
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'returns an Array' do
|
115
|
+
expect(@results).to be_an(Array)
|
116
|
+
end
|
117
|
+
describe 'the array' do
|
118
|
+
it 'is composed of CheapShark::Store objects' do
|
119
|
+
@results.each do |item|
|
120
|
+
expect(item).to be_a(CheapShark::Store)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# API always responds 200
|
129
|
+
# Garbage input returns empty hash
|
130
|
+
# e.g.: http://www.cheapshark.com/api/1.0/deals?storeID=a
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../../lib/cheapshark/fetchers/games_fetcher'
|
2
|
+
|
3
|
+
describe CheapShark::DealFetcher do
|
4
|
+
|
5
|
+
context 'when using the deal ID for Borderlands 2 on Steam' do
|
6
|
+
before(:each) do
|
7
|
+
VCR.use_cassette 'deal.id_DCqsq6_unescape' do
|
8
|
+
@results = CheapShark.deal(id: 'DCqsq6Hnmtzu2UVkBpD133kL1pG93Ovz4%2BEjTuJAx9c%3D')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'has a method #store_id' do
|
12
|
+
end
|
13
|
+
describe '#store_id' do
|
14
|
+
it 'returns an Integer' do
|
15
|
+
expect(@store_id).to be_an(Integer)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'has a method #game_id' do
|
20
|
+
end
|
21
|
+
describe '#game_id' do
|
22
|
+
it 'returns an Integer' do
|
23
|
+
expect(@game_id).to be_an(Integer)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'has a method #game' do
|
28
|
+
end
|
29
|
+
describe '#game' do
|
30
|
+
it 'returns a String' do
|
31
|
+
expect(@game).to be_a(String)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative '../../lib/cheapshark/fetchers/games_fetcher'
|
2
|
+
|
3
|
+
describe CheapShark::GamesFetcher do
|
4
|
+
|
5
|
+
context 'when searching for 3 games with the title "batman"' do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
VCR.use_cassette 'games.title_batman.limit_3' do
|
9
|
+
@search = CheapShark::GamesFetcher.new(title: 'batman', limit: 3)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has a method #results' do
|
14
|
+
expect(@search.methods.include? :results).to eq(true)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#results' do
|
18
|
+
before(:each) do
|
19
|
+
@results = @search.results
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
it 'returns an array' do
|
24
|
+
expect(@results).to be_an(Array)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'the array' do
|
28
|
+
|
29
|
+
it 'contains three items' do
|
30
|
+
expect(@results).to be_an(Array)
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'each item' do
|
34
|
+
|
35
|
+
it 'is a CheapShark::Game' do
|
36
|
+
@results.each do |item|
|
37
|
+
expect(item).to be_a(CheapShark::Game)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require_relative '../../lib/cheapshark/models/game'
|
2
|
+
require_relative '../../lib/cheapshark/models/deal'
|
3
|
+
|
4
|
+
describe CheapShark::Game do
|
5
|
+
|
6
|
+
context 'with a query_type of :search' do
|
7
|
+
context 'when evaluating data for Batman: Arkham City' do
|
8
|
+
before(:each) do
|
9
|
+
@game = CheapShark::Game.new(:search, {
|
10
|
+
"gameID" => "14",
|
11
|
+
"steamAppID" => 0,
|
12
|
+
"cheapest" => "19.99",
|
13
|
+
"cheapestDealID" => "se5gAdztkrc9svaLPhaVb1drhQP3tlcztIhqLh7cTA0%3D",
|
14
|
+
"external" => "Batman: Arkham City",
|
15
|
+
"thumb" => "http://static.metacritic.com/images/products/games/7/8ca786aa6ce79e3b0c30cdda2f3cb821-53.jpg"
|
16
|
+
})
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'has a method #cheapest' do
|
20
|
+
expect(@game.methods.include? :cheapest).to eq(true)
|
21
|
+
end
|
22
|
+
describe '#cheapest' do
|
23
|
+
it 'returns a Float' do
|
24
|
+
expect(@game.cheapest).to be_a(Float)
|
25
|
+
end
|
26
|
+
it 'returns 19.99' do
|
27
|
+
expect(@game.cheapest).to eq(19.99)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'has a method #cheapest_deal_id' do
|
32
|
+
expect(@game.methods.include? :cheapest_deal_id).to eq(true)
|
33
|
+
end
|
34
|
+
describe '#cheapest_deal_id' do
|
35
|
+
it 'returns a String' do
|
36
|
+
expect(@game.cheapest_deal_id).to be_a(String)
|
37
|
+
end
|
38
|
+
it 'returns "se5gAdztkrc9svaLPhaVb1drhQP3tlcztIhqLh7cTA0%3D"' do
|
39
|
+
expect(@game.cheapest_deal_id).to eq("se5gAdztkrc9svaLPhaVb1drhQP3tlcztIhqLh7cTA0%3D")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'has a method #game_id' do
|
44
|
+
expect(@game.methods.include? :game_id).to eq(true)
|
45
|
+
end
|
46
|
+
describe '#game_id' do
|
47
|
+
it 'returns an Integer' do
|
48
|
+
expect(@game.game_id).to be_an(Integer)
|
49
|
+
end
|
50
|
+
it 'returns 14' do
|
51
|
+
expect(@game.game_id).to eq(14)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'has a method #steam_app_id' do
|
56
|
+
expect(@game.methods.include? :steam_app_id).to eq(true)
|
57
|
+
end
|
58
|
+
describe '#steam_app_id' do
|
59
|
+
it 'returns 0' do
|
60
|
+
expect(@game.steam_app_id).to eq(0)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'has a method #thumb' do
|
65
|
+
expect(@game.methods.include? :thumb).to eq(true)
|
66
|
+
end
|
67
|
+
describe '#thumb' do
|
68
|
+
it 'returns a String' do
|
69
|
+
expect(@game.thumb).to be_a(String)
|
70
|
+
end
|
71
|
+
it 'returns "http://static.metacritic.com/images/products/games/7/8ca786aa6ce79e3b0c30cdda2f3cb821-53.jpg"' do
|
72
|
+
expect(@game.thumb).to eq("http://static.metacritic.com/images/products/games/7/8ca786aa6ce79e3b0c30cdda2f3cb821-53.jpg")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'has a method #title' do
|
77
|
+
expect(@game.methods.include? :title).to eq(true)
|
78
|
+
end
|
79
|
+
describe '#title' do
|
80
|
+
it 'returns a String' do
|
81
|
+
expect(@game.title).to be_a(String)
|
82
|
+
end
|
83
|
+
it 'returns "Batman: Arkham City"' do
|
84
|
+
expect(@game.title).to eq("Batman: Arkham City")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
context 'with a query_type of :by_id' do
|
91
|
+
context 'when evaluating data for Batman: Arkham City' do
|
92
|
+
before(:each) do
|
93
|
+
@game = CheapShark::Game.new(:by_id, {
|
94
|
+
"info" => {
|
95
|
+
"title" => "Batman: Arkham City",
|
96
|
+
},
|
97
|
+
"cheapestPriceEver" => {
|
98
|
+
"price" => "5.00",
|
99
|
+
"date" => "1372922175",
|
100
|
+
},
|
101
|
+
"deals" => [
|
102
|
+
{
|
103
|
+
"storeId" => 9,
|
104
|
+
"dealId" => "Rvw%2FIP%2Fivqs%2Fz%2BTxA2NGkLrvByenFMiDljgydVBFkMw%3D",
|
105
|
+
"price" => 19.99,
|
106
|
+
"retailPrice" => 19.99
|
107
|
+
},
|
108
|
+
{
|
109
|
+
"storeId" => 3,
|
110
|
+
"dealId" => "jGokNhCpCI6y3CrLaPJ74lghhmx1DXT6BXlMeun7yEA%3D",
|
111
|
+
"price" => 29.94,
|
112
|
+
"retailPrice" => 29.94
|
113
|
+
},
|
114
|
+
{
|
115
|
+
"storeId" => 5,
|
116
|
+
"dealId" => "se5gAdztkrc9svaLPhaVb1drhQP3tlcztIhqLh7cTA0%3D",
|
117
|
+
"price" => 29.99,
|
118
|
+
"retailPrice" => 29.99
|
119
|
+
}
|
120
|
+
]
|
121
|
+
})
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'has a method #title' do
|
125
|
+
expect(@game.methods.include? :title).to eq(true)
|
126
|
+
end
|
127
|
+
describe '#title' do
|
128
|
+
it 'returns a String' do
|
129
|
+
expect(@game.title).to be_a(String)
|
130
|
+
end
|
131
|
+
it 'returns "Batman: Arkham City"' do
|
132
|
+
expect(@game.title).to eq("Batman: Arkham City")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'has a method #cheapest' do
|
137
|
+
expect(@game.methods.include? :cheapest).to eq(true)
|
138
|
+
end
|
139
|
+
describe '#cheapest' do
|
140
|
+
it 'returns a Float' do
|
141
|
+
expect(@game.cheapest).to be_a(Float)
|
142
|
+
end
|
143
|
+
it 'returns 5.00' do
|
144
|
+
expect(@game.cheapest).to eq(5.00)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'has a method #cheapest_date' do
|
149
|
+
expect(@game.methods.include? :cheapest_date).to eq(true)
|
150
|
+
end
|
151
|
+
describe '#cheapest_date' do
|
152
|
+
it 'returns a Time' do
|
153
|
+
expect(@game.cheapest_date).to be_a(Time)
|
154
|
+
end
|
155
|
+
it 'returns 2013-07-04 07:16:15 UTC' do
|
156
|
+
expect(@game.cheapest_date).to eq(Time.at(1372922175))
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'has a method #deals' do
|
161
|
+
expect(@game.methods.include? :deals).to eq(true)
|
162
|
+
end
|
163
|
+
describe '#deals' do
|
164
|
+
it 'returns a Array' do
|
165
|
+
expect(@game.deals).to be_an(Array)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
require 'webmock/rspec'
|
4
|
+
require 'vcr'
|
5
|
+
|
6
|
+
require_relative 'support/cheapshark_api_mock'
|
7
|
+
|
8
|
+
# WebMock.disable_net_connect!(allow_localhost: true)
|
9
|
+
|
10
|
+
VCR.configure do |config|
|
11
|
+
config.cassette_library_dir = 'spec/support/cassettes'
|
12
|
+
config.hook_into :webmock
|
13
|
+
config.ignore_localhost = true
|
14
|
+
# config.allow_http_connections_when_no_cassette = true
|
15
|
+
# config.ignore_hosts ''
|
16
|
+
end
|
17
|
+
|
18
|
+
# RSpec.configure do |config|
|
19
|
+
# config.before(:each) do
|
20
|
+
# stub_request(:any, %r{www.cheapshark.com/api/1.0}).to_rack(CheapsharkApiMock)
|
21
|
+
# end
|
22
|
+
# end
|