gowalla 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gowalla.rb +2 -1
- data/lib/gowalla/client.rb +25 -42
- data/test/gowalla_test.rb +0 -4
- metadata +15 -3
data/lib/gowalla.rb
CHANGED
@@ -2,6 +2,7 @@ require 'hashie'
|
|
2
2
|
require 'faraday'
|
3
3
|
require 'multi_json'
|
4
4
|
require 'oauth2'
|
5
|
+
require 'faraday_middleware'
|
5
6
|
|
6
7
|
directory = File.expand_path(File.dirname(__FILE__))
|
7
8
|
|
@@ -9,7 +10,7 @@ Hash.send :include, Hashie::HashExtensions
|
|
9
10
|
|
10
11
|
module Gowalla
|
11
12
|
|
12
|
-
VERSION = "0.2.
|
13
|
+
VERSION = "0.2.1".freeze
|
13
14
|
|
14
15
|
# config/initializers/gowalla.rb (for instance)
|
15
16
|
#
|
data/lib/gowalla/client.rb
CHANGED
@@ -15,6 +15,7 @@ module Gowalla
|
|
15
15
|
@access_token = options[:access_token]
|
16
16
|
password = options[:password] || Gowalla.password
|
17
17
|
connection.basic_auth(@username, password) unless @api_secret
|
18
|
+
connection.token_auth(@access_token) if @access_token
|
18
19
|
end
|
19
20
|
|
20
21
|
# Retrieve information about a specific user
|
@@ -23,7 +24,7 @@ module Gowalla
|
|
23
24
|
# @return [Hashie::Mash] User info
|
24
25
|
def user(user_id=nil)
|
25
26
|
user_id ||= username
|
26
|
-
|
27
|
+
connection.get("/users/#{user_id}").body
|
27
28
|
end
|
28
29
|
|
29
30
|
# Retrieve information about a specific item
|
@@ -31,7 +32,7 @@ module Gowalla
|
|
31
32
|
# @param [Integer] id Item ID
|
32
33
|
# @return [Hashie::Mash] item info
|
33
34
|
def item(id)
|
34
|
-
|
35
|
+
connection.get("/items/#{id}").body
|
35
36
|
end
|
36
37
|
|
37
38
|
# Retrieve a list of the stamps the user has collected
|
@@ -43,7 +44,7 @@ module Gowalla
|
|
43
44
|
response = connection.get do |req|
|
44
45
|
req.url "/users/#{user_id}/stamps", :limit => limit
|
45
46
|
end
|
46
|
-
|
47
|
+
response.body.stamps
|
47
48
|
end
|
48
49
|
|
49
50
|
# Retrieve a list of spots the user has visited most often
|
@@ -51,7 +52,7 @@ module Gowalla
|
|
51
52
|
# @param [String] user_id (authenticated basic auth user) User ID (screen name)
|
52
53
|
# @return [Hashie::Mash] item info
|
53
54
|
def top_spots(user_id=self.username)
|
54
|
-
|
55
|
+
connection.get("/users/#{user_id}/top_spots").body.top_spots
|
55
56
|
end
|
56
57
|
|
57
58
|
# Retrieve information about a specific trip
|
@@ -59,7 +60,7 @@ module Gowalla
|
|
59
60
|
# @param [Integer] trip_id Trip ID
|
60
61
|
# @return [Hashie::Mash] trip info
|
61
62
|
def trip(trip_id)
|
62
|
-
|
63
|
+
connection.get("/trips/#{trip_id}").body
|
63
64
|
end
|
64
65
|
|
65
66
|
# Retrieve information about a specific spot
|
@@ -67,7 +68,7 @@ module Gowalla
|
|
67
68
|
# @param [Integer] spot_id Spot ID
|
68
69
|
# @return [Hashie::Mash] Spot info
|
69
70
|
def spot(spot_id)
|
70
|
-
|
71
|
+
connection.get("/spots/#{spot_id}").body
|
71
72
|
end
|
72
73
|
|
73
74
|
# Retrieve a list of check-ins at a particular spot. Shows only the activity that is visible to a given user.
|
@@ -75,7 +76,7 @@ module Gowalla
|
|
75
76
|
# @param [Integer] spot_id Spot ID
|
76
77
|
# @return [Hashie::Mash] Spot info
|
77
78
|
def spot_events(spot_id)
|
78
|
-
|
79
|
+
connection.get("/spots/#{spot_id}/events").body.activity
|
79
80
|
end
|
80
81
|
|
81
82
|
# Retrieve a list of items available at a particular spot
|
@@ -83,7 +84,7 @@ module Gowalla
|
|
83
84
|
# @param [Integer] spot_id Spot ID
|
84
85
|
# @return [Hashie::Mash] Spot info
|
85
86
|
def spot_items(spot_id)
|
86
|
-
|
87
|
+
connection.get("/spots/#{spot_id}/items").body.items
|
87
88
|
end
|
88
89
|
|
89
90
|
# Retrieve a list of spots within a specified distance of a location
|
@@ -97,7 +98,7 @@ module Gowalla
|
|
97
98
|
response = connection.get do |req|
|
98
99
|
req.url "/spots", query
|
99
100
|
end
|
100
|
-
|
101
|
+
response.body.spots
|
101
102
|
end
|
102
103
|
|
103
104
|
# List of trips
|
@@ -111,14 +112,14 @@ module Gowalla
|
|
111
112
|
response = connection.get do |req|
|
112
113
|
req.url "/trips", query
|
113
114
|
end
|
114
|
-
|
115
|
+
response.body.trips
|
115
116
|
end
|
116
117
|
|
117
118
|
# Lists all spot categories
|
118
119
|
#
|
119
120
|
# @return [<Hashie::Mash>] category info
|
120
121
|
def categories
|
121
|
-
|
122
|
+
connection.get("/categories").body.spot_categories
|
122
123
|
end
|
123
124
|
|
124
125
|
# Retrieve information about a specific category
|
@@ -126,7 +127,7 @@ module Gowalla
|
|
126
127
|
# @param [Integer] id Category ID
|
127
128
|
# @return [Hashie::Mash] category info
|
128
129
|
def category(id)
|
129
|
-
|
130
|
+
connection.get("/categories/#{id}").body
|
130
131
|
end
|
131
132
|
|
132
133
|
# Check for missing access token
|
@@ -136,20 +137,19 @@ module Gowalla
|
|
136
137
|
@api_secret and @access_token.to_s == ''
|
137
138
|
end
|
138
139
|
|
139
|
-
# Raw HTTP connection, either Faraday::Connection
|
140
|
+
# Raw HTTP connection, either Faraday::Connection
|
140
141
|
#
|
141
|
-
# @return [
|
142
|
+
# @return [Faraday::Connection]
|
142
143
|
def connection
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
:url => "http://api.gowalla.com",
|
151
|
-
:headers => headers
|
144
|
+
url = @access_token ? "https://api.gowalla.com" : "http://api.gowalla.com"
|
145
|
+
params = {}
|
146
|
+
params[:access_token] = @access_token if @access_token
|
147
|
+
@connection ||= Faraday::Connection.new(:url => url, :params => params, :headers => default_headers) do |builder|
|
148
|
+
builder.adapter Faraday.default_adapter
|
149
|
+
builder.use Faraday::Response::MultiJson
|
150
|
+
builder.use Faraday::Response::Mashify
|
152
151
|
end
|
152
|
+
|
153
153
|
end
|
154
154
|
|
155
155
|
# Provides raw access to the OAuth2 Client
|
@@ -189,28 +189,11 @@ module Gowalla
|
|
189
189
|
def default_headers
|
190
190
|
headers = {
|
191
191
|
:accept => 'application/json',
|
192
|
-
:user_agent => 'Ruby gem'
|
192
|
+
:user_agent => 'Ruby gem',
|
193
|
+
'X-Gowalla-API-Key' => api_key
|
193
194
|
}
|
194
195
|
end
|
195
196
|
|
196
|
-
# @private
|
197
|
-
def handle_response(response)
|
198
|
-
case response.status
|
199
|
-
when 200
|
200
|
-
body = response.respond_to?(:body) ? response.body : response
|
201
|
-
data = MultiJson.decode(body)
|
202
|
-
if data.is_a?(Hash)
|
203
|
-
Hashie::Mash.new(data)
|
204
|
-
else
|
205
|
-
if data.first.is_a?(Hash)
|
206
|
-
data.map{|item| Hashie::Mash.new(item)}
|
207
|
-
else
|
208
|
-
data
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
197
|
|
215
198
|
end
|
216
199
|
|
data/test/gowalla_test.rb
CHANGED
@@ -154,10 +154,6 @@ class GowallaTest < Test::Unit::TestCase
|
|
154
154
|
@client.oauth_client.class.to_s.should == "OAuth2::Client"
|
155
155
|
end
|
156
156
|
|
157
|
-
should "create an OAuth2 connection" do
|
158
|
-
@client.connection.class.to_s.should == "OAuth2::AccessToken"
|
159
|
-
end
|
160
|
-
|
161
157
|
should "indicate if it needs an access_token" do
|
162
158
|
@client.needs_access?.should == true
|
163
159
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Wynn Netherland
|
@@ -73,6 +73,18 @@ dependencies:
|
|
73
73
|
type: :runtime
|
74
74
|
- !ruby/object:Gem::Dependency
|
75
75
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
name: faraday-middleware
|
83
|
+
prerelease: false
|
84
|
+
requirement: *id005
|
85
|
+
type: :runtime
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
76
88
|
requirements:
|
77
89
|
- - ~>
|
78
90
|
- !ruby/object:Gem::Version
|
@@ -83,7 +95,7 @@ dependencies:
|
|
83
95
|
version: 2.10.0
|
84
96
|
name: shoulda
|
85
97
|
prerelease: false
|
86
|
-
requirement: *
|
98
|
+
requirement: *id006
|
87
99
|
type: :development
|
88
100
|
description: Ruby wrapper for the Gowalla API
|
89
101
|
email: wynn.netherland@gmail.com
|