untappd-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
6
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in untappd-api.gemspec
4
+ gemspec
@@ -0,0 +1,16 @@
1
+ = untappd-api
2
+ A simple Ruby wrapper for accessing the Untappd API.
3
+
4
+ For more information, see http://untappd.com/api/dashboard.
5
+
6
+ == Usage
7
+ Each method returns a Hashie::Mash (an extended Hash that gives object-like access, see https://github.com/intridea/hashie) or an Array of Hashie::Mash.
8
+
9
+ === Example:
10
+ require 'untappd-api'
11
+
12
+ client = Untappd::Base.new("gambrinus", PASSWORD, API_KEY)
13
+ client.user.first_name #=> "Jeff"
14
+ beer = client.beer_info(:bid => 17904)
15
+ beer.name #=> "Third Coast Old Ale"
16
+ beer.brewery #=> "Bell's Brewery, Inc."
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,146 @@
1
+ require 'httparty'
2
+ require 'hashie'
3
+ require 'digest/md5'
4
+
5
+ Hash.send :include, Hashie::HashExtensions
6
+
7
+ module Untappd
8
+ class Base
9
+ include HTTParty
10
+ BASE_URI = 'http://api.untappd.com/v2'
11
+ base_uri BASE_URI
12
+
13
+ def initialize(user, pass, key)
14
+ @auth = { :username => user, :password => Digest::MD5.hexdigest(pass) }
15
+ @key = key
16
+ end
17
+
18
+ # Get extended information about a beer.
19
+ # Params:
20
+ # :bid => The numeric beer ID of the beer you wish to look up.
21
+ def beer_info(params={})
22
+ get('beer_info', params)
23
+ end
24
+
25
+ # Get a list of matching beers.
26
+ # Params:
27
+ # :q => Name of the beer you wish to search for.
28
+ def beer_search(params={})
29
+ get('beer_search', params)
30
+ end
31
+
32
+ # Get extended details for a particular checkin,
33
+ # which includes location, comments and toasts.
34
+ # Params:
35
+ # :id => The numeric ID of the check-in.
36
+ def checkin_details(params={})
37
+ get('details', params)
38
+ end
39
+
40
+ # Get the friend check-in feed of the authenticated user.
41
+ # Params:
42
+ # :since => The numeric ID of the last recent check-in. (Optional)
43
+ # :offset => The offset that you like the dataset to begin with. (Optional)
44
+ def friend_feed(params={})
45
+ get('feed', params)
46
+ end
47
+
48
+ # Get the public feed for Untappd.
49
+ # Params:
50
+ # :latitude => The numeric Latitude to filter the public feed. (Optional)
51
+ # :longitude => The numeric Longitude to filter the public feed. (Optional)
52
+ # :since => The numeric ID of the last recent check-in. (Optional)
53
+ # :offset => The offset that you like the dataset to begin with. (Optional)
54
+ def public_feed(params={})
55
+ get('thepub', params)
56
+ end
57
+
58
+ # Get the user information for a selected user.
59
+ # Params:
60
+ # :user => The username of the person who you wish to obtain the user information. (Optional)
61
+ def user(params={})
62
+ result = get('user', params)
63
+ result.user unless result.nil?
64
+ end
65
+
66
+ # Get a list of the user's badges.
67
+ # Params:
68
+ # :user => The username of the person who you wish to obtain the user information. (Optional)
69
+ # :sort => Filters the badge list by type: "beer", "venue", or "special". (Optional)
70
+ def user_badges(params={})
71
+ get('user_badge', params)
72
+ end
73
+
74
+ # Get the user's distinct beers.
75
+ # Params:
76
+ # :user => The username that you wish to call the request upon. (Optional)
77
+ # :offset => The offset that you like the dataset to begin with. (Optional)
78
+ def user_distinct_beers(params={})
79
+ get('user_distinct', params)
80
+ end
81
+
82
+ # Get the friend check-in feed of the selected user.
83
+ # Params:
84
+ # :user => The username that you wish to call the request upon. (Optional)
85
+ # :since => The numeric ID of the last recent check-in. (Optional)
86
+ # :offset => The offset that you like the dataset to begin with. (Optional)
87
+ def user_feed(params={})
88
+ get('user_feed', params)
89
+ end
90
+
91
+ # Get a list of the user's friends.
92
+ # Params:
93
+ # :user => The username that you wish to call the request upon. (Optional)
94
+ # :offset => The offset that you like the dataset to begin with. (Optional)
95
+ def user_friends(params={})
96
+ get('friends', params)
97
+ end
98
+
99
+ # Get the user's wish listed beers.
100
+ # Params:
101
+ # :user => The username that you wish to call the request upon. (Optional)
102
+ # :offset => The offset that you like the dataset to begin with. (Optional)
103
+ def user_wish_list(params={})
104
+ get('wish_list', params)
105
+ end
106
+
107
+ private
108
+
109
+ def get(method, params={})
110
+ path = "/#{method}?key=#{@key}"
111
+ params.each { |k,v| path += "&#{k.to_s}=#{v.to_s}" }
112
+
113
+ options = {:basic_auth => @auth}
114
+ response = self.class.get(URI.escape(path), options)
115
+ raise_errors(response)
116
+
117
+ response.parsed_response.to_mash.results
118
+ end
119
+
120
+ def raise_errors(response)
121
+ message = "#{response.body} - #{BASE_URI}#{response.request.path}"
122
+
123
+ case response.code
124
+ when 400
125
+ raise BadRequest, message
126
+ when 401
127
+ raise Unauthorized, message
128
+ when 403
129
+ raise General, message
130
+ when 404
131
+ raise NotFound, message
132
+ when 500
133
+ raise InternalError, message
134
+ when 501..503
135
+ raise Unavailable, message
136
+ end
137
+ end
138
+ end
139
+
140
+ class BadRequest < StandardError; end
141
+ class Unauthorized < StandardError; end
142
+ class General < StandardError; end
143
+ class Unavailable < StandardError; end
144
+ class InternalError < StandardError; end
145
+ class NotFound < StandardError; end
146
+ end
@@ -0,0 +1,3 @@
1
+ module Untappd
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,103 @@
1
+ require 'untappd-api'
2
+
3
+ describe Untappd::Base do
4
+ before do
5
+ @user = "YOUR_USERNAME"
6
+ pass = "YOUR_PASSWORD"
7
+ key = "YOUR_KEY"
8
+ @client = Untappd::Base.new(@user, pass, key)
9
+ end
10
+
11
+ describe "beer_info method" do
12
+ it "should find the correct beer" do
13
+ beer_name = "Hocus Pocus"
14
+ @client.beer_info(:bid => 1).name.should == beer_name
15
+ end
16
+
17
+ it "should raise Unauthorized exception with bad parameters" do
18
+ expect {
19
+ @client.beer_info
20
+ }.to raise_exception(Untappd::Unauthorized, /You must provide a beer id to continue/)
21
+ end
22
+ end
23
+
24
+ describe "beer_search method" do
25
+ it "should return an Array of search results" do
26
+ @client.beer_search(:q => "Devil").size.should >= 0
27
+ end
28
+
29
+ it "should raise Unavailable exception with bad parameters" do
30
+ expect {
31
+ @client.beer_search
32
+ }.to raise_exception(Untappd::Unavailable, /You have not passed anything to search/)
33
+ end
34
+ end
35
+
36
+ describe "checkin_details method" do
37
+ it "should return the checkin details for given checkin id" do
38
+ pending("Checkin id is currently not exposed.")
39
+ end
40
+
41
+ it "should raise Unauthorized exception with bad parameters" do
42
+ expect {
43
+ @client.checkin_details
44
+ }.to raise_exception(Untappd::Unauthorized, /You must provide a check-in ID to continue/)
45
+ end
46
+ end
47
+
48
+ describe "friend_feed method" do
49
+ it "should return the authenticated user's friend feed" do
50
+ @client.friend_feed.size.should >= 0
51
+ end
52
+ end
53
+
54
+ describe "public_feed method" do
55
+ it "should return the public feed" do
56
+ @client.public_feed.size.should >= 0
57
+ end
58
+ end
59
+
60
+ describe "user method" do
61
+ it "should return the authenticated user if no user specified" do
62
+ @client.user.user_name.should == @user
63
+ end
64
+
65
+ it "should return the specified user if user parameter is set" do
66
+ @client.user(:user => "gambrinus").user_name.should == "gambrinus"
67
+ end
68
+
69
+ it "should return nil if the specified user is not found" do
70
+ @client.user(:user => ".....").should be_nil
71
+ end
72
+ end
73
+
74
+ describe "user_badges method" do
75
+ it "should return the authenticated user's badges" do
76
+ @client.user_badges.size.should >= 0
77
+ end
78
+ end
79
+
80
+ describe "user_distinct_beers method" do
81
+ it "should return the authenticated user's distinct beers" do
82
+ @client.user_distinct_beers.size.should >= 0
83
+ end
84
+ end
85
+
86
+ describe "user_feed method" do
87
+ it "should return the authenticated user's feed" do
88
+ @client.user_feed.size.should >= 0
89
+ end
90
+ end
91
+
92
+ describe "user_friends method" do
93
+ it "should return the authenticated user's friends" do
94
+ @client.user_friends.size.should >= 0
95
+ end
96
+ end
97
+
98
+ describe "user_wish_list method" do
99
+ it "should return the authenticated user's wish list" do
100
+ @client.user_wish_list.size.should >= 0
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "untappd-api/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "untappd-api"
7
+ s.version = Untappd::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jeff Smith"]
10
+ s.email = ["jffreyjs@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Ruby wrapper for the untappd API.}
13
+ s.description = %q{Ruby wrapper for the untappd API.}
14
+
15
+ s.rubyforge_project = "untappd-api"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ s.specification_version = 3
24
+
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']
27
+ s.add_dependency %q<httparty>, ['~> 0.7.4']
28
+ s.add_dependency %q<hashie>, ['~> 1.0.0']
29
+ else
30
+ s.add_dependency %q<rspec>, ['~> 2.0.0.beta.22']
31
+ s.add_dependency %q<httparty>, ['~> 0.7.4']
32
+ s.add_dependency %q<hashie>, ['~> 1.0.0']
33
+ end
34
+ else
35
+ s.add_dependency %q<rspec>, ['~> 2.0.0.beta.22']
36
+ s.add_dependency %q<httparty>, ['~> 0.7.4']
37
+ s.add_dependency %q<hashie>, ['~> 1.0.0']
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: untappd-api
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jeff Smith
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-20 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 0
32
+ - beta
33
+ - 22
34
+ version: 2.0.0.beta.22
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: httparty
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 0
47
+ - 7
48
+ - 4
49
+ version: 0.7.4
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: hashie
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 1
62
+ - 0
63
+ - 0
64
+ version: 1.0.0
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ description: Ruby wrapper for the untappd API.
68
+ email:
69
+ - jffreyjs@gmail.com
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ extra_rdoc_files: []
75
+
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - README.rdoc
80
+ - Rakefile
81
+ - lib/untappd-api.rb
82
+ - lib/untappd-api/version.rb
83
+ - spec/untappd-api_spec.rb
84
+ - untappd-api.gemspec
85
+ has_rdoc: true
86
+ homepage: ""
87
+ licenses: []
88
+
89
+ post_install_message:
90
+ rdoc_options: []
91
+
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirements: []
111
+
112
+ rubyforge_project: untappd-api
113
+ rubygems_version: 1.3.7
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Ruby wrapper for the untappd API.
117
+ test_files: []
118
+