Skip to content

Commit 4c5558e

Browse files
darbyfreycmar
authored andcommitted
Updated examples and docs, cleaned up some code
1 parent f87c1e9 commit 4c5558e

File tree

11 files changed

+238
-257
lines changed

11 files changed

+238
-257
lines changed

README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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+
* 0.0.5 Brewery Info and Search
16+
* 0.0.4 Complete coverage of v3 API. Checkins, Comments, Toasts, gmt_offset configuration
17+
* 0.0.3 Venue Info & Feed, Trending Beer, Brewery Feed, Checkin info & Feed (the pub), Renamed Beer.checkins to Beer.feed
18+
* 0.0.2 User feed, distinct beers, info, badges, friends, wish list
19+
* 0.0.1 Beer Search, Info and Checkins
20+
21+
## API Coverage
22+
23+
**Beer Object**
24+
* Beer Feed - Untappd::Beer.feed(beer_id, options={})
25+
* Beer Info - Untappd::Beer.info(beer_id, options={})
26+
* Beer Search - Untappd::Beer.search(q, options={})
27+
* Trending - Untappd::Beer.trending
28+
29+
**User Object**
30+
* User Feed - Untappd::User.feed(username, options={})
31+
* User Info - Untappd::User.info(username)
32+
* User Badges - Untappd::User.badges(username, options={})
33+
* User Friends - Untappd::User.friends(username, options={})
34+
* User Wish List - Untappd::User.wish_list(username, options={})
35+
* User Distinct Beers - Untappd::User.distinct(username, options={})
36+
* Friend Feed - Untappd::User.friend_feed(access_token, options={})
37+
38+
**Venue Object**
39+
* Venue Feed - Untappd::Venue.feed(venue_id, options={})
40+
* Venue Info - Untappd::Venue.info(venue_id)
41+
42+
**Brewery Object**
43+
* Brewery Checkins - Untappd::Brewery.feed(brewery_id, options={})
44+
* Brewery Info - Untappd::Brewery.info(brewery_id)
45+
* Brewery Search - Untappd::Brewery.search(q)
46+
47+
**Checkin Object**
48+
* Checkin Info - Untappd::Checkin.info(checkin_id)
49+
* The Pub Feed - Untappd::Checkin.feed(options={})
50+
* Checkin - Untappd::Checkin.create(access_token, gmt_offset, timezone, beer_id, options={})
51+
* Add Comment - Untappd::Checkin.add_comment(access_token, checkin_id, comment)
52+
* Remove Comment - Untappd::Checkin.remove_comment(access_token, comment_id)
53+
* Toast/Remove Toast - Untappd::Checkin.toggle_toast(access_token, checkin_id)
54+
55+
**TODO**
56+
* Add To Wish List - /v4/user/wishlist/add
57+
* Remove From Wish List - /v4/user/wishlist/delete
58+
* Pending Friends - /v4/user/pending
59+
* Accept Friends - /v4/friend/accept/TARGET_ID
60+
* Reject Friends - /v4/friend/reject/TARGET_ID
61+
* Remove Friends - /v4/friend/remove/TARGET_ID
62+
* Request Friends - /v4/friend/request/TARGET_ID
63+
* Notifications - /v4/notifications
64+
* Foursquare Venue Lookup - /v4/venue/foursquare_lookup/VENUE_ID
65+
66+
## Examples
67+
68+
### Configuration
69+
70+
Add to your Gemfile
71+
72+
gem 'untappd'
73+
74+
Configure your API KEY
75+
76+
Untappd.configure do |config|
77+
config.client_id = 'YOUR_CLIENT_ID'
78+
config.client_secret = 'YOUR_CLIENT_SECRET'
79+
config.redirect_url = 'YOUR_OAUTH_REDIRECT_URL' # only if you're using OAuth
80+
config.gmt_offset = -5
81+
end
82+
83+
### OAuth
84+
85+
To generate an OAuth authentication request, simply call
86+
87+
Untappd::OAuth.authenticate_url
88+
89+
This will generate a URL that the user can access in order to authorize the application.
90+
It will look something like this:
91+
92+
=> "https://untappd.com/oauth/authenticate/?client_id=YOUR_CLIENT_ID&response_type=token&redirect_url=YOUR_OAUTH_REDIRECT_URL"
93+
94+
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.
95+
96+
### Examples
97+
98+
Get all the checkins for Arrogant Bastard Ale
99+
100+
checkins = Untappd::Beer.feed(18099) # or Untappd::User.feed("cmar")
101+
checkins.checkins.items.each do |checkin|
102+
puts "#{checkin.user.first_name} at #{checkin.created_at}"
103+
end
104+
105+
Create Checkin
106+
107+
#foursqure, lat, lng are optional
108+
Untappd::Checkin.create(ACCESS_TOKEN, -6, 'CST', 4665
109+
:foursquare_id => "4ad6bf91f964a520380821e3",
110+
:user_lat => "51.4718",
111+
:user_lng => "-0.489278")
112+
113+
Search for beers with the name Stone
114+
115+
beers = Untappd::Beer.search('stone')
116+
beers.beers.items.each do |beer|
117+
puts "#{beer.beer.beer_name}"
118+
end
119+
120+
Get extended info for Arrogant Bastard Ale
121+
122+
info = Untappd::Beer.info(18099)
123+
puts "#{info.beer.beer_name} by #{info.beer.brewery.brewery_name}"
124+
125+
All Methods can take additional options specified in the API
126+
127+
checkins = Untappd::Beer.feed(18099, :offset => 100)
128+
129+
beers = Untappd::Beer.search('stone', :sort => "count")
130+
131+
### Debugging
132+
You can dump any result to see what values are available with
133+
134+
info = Untappd::Beer.info(18099)
135+
puts info.inspect

README.rdoc

Lines changed: 0 additions & 118 deletions
This file was deleted.

examples/aba_checkins.rb

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,14 @@
33
require 'untappd'
44

55
Untappd.configure do |config|
6-
config.apikey = 'YOUR_API_KEY'
6+
config.client_id = 'YOUR_CLIENT_ID'
7+
config.client_secret = 'YOUR_CLIENT_SECRET'
78
end
89

910
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}"
1213
end
1314

1415
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}"

examples/checkin.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@
33
require 'untappd'
44

55
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'
88
end
99

10-
username = "cmar"
11-
password = "password"
10+
access_token = 'YOUR_ACCESS_TOKEN'
1211

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")
1716

1817
puts checkin.inspect
1918

2019

21-
feed = Untappd::User.friend_feed(username, password)
20+
feed = Untappd::User.friend_feed(access_token)
2221
puts feed.inspect
2322

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")
2524
puts comment.inspect
2625

27-
result = Untappd::Checkin.toast(username, password, 414882)
26+
result = Untappd::Checkin.toggle_toast(access_token, 414882)
2827
puts result.inspect

examples/user_feed.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
#list the recent checkins for Arrogant Bastard Ale
1+
#list the recent checkins for username "cmar"
22
require 'rubygems'
33
require 'untappd'
44

55
Untappd.configure do |config|
6-
config.apikey = 'YOUR_API_KEY'
6+
config.client_id = 'YOUR_CLIENT_ID'
7+
config.client_secret = 'YOUR_CLIENT_SECRET'
78
end
89

910
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}"
1213
end

0 commit comments

Comments
 (0)