untappd-api 0.0.2 → 0.1.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.
Files changed (48) hide show
  1. data/README.rdoc +16 -6
  2. data/lib/untappd.rb +28 -0
  3. data/lib/untappd/api.rb +79 -0
  4. data/lib/untappd/client.rb +17 -0
  5. data/lib/untappd/client/beer.rb +65 -0
  6. data/lib/untappd/client/brewery.rb +48 -0
  7. data/lib/untappd/client/checkin.rb +113 -0
  8. data/lib/untappd/client/user.rb +95 -0
  9. data/lib/untappd/client/venue.rb +34 -0
  10. data/lib/untappd/configuration.rb +52 -0
  11. data/lib/untappd/error.rb +27 -0
  12. data/lib/untappd/version.rb +3 -0
  13. data/spec/fixtures/add_comment.json +1 -0
  14. data/spec/fixtures/badges.json +1 -0
  15. data/spec/fixtures/beer.json +1 -0
  16. data/spec/fixtures/beer_feed.json +1 -0
  17. data/spec/fixtures/beer_search.json +1 -0
  18. data/spec/fixtures/brewery.json +1 -0
  19. data/spec/fixtures/brewery_feed.json +1 -0
  20. data/spec/fixtures/brewery_search.json +1 -0
  21. data/spec/fixtures/checkin.json +1 -0
  22. data/spec/fixtures/checkin_details.json +1 -0
  23. data/spec/fixtures/delete_comment.json +1 -0
  24. data/spec/fixtures/distinct_beers.json +1 -0
  25. data/spec/fixtures/friend_feed.json +1 -0
  26. data/spec/fixtures/friends.json +1 -0
  27. data/spec/fixtures/public_feed.json +1 -0
  28. data/spec/fixtures/toast.json +1 -0
  29. data/spec/fixtures/trending_beers.json +1 -0
  30. data/spec/fixtures/untoast.json +1 -0
  31. data/spec/fixtures/user.json +1 -0
  32. data/spec/fixtures/user_feed.json +1 -0
  33. data/spec/fixtures/venue.json +1 -0
  34. data/spec/fixtures/venue_feed.json +1 -0
  35. data/spec/fixtures/wish_list.json +1 -0
  36. data/spec/spec_helper.rb +47 -0
  37. data/spec/untappd/api_spec.rb +68 -0
  38. data/spec/untappd/client/beer_spec.rb +102 -0
  39. data/spec/untappd/client/brewery_spec.rb +81 -0
  40. data/spec/untappd/client/checkin_spec.rb +185 -0
  41. data/spec/untappd/client/user_spec.rb +340 -0
  42. data/spec/untappd/client/venue_spec.rb +56 -0
  43. data/spec/untappd_spec.rb +80 -0
  44. data/untappd-api.gemspec +8 -2
  45. metadata +130 -66
  46. data/lib/untappd-api.rb +0 -192
  47. data/lib/untappd-api/version.rb +0 -3
  48. data/spec/untappd-api_spec.rb +0 -5
@@ -0,0 +1,185 @@
1
+ require 'spec_helper'
2
+
3
+ describe Untappd::Client do
4
+ before do
5
+ @query = { :key => "AK" }
6
+ @checkin_id = "674828"
7
+ @beer_id = "6284"
8
+ @user = "gambrinus"
9
+ @pass = "fake_password"
10
+ @hashed_pass = Digest::MD5.hexdigest(@pass)
11
+ @client = Untappd::Client.new(:application_key => "AK")
12
+ end
13
+
14
+ describe ".public_feed" do
15
+
16
+ before do
17
+ stub_get("/thepub").
18
+ with(:query => @query).
19
+ to_return(:body => fixture("public_feed.json"),
20
+ :headers => { :content_type => "application/json; charset=utf8" } )
21
+ end
22
+
23
+ it "should get the correct resource" do
24
+ @client.public_feed
25
+ a_get("/thepub").
26
+ with(:query => @query).
27
+ should have_been_made
28
+ end
29
+
30
+ it "should return up to 25 of the most recent checkins" do
31
+ checkins = @client.public_feed
32
+ checkins.should be_an Array
33
+ end
34
+ end
35
+
36
+ describe ".checkin_details" do
37
+
38
+ before do
39
+ @query.merge!({ :id => @checkin_id })
40
+ stub_get("/details").
41
+ with(:query => @query).
42
+ to_return(:body => fixture("checkin_details.json"),
43
+ :headers => { :content_type => "application/json; charset=utf8" } )
44
+ end
45
+
46
+ it "should get the correct resource" do
47
+ @client.checkin_details(@checkin_id)
48
+ a_get("/details").
49
+ with(:query => @query).
50
+ should have_been_made
51
+ end
52
+
53
+ it "should return requested checkin info" do
54
+ checkin = @client.checkin_details(@checkin_id)
55
+ checkin.checkin_id.should == @checkin_id
56
+ end
57
+ end
58
+
59
+ describe ".checkin" do
60
+
61
+ before do
62
+ @client.username = @user
63
+ @client.password = @pass
64
+ @body = { :bid => @beer_id, :gmt_offset => "-5" }
65
+ stub_post_with_auth("/checkin", @user, @hashed_pass).
66
+ with(:query => @query, :body => @body ).
67
+ to_return(:body => fixture("checkin.json"),
68
+ :headers => { :content_type => "application/json; charset=utf8" } )
69
+ end
70
+
71
+ it "should get the correct resource" do
72
+ @client.checkin(@beer_id, -5)
73
+ a_post_with_auth("/checkin", @user, @hashed_pass).
74
+ with(:query => @query, :body => @body).
75
+ should have_been_made
76
+ end
77
+
78
+ it "should return a successful checkin for the specified beer" do
79
+ result = @client.checkin(@beer_id, -5)
80
+ result.result.should == "success"
81
+ end
82
+ end
83
+
84
+ describe ".add_comment" do
85
+
86
+ before do
87
+ @client.username = @user
88
+ @client.password = @pass
89
+ @comment = "Test"
90
+ @body = { :checkin_id => @checkin_id, :comment => @comment }
91
+ stub_post_with_auth("/add_comment", @user, @hashed_pass).
92
+ with(:query => @query, :body => @body).
93
+ to_return(:body => fixture("add_comment.json"),
94
+ :headers => { :content_type => "application/json; charset=utf8" } )
95
+ end
96
+
97
+ it "should post to the correct resource" do
98
+ @client.add_comment(@checkin_id, @comment)
99
+ a_post_with_auth("/add_comment", @user, @hashed_pass).
100
+ with(:query => @query, :body => @body).
101
+ should have_been_made
102
+ end
103
+
104
+ it "should return the comment details on success" do
105
+ response = @client.add_comment(@checkin_id, @comment)
106
+ response.results.comment_details.comment_text.should == @comment
107
+ end
108
+ end
109
+
110
+ describe ".delete_comment" do
111
+
112
+ before do
113
+ @client.username = @user
114
+ @client.password = @pass
115
+ @comment_id = "45448"
116
+ @body = { :comment_id => @comment_id }
117
+ stub_post_with_auth("/delete_comment", @user, @hashed_pass).
118
+ with(:query => @query, :body => @body).
119
+ to_return(:body => fixture("delete_comment.json"),
120
+ :headers => { :content_type => "application/json; charset=utf8" } )
121
+ end
122
+
123
+ it "should post to the correct resource" do
124
+ @client.delete_comment(@comment_id)
125
+ a_post_with_auth("/delete_comment", @user, @hashed_pass).
126
+ with(:query => @query, :body => @body).
127
+ should have_been_made
128
+ end
129
+
130
+ it "should return a successful result" do
131
+ response = @client.delete_comment(@comment_id)
132
+ response.results.should == "success"
133
+ end
134
+ end
135
+
136
+ describe ".toast" do
137
+
138
+ before do
139
+ @client.username = @user
140
+ @client.password = @pass
141
+ @body = { :checkin_id => @checkin_id }
142
+ stub_post_with_auth("/toast", @user, @hashed_pass).
143
+ with(:query => @query, :body => @body).
144
+ to_return(:body => fixture("toast.json"),
145
+ :headers => { :content_type => "application/json; charset=utf8" } )
146
+ end
147
+
148
+ it "should post to the correct resource" do
149
+ @client.toast(@checkin_id)
150
+ a_post_with_auth("/toast", @user, @hashed_pass).
151
+ with(:query => @query, :body => @body).
152
+ should have_been_made
153
+ end
154
+
155
+ it "should return a successful result" do
156
+ response = @client.toast(@checkin_id)
157
+ response.results.should == "success"
158
+ end
159
+ end
160
+
161
+ describe ".untoast" do
162
+
163
+ before do
164
+ @client.username = @user
165
+ @client.password = @pass
166
+ @body = { :checkin_id => @checkin_id }
167
+ stub_post_with_auth("/delete_toast", @user, @hashed_pass).
168
+ with(:query => @query, :body => @body).
169
+ to_return(:body => fixture("toast.json"),
170
+ :headers => { :content_type => "application/json; charset=utf8" } )
171
+ end
172
+
173
+ it "should post to the correct resource" do
174
+ @client.untoast(@checkin_id)
175
+ a_post_with_auth("/delete_toast", @user, @hashed_pass).
176
+ with(:query => @query, :body => @body).
177
+ should have_been_made
178
+ end
179
+
180
+ it "should return a successful result" do
181
+ response = @client.untoast(@checkin_id)
182
+ response.results.should == "success"
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,340 @@
1
+ require 'spec_helper'
2
+
3
+ describe Untappd::Client do
4
+ before do
5
+ @query = { :key => "AK" }
6
+ @checkin_id = "674828"
7
+ @beer_id = "6284"
8
+ @user = "gambrinus"
9
+ @pass = "fake_password"
10
+ @hashed_pass = Digest::MD5.hexdigest(@pass)
11
+ @client = Untappd::Client.new(:application_key => "AK")
12
+ end
13
+
14
+ describe ".user_feed" do
15
+
16
+ context "without authentication" do
17
+
18
+ before do
19
+ @query.merge!({ :user => @user })
20
+ stub_get("/user_feed").
21
+ with(:query => @query).
22
+ to_return(:body => fixture("user_feed.json"),
23
+ :headers => { :content_type => "application/json; charset=utf8" } )
24
+ end
25
+
26
+ it "should get the correct resource" do
27
+ @client.user_feed(:user => @user)
28
+ a_get("/user_feed").
29
+ with(:query => @query).
30
+ should have_been_made
31
+ end
32
+
33
+ it "should return up to 25 of the most recent checkins for specified user" do
34
+ checkins = @client.user_feed(:user => @user)
35
+ checkins.should be_an Array
36
+ checkins.first.user.user_name.should == @user
37
+ end
38
+ end
39
+
40
+ context "with authentication" do
41
+
42
+ before do
43
+ @client.username = @user
44
+ @client.password = @pass
45
+ stub_get_with_auth("/user_feed", @user, @hashed_pass).
46
+ with(:query => @query).
47
+ to_return(:body => fixture("user_feed.json"),
48
+ :headers => { :content_type => "application/json; charset=utf8" } )
49
+ end
50
+
51
+ it "should get the correct resource" do
52
+ @client.user_feed
53
+ a_get_with_auth("/user_feed", @user, @hashed_pass).
54
+ with(:query => @query).
55
+ should have_been_made
56
+ end
57
+
58
+ it "should return up to 25 of the most recent checkins for authenticated user" do
59
+ checkins = @client.user_feed
60
+ checkins.should be_an Array
61
+ checkins.first.user.user_name.should == @user
62
+ end
63
+ end
64
+ end
65
+
66
+ describe ".friend_feed" do
67
+
68
+ before do
69
+ @client.username = @user
70
+ @client.password = @pass
71
+ stub_get_with_auth("/feed", @user, @hashed_pass).
72
+ with(:query => @query).
73
+ to_return(:body => fixture("friend_feed.json"),
74
+ :headers => { :content_type => "application/json; charset=utf8" } )
75
+ end
76
+
77
+ it "should get the correct resource" do
78
+ @client.friend_feed
79
+ a_get_with_auth("/feed", @user, @hashed_pass).
80
+ with(:query => @query).
81
+ should have_been_made
82
+ end
83
+
84
+ it "should return up to 25 checkins for authenticated user's friends" do
85
+ checkins = @client.friend_feed
86
+ checkins.should be_an Array
87
+ end
88
+ end
89
+
90
+ describe ".user" do
91
+
92
+ context "without authentication" do
93
+
94
+ before do
95
+ @query.merge!({ :user => @user })
96
+ stub_get("/user").
97
+ with(:query => @query).
98
+ to_return(:body => fixture("user.json"),
99
+ :headers => { :content_type => "application/json; charset=utf8" } )
100
+ end
101
+
102
+ it "should get the correct resource" do
103
+ @client.user(:user => @user)
104
+ a_get("/user").
105
+ with(:query => @query).
106
+ should have_been_made
107
+ end
108
+
109
+ it "should return requested user info" do
110
+ result = @client.user(:user => @user)
111
+ result.user.user_name.should == @user
112
+ end
113
+ end
114
+
115
+ context "with authentication" do
116
+
117
+ before do
118
+ @client.username = @user
119
+ @client.password = @pass
120
+ stub_get_with_auth("/user", @user, @hashed_pass).
121
+ with(:query => @query).
122
+ to_return(:body => fixture("user.json"),
123
+ :headers => { :content_type => "application/json; charset=utf8" } )
124
+ end
125
+
126
+ it "should get the correct resource" do
127
+ @client.user
128
+ a_get_with_auth("/user", @user, @hashed_pass).
129
+ with(:query => @query).
130
+ should have_been_made
131
+ end
132
+
133
+ it "should return the authenticated user info" do
134
+ result = @client.user
135
+ result.user.user_name.should == @user
136
+ end
137
+ end
138
+ end
139
+
140
+ describe ".badges" do
141
+
142
+ context "without authentication" do
143
+
144
+ before do
145
+ @query.merge!({ :user => @user })
146
+ stub_get("/user_badge").
147
+ with(:query => @query).
148
+ to_return(:body => fixture("badges.json"),
149
+ :headers => { :content_type => "application/json; charset=utf8" } )
150
+ end
151
+
152
+ it "should get the correct resource" do
153
+ @client.badges(:user => @user)
154
+ a_get("/user_badge").
155
+ with(:query => @query).
156
+ should have_been_made
157
+ end
158
+
159
+ it "should return the badge info for the requested user" do
160
+ result = @client.badges(:user => @user)
161
+ result.should be_an Array
162
+ end
163
+ end
164
+
165
+ context "with authentication" do
166
+
167
+ before do
168
+ @client.username = @user
169
+ @client.password = @pass
170
+
171
+ stub_get_with_auth("/user_badge", @user, @hashed_pass).
172
+ with(:query => @query).
173
+ to_return(:body => fixture("badges.json"),
174
+ :headers => { :content_type => "application/json; charset=utf8" } )
175
+ end
176
+
177
+ it "should get the correct resource" do
178
+ @client.badges
179
+ a_get_with_auth("/user_badge", @user, @hashed_pass).
180
+ with(:query => @query).
181
+ should have_been_made
182
+ end
183
+
184
+ it "should return the badge info for the authenticated user" do
185
+ result = @client.badges
186
+ result.should be_an Array
187
+ end
188
+ end
189
+ end
190
+
191
+ describe ".friends" do
192
+
193
+ context "without authentication" do
194
+
195
+ before do
196
+ @query.merge!({ :user => @user })
197
+ stub_get("/friends").
198
+ with(:query => @query).
199
+ to_return(:body => fixture("friends.json"),
200
+ :headers => { :content_type => "application/json; charset=utf8" } )
201
+ end
202
+
203
+ it "should get the correct resource" do
204
+ @client.friends(:user => @user)
205
+ a_get("/friends").
206
+ with(:query => @query).
207
+ should have_been_made
208
+ end
209
+
210
+ it "should return the friend info for the requested user" do
211
+ result = @client.friends(:user => @user)
212
+ result.should be_an Array
213
+ end
214
+ end
215
+
216
+ context "with authentication" do
217
+
218
+ before do
219
+ @client.username = @user
220
+ @client.password = @pass
221
+ stub_get_with_auth("/friends", @user, @hashed_pass).
222
+ with(:query => @query).
223
+ to_return(:body => fixture("friends.json"),
224
+ :headers => { :content_type => "application/json; charset=utf8" } )
225
+ end
226
+
227
+ it "should get the correct resource" do
228
+ @client.friends
229
+ a_get_with_auth("/friends", @user, @hashed_pass).
230
+ with(:query => @query).
231
+ should have_been_made
232
+ end
233
+
234
+ it "should return the friend info for the authenticated user" do
235
+ result = @client.friends
236
+ result.should be_an Array
237
+ end
238
+ end
239
+ end
240
+
241
+ describe ".wish_list" do
242
+
243
+ context "without authentication" do
244
+
245
+ before do
246
+ @query.merge!({ :user => @user })
247
+ stub_get("/wish_list").
248
+ with(:query => @query).
249
+ to_return(:body => fixture("wish_list.json"),
250
+ :headers => { :content_type => "application/json; charset=utf8" } )
251
+ end
252
+
253
+ it "should get the correct resource" do
254
+ @client.wish_list(:user => @user)
255
+ a_get("/wish_list").
256
+ with(:query => @query).
257
+ should have_been_made
258
+ end
259
+
260
+ it "should return the wish list for the requested user" do
261
+ result = @client.wish_list(:user => @user)
262
+ result.should be_an Array
263
+ end
264
+ end
265
+
266
+ context "with authentication" do
267
+
268
+ before do
269
+ @client.username = @user
270
+ @client.password = @pass
271
+ stub_get_with_auth("/wish_list", @user, @hashed_pass).
272
+ with(:query => @query).
273
+ to_return(:body => fixture("wish_list.json"),
274
+ :headers => { :content_type => "application/json; charset=utf8" } )
275
+ end
276
+
277
+ it "should get the correct resource" do
278
+ @client.wish_list
279
+ a_get_with_auth("/wish_list", @user, @hashed_pass).
280
+ with(:query => @query).
281
+ should have_been_made
282
+ end
283
+
284
+ it "should return the wish list for the authenticated user" do
285
+ result = @client.wish_list
286
+ result.should be_an Array
287
+ end
288
+ end
289
+ end
290
+
291
+ describe ".distinct_beers" do
292
+
293
+ context "without authentication" do
294
+
295
+ before do
296
+ @query.merge!({ :user => @user })
297
+ stub_get("/user_distinct").
298
+ with(:query => @query).
299
+ to_return(:body => fixture("distinct_beers.json"),
300
+ :headers => { :content_type => "application/json; charset=utf8" } )
301
+ end
302
+
303
+ it "should get the correct resource" do
304
+ @client.distinct_beers(:user => @user)
305
+ a_get("/user_distinct").
306
+ with(:query => @query).
307
+ should have_been_made
308
+ end
309
+
310
+ it "should return up to 25 distinct beers for the requested user" do
311
+ result = @client.distinct_beers(:user => @user)
312
+ result.should be_an Array
313
+ end
314
+ end
315
+
316
+ context "with authentication" do
317
+
318
+ before do
319
+ @client.username = @user
320
+ @client.password = @pass
321
+ stub_get_with_auth("/user_distinct", @user, @hashed_pass).
322
+ with(:query => @query).
323
+ to_return(:body => fixture("distinct_beers.json"),
324
+ :headers => { :content_type => "application/json; charset=utf8" } )
325
+ end
326
+
327
+ it "should get the correct resource" do
328
+ @client.distinct_beers
329
+ a_get_with_auth("/user_distinct", @user, @hashed_pass).
330
+ with(:query => @query).
331
+ should have_been_made
332
+ end
333
+
334
+ it "should return up to 25 distinct beers for the authenticated user" do
335
+ result = @client.distinct_beers
336
+ result.should be_an Array
337
+ end
338
+ end
339
+ end
340
+ end