untappd 0.0.5 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +23 -15
  4. data/README.md +137 -0
  5. data/Rakefile +7 -2
  6. data/examples/aba_checkins.rb +5 -41
  7. data/examples/checkin.rb +10 -11
  8. data/examples/user_feed.rb +5 -4
  9. data/lib/untappd.rb +4 -23
  10. data/lib/untappd/base.rb +11 -9
  11. data/lib/untappd/beer.rb +20 -44
  12. data/lib/untappd/brewery.rb +13 -31
  13. data/lib/untappd/checkin.rb +53 -93
  14. data/lib/untappd/config.rb +28 -0
  15. data/lib/untappd/oauth.rb +9 -0
  16. data/lib/untappd/user.rb +38 -59
  17. data/lib/untappd/venue.rb +9 -21
  18. data/lib/untappd/version.rb +1 -1
  19. data/spec/beer_spec.rb +19 -64
  20. data/spec/brewery_spec.rb +12 -49
  21. data/spec/checkin_spec.rb +29 -75
  22. data/spec/config_spec.rb +17 -0
  23. data/spec/oauth_spec.rb +17 -0
  24. data/spec/spec_helper.rb +24 -0
  25. data/spec/user_spec.rb +26 -108
  26. data/spec/vcr/Beer/get_feed.yml +239 -0
  27. data/spec/vcr/Beer/get_info.yml +186 -0
  28. data/spec/vcr/Beer/get_search.yml +324 -0
  29. data/spec/vcr/Beer/get_trending_beers.yml +108 -0
  30. data/spec/vcr/Brewery/get_feed.yml +219 -0
  31. data/spec/vcr/Brewery/get_info.yml +372 -0
  32. data/spec/vcr/Brewery/get_search.yml +51 -0
  33. data/spec/vcr/Checkin/get/gets_info.yml +49 -0
  34. data/spec/vcr/Checkin/get/gets_thepub_feed.yml +240 -0
  35. data/spec/vcr/Checkin/post/add_comment.yml +47 -0
  36. data/spec/vcr/Checkin/post/adds_toast.yml +45 -0
  37. data/spec/vcr/Checkin/post/creates_checkin.yml +53 -0
  38. data/spec/vcr/Checkin/post/removes_comment.yml +46 -0
  39. data/spec/vcr/Checkin/post/removes_toast.yml +44 -0
  40. data/spec/vcr/User/get_badges.yml +45 -0
  41. data/spec/vcr/User/get_distinct_beers.yml +82 -0
  42. data/spec/vcr/User/get_feed.yml +78 -0
  43. data/spec/vcr/User/get_friend_feed.yml +460 -0
  44. data/spec/vcr/User/get_friends.yml +43 -0
  45. data/spec/vcr/User/get_info.yml +109 -0
  46. data/spec/vcr/User/get_wish_list.yml +47 -0
  47. data/spec/vcr/Venue/gets_info.yml +67 -0
  48. data/spec/vcr/Venue/gets_the_feed.yml +65 -0
  49. data/spec/venue_spec.rb +8 -36
  50. data/untappd.gemspec +3 -1
  51. metadata +146 -78
  52. data/README.rdoc +0 -107
  53. data/spec/untappd_spec.rb +0 -13
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ .rvmrc
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
1
  source "http://rubygems.org"
2
+ gem 'rake'
3
+
4
+ ruby '1.9.3'
2
5
 
3
6
  # Specify your gem's dependencies in untappd.gemspec
4
7
  gemspec
@@ -1,30 +1,38 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- untappd (0.0.4)
4
+ untappd (4.0.0)
5
5
  hashie (>= 1.0.0)
6
6
  httparty (>= 0.7.3)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- crack (0.1.8)
12
- diff-lcs (1.1.2)
13
- hashie (1.0.0)
14
- httparty (0.7.4)
15
- crack (= 0.1.8)
16
- rspec (2.5.0)
17
- rspec-core (~> 2.5.0)
18
- rspec-expectations (~> 2.5.0)
19
- rspec-mocks (~> 2.5.0)
20
- rspec-core (2.5.1)
21
- rspec-expectations (2.5.0)
22
- diff-lcs (~> 1.1.2)
23
- rspec-mocks (2.5.0)
11
+ diff-lcs (1.1.3)
12
+ fakeweb (1.3.0)
13
+ hashie (1.2.0)
14
+ httparty (0.10.0)
15
+ multi_json (~> 1.0)
16
+ multi_xml
17
+ multi_json (1.5.0)
18
+ multi_xml (0.5.2)
19
+ rake (10.0.2)
20
+ rspec (2.12.0)
21
+ rspec-core (~> 2.12.0)
22
+ rspec-expectations (~> 2.12.0)
23
+ rspec-mocks (~> 2.12.0)
24
+ rspec-core (2.12.1)
25
+ rspec-expectations (2.12.0)
26
+ diff-lcs (~> 1.1.3)
27
+ rspec-mocks (2.12.0)
28
+ vcr (2.3.0)
24
29
 
25
30
  PLATFORMS
26
31
  ruby
27
32
 
28
33
  DEPENDENCIES
29
- rspec (>= 2.5.0)
34
+ fakeweb (>= 1.3.0)
35
+ rake
36
+ rspec (>= 2.12.0)
30
37
  untappd!
38
+ vcr (>= 2.3.0)
@@ -0,0 +1,137 @@
1
+ # Untappd
2
+
3
+ Wrapper around the Untappd API. This organizes the untappd api
4
+ into proper RESTFUL objects. See API coverage below for mapping from
5
+ the API documentation.
6
+
7
+ * You will need to register for an API key: http://untappd.com/api/register.
8
+ * Attempting to wrap all the API documented here: https://untappd.com/api/docs/v4.
9
+ * Required parameters are passed as arguments to the method, optional parameters should be included in the options hash.
10
+ * Methods requiring user authentication will require an OAuth access_token. See OAuth Examples below.
11
+ * All responses are wrapped in a Hashie::Mash
12
+
13
+ ## Releases
14
+
15
+ * 4.0.0 supports the v4 API (https://untappd.com/api/docs/v4)
16
+ * 0.0.5 Brewery Info and Search
17
+ * 0.0.4 Complete coverage of v3 API. Checkins, Comments, Toasts, gmt_offset configuration
18
+ * 0.0.3 Venue Info & Feed, Trending Beer, Brewery Feed, Checkin info & Feed (the pub), Renamed Beer.checkins to Beer.feed
19
+ * 0.0.2 User feed, distinct beers, info, badges, friends, wish list
20
+ * 0.0.1 Beer Search, Info and Checkins
21
+
22
+ ## API Coverage
23
+
24
+ **Beer Object**
25
+ * Beer Feed - Untappd::Beer.feed(beer_id, options={})
26
+ * Beer Info - Untappd::Beer.info(beer_id, options={})
27
+ * Beer Search - Untappd::Beer.search(q, options={})
28
+ * Trending - Untappd::Beer.trending
29
+
30
+ **User Object**
31
+ * User Feed - Untappd::User.feed(username, options={})
32
+ * User Info - Untappd::User.info(username)
33
+ * User Badges - Untappd::User.badges(username, options={})
34
+ * User Friends - Untappd::User.friends(username, options={})
35
+ * User Wish List - Untappd::User.wish_list(username, options={})
36
+ * User Distinct Beers - Untappd::User.distinct(username, options={})
37
+ * Friend Feed - Untappd::User.friend_feed(access_token, options={})
38
+
39
+ **Venue Object**
40
+ * Venue Feed - Untappd::Venue.feed(venue_id, options={})
41
+ * Venue Info - Untappd::Venue.info(venue_id)
42
+
43
+ **Brewery Object**
44
+ * Brewery Checkins - Untappd::Brewery.feed(brewery_id, options={})
45
+ * Brewery Info - Untappd::Brewery.info(brewery_id)
46
+ * Brewery Search - Untappd::Brewery.search(q)
47
+
48
+ **Checkin Object**
49
+ * Checkin Info - Untappd::Checkin.info(checkin_id)
50
+ * The Pub Feed - Untappd::Checkin.feed(options={})
51
+ * Checkin - Untappd::Checkin.create(access_token, gmt_offset, timezone, beer_id, options={})
52
+ * Add Comment - Untappd::Checkin.add_comment(access_token, checkin_id, comment)
53
+ * Remove Comment - Untappd::Checkin.remove_comment(access_token, comment_id)
54
+ * Toast/Remove Toast - Untappd::Checkin.toggle_toast(access_token, checkin_id)
55
+
56
+ **TODO**
57
+ * Add To Wish List - /v4/user/wishlist/add
58
+ * Remove From Wish List - /v4/user/wishlist/delete
59
+ * Pending Friends - /v4/user/pending
60
+ * Accept Friends - /v4/friend/accept/TARGET_ID
61
+ * Reject Friends - /v4/friend/reject/TARGET_ID
62
+ * Remove Friends - /v4/friend/remove/TARGET_ID
63
+ * Request Friends - /v4/friend/request/TARGET_ID
64
+ * Notifications - /v4/notifications
65
+ * Foursquare Venue Lookup - /v4/venue/foursquare_lookup/VENUE_ID
66
+
67
+ ## Examples
68
+
69
+ ### Configuration
70
+
71
+ Add to your Gemfile
72
+
73
+ gem 'untappd'
74
+
75
+ Configure your API KEY
76
+
77
+ Untappd.configure do |config|
78
+ config.client_id = 'YOUR_CLIENT_ID'
79
+ config.client_secret = 'YOUR_CLIENT_SECRET'
80
+ config.redirect_url = 'YOUR_OAUTH_REDIRECT_URL' # only if you're using OAuth
81
+ config.gmt_offset = -5
82
+ end
83
+
84
+ ### OAuth
85
+
86
+ To generate an OAuth authentication request, simply call
87
+
88
+ Untappd::OAuth.authenticate_url
89
+
90
+ This will generate a URL that the user can access in order to authorize the application.
91
+ It will look something like this:
92
+
93
+ => "https://untappd.com/oauth/authenticate/?client_id=YOUR_CLIENT_ID&response_type=token&redirect_url=YOUR_OAUTH_REDIRECT_URL"
94
+
95
+ After the user has authenticated your application, they will be redirected back to `YOUR_OAUTH_REDIRECT_URL` with their access token appended to the query string.
96
+
97
+ ### Examples
98
+
99
+ Get all the checkins for Arrogant Bastard Ale
100
+
101
+ checkins = Untappd::Beer.feed(18099) # or Untappd::User.feed("cmar")
102
+ checkins.checkins.items.each do |checkin|
103
+ puts "#{checkin.user.first_name} at #{checkin.created_at}"
104
+ end
105
+
106
+ Create Checkin
107
+
108
+ #foursqure, lat, lng are optional
109
+ Untappd::Checkin.create(ACCESS_TOKEN, 4665,
110
+ :foursquare_id => "4ad6bf91f964a520380821e3",
111
+ :timezone => 'EST',
112
+ :user_lat => "51.4718",
113
+ :user_lng => "-0.489278")
114
+
115
+ Search for beers with the name Stone
116
+
117
+ beers = Untappd::Beer.search('stone')
118
+ beers.beers.items.each do |beer|
119
+ puts "#{beer.beer.beer_name}"
120
+ end
121
+
122
+ Get extended info for Arrogant Bastard Ale
123
+
124
+ info = Untappd::Beer.info(18099)
125
+ puts "#{info.beer.beer_name} by #{info.beer.brewery.brewery_name}"
126
+
127
+ All Methods can take additional options specified in the API
128
+
129
+ checkins = Untappd::Beer.feed(18099, :offset => 100)
130
+
131
+ beers = Untappd::Beer.search('stone', :sort => "count")
132
+
133
+ ### Debugging
134
+ You can dump any result to see what values are available with
135
+
136
+ info = Untappd::Beer.info(18099)
137
+ puts info.inspect
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -3,50 +3,14 @@ require 'rubygems'
3
3
  require 'untappd'
4
4
 
5
5
  Untappd.configure do |config|
6
- config.apikey = 'YOUR_API_KEY'
6
+ config.client_id = 'YOUR_CLIENT_ID'
7
+ config.client_secret = 'YOUR_CLIENT_SECRET'
7
8
  end
8
9
 
9
10
  checkins = Untappd::Beer.feed(18099)
10
- checkins.each do |checkin|
11
- puts "#{checkin.user.first_name} at #{checkin.created_at}"
11
+ checkins.checkins.items.each do |checkin|
12
+ puts "#{checkin.user.first_name} at #{checkin.created_at}"
12
13
  end
13
14
 
14
15
  info = Untappd::Beer.info(18099)
15
- puts "#{info.name} by #{info.brewery}"
16
- puts info.inspect
17
-
18
- # Example JSON response
19
- # {
20
- # "next_query":"http:\/\/api.untappd.com\/v3\/beer_checkins?bid=18099&since=603321",
21
- # "next_page":"http:\/\/api.untappd.com\/v3\/beer_checkins?bid=18099&offset=25",
22
- # "http_code":200,
23
- # "results":
24
- # [
25
- # {
26
- # "user":
27
- # {
28
- # "user_name":"JJP1115",
29
- # "first_name":"Jim",
30
- # "last_name":"P.",
31
- # "user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=a0bb3b077c11e0c087e53212bf49ba49&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg",
32
- # "location":"Berkeley,
33
- # Illinois",
34
- # "bio":"",
35
- # "is_friends":null,
36
- # "url":"http:\/\/www.facebook.com\/#!\/JPerez1115"
37
- # },
38
- # "checkin_id":"610208",
39
- # "beer_id":"18099",
40
- # "brewery_id":"1204",
41
- # "beer_name":"Arrogant Bastard Ale",
42
- # "brewery_name":"Stone Brewing Co.",
43
- # "created_at":"Fri,
44
- # 08 Apr 2011 05:24:23 +0000",
45
- # "check_in_comment":"",
46
- # "checkin_link":"http:\/\/untappd.com\/user\/JJP1115\/checkin\/NUekq56",
47
- # "beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-arrogantBastardAle.jpg",
48
- # "venue_name":null,
49
- # "venue_id":null,
50
- # "venue_lat":null,
51
- # "venue_lng":null
52
- # },
16
+ puts "#{info.beer.beer_name} by #{info.beer.brewery.brewery_name}"
@@ -3,26 +3,25 @@ require 'rubygems'
3
3
  require 'untappd'
4
4
 
5
5
  Untappd.configure do |config|
6
- config.apikey = 'YOUR_API_KEY'
7
- config.gmt_offset = -5
6
+ config.client_id = 'YOUR_CLIENT_ID'
7
+ config.client_secret = 'YOUR_CLIENT_SECRET'
8
8
  end
9
9
 
10
- username = "cmar"
11
- password = "password"
10
+ access_token = 'YOUR_ACCESS_TOKEN'
12
11
 
13
- checkin = Untappd::Checkin.create(username, password, 4665,
14
- :foursquare_id => "4ad6bf91f964a520380821e3",
15
- :user_lat => "51.4718",
16
- :user_lng => "-0.489278")
12
+ Untappd::Checkin.create(access_token, -6, 'CST', 4665
13
+ :foursquare_id => "4ad6bf91f964a520380821e3",
14
+ :user_lat => "51.4718",
15
+ :user_lng => "-0.489278")
17
16
 
18
17
  puts checkin.inspect
19
18
 
20
19
 
21
- feed = Untappd::User.friend_feed(username, password)
20
+ feed = Untappd::User.friend_feed(access_token)
22
21
  puts feed.inspect
23
22
 
24
- comment = Untappd::Checkin.add_comment(username, password, 414882, "this is a test")
23
+ comment = Untappd::Checkin.add_comment(access_token, 414882, "this is a test")
25
24
  puts comment.inspect
26
25
 
27
- result = Untappd::Checkin.toast(username, password, 414882)
26
+ result = Untappd::Checkin.toggle_toast(access_token, 414882)
28
27
  puts result.inspect
@@ -1,12 +1,13 @@
1
- #list the recent checkins for Arrogant Bastard Ale
1
+ #list the recent checkins for username "cmar"
2
2
  require 'rubygems'
3
3
  require 'untappd'
4
4
 
5
5
  Untappd.configure do |config|
6
- config.apikey = 'YOUR_API_KEY'
6
+ config.client_id = 'YOUR_CLIENT_ID'
7
+ config.client_secret = 'YOUR_CLIENT_SECRET'
7
8
  end
8
9
 
9
10
  feed = Untappd::User.feed("cmar")
10
- feed.each do |f|
11
- puts "#{f.user.first_name} at #{f.created_at}"
11
+ feed.checkins.items.each do |f|
12
+ puts "#{f.beer.beer_name} from #{f.brewery.brewery_name} by #{f.user.first_name} at #{f.created_at}"
12
13
  end
@@ -1,6 +1,10 @@
1
1
  require 'rubygems'
2
2
 
3
+ require 'time'
4
+
5
+ require "untappd/config"
3
6
  require "untappd/base"
7
+ require "untappd/oauth"
4
8
  require "untappd/beer"
5
9
  require "untappd/user"
6
10
  require "untappd/venue"
@@ -8,27 +12,4 @@ require "untappd/brewery"
8
12
  require "untappd/checkin"
9
13
 
10
14
  module Untappd
11
- @@apikey = nil
12
- @@gmt_offset = 0
13
-
14
- def self.apikey
15
- @@apikey
16
- end
17
-
18
- def self.apikey=(apikey)
19
- @@apikey = apikey
20
- end
21
-
22
- def self.gmt_offset
23
- @@gmt_offset
24
- end
25
-
26
- def self.gmt_offset=(gmt_offset)
27
- @@gmt_offset = gmt_offset
28
- end
29
-
30
- def self.configure
31
- yield self
32
- end
33
-
34
15
  end
@@ -3,24 +3,26 @@ require 'hashie'
3
3
  require 'digest/md5'
4
4
 
5
5
  module Untappd
6
-
6
+
7
7
  class Base
8
8
  include HTTParty
9
- base_uri 'http://api.untappd.com/v3'
9
+ base_uri Untappd.config.base_uri
10
10
  format :json
11
-
11
+
12
12
  def self.response_to_mash(response)
13
13
  if response.code == 200
14
- Hashie::Mash.new(response).results
14
+ Hashie::Mash.new(response).response
15
15
  else
16
16
  Hashie::Mash.new {}
17
17
  end
18
18
  end
19
-
20
- def self.auth_hash(username, password)
21
- {:username => username,
22
- :password => Digest::MD5.hexdigest(password)}
19
+
20
+ def self.auth_options
21
+ {
22
+ :client_id => Untappd.config.client_id,
23
+ :client_secret => Untappd.config.client_secret
24
+ }
23
25
  end
24
26
  end
25
-
27
+
26
28
  end
@@ -1,56 +1,32 @@
1
1
  module Untappd
2
-
3
2
  class Beer < Base
4
-
5
- # since (optional) - The numeric ID of the last recent check-in. This provided to you in the next_query attribute.
6
- # offset (optional) - The offset that you like the dataset to begin with.
7
- # Each set returns 25 max records, so you can use that paginate the feed.
3
+ # options:
4
+ # * min_id (int, optional) - The numeric ID of the most recent check-in. This is provided to
5
+ # you in the next_query attribute.
6
+ # * max_id (int, optional) - The checkin ID that you want the results to start with
7
+ # * limit (int, optional) - The number of results to return, maximum of 50, default is 25
8
8
  def self.feed(beer_id, options={})
9
- options.merge!({
10
- :key => Untappd::apikey,
11
- :bid => beer_id
12
- })
13
-
14
- response_to_mash get("/beer_checkins", :query => options)
9
+ options.merge!(auth_options)
10
+ response = response_to_mash get("/beer/checkins/#{beer_id}", :query => options)
15
11
  end
16
-
17
- #
18
- def self.info(beer_id, options={})
19
- options.merge!({
20
- :key => Untappd::apikey,
21
- :bid => beer_id
22
- })
23
12
 
24
- response_to_mash get("/beer_info", :query => options)
13
+ def self.info(beer_id, options={})
14
+ options.merge!(auth_options)
15
+ response_to_mash get("/beer/info/#{beer_id}", :query => options)
25
16
  end
26
-
27
- # offset (optional) - The offset that you like the dataset to
28
- # begin with. Each set returns 25 max records, so you can use that paginate the results.
29
- # sort (optional): "count" or "name" (default) - This can let you choose if you
30
- # want the results to be returned in Alphabetical order (name) or by
31
- # checkin count (count). By default the search returns all values in Alphabetical order.
32
- def self.search(q, options={})
33
- options.merge!({
34
- :key => Untappd::apikey,
35
- :q => q
36
- })
37
17
 
38
- response_to_mash get("/beer_search", :query => options)
18
+ # options:
19
+ # * sort (optional): "count" or "name" (default) - This can let you choose if you want the
20
+ # results to be returned in Alphabetical order (name) or by checkin count (count). By default
21
+ # the search returns all values in Alphabetical order.
22
+ def self.search(q, options={})
23
+ options.merge!(auth_options)
24
+ options.merge!({ :q => q })
25
+ response_to_mash get("/search/beer/", :query => options)
39
26
  end
40
-
41
- # type (optional) - 4 options: "all", "macro", "micro", "local". "All" is set to default.
42
- # limit (optional) - The number of records that you will return (max 10)
43
- # age (optional) - 3 options: "daily", "weekly", "monthly".
44
- # geolat (optional) - The numeric Latitude to filter the public feed. This is required for local "type".
45
- # geolng (optional) - The numeric Longitude to filter the public feed. This is required for local "type".
46
- def self.trending(options={})
47
- options.merge!({
48
- :key => Untappd::apikey
49
- })
50
27
 
51
- response_to_mash get("/trending", :query => options)
28
+ def self.trending
29
+ response_to_mash get("/beer/trending", :query => auth_options)
52
30
  end
53
-
54
31
  end
55
-
56
32
  end