whatser 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/.document +5 -0
  2. data/Gemfile +12 -0
  3. data/Gemfile.lock +34 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +310 -0
  6. data/Rakefile +53 -0
  7. data/VERSION +1 -0
  8. data/lib/whatser/api/batch.rb +0 -0
  9. data/lib/whatser/api/facebook.rb +13 -0
  10. data/lib/whatser/api/foursquare.rb +5 -0
  11. data/lib/whatser/api/gowalla.rb +5 -0
  12. data/lib/whatser/api/response.rb +84 -0
  13. data/lib/whatser/api/service.rb +15 -0
  14. data/lib/whatser/api/twitter.rb +13 -0
  15. data/lib/whatser/client.rb +54 -0
  16. data/lib/whatser/configuration.rb +15 -0
  17. data/lib/whatser/errors.rb +4 -0
  18. data/lib/whatser/net/http.rb +26 -0
  19. data/lib/whatser/net/oauth.rb +41 -0
  20. data/lib/whatser/resources/activity_feed.rb +20 -0
  21. data/lib/whatser/resources/check_in.rb +25 -0
  22. data/lib/whatser/resources/city.rb +16 -0
  23. data/lib/whatser/resources/collection.rb +68 -0
  24. data/lib/whatser/resources/data_source.rb +24 -0
  25. data/lib/whatser/resources/detail.rb +40 -0
  26. data/lib/whatser/resources/follow.rb +42 -0
  27. data/lib/whatser/resources/media.rb +41 -0
  28. data/lib/whatser/resources/poi.rb +74 -0
  29. data/lib/whatser/resources/resource.rb +53 -0
  30. data/lib/whatser/resources/review.rb +40 -0
  31. data/lib/whatser/resources/subscription.rb +12 -0
  32. data/lib/whatser/resources/tag.rb +32 -0
  33. data/lib/whatser/resources/user.rb +81 -0
  34. data/lib/whatser.rb +38 -0
  35. data/test/helper.rb +25 -0
  36. data/test/test_activity_feed.rb +20 -0
  37. data/test/test_check_in.rb +28 -0
  38. data/test/test_city.rb +16 -0
  39. data/test/test_client.rb +84 -0
  40. data/test/test_collection.rb +28 -0
  41. data/test/test_configuration.rb +26 -0
  42. data/test/test_data_source.rb +35 -0
  43. data/test/test_detail.rb +38 -0
  44. data/test/test_facebook.rb +7 -0
  45. data/test/test_follow.rb +33 -0
  46. data/test/test_foursquare.rb +7 -0
  47. data/test/test_gowalla.rb +7 -0
  48. data/test/test_hondius.rb +12 -0
  49. data/test/test_http.rb +40 -0
  50. data/test/test_oauth.rb +37 -0
  51. data/test/test_poi.rb +75 -0
  52. data/test/test_resource.rb +73 -0
  53. data/test/test_response.rb +44 -0
  54. data/test/test_review.rb +37 -0
  55. data/test/test_subscription.rb +11 -0
  56. data/test/test_tag.rb +32 -0
  57. data/test/test_twitter.rb +7 -0
  58. data/test/test_user.rb +53 -0
  59. data/whatser.gemspec +140 -0
  60. metadata +236 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'httparty'
4
+ gem 'oauth2'
5
+ gem 'json'
6
+
7
+
8
+ group :development do
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.5.1"
11
+ gem "rcov", ">= 0"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.1)
5
+ crack (0.1.8)
6
+ faraday (0.4.6)
7
+ addressable (>= 2.1.1)
8
+ rack (>= 1.0.1)
9
+ git (1.2.5)
10
+ httparty (0.6.1)
11
+ crack (= 0.1.8)
12
+ jeweler (1.5.1)
13
+ bundler (~> 1.0.0)
14
+ git (>= 1.2.5)
15
+ rake
16
+ json (1.4.6)
17
+ multi_json (0.0.4)
18
+ oauth2 (0.0.13)
19
+ faraday (~> 0.4.1)
20
+ multi_json (>= 0.0.4)
21
+ rack (1.2.1)
22
+ rake (0.8.7)
23
+ rcov (0.9.8)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.0.0)
30
+ httparty
31
+ jeweler (~> 1.5.1)
32
+ json
33
+ oauth2
34
+ rcov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Travis Dunn / Whatser Company
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,310 @@
1
+ = Whatser Gem
2
+
3
+ The 'Whatser API' Gem is a simple Ruby / Rails wrapper for interacting with Whatser's location-based web services (see http://docs.sogeoapi.com for more details).
4
+
5
+ == Overview
6
+
7
+ * read/write API access
8
+ * OAuth 2 authentication (using oauth2)
9
+ * network connectivity (using httparty)
10
+ * simple DSL for API resource classes (spots, media, reviews, check ins, etc.)
11
+ * user spot collection management
12
+ * social network integration (facebook, twitter, foursquare, gowalla)
13
+ * photo uploads
14
+
15
+ == Usage
16
+
17
+ === 0. Register your application with the Whatser API
18
+
19
+ In order to use the Whatser Gem, you'll need to register for a Whatser user account (https://production-2.sogeoapi.com/oauth/user/new), and create a client application for that user which will then give you an application key and secret (https://production-2.sogeoapi.com/oauth/user/client_applications/new).
20
+
21
+ Once you have your key and secret, you can start using the gem by instantiating a Whatser client with those credentials:
22
+
23
+ === 1. Instantiate a Client (on demand or with default configuration)
24
+
25
+ Declare Whatser in your Gemfile:
26
+
27
+ gem 'whatser', :git => "git@github.com:sogeo/whatser"
28
+
29
+ And instantiate a Whatser client as need:
30
+
31
+ client = Whatser::Client.new(:api_key => 'key', :api_secret => 'secret', :oauth_token => '123abc')
32
+
33
+ or...
34
+
35
+ Whatser::Client.configure do |config|
36
+ config.api_key = 'key'
37
+ config.api_secret = 'secret'
38
+ end
39
+ client1 = Whatser::Client.new( :oauth_token => '123abc' )
40
+ client2 = Whatser::Client.new( :oauth_token => '789xyz' )
41
+
42
+ === 2. Authenticate a User
43
+
44
+ Nearly every API call must be performed in the context of a user, and users authenticate with the API by using an oauth token.
45
+
46
+ If you don't already have an oauth token for your user, you can get one by following the standard OAuth 2 web server flow (http://tools.ietf.org/html/draft-ietf-oauth-v2-10).
47
+
48
+ First, redirect your user to the Whatser website where they will be presented with a login screen and a dialog to authorize your application to access their Whatser account. In a Rails controller, the command would likely look as follows. e.g.
49
+
50
+ redirect_to Whatser.client.oauth_authorize_url( :redirect_uri => 'https://example.com/callback' )
51
+
52
+ Second, you'll need a controller action on your web app to which the Whatser API will redirect the user after they complete the authorization process. Within this action, you'll need to capture the access token parameter and use to obtain a user oauth token, after which the authorization will be complete, and you may begin accessing the API with your user. e.g.
53
+
54
+ def oauth_callback
55
+ code = params[:access_token]
56
+ session[:oauth_token] = Whatser.client.get_oauth_token(code, :redirect_uri => 'https://example.com/callback').token
57
+ end
58
+
59
+ Note, you should store your user's oauth token so it can be used to instantiate Whatser client sessions as needed.
60
+
61
+ === 3. Access the API
62
+
63
+ Once you have an oauth token for a user, you can access the Whatser API by instantiating a Whatser client and making calls using the Whatser resource classes. e.g.
64
+
65
+ client = Whatser::Client.new( :oauth_token => '123abc' )
66
+ client.authorized?
67
+ authenticated_user = client.user.me
68
+ spots = client.spots.search(:geo => "52.3665312,4.8931739", :text => "pizza", :per_page => 30).data
69
+ spots.each { |spot| spot.tag('my tag') }
70
+ a_spot = client.spots.find(12345).data
71
+ my_spot = client.spots.create(:name => 'work', :street => 'main street', 'city' => 'metropolis').data
72
+ new_spot = client.spots.new(:name => 'work', :street => 'main street', 'city' => 'metropolis')
73
+ new_spot.save
74
+ new_spot.delete
75
+
76
+ Responses from the API are wrapped in the Whatser::Response class, allowing you to inspect the detailed results of your API requests, e.g.
77
+
78
+ client = Whatser::Client.new( :oauth_token => '123abc' )
79
+ results = client.spots.search(:geo => "52.3665312,4.8931739", :text => "pizza", :per_page => 30)
80
+ results.http_status
81
+ results.error.blank?
82
+ results.error_description
83
+ results.data
84
+
85
+ You can use the Response helpers to easily inspect your the result of your request.
86
+
87
+ if results.succeeded?
88
+ elsif results.unauthorized?
89
+ elsif results.forbidden?
90
+ elsif results.not_found?
91
+ elsif results.not_allowed?
92
+ elsif results.not_acceptable?
93
+ elsif results.confict?
94
+ elsif results.unprocessable_entity?
95
+ elsif results.server_error?
96
+ end
97
+
98
+ == Resource Guide
99
+
100
+ === Users
101
+
102
+ The API stores user profiles, which may have originated either directly from API registration, or else by connecting through a social network. In order to access the API on behalf of a user, you'll need an oauth token representing that user's credentials.
103
+
104
+ Whatser.client.users.me
105
+ Whatser.client.users.search( :text => 'name or email', :page => 1, :per_page => 10 )
106
+ Whatser.client.users.suggested( :page => 1, :per_page => 10 )
107
+ Whatser.client.users.invite( :emails => 'first@example.com;second@example.com;third@example.com' )
108
+ Whatser.client.users.create( params[:user] )
109
+ m = Whatser.client.users.find( user_id )
110
+ m.connection
111
+
112
+ <Whatser::User @bio="Example", @location="Amsterdam, NL", @facebook_id="1234567890", @email="user@example.com", @gowalla_id="1234567890", @avatar_pic="http://example.com/img/14.jpg", @promoted=false, @name="User", @twitter_name="example", @last_login_at="2010-12-24T16:46:23Z", @twitter_id="1234567890", @id=101, @foursquare_id="1234567890">
113
+
114
+ The API also permits anonymous user access, but in order to do so an anonymous user must first be created. Anonymous users have limited privileges and no email address, but otherwise function identically to authorized users. After the user is created, you can get the oauth token to use with your client and perform actions on behalf of the anonymous user.
115
+
116
+ client = Whatser::Client.new
117
+ anonymous = client.users.anonymous
118
+ client.oauth_token = anonymous.oauth_token
119
+ suggested_poi = client.spots.suggested
120
+ client.collections.add( suggested_poi.data.first.id )
121
+
122
+
123
+ === Spots (Points of Interest)
124
+
125
+ A spot is a named geographical location and the most fundamental kind of content in the API. Typically with counterparts in Gowalla or Foursquare, spots have various associated content such as photos or tags. If you supply only the lat and lng, or only the address, the spot will be automatically geocoded/reverse geocoded appropriately.
126
+
127
+ Whatser.client.spots.suggested( :page => 1, :per_page => 10 )
128
+ Whatser.client.spots.search( :geo => "52.3665312,4.8931739", :stats => true, :details => true )
129
+ Whatser.client.spots.find( spot_id )
130
+ Whatser.client.spots.create( :name => 'my spot', :lat => 52.0, :lng => 4.0, :street => '123 st.', :region => 'Noord Holland', :city => 'Amsterdam', :postal_code => '1012', :country => 'Netherlands' )
131
+ Whatser.client.spots.delete( spot_id )
132
+ m = Whatser.client.spots.new( :name => 'my spot', :lat => 52.0, :lng => 4.0 )
133
+ m.save
134
+ m.delete
135
+
136
+ <Whatser::Poi @lng=4.0, @region="Noord Holland", @gowalla_id="123456", @lat=52.0, @tag_list=nil, @city="Amsterdam", @name="Example Spot", @country="Netherlands", @street="example street", @id=101, @postal_code="1012", @foursquare_id="123456", @created_at="2010-12-24T16:46:23Z">
137
+
138
+
139
+ === Collections
140
+
141
+ A collection is a set of spots of particular interest to a user. By adding spots to their personal collection, users build a list of their favorite locations around a city.
142
+
143
+ Whatser.client.collections.mine( :page => 1, :per_page => 10 )
144
+ Whatser.client.collections.add( spot_id )
145
+
146
+ <Whatser::Collection @data=[#<Whatser::Poi>, #<Whatser::Poi>], @city_name="Amsterdam", @city=["Amsterdam"]>
147
+
148
+ As a convenience you can also iterate over a collection's spot data:
149
+
150
+ collection = Whatser::Collection.new( [spot1, spot2, spot3] )
151
+ collection.each { |c| puts c.name }
152
+
153
+ === Cities
154
+
155
+ A user's cities represent the cities in which they have collected spots.
156
+
157
+ Whatser.client.cities.mine( :page => 1, :per_page => 10 )
158
+ Whatser.client.cities.user( user_id, :page => 1, :per_page => 10 )
159
+
160
+ <Whatser::City @count=5, @name="Amsterdam">
161
+
162
+
163
+ === Reviews
164
+
165
+ A review is a short- to long-form text article about a spot.
166
+
167
+ Whatser.client.reviews.list( spot_id, :page => 1, :per_page => 10 )
168
+ Whatser.client.reviews.find( spot_id, review_id )
169
+ Whatser.client.reviews.create( spot_id, :body => 'my spot review.' )
170
+ Whatser.client.reviews.delete( spot_id, review_id )
171
+ m = Whatser.client.reviews.new( :body => 'my spot review.' )
172
+ m.save
173
+ m.delete
174
+
175
+ <Whatser::Review @user_id=null, @id=101, @body="whatser spot review.", @created_at="2010-12-24T16:45:55Z">
176
+
177
+
178
+ === Details
179
+
180
+ Details are miscellaneous, freeform information about a spot, such as operating hours, pricing, etc. The data attribute serializes a hash, which can be used to store arbitrary spot details.
181
+
182
+ Whatser.client.details.list( spot_id, :page => 1, :per_page => 10 )
183
+ Whatser.client.details.find( spot_id, details_id )
184
+ Whatser.client.details.create( spot_id, :data => {:title => 'details', :opening_hours => '8:00-5:00'} )
185
+ Whatser.client.details.delete( spot_id, review_id )
186
+ m = Whatser.client.details.new( :data => {:title => 'details', :opening_hours => '8:00-5:00'} )
187
+ m.save
188
+ m.delete
189
+
190
+ <Whatser::Detail @data={"meta"=>"Long metadata here", "opening_hours" => "9-5"}, @user_id=null, @id=101>
191
+
192
+
193
+ === Media
194
+
195
+ Media are photos, logos, and other graphics associated with a spot. You can create new media either by supplying a file for a multipart upload, or else with a link to an existing online image.
196
+
197
+ Whatser.client.media.list( spot_id, :page => 1, :per_page => 10 )
198
+ Whatser.client.media.find( spot_id, media_id )
199
+ Whatser.client.media.delete( spot_id, media_id )
200
+ Whatser.client.media.create( spot_id, :remote_resource => 'http://example.com/img/whatser.png' )
201
+ m = Whatser.client.media.new( :spot_id => 1, :resource => <File> )
202
+ m.save
203
+ m.delete
204
+
205
+ <Whatser::Media @mid_pic="http://example.com/images/medium/4394.jpg", @name="photo.jpg", @small_pic="http://example.com/images/small/4394.jpg", @poi_id=101, @mime="image/jpeg", @thumb_pic="http://example.com/images/thumb/4394.jpg", @user_id=1, @id=33, @url="http://example.com/images/original/4394.jpg", @created_at="2010-12-20T08:25:56Z">
206
+
207
+
208
+ === Tags
209
+
210
+ Tags are freeform text that reflect user thoughts, opinions, and feedback on specific spots.
211
+
212
+ Whatser.client.tags.list( spot_id )
213
+ Whatser.client.tags.create( spot_id, 'my tag' )
214
+ Whatser.client.tags.delete( spot_id, 'my tag' )
215
+ m = Whatser.client.tags.new( :name => 'my tag' )
216
+ m.save
217
+ m.delete
218
+
219
+ <Whatser::Tag @name="my tag">
220
+
221
+
222
+ === Follows
223
+
224
+ Follows represent a user's interest in another user, namely the user's spot activity, collections, and content. Following another user integrates that user's Whatser social and POI graph into the follower's suggestions and other dynamic Whatser content.
225
+
226
+ Whatser.client.follows.list( :page => 1, :per_page => 10 )
227
+ Whatser.client.follows.create( user_id )
228
+ Whatser.client.follows.ignore( user_id )
229
+ Whatser.client.follows.connection( user_id )
230
+ m = Whatser.client.follows.new( params[:user] )
231
+ m.save
232
+ m.delete
233
+
234
+ <Whatser::Follow @location="Amsterdam, NL", @premium=false, @avatar_pic="http://example.com/avatars/thumb/1.jpg", @promoted=false, @name="Example User", @id=1>
235
+
236
+
237
+ === Check Ins
238
+
239
+ A check in represents a user's visit to a spot, and will typically have a counterpart in other location-based applications such as Foursquare, Gowalla, and Facebook Places.
240
+
241
+ Whatser.client.check_ins.list( :page => 1, :per_page => 10 )
242
+ Whatser.client.check_ins.create( spot_id, :lat => 52.3665312, :lng => 4.8931739, :gowalla => true, :foursquare => true, :check_in_at => Time.now - 15.minutes, :check_out_at => Time.now, :rating => 2, :message => 'checked in' )
243
+ m = Whatser.check_ins.new( :check_in_at => Time.now )
244
+ m.save
245
+
246
+ <Whatser::CheckIn @message="statuscastin' over here", @lng=4.8931739, @rating=3, @lat=52.3665312, @check_out_at="2010-12-24T16:46:38Z", @name="Popular Spot", @poi_id=101, @check_in_at="2010-12-24T16:31:38Z", @user_id=101>
247
+
248
+
249
+ === Data Sources
250
+
251
+ A data source represents a free or purchasable content stream of collected spots, media, and reviews. Users can subscribe to data sources in order to access their content in Whatser. To begin the subscription and payment process, redirect your user to the data source's subscription_url.
252
+
253
+ Whatser.client.data_sources.list( :page => 1, :per_page => 10 )
254
+ Whatser.client.data_sources.for_users( :user_id => [101,23], :page => 1, :per_page => 10 )
255
+ m = Whatser.client.data_sources.find( 1 )
256
+ redirect_to m.subscription_url(:display => 'touch')
257
+
258
+ <Whatser::DataSource @review_count=405, @poi_count=0, @price=0.0, @collection_count=0, @name="Rough Guides - Barcelona", @media_count=0, @id=9, @users=[{"name": "premium user", "id": 33}]>
259
+
260
+
261
+ === Social Networks
262
+
263
+ The API integrates with several social networks (Facebook, Foursquare, Gowalla, and Twitter), allowing users from those networks to login from or connect their accounts with Whatser. All four networks are supported for connecting a user account (via the OAuth 2 web authorization flow), and disconnecting a user account. In addition, the API provides access to other select parts of these networks to support social media and location-based user activity.
264
+
265
+ To connect a user to or register a new user through their social network, redirect the user to the service's connection_url. Once the user has been connected their network, they are then redirected through the Whatser authentication path as normal, where you can then retrieve their oauth access token.
266
+
267
+ redirect_to Whatser.client.facebook.connection_url(:display => 'wap')
268
+ Whatser.client.facebook.disconnection_url
269
+ redirect_to Whatser.client.foursquare.connection_url(:display => 'touch')
270
+ Whatser.client.foursquare.disconnection_url
271
+ redirect_to Whatser.client.gowalla.connection_url(:display => 'web')
272
+ Whatser.client.gowalla.disconnection_url
273
+ redirect_to Whatser.client.twitter.connection_url(:display => 'touch')
274
+ Whatser.client.twitter.disconnection_url
275
+
276
+ The Twitter and Facebook classes allow for content publishing, meaning status tweets and wall posts, respectively. For Facebook wall posts, supplying one or more user ids to the method will post to the wall of those users (Facebook permissions permitting), while omitting it will post only to the authorized user's wall by default.
277
+
278
+ Whatser.client.facebook.wall_post(:name => 'my link', :link => 'http://example.com', :caption => 'click this link', :description => 'summary here', :picture => 'http://example.com/img/whatser.png', :user_id => '101,201,33')
279
+ Whatser.client.twitter.status_update('tweeting!', :lat => 52.3665312, :long => 4.8931739, :display_coordinates => true, :place_id => twitter_places_id)
280
+
281
+ When a user connects a social network account to the Whatser API, their friends are automatically imported at this time. To keep a user's friends updated, you can call a get_friends method on the Twitter and Facebook classes to import any new friends of that user who have recently registered with Whatser. Note, only newly imported friends are returned.
282
+
283
+ Whatser.client.facebook.get_friends
284
+ Whatser.client.twitter.get_friends
285
+
286
+ You can use convenience methods on users and spots to determine their connections to external networks.
287
+
288
+ m = Whatser.client.users.find(1)
289
+ m.facebook_connected?
290
+ m.foursquare_connected?
291
+ m.gowalla_connected?
292
+ m.twitter_connected?
293
+
294
+ m = Whatser.client.spots.find(1)
295
+ m.foursquare_connected?
296
+ m.gowalla_connected?
297
+
298
+ == Contact
299
+
300
+ * Developer Email: travis@sogeocompany.com
301
+ * API Documentation: http://docs.sogeoapi.com
302
+ * Facebook: http://www.facebook.com/sogeo
303
+ * Whatser: http://www.whatser.com
304
+ * Twitter: @sogeoapi
305
+
306
+ == Copyright
307
+
308
+ Copyright (c) 2010 Travis Dunn / SoGeo Company. See LICENSE.txt for
309
+ further details.
310
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "whatser"
16
+ gem.homepage = "http://github.com/sogeo/whatser"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{An HTTP and model DSL wrapper for the Whatser API}
19
+ gem.description = %Q{The 'Whatser API' Gem is a simple Ruby / Rails wrapper for interacting with Whatser's location-based web services (see http://docs.sogeoapi.com for more details).}
20
+ gem.email = "cmd@travisdunn.com"
21
+ gem.authors = ["Travis Dunn"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "whatser #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
File without changes
@@ -0,0 +1,13 @@
1
+ module Whatser
2
+ class Facebook < Whatser::Service
3
+ @key = 'facebook'
4
+
5
+ def get_friends(opts={})
6
+ api_request :get, "/oauth/services/facebook/friends", {:query => opts}, :model => Whatser::User
7
+ end
8
+
9
+ def wall_post(params={})
10
+ api_request :post, "/oauth/services/facebook/publish", {:body => params}
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Whatser
2
+ class Foursquare < Whatser::Service
3
+ @key = 'foursquare'
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Whatser
2
+ class Gowalla < Whatser::Service
3
+ @key = 'gowalla'
4
+ end
5
+ end
@@ -0,0 +1,84 @@
1
+ require 'json'
2
+
3
+ module Whatser
4
+ class Response
5
+ include Enumerable
6
+
7
+ attr_accessor :data,:http_status,:version,:scope
8
+ attr_accessor :page,:per_page,:more
9
+ attr_accessor :error,:error_description,:error_uri
10
+
11
+ attr_accessor :expires_in,:refresh_token,:access_token
12
+
13
+ API_RESPONSE_KEYS = ['data','http_status','version','scope','page','per_page','more','error','error_description','error_uri']
14
+
15
+ def initialize(json_or_hash, opts={})
16
+ return if json_or_hash.blank?
17
+
18
+ begin
19
+ hash = json_or_hash.is_a?(String) ? JSON.parse(json_or_hash) : json_or_hash
20
+ rescue JSON::ParserError
21
+ hash = {}
22
+ end
23
+
24
+ load_from_hash(hash, opts[:keys])
25
+ ensure_status_code( opts[:code] )
26
+ end
27
+
28
+ def ensure_status_code(code)
29
+ self.http_status ||= code
30
+ end
31
+
32
+ def load_from_hash(hash,keys=nil)
33
+ return unless hash.is_a?(Hash)
34
+ keys ||= API_RESPONSE_KEYS
35
+ keys.each do |a|
36
+ send("#{a}=", hash[a]) if hash.has_key?(a)
37
+ end
38
+ end
39
+
40
+ def data_enum
41
+ data.blank? ? [] : (data.is_a?(Array) ? data : [data])
42
+ end
43
+
44
+ def each(&block)
45
+ data_enum.each(&block)
46
+ end
47
+
48
+ def succeeded?
49
+ http_status == 200
50
+ end
51
+
52
+ def unauthorized?
53
+ http_status == 401
54
+ end
55
+
56
+ def forbidden?
57
+ http_status == 403
58
+ end
59
+
60
+ def not_found?
61
+ http_status == 404
62
+ end
63
+
64
+ def not_allowed?
65
+ http_status == 405
66
+ end
67
+
68
+ def not_acceptable?
69
+ http_status == 406
70
+ end
71
+
72
+ def confict?
73
+ http_status == 409
74
+ end
75
+
76
+ def unprocessable_entity?
77
+ http_status == 422
78
+ end
79
+
80
+ def server_error?
81
+ http_status == 500
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,15 @@
1
+ module Whatser
2
+ class Service < Whatser::Resource
3
+ def key
4
+ self.class.name.split('::').last.downcase
5
+ end
6
+
7
+ def connection_url
8
+ "#{client.api_uri}/oauth/services/#{key}/authorize"
9
+ end
10
+
11
+ def disconnection_url
12
+ "#{client.api_uri}/oauth/services/#{key}/disconnect"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Whatser
2
+ class Twitter < Whatser::Service
3
+ @key = 'twitter'
4
+
5
+ def get_friends(opts={})
6
+ api_request :get, "/oauth/services/twitter/friends", {:query => opts}, :model => Whatser::User
7
+ end
8
+
9
+ def status_update(status, params={})
10
+ api_request :post, "/oauth/services/twitter/publish", {:body => {'status' => status}.merge(params) }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,54 @@
1
+ module Whatser
2
+ class Client
3
+ ['net','client','api'].each do |p|
4
+ Dir[File.expand_path("/#{p}/*.rb", __FILE__)].each{|f| require f}
5
+ end
6
+
7
+ class << self
8
+ attr_accessor *Whatser::Configuration::VALID_OPTIONS_KEYS
9
+
10
+ def configure
11
+ yield self
12
+ true
13
+ end
14
+ end
15
+
16
+ attr_accessor *Whatser::Configuration::VALID_OPTIONS_KEYS
17
+ def initialize(options={})
18
+ Whatser::Configuration::VALID_OPTIONS_KEYS.each do |key|
19
+ if options[key].blank?
20
+ send("#{key}=", self.class.send(key) )
21
+ else
22
+ send("#{key}=", options[key])
23
+ end
24
+ end
25
+ end
26
+
27
+ def check_ins; Whatser::CheckIn.set(self); end
28
+ def collections; Whatser::Collection.set(self); end
29
+ def data_sources; Whatser::DataSource.set(self); end
30
+ def details; Whatser::Detail.set(self); end
31
+ def media; Whatser::Media.set(self); end
32
+ def spots; Whatser::Poi.set(self); end
33
+ def users; Whatser::User.set(self); end
34
+ def follows; Whatser::Follow.set(self); end
35
+ def reviews; Whatser::Review.set(self); end
36
+ def subscriptions; Whatser::Subscription.set(self); end
37
+ def tags; Whatser::Tag.set(self); end
38
+ def cities; Whatser::City.set(self); end
39
+ def feeds; Whatser::ActivityFeed.set(self); end
40
+
41
+ def facebook; Whatser::Facebook.set(self); end
42
+ def foursquare; Whatser::Foursquare.set(self); end
43
+ def gowalla; Whatser::Gowalla.set(self); end
44
+ def twitter; Whatser::Twitter.set(self); end
45
+
46
+ include Whatser::Configuration
47
+ include Whatser::Http
48
+ include Whatser::OAuth
49
+
50
+ def authorized?
51
+ !oauth_token.blank?
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,15 @@
1
+ module Whatser
2
+ module Configuration
3
+ VALID_OPTIONS_KEYS = [:api_key,:api_secret,:username,:password,:oauth_token,:api_uri,:redirect_uri]
4
+
5
+ DEFAULT_API_URI = 'https://production-2.sogeoapi.com'.freeze
6
+
7
+ def self.included(base)
8
+ base.api_key = nil
9
+ base.api_secret = nil
10
+ base.oauth_token = nil
11
+ base.redirect_uri = nil
12
+ base.api_uri = DEFAULT_API_URI
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ module Whatser
2
+ # Base error class for rescuing from all Whatser API errors
3
+ class Error < StandardError; end
4
+ end