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,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Untappd::Client do
4
+ before do
5
+ @query = { :key => "AK" }
6
+ @venue_id = "14411"
7
+ @client = Untappd::Client.new(:application_key => "AK")
8
+ end
9
+
10
+ describe ".venue_feed" do
11
+
12
+ before do
13
+ @query.merge!({ :venue_id => @venue_id })
14
+ stub_get("/venue_checkins").
15
+ with(:query => @query).
16
+ to_return(:body => fixture("venue_feed.json"),
17
+ :headers => { :content_type => "application/json; charset=utf8" } )
18
+ end
19
+
20
+ it "should get the correct resource" do
21
+ @client.venue_feed(@venue_id)
22
+ a_get("/venue_checkins").
23
+ with(:query => @query).
24
+ should have_been_made
25
+ end
26
+
27
+ it "should return up to 25 of the most recent checkins for this venue" do
28
+ checkins = @client.venue_feed(@venue_id)
29
+ checkins.should be_an Array
30
+ checkins.first.venue_id.should == @venue_id
31
+ end
32
+ end
33
+
34
+ describe ".venue" do
35
+
36
+ before do
37
+ @query.merge!({ :venue_id => @venue_id })
38
+ stub_get("/venue_info").
39
+ with(:query => @query).
40
+ to_return(:body => fixture("venue.json"),
41
+ :headers => { :content_type => "application/json; charset=utf8" } )
42
+ end
43
+
44
+ it "should get the correct resource" do
45
+ @client.venue(@venue_id)
46
+ a_get("/venue_info").
47
+ with(:query => @query).
48
+ should have_been_made
49
+ end
50
+
51
+ it "should return the requested venue info" do
52
+ venue = @client.venue(@venue_id)
53
+ venue.internal_venue_id.should == @venue_id
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Untappd do
4
+
5
+ before do
6
+ @key = "APP_KEY"
7
+ Untappd.configure do |config|
8
+ config.application_key = @key
9
+ end
10
+ end
11
+
12
+ after do
13
+ Untappd.reset
14
+ end
15
+
16
+ context "when delegating to a client" do
17
+ before do
18
+ stub_get("/user_feed").
19
+ with(:query => { :key => @key, :user => "gambrinus" }).
20
+ to_return(:body => fixture("user_feed.json"),
21
+ :headers => { :content_type => "application/json; charset=utf-8" })
22
+ end
23
+
24
+ it "should get the correct resource" do
25
+ Untappd.user_feed(:user => "gambrinus")
26
+ a_get("/user_feed").
27
+ with(:query => { :key => @key, :user => "gambrinus" }).
28
+ should have_been_made
29
+ end
30
+
31
+ it "should return the same results as a client" do
32
+ Untappd.user_feed(:user => "gambrinus").should == Untappd::Client.new.user_feed(:user => "gambrinus")
33
+ end
34
+
35
+ describe ".client" do
36
+ it "should be an Untappd::Client" do
37
+ Untappd.client.should be_a Untappd::Client
38
+ end
39
+ end
40
+
41
+ describe ".endpoint" do
42
+ it "should return the default endpoint" do
43
+ Untappd.endpoint.should == Untappd::Configuration::DEFAULT_ENDPOINT
44
+ end
45
+ end
46
+
47
+ describe ".endpoint=" do
48
+ it "should set the endpoint" do
49
+ Untappd.endpoint = "http://github.com/"
50
+ Untappd.endpoint.should == "http://github.com/"
51
+ end
52
+ end
53
+
54
+ describe ".user_agent" do
55
+ it "should return the default user agent" do
56
+ Untappd.user_agent.should == Untappd::Configuration::DEFAULT_USER_AGENT
57
+ end
58
+ end
59
+
60
+ describe ".user_agent=" do
61
+ it "should set the user agent" do
62
+ Untappd.user_agent = "Custom User Agent"
63
+ Untappd.user_agent.should == "Custom User Agent"
64
+ end
65
+ end
66
+
67
+ describe ".configure" do
68
+
69
+ Untappd::Configuration::VALID_OPTIONS_KEYS.each do |key|
70
+
71
+ it "should set the #{key}" do
72
+ Untappd.configure do |config|
73
+ config.send("#{key}=", key.to_s)
74
+ Untappd.send(key).should == key.to_s
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "untappd-api/version"
3
+ require "untappd/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "untappd-api"
@@ -23,14 +23,20 @@ Gem::Specification.new do |s|
23
23
  s.specification_version = 3
24
24
 
25
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_development_dependency %q<rspec>, ['~> 2.0.0.beta.22']
26
+ s.add_development_dependency %q<rspec>, ['~> 2.9.0']
27
+ s.add_development_dependency %q<webmock>, ['~> 1.6.2']
27
28
  s.add_dependency %q<httparty>, ['~> 0.7.4']
29
+ s.add_dependency %q<hashie>, ['~> 1.0.0']
28
30
  else
29
31
  s.add_dependency %q<rspec>, ['~> 2.0.0.beta.22']
32
+ s.add_dependency %q<webmock>, ['~> 1.6.2']
30
33
  s.add_dependency %q<httparty>, ['~> 0.7.4']
34
+ s.add_dependency %q<hashie>, ['~> 1.0.0']
31
35
  end
32
36
  else
33
37
  s.add_dependency %q<rspec>, ['~> 2.0.0.beta.22']
38
+ s.add_dependency %q<webmock>, ['~> 1.6.2']
34
39
  s.add_dependency %q<httparty>, ['~> 0.7.4']
40
+ s.add_dependency %q<hashie>, ['~> 1.0.0']
35
41
  end
36
42
  end
metadata CHANGED
@@ -1,104 +1,168 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: untappd-api
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Jeff Smith
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-02-28 00:00:00 -05:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rspec
16
+ requirement: &2152171100 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.9.0
22
+ type: :development
22
23
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: *2152171100
25
+ - !ruby/object:Gem::Dependency
26
+ name: webmock
27
+ requirement: &2152170340 !ruby/object:Gem::Requirement
24
28
  none: false
25
- requirements:
29
+ requirements:
26
30
  - - ~>
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 2
30
- - 0
31
- - 0
32
- - beta
33
- - 22
34
- version: 2.0.0.beta.22
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.2
35
33
  type: :development
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: httparty
39
34
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ version_requirements: *2152170340
36
+ - !ruby/object:Gem::Dependency
37
+ name: httparty
38
+ requirement: &2152169740 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
40
+ requirements:
43
41
  - - ~>
44
- - !ruby/object:Gem::Version
45
- segments:
46
- - 0
47
- - 7
48
- - 4
42
+ - !ruby/object:Gem::Version
49
43
  version: 0.7.4
50
44
  type: :runtime
51
- version_requirements: *id002
45
+ prerelease: false
46
+ version_requirements: *2152169740
47
+ - !ruby/object:Gem::Dependency
48
+ name: hashie
49
+ requirement: &2152169060 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *2152169060
52
58
  description: Ruby wrapper for the untappd API.
53
- email:
59
+ email:
54
60
  - jffreyjs@gmail.com
55
61
  executables: []
56
-
57
62
  extensions: []
58
-
59
63
  extra_rdoc_files: []
60
-
61
- files:
64
+ files:
62
65
  - .gitignore
63
66
  - Gemfile
64
67
  - MIT-LICENSE
65
68
  - README.rdoc
66
69
  - Rakefile
67
- - lib/untappd-api.rb
68
- - lib/untappd-api/version.rb
69
- - spec/untappd-api_spec.rb
70
+ - lib/untappd.rb
71
+ - lib/untappd/api.rb
72
+ - lib/untappd/client.rb
73
+ - lib/untappd/client/beer.rb
74
+ - lib/untappd/client/brewery.rb
75
+ - lib/untappd/client/checkin.rb
76
+ - lib/untappd/client/user.rb
77
+ - lib/untappd/client/venue.rb
78
+ - lib/untappd/configuration.rb
79
+ - lib/untappd/error.rb
80
+ - lib/untappd/version.rb
81
+ - spec/fixtures/add_comment.json
82
+ - spec/fixtures/badges.json
83
+ - spec/fixtures/beer.json
84
+ - spec/fixtures/beer_feed.json
85
+ - spec/fixtures/beer_search.json
86
+ - spec/fixtures/brewery.json
87
+ - spec/fixtures/brewery_feed.json
88
+ - spec/fixtures/brewery_search.json
89
+ - spec/fixtures/checkin.json
90
+ - spec/fixtures/checkin_details.json
91
+ - spec/fixtures/delete_comment.json
92
+ - spec/fixtures/distinct_beers.json
93
+ - spec/fixtures/friend_feed.json
94
+ - spec/fixtures/friends.json
95
+ - spec/fixtures/public_feed.json
96
+ - spec/fixtures/toast.json
97
+ - spec/fixtures/trending_beers.json
98
+ - spec/fixtures/untoast.json
99
+ - spec/fixtures/user.json
100
+ - spec/fixtures/user_feed.json
101
+ - spec/fixtures/venue.json
102
+ - spec/fixtures/venue_feed.json
103
+ - spec/fixtures/wish_list.json
104
+ - spec/spec_helper.rb
105
+ - spec/untappd/api_spec.rb
106
+ - spec/untappd/client/beer_spec.rb
107
+ - spec/untappd/client/brewery_spec.rb
108
+ - spec/untappd/client/checkin_spec.rb
109
+ - spec/untappd/client/user_spec.rb
110
+ - spec/untappd/client/venue_spec.rb
111
+ - spec/untappd_spec.rb
70
112
  - untappd-api.gemspec
71
- has_rdoc: true
72
- homepage: ""
113
+ homepage: ''
73
114
  licenses: []
74
-
75
115
  post_install_message:
76
116
  rdoc_options: []
77
-
78
- require_paths:
117
+ require_paths:
79
118
  - lib
80
- required_ruby_version: !ruby/object:Gem::Requirement
119
+ required_ruby_version: !ruby/object:Gem::Requirement
81
120
  none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- segments:
86
- - 0
87
- version: "0"
88
- required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
126
  none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- segments:
94
- - 0
95
- version: "0"
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
96
131
  requirements: []
97
-
98
132
  rubyforge_project: untappd-api
99
- rubygems_version: 1.3.7
133
+ rubygems_version: 1.8.10
100
134
  signing_key:
101
135
  specification_version: 3
102
136
  summary: Ruby wrapper for the untappd API.
103
- test_files: []
104
-
137
+ test_files:
138
+ - spec/fixtures/add_comment.json
139
+ - spec/fixtures/badges.json
140
+ - spec/fixtures/beer.json
141
+ - spec/fixtures/beer_feed.json
142
+ - spec/fixtures/beer_search.json
143
+ - spec/fixtures/brewery.json
144
+ - spec/fixtures/brewery_feed.json
145
+ - spec/fixtures/brewery_search.json
146
+ - spec/fixtures/checkin.json
147
+ - spec/fixtures/checkin_details.json
148
+ - spec/fixtures/delete_comment.json
149
+ - spec/fixtures/distinct_beers.json
150
+ - spec/fixtures/friend_feed.json
151
+ - spec/fixtures/friends.json
152
+ - spec/fixtures/public_feed.json
153
+ - spec/fixtures/toast.json
154
+ - spec/fixtures/trending_beers.json
155
+ - spec/fixtures/untoast.json
156
+ - spec/fixtures/user.json
157
+ - spec/fixtures/user_feed.json
158
+ - spec/fixtures/venue.json
159
+ - spec/fixtures/venue_feed.json
160
+ - spec/fixtures/wish_list.json
161
+ - spec/spec_helper.rb
162
+ - spec/untappd/api_spec.rb
163
+ - spec/untappd/client/beer_spec.rb
164
+ - spec/untappd/client/brewery_spec.rb
165
+ - spec/untappd/client/checkin_spec.rb
166
+ - spec/untappd/client/user_spec.rb
167
+ - spec/untappd/client/venue_spec.rb
168
+ - spec/untappd_spec.rb
@@ -1,192 +0,0 @@
1
- require 'httparty'
2
- require 'digest/md5'
3
-
4
- module Untappd
5
- class Base
6
- include HTTParty
7
- BASE_URI = 'http://api.untappd.com/v3'
8
- base_uri BASE_URI
9
-
10
- def initialize(key, user = nil, pass = nil)
11
- @auth = {}
12
- if user && pass
13
- @auth = { :username => user, :password => Digest::MD5.hexdigest(pass) }
14
- end
15
- @key = key
16
- end
17
-
18
- # Get the beer's feed
19
- # Params:
20
- # :bid => Your API Key provided when you are approved
21
- # :since => The numeric ID of the last recent check-in. (Optional)
22
- # :offset => The offset that you like the dataset to begin with. (Optional)
23
- def beer_feed(params={})
24
- get('beer_checkins', params)
25
- end
26
-
27
- # Get extended information about a beer.
28
- # Params:
29
- # :bid => The numeric beer ID of the beer you wish to look up.
30
- def beer_info(params={})
31
- get('beer_info', params)
32
- end
33
-
34
- # Get a list of matching beers.
35
- # Params:
36
- # :q => Name of the beer you wish to search for.
37
- def beer_search(params={})
38
- get('beer_search', params)
39
- end
40
-
41
- # Get the brewery's feed
42
- # Params:
43
- # :brewery_id => Your API Key provided when you are approved
44
- # :since => The numeric ID of the last recent check-in. (Optional)
45
- # :offset => The offset that you like the dataset to begin with. (Optional)
46
- def brewery_feed(params={})
47
- get('brewery_checkins', params)
48
- end
49
-
50
- # Get extended details for a particular checkin,
51
- # which includes location, comments and toasts.
52
- # Params:
53
- # :id => The numeric ID of the check-in.
54
- def checkin_info(params={})
55
- get('details', params)
56
- end
57
-
58
- # Get the friend check-in feed of the authenticated user.
59
- # Params:
60
- # :since => The numeric ID of the last recent check-in. (Optional)
61
- # :offset => The offset that you like the dataset to begin with. (Optional)
62
- def friend_feed(params={})
63
- get('feed', params)
64
- end
65
-
66
- # Get the public feed for Untappd.
67
- # Params:
68
- # :latitude => The numeric Latitude to filter the public feed. (Optional)
69
- # :longitude => The numeric Longitude to filter the public feed. (Optional)
70
- # :since => The numeric ID of the last recent check-in. (Optional)
71
- # :offset => The offset that you like the dataset to begin with. (Optional)
72
- def public_feed(params={})
73
- get('thepub', params)
74
- end
75
-
76
- # Get currently trending beers.
77
- # Params:
78
- # :type => "all", "macro", "micro", "local". "all" set to default. (Optional)
79
- # :limit => The number of records that will return (max 10). (Optional)
80
- # :age => "daily", "weekly", "monthly". (Optional)
81
- # :geolat => The numeric Latitude to filter the public feed. (Optional, required for type "local")
82
- # :geolng => The numeric Longitude to filter the public feed. (Optional, required for type "local")
83
- def trending(params={})
84
- get('trending', params)
85
- end
86
-
87
- # Get the user information for a selected user.
88
- # Params:
89
- # :user => The username of the person who you wish to obtain the user information. (Optional)
90
- def user_info(params={})
91
- get('user', params)
92
- end
93
-
94
- # Get a list of the user's badges.
95
- # Params:
96
- # :user => The username of the person who you wish to obtain the user information. (Optional)
97
- # :sort => Filters the badge list by type: "beer", "venue", or "special". (Optional)
98
- def user_badges(params={})
99
- get('user_badge', params)
100
- end
101
-
102
- # Get the user's distinct beers.
103
- # Params:
104
- # :user => The username that you wish to call the request upon. (Optional)
105
- # :offset => The offset that you like the dataset to begin with. (Optional)
106
- def user_distinct_beers(params={})
107
- get('user_distinct', params)
108
- end
109
-
110
- # Get the friend check-in feed of the selected user.
111
- # Params:
112
- # :user => The username that you wish to call the request upon. (Optional)
113
- # :since => The numeric ID of the last recent check-in. (Optional)
114
- # :offset => The offset that you like the dataset to begin with. (Optional)
115
- def user_feed(params={})
116
- get('user_feed', params)
117
- end
118
-
119
- # Get a list of the user's friends.
120
- # Params:
121
- # :user => The username that you wish to call the request upon. (Optional)
122
- # :offset => The offset that you like the dataset to begin with. (Optional)
123
- def user_friends(params={})
124
- get('friends', params)
125
- end
126
-
127
- # Get the user's wish listed beers.
128
- # Params:
129
- # :user => The username that you wish to call the request upon. (Optional)
130
- # :offset => The offset that you like the dataset to begin with. (Optional)
131
- def user_wish_list(params={})
132
- get('wish_list', params)
133
- end
134
-
135
- # Get the venue's feed
136
- # Params:
137
- # :venue_id => Your API Key provided when you are approved
138
- # :since => The numeric ID of the last recent check-in. (Optional)
139
- # :offset => The offset that you like the dataset to begin with. (Optional)
140
- def venue_feed(params={})
141
- get('venue_checkins', params)
142
- end
143
-
144
- # Get extended information about a venue.
145
- # Params:
146
- # :venue_id => The numeric beer ID of the beer you wish to look up.
147
- def venue_info(params={})
148
- get('venue_info', params)
149
- end
150
-
151
- private
152
-
153
- def get(method, params={})
154
- path = "/#{method}?key=#{@key}"
155
- params.each { |k,v| path += "&#{k.to_s}=#{v.to_s}" }
156
-
157
- options = {}
158
- options.merge({:basic_auth => @auth}) unless @auth.empty?
159
-
160
- response = self.class.get(URI.escape(path), options)
161
- raise_errors(response)
162
-
163
- response.parsed_response
164
- end
165
-
166
- def raise_errors(response)
167
- message = "#{response.body} - #{BASE_URI}#{response.request.path}"
168
-
169
- case response.code
170
- when 400
171
- raise BadRequest, message
172
- when 401
173
- raise Unauthorized, message
174
- when 403
175
- raise General, message
176
- when 404
177
- raise NotFound, message
178
- when 500
179
- raise InternalError, message
180
- when 501..503
181
- raise Unavailable, message
182
- end
183
- end
184
- end
185
-
186
- class BadRequest < StandardError; end
187
- class Unauthorized < StandardError; end
188
- class General < StandardError; end
189
- class Unavailable < StandardError; end
190
- class InternalError < StandardError; end
191
- class NotFound < StandardError; end
192
- end