stew 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Guardfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +97 -0
- data/Rakefile +9 -0
- data/lib/stew.rb +58 -0
- data/lib/stew/community/profile.rb +23 -0
- data/lib/stew/community/profile_friends.rb +18 -0
- data/lib/stew/community/profile_game.rb +28 -0
- data/lib/stew/community/profile_games.rb +17 -0
- data/lib/stew/community/steam_id.rb +52 -0
- data/lib/stew/community_client.rb +42 -0
- data/lib/stew/store/app.rb +76 -0
- data/lib/stew/store/app_offer.rb +38 -0
- data/lib/stew/store/app_offer_sale.rb +23 -0
- data/lib/stew/store/app_offers.rb +25 -0
- data/lib/stew/store_client.rb +39 -0
- data/lib/stew/version.rb +3 -0
- data/lib/stew/web_client.rb +30 -0
- data/lib/stew/xml_client.rb +49 -0
- data/spec/fixtures/profiles/4d.txt +16 -0
- data/spec/fixtures/profiles/76561197992917668.txt +122 -0
- data/spec/fixtures/profiles/76561197992917668.yml +94 -0
- data/spec/fixtures/profiles/friends/76561197992917668.yml +36 -0
- data/spec/fixtures/profiles/games/76561197992917668.yml +616 -0
- data/spec/fixtures/store/apps/16870.txt +1078 -0
- data/spec/fixtures/store/apps/211400_offers_sale.txt +46 -0
- data/spec/fixtures/store/apps/211400_sale.txt +1327 -0
- data/spec/fixtures/store/apps/211420.txt +1320 -0
- data/spec/fixtures/store/apps/211420_us.txt +1306 -0
- data/spec/fixtures/store/apps/219150.txt +1134 -0
- data/spec/fixtures/store/apps/2290.txt +1059 -0
- data/spec/fixtures/store/apps/49520.txt +1471 -0
- data/spec/fixtures/store/apps/49520_offers.txt +111 -0
- data/spec/fixtures/store/apps/no_app.txt +5 -0
- data/spec/integration/community_integration_spec.rb +50 -0
- data/spec/integration/store_integration_spec.rb +129 -0
- data/spec/lib/stew/community/profile_friends_spec.rb +38 -0
- data/spec/lib/stew/community/profile_game_spec.rb +37 -0
- data/spec/lib/stew/community/profile_games_spec.rb +36 -0
- data/spec/lib/stew/community/profile_spec.rb +18 -0
- data/spec/lib/stew/community/steam_id_spec.rb +116 -0
- data/spec/lib/stew/community_client_spec.rb +88 -0
- data/spec/lib/stew/store/app_offer_sale_spec.rb +36 -0
- data/spec/lib/stew/store/app_offer_spec.rb +47 -0
- data/spec/lib/stew/store/app_offers_spec.rb +64 -0
- data/spec/lib/stew/store/app_spec.rb +142 -0
- data/spec/lib/stew/store_client_spec.rb +58 -0
- data/spec/lib/stew/web_client_spec.rb +25 -0
- data/spec/lib/stew/xml_client_spec.rb +36 -0
- data/spec/lib/stew_spec.rb +4 -0
- data/spec/spec_helper.rb +23 -0
- data/stew.gemspec +38 -0
- metadata +412 -0
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Stew::CommunityClient" do
|
4
|
+
let(:client){double('xml_client')}
|
5
|
+
subject{Stew::CommunityClient.new({:client => client})}
|
6
|
+
let(:id){76561197992917668}
|
7
|
+
|
8
|
+
describe "#steam_id_from_vanity_name" do
|
9
|
+
let(:response){YAML.load_file("spec/fixtures/profiles/#{id}.yml")}
|
10
|
+
let(:name){"Somename"}
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
Stew::XmlClient.any_instance.should_receive(:get).with("/id/#{name}").and_return(response)
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when the vanity name exists" do
|
17
|
+
it "returns the 64-bit id" do
|
18
|
+
Stew::CommunityClient.steam_id_from_vanity_name(name).should eq id
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "setting the base path" do
|
24
|
+
context "when the base path is not set" do
|
25
|
+
let(:response){YAML.load_file("spec/fixtures/profiles/#{id}.yml")}
|
26
|
+
|
27
|
+
it "should perform requests to the 'profile'" do
|
28
|
+
client.should_receive(:get).with("/profiles/#{id}/").and_return(response)
|
29
|
+
subject.profile(id)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when the base path is set to 'id'" do
|
34
|
+
let(:response){YAML.load_file("spec/fixtures/profiles/#{id}.yml")}
|
35
|
+
subject{Stew::CommunityClient.new({:client => client, :base_path => 'id'})}
|
36
|
+
|
37
|
+
it "should perform profile-requests to the 'id'" do
|
38
|
+
client.should_receive(:get).with("/id/#{id}/").and_return(response)
|
39
|
+
subject.profile(id)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe ".profile" do
|
45
|
+
let(:response){YAML.load_file("spec/fixtures/profiles/#{id}.yml")}
|
46
|
+
|
47
|
+
it "sends the correct message to its client" do
|
48
|
+
client.should_receive(:get).with("/profiles/#{id}/").and_return(response)
|
49
|
+
subject.profile(id)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "creates a profile object" do
|
53
|
+
client.stub(:get).with("/profiles/#{id}/").and_return(response)
|
54
|
+
Stew::Community::Profile.should_receive(:new).with(response['profile'])
|
55
|
+
subject.profile(id)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe ".profile_games" do
|
60
|
+
let(:response){YAML.load_file("spec/fixtures/profiles/games/#{id}.yml")}
|
61
|
+
|
62
|
+
it "sends the correct message to its client" do
|
63
|
+
client.should_receive(:get).with("/profiles/#{id}/games").and_return(response)
|
64
|
+
subject.profile_games(id)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "creates a ProfileGames object" do
|
68
|
+
client.stub(:get).with("/profiles/#{id}/games").and_return(response)
|
69
|
+
Stew::Community::ProfileGames.should_receive(:new).with(response['gamesList']['games']['game'])
|
70
|
+
subject.profile_games(id)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe ".profile_friends" do
|
75
|
+
let(:response){YAML.load_file("spec/fixtures/profiles/friends/#{id}.yml")}
|
76
|
+
|
77
|
+
it "sends the correct message to its client" do
|
78
|
+
client.should_receive(:get).with("/profiles/#{id}/friends").and_return(response)
|
79
|
+
subject.profile_friends(id)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns the value of the ['friendsList']['friends']['friend'] key from the response hash" do
|
83
|
+
client.stub(:get).with("/profiles/#{id}/friends").and_return(response)
|
84
|
+
Stew::Community::ProfileFriends.should_receive(:new).with(response['friendsList']['friends']['friend'])
|
85
|
+
subject.profile_friends(id)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Stew::Store::AppOfferSale" do
|
4
|
+
let(:price){Money.new(599,'EUR')}
|
5
|
+
let(:regular_price){Money.new(1199,'EUR')}
|
6
|
+
let(:name){"Deadlight"}
|
7
|
+
|
8
|
+
let(:node){Nokogiri.HTML(open("spec/fixtures/store/apps/211400_offers_sale.txt"))}
|
9
|
+
|
10
|
+
subject{Stew::Store::AppOfferSale.new(node)}
|
11
|
+
|
12
|
+
describe "attributes" do
|
13
|
+
it "sets the name" do
|
14
|
+
subject.name.should eq name
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets the description to nil" do
|
18
|
+
subject.description.should be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sets the price" do
|
22
|
+
subject.price.should eq price
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets the regular_price" do
|
26
|
+
subject.regular_price.should eq regular_price
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ".sale?" do
|
31
|
+
it "is true" do
|
32
|
+
subject.sale?.should be_true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Stew::Store::AppOffer" do
|
4
|
+
let(:name){'Borderlands 2'}
|
5
|
+
let(:description){'Includes four copies of Borderlands 2 - Send the extra copies to your friends'}
|
6
|
+
let(:price){Money.new(4999,'EUR')}
|
7
|
+
|
8
|
+
let(:node){Nokogiri.HTML(open("spec/fixtures/store/apps/49520_offers.txt"))}
|
9
|
+
|
10
|
+
subject{Stew::Store::AppOffer.new(node)}
|
11
|
+
|
12
|
+
describe ".create" do
|
13
|
+
context "when the app is not on sale" do
|
14
|
+
it "returns an AppOffer instance" do
|
15
|
+
Stew::Store::AppOffer.create(node).should be_a(Stew::Store::AppOffer)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when the app is on sale" do
|
20
|
+
let(:node){Nokogiri.HTML(open("spec/fixtures/store/apps/211400_offers_sale.txt"))}
|
21
|
+
|
22
|
+
it "returns an AppOfferSale instance" do
|
23
|
+
Stew::Store::AppOffer.create(node).should be_a(Stew::Store::AppOfferSale)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "attributes" do
|
29
|
+
it "sets the name" do
|
30
|
+
subject.name.should eq name
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sets the description" do
|
34
|
+
subject.description.should eq description
|
35
|
+
end
|
36
|
+
|
37
|
+
it "sets the price" do
|
38
|
+
subject.price.should eq price
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe ".sale?" do
|
43
|
+
it "is false" do
|
44
|
+
subject.sale?.should be_false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Stew::Store::AppOffers" do
|
4
|
+
let(:file_name){"49520_offers"}
|
5
|
+
let(:node){Nokogiri.HTML(open("spec/fixtures/store/apps/#{file_name}.txt"))}
|
6
|
+
|
7
|
+
subject{Stew::Store::AppOffers.new(node)}
|
8
|
+
|
9
|
+
describe ".entries" do
|
10
|
+
it "sets the app offers" do
|
11
|
+
node.css("div.game_area_purchase_game").each do |item|
|
12
|
+
Stew::Store::AppOffer.should_receive(:create).with(item)
|
13
|
+
end
|
14
|
+
Stew::Store::AppOffers.new(node)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has the correct amount of offers" do
|
18
|
+
subject.count.should eq 4
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has offers" do
|
22
|
+
subject.each do |offer|
|
23
|
+
offer.should be_a(Stew::Store::AppOffer)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".sale?" do
|
29
|
+
context "when the app has no sale" do
|
30
|
+
it "returns false" do
|
31
|
+
subject.sale?.should be_false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when the app has a sale" do
|
36
|
+
let(:file_name){"211400_offers_sale"}
|
37
|
+
it "returns true" do
|
38
|
+
subject.sale?.should be_true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ".sales" do
|
44
|
+
context "when the app has no sale" do
|
45
|
+
it "returns an empty array" do
|
46
|
+
subject.sales.should eq []
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when the app is on sale" do
|
51
|
+
let(:file_name){"211400_offers_sale"}
|
52
|
+
|
53
|
+
it "returns an array of the AppOffers on sale" do
|
54
|
+
subject.sales.count.should eq 2
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns an array of AppOfferSale objects" do
|
58
|
+
subject.sales.each do |app_offer|
|
59
|
+
app_offer.should be_a(Stew::Store::AppOfferSale)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Stew::Store::App do
|
6
|
+
let(:response){open("spec/fixtures/store/apps/#{id}.txt")}
|
7
|
+
#let(:document){Nokogiri.HTML(response)}
|
8
|
+
|
9
|
+
subject{Stew::Store::App.new(response)}
|
10
|
+
|
11
|
+
describe "attributes" do
|
12
|
+
context "when the parse is successful" do
|
13
|
+
let(:id){211420}
|
14
|
+
|
15
|
+
describe ".name" do
|
16
|
+
it "sets the name" do
|
17
|
+
subject.name.should eq "Dark Souls™: Prepare To Die™ Edition"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ".score" do
|
22
|
+
context "when the app has a score" do
|
23
|
+
it "sets the store" do
|
24
|
+
subject.score.should eq 85
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when the app has no score" do
|
29
|
+
let(:id){2290}
|
30
|
+
|
31
|
+
it "sets the store to nil" do
|
32
|
+
subject.score.should be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe ".release_date" do
|
38
|
+
it "sets the release date" do
|
39
|
+
subject.release_date.should eq Date.parse("Aug 23, 2012")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ".dlc?" do
|
44
|
+
context "when the app is not DLC" do
|
45
|
+
it "returns false" do
|
46
|
+
subject.dlc?.should be_false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when the app is DLC" do
|
51
|
+
let(:id){16870}
|
52
|
+
|
53
|
+
it "returns true" do
|
54
|
+
subject.dlc?.should be_true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe ".developer" do
|
60
|
+
it "returns the developer" do
|
61
|
+
subject.developer.should eq 'FromSoftware'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe ".publisher" do
|
66
|
+
it "returns the publisher" do
|
67
|
+
subject.publisher.should eq 'Namco Bandai Games'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe ".indie?" do
|
72
|
+
context "when the game is indie" do
|
73
|
+
let(:id){219150}
|
74
|
+
|
75
|
+
it "returns true" do
|
76
|
+
subject.indie?.should be_true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when the game is not indie" do
|
81
|
+
it "returns false" do
|
82
|
+
subject.indie?.should be_false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe ".price" do
|
88
|
+
it "returns the price of the first offer" do
|
89
|
+
subject.price.should eq Money.new(3999,'EUR')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe ".free?" do
|
94
|
+
it "returns true if the the app is free" do
|
95
|
+
subject.free?.should be_false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "offers" do
|
100
|
+
it "creates an AppOffers instance with the offer node" do
|
101
|
+
subject.offers.count.should eq 1
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "when the parse is unsuccessful" do
|
107
|
+
let(:id){"no_app"}
|
108
|
+
|
109
|
+
%w(name score release_date developer publisher).each do |attribute|
|
110
|
+
describe ".#{attribute}" do
|
111
|
+
it "should be nil" do
|
112
|
+
subject.send(attribute).should be_nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe ".genres" do
|
118
|
+
it "should return an empty array" do
|
119
|
+
subject.genres.should eq []
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe ".dlc?" do
|
124
|
+
it "should be nil" do
|
125
|
+
subject.dlc?.should be_nil
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe ".indie" do
|
130
|
+
it "should be false" do
|
131
|
+
subject.indie?.should be_false
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe ".price" do
|
136
|
+
it "should be nil" do
|
137
|
+
subject.price.should be_nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Stew::StoreClient" do
|
4
|
+
let(:client){double('web_client')}
|
5
|
+
let(:response){open("spec/fixtures/store/apps/#{id}.txt")}
|
6
|
+
let(:region){:us}
|
7
|
+
subject{Stew::StoreClient.new({:client => client})}
|
8
|
+
|
9
|
+
describe ".app" do
|
10
|
+
let(:id) {211420}
|
11
|
+
it "sends the correct message to its client" do
|
12
|
+
client.should_receive(:get).with("/app/#{id}", {:cc => region}).and_return(response)
|
13
|
+
Stew::Store::App.should_receive(:new).with(response)
|
14
|
+
subject.app(id)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#create_app" do
|
19
|
+
let(:id){211420}
|
20
|
+
|
21
|
+
context "when given an integer" do
|
22
|
+
it "creates an app with the given integer as id" do
|
23
|
+
client.stub(:get).with("/app/#{id}", {:cc => :us}).and_return(response)
|
24
|
+
Stew::Store::App.should_receive(:new).with(response)
|
25
|
+
subject.create_app(id)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when given a url with a region" do
|
30
|
+
let(:region){:uk}
|
31
|
+
let(:url){"http://store.steampowered.com/app/#{id}/?cc=#{region}"}
|
32
|
+
|
33
|
+
it "creates an app" do
|
34
|
+
client.stub(:get).with("/app/#{id}", {:cc => region}).and_return(response)
|
35
|
+
Stew::Store::App.should_receive(:new).with(response)
|
36
|
+
subject.create_app(url)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when given a url without a region" do
|
41
|
+
let(:url){"http://store.steampowered.com/app/#{id}"}
|
42
|
+
|
43
|
+
it "creates an app" do
|
44
|
+
client.stub(:get).with("/app/#{id}", {:cc => :us}).and_return(response)
|
45
|
+
Stew::Store::App.should_receive(:new).with(response)
|
46
|
+
subject.create_app(url)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when the given parameter cannot be matched" do
|
51
|
+
let(:url){"sodijfsdf"}
|
52
|
+
|
53
|
+
it "raises a Stew::Store::AppIdNotFoundError" do
|
54
|
+
expect{subject.create_app(url)}.to raise_error(Stew::AppIdNotFoundError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Stew::WebClient", :vcr do
|
4
|
+
let(:uri){'http://store.steampowered.com/'}
|
5
|
+
|
6
|
+
subject{Stew::WebClient.new(uri)}
|
7
|
+
|
8
|
+
describe ".get" do
|
9
|
+
let(:id){216390}
|
10
|
+
|
11
|
+
context "without optional parameters" do
|
12
|
+
it "performs a request to the given URL" do
|
13
|
+
response = subject.get("app/#{id}")
|
14
|
+
response.should include("http://store.steampowered.com/app/#{id}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with optional parameters" do
|
19
|
+
it "performs a request to the given URL" do
|
20
|
+
response = subject.get("app/#{id}", {:foo => :bar})
|
21
|
+
response.should include("http://store.steampowered.com/app/#{id}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|