gowalla 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gowalla.rb CHANGED
@@ -10,7 +10,7 @@ Hash.send :include, Hashie::HashExtensions
10
10
 
11
11
  module Gowalla
12
12
 
13
- VERSION = "0.2.1".freeze
13
+ VERSION = "0.3.0".freeze
14
14
 
15
15
  # config/initializers/gowalla.rb (for instance)
16
16
  #
@@ -33,6 +33,11 @@ module Gowalla
33
33
  attr_accessor :username
34
34
  attr_accessor :password
35
35
  attr_accessor :api_secret
36
+ attr_accessor :test_mode
37
+
38
+ def test_mode?
39
+ !!self.test_mode
40
+ end
36
41
  end
37
42
 
38
43
  end
@@ -87,6 +87,29 @@ module Gowalla
87
87
  connection.get("/spots/#{spot_id}/items").body.items
88
88
  end
89
89
 
90
+ # Retrieve a list of flags for a particular spot
91
+ #
92
+ # @param [Integer] spot_id Spot ID
93
+ # @return [Hashie::Mash] Array of Flags
94
+ def spot_flags(spot_id)
95
+ connection.get("/spots/#{spot_id}/flags").body.flags
96
+ end
97
+
98
+ # Retrieve a list of flags
99
+ #
100
+ # @return [<Hashie::Mash>] Flag info
101
+ def list_flags(options={})
102
+ connection.get("/flags").body.flags
103
+ end
104
+
105
+ # Retrieve information about a particular flag
106
+ #
107
+ # @param [Integer] flag_id Flag ID
108
+ # @return [Hashie::Mash] Flag info
109
+ def flag(flag_id)
110
+ connection.get("/flags/#{flag_id}").body
111
+ end
112
+
90
113
  # Retrieve a list of spots within a specified distance of a location
91
114
  #
92
115
  # @option options [Float] :latitude Latitude of search location
@@ -130,6 +153,32 @@ module Gowalla
130
153
  connection.get("/categories/#{id}").body
131
154
  end
132
155
 
156
+ # Fetch info for a checkin
157
+ #
158
+ # @param [Integer] id Checkin ID
159
+ # @return [Hashie::Mash] checkin info
160
+ def checkin_info(id)
161
+ connection.get("/checkins/#{id}").body
162
+ end
163
+
164
+ # Check in at a spot
165
+ #
166
+ # @option details [Integer] :spot_id Spot ID
167
+ # @option details [Float] :lat Latitude of spot
168
+ # @option details [Float] :lng Longitude of spot
169
+ # @option details [String] :comment Checkin comment
170
+ # @option details [Boolean] :post_to_twitter Post Checkin to Twitter
171
+ # @option details [Boolean] :post_to_facebook Post Checkin to Facebook
172
+ def checkin(details={})
173
+ checkin_path = "/checkins"
174
+ checkin_path += "/test" if Gowalla.test_mode?
175
+ response = connection.post do |req|
176
+ req.url checkin_path
177
+ req.body = details
178
+ end
179
+ response.body
180
+ end
181
+
133
182
  # Check for missing access token
134
183
  #
135
184
  # @return [Boolean] whether or not to redirect to get an access token
data/test/gowalla_test.rb CHANGED
@@ -58,6 +58,15 @@ class GowallaTest < Test::Unit::TestCase
58
58
  category = @client.category(1)
59
59
  category.name.should == 'Coffee Shop'
60
60
  end
61
+
62
+ should "retrieve flags associated with that spot" do
63
+ stub_get("http://pengwynn:0U812@api.gowalla.com/spots/1/flags", "flags.json")
64
+ flags = @client.spot_flags(1)
65
+ flags.first.spot.name.should == 'Wild Gowallaby #1'
66
+ flags.first.user.url.should == '/users/340897'
67
+ flags.first[:type].should == 'invalid'
68
+ flags.first.status.should == 'open'
69
+ end
61
70
  end
62
71
 
63
72
  context "and working with Users" do
@@ -113,6 +122,34 @@ class GowallaTest < Test::Unit::TestCase
113
122
  end
114
123
  end
115
124
 
125
+ context "and working with Flags" do
126
+ should "retrieve a list of flags" do
127
+ stub_get("http://pengwynn:0U812@api.gowalla.com/flags", "flags.json")
128
+ flags = @client.list_flags
129
+ flags.first.spot.name.should == 'Wild Gowallaby #1'
130
+ flags.first.user.url.should == '/users/340897'
131
+ flags.first[:type].should == 'invalid'
132
+ flags.first.status.should == 'open'
133
+ end
134
+
135
+ should "retrieve information about a specific flag" do
136
+ stub_get("http://pengwynn:0U812@api.gowalla.com/flags/1", "flag.json")
137
+ flag = @client.flag(1)
138
+ flag.spot.name.should == 'Wild Gowallaby #1'
139
+ flag.user.url.should == '/users/340897'
140
+ flag[:type].should == 'invalid'
141
+ flag.status.should == 'open'
142
+ end
143
+ end
144
+
145
+ context "and working with checkins" do
146
+ should "fetch info for a checkin" do
147
+ stub_get("http://pengwynn:0U812@api.gowalla.com/checkins/88", "checkin.json")
148
+ checkin = @client.checkin_info(88)
149
+ checkin.spot.name.should == 'Movie Tavern'
150
+ checkin.message.should == 'There sending us Back-- to the Future!'
151
+ end
152
+ end
116
153
  end
117
154
 
118
155
  context "when using basic auth" do
@@ -132,6 +169,19 @@ class GowallaTest < Test::Unit::TestCase
132
169
 
133
170
  @client.username.should == 'username'
134
171
  end
172
+
173
+ should "configure test mode" do
174
+ Gowalla.configure do |config|
175
+ config.api_key = 'api_key'
176
+ config.api_secret = nil
177
+ config.username = 'username'
178
+ config.password = 'password'
179
+ config.test_mode = true
180
+ end
181
+
182
+ Gowalla.test_mode?.should == true
183
+
184
+ end
135
185
  end
136
186
 
137
187
  context "when using OAuth2" do
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Wynn Netherland
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-26 00:00:00 -05:00
17
+ date: 2010-08-09 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency