whatser 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +310 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/whatser/api/batch.rb +0 -0
- data/lib/whatser/api/facebook.rb +13 -0
- data/lib/whatser/api/foursquare.rb +5 -0
- data/lib/whatser/api/gowalla.rb +5 -0
- data/lib/whatser/api/response.rb +84 -0
- data/lib/whatser/api/service.rb +15 -0
- data/lib/whatser/api/twitter.rb +13 -0
- data/lib/whatser/client.rb +54 -0
- data/lib/whatser/configuration.rb +15 -0
- data/lib/whatser/errors.rb +4 -0
- data/lib/whatser/net/http.rb +26 -0
- data/lib/whatser/net/oauth.rb +41 -0
- data/lib/whatser/resources/activity_feed.rb +20 -0
- data/lib/whatser/resources/check_in.rb +25 -0
- data/lib/whatser/resources/city.rb +16 -0
- data/lib/whatser/resources/collection.rb +68 -0
- data/lib/whatser/resources/data_source.rb +24 -0
- data/lib/whatser/resources/detail.rb +40 -0
- data/lib/whatser/resources/follow.rb +42 -0
- data/lib/whatser/resources/media.rb +41 -0
- data/lib/whatser/resources/poi.rb +74 -0
- data/lib/whatser/resources/resource.rb +53 -0
- data/lib/whatser/resources/review.rb +40 -0
- data/lib/whatser/resources/subscription.rb +12 -0
- data/lib/whatser/resources/tag.rb +32 -0
- data/lib/whatser/resources/user.rb +81 -0
- data/lib/whatser.rb +38 -0
- data/test/helper.rb +25 -0
- data/test/test_activity_feed.rb +20 -0
- data/test/test_check_in.rb +28 -0
- data/test/test_city.rb +16 -0
- data/test/test_client.rb +84 -0
- data/test/test_collection.rb +28 -0
- data/test/test_configuration.rb +26 -0
- data/test/test_data_source.rb +35 -0
- data/test/test_detail.rb +38 -0
- data/test/test_facebook.rb +7 -0
- data/test/test_follow.rb +33 -0
- data/test/test_foursquare.rb +7 -0
- data/test/test_gowalla.rb +7 -0
- data/test/test_hondius.rb +12 -0
- data/test/test_http.rb +40 -0
- data/test/test_oauth.rb +37 -0
- data/test/test_poi.rb +75 -0
- data/test/test_resource.rb +73 -0
- data/test/test_response.rb +44 -0
- data/test/test_review.rb +37 -0
- data/test/test_subscription.rb +11 -0
- data/test/test_tag.rb +32 -0
- data/test/test_twitter.rb +7 -0
- data/test/test_user.rb +53 -0
- data/whatser.gemspec +140 -0
- metadata +236 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
module Whatser
|
2
|
+
module Http
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base_uri base.api_uri
|
7
|
+
end
|
8
|
+
|
9
|
+
def request(verb, path, params={}, options={})
|
10
|
+
response = HTTParty.send( verb, compose_url(path), request_options( params ) )
|
11
|
+
Whatser::Response.new( response.body, {:code => response.code}.merge(options) )
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def compose_url(path)
|
17
|
+
"#{api_uri}#{path}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def request_options(params={})
|
21
|
+
params ||= {}
|
22
|
+
return { :query => {:oauth_token => oauth_token}.merge(params[:query] || {}),
|
23
|
+
:body => params[:body] }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'oauth2'
|
2
|
+
|
3
|
+
module Whatser
|
4
|
+
module OAuth
|
5
|
+
def oauth_client
|
6
|
+
OAuth2::Client.new(api_key, api_secret, :site => api_uri)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_oauth_token(code, params={})
|
10
|
+
oauth_client.web_server.get_access_token( code, params)
|
11
|
+
end
|
12
|
+
|
13
|
+
def oauth_authorize_url(params={})
|
14
|
+
oauth_client.web_server.authorize_url(params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def login(email, password)
|
18
|
+
request( :get, '/oauth/access_token', {:query => password_grant_params(email, password)}, :auth => :key, :keys => auth_keys )
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def auth_keys
|
24
|
+
['access_token','refresh_token','expires_in']
|
25
|
+
end
|
26
|
+
|
27
|
+
def hash_to_query(hash)
|
28
|
+
hash.collect do |key, value|
|
29
|
+
"#{key}=#{value}"
|
30
|
+
end * '&'
|
31
|
+
end
|
32
|
+
|
33
|
+
def password_grant_params(email, password)
|
34
|
+
{'grant_type' => 'password',
|
35
|
+
'client_id' => api_key,
|
36
|
+
'client_secret' => api_secret,
|
37
|
+
'username' => email,
|
38
|
+
'password' => password}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Whatser
|
2
|
+
class ActivityFeed < Whatser::Resource
|
3
|
+
attr_accessor :user_id,:user_name,:user_avatar,:poi_id,:poi_name,:object_id,:object_name,:object_avatar
|
4
|
+
attr_accessor :city,:message,:created_At
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def mine(params={})
|
8
|
+
user('me', params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def global(params={})
|
12
|
+
api_request :get, "/api/users/activity_feed", {:query => params}
|
13
|
+
end
|
14
|
+
|
15
|
+
def user(user_id, params={})
|
16
|
+
api_request :get, "/api/users/#{user_id}/activity_feed", {:query => params}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Whatser
|
2
|
+
class CheckIn < Whatser::Resource
|
3
|
+
attr_accessor :id,:user_id,:poi_id
|
4
|
+
attr_accessor :name,:lat,:lng,:check_in_at,:check_out_at,:rating,:message
|
5
|
+
attr_accessor :locate_user, :gowalla_share, :foursquare_share
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def list(opts={})
|
9
|
+
api_request :get, "/api/check_ins", {:query => opts}
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(poi_id, params={})
|
13
|
+
api_request :post, "/api/poi/#{poi_id}/check_ins", {:body => {'check_in' => params} }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def save
|
18
|
+
self.class.create( self.poi_id, self.to_params )
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_params
|
22
|
+
{:lat => lat, :lng => lng, :locate => locate_user, :gowalla => gowalla_share, :foursquare => foursquare_share, :check_in_at => check_in_at, :check_out_at => check_out_at}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Whatser
|
2
|
+
class City < Whatser::Resource
|
3
|
+
attr_accessor :name,:count
|
4
|
+
alias :collections_count :count
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def mine(params={})
|
8
|
+
api_request :get, "/api/users/me/black/book/cities", {:query => params}
|
9
|
+
end
|
10
|
+
|
11
|
+
def user(user_id, params={})
|
12
|
+
api_request :get, "/api/users/#{user_id}/black/book/cities", {:query => params}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Whatser
|
2
|
+
class Collection < Whatser::Resource
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_accessor :data,:city,:city_name
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def mine(opts={})
|
9
|
+
collect_api_request :get, "/api/users/me/black/book", {:query => opts}
|
10
|
+
end
|
11
|
+
|
12
|
+
def list(user_id, opts={})
|
13
|
+
collect_api_request :get, "/api/users/#{user_id}/black/book", {:query => opts}
|
14
|
+
end
|
15
|
+
|
16
|
+
def add(poi_id, opts={})
|
17
|
+
api_request :post, "/api/poi/#{poi_id}/black/book", {:body => ''}, :model => Whatser::Poi
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(poi_id)
|
21
|
+
api_request :delete, "/api/poi/#{poi_id}/black/book", {:body => ''}, :model => Whatser::Poi
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def collect_api_request(verb, path, opts={})
|
27
|
+
res = api_request(verb, path, opts, :model => Whatser::Poi)
|
28
|
+
collection = Whatser::Collection.new(res.data)
|
29
|
+
|
30
|
+
collection.data = res.data
|
31
|
+
res.data = collection
|
32
|
+
return res
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def add(poi_id, opts={})
|
37
|
+
Whatser::Collection.add(poi_id, opts)
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete(poi_id)
|
41
|
+
Whatser::Collection.delete(poi_id, opts)
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize(collection_data=nil)
|
45
|
+
self.data = collection_data || []
|
46
|
+
set_city
|
47
|
+
end
|
48
|
+
|
49
|
+
def each(&block)
|
50
|
+
(data || []).each(&block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def size
|
54
|
+
(data || []).size
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def set_city
|
60
|
+
self.city ||= []
|
61
|
+
data.each do |poi|
|
62
|
+
next unless poi.is_a?(Whatser::Poi)
|
63
|
+
self.city << poi.city unless city.include?(poi.city)
|
64
|
+
end
|
65
|
+
self.city_name = city.join(", ")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Whatser
|
2
|
+
class DataSource < Whatser::Resource
|
3
|
+
attr_accessor :id
|
4
|
+
attr_accessor :name,:price,:review_count,:media_count,:collection_count,:poi_count
|
5
|
+
attr_accessor :users
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def list(opts={})
|
9
|
+
api_request :get, "/api/data_sources", {:query => opts}
|
10
|
+
end
|
11
|
+
|
12
|
+
def for_users(user_id, opts={})
|
13
|
+
user_id = user_id.is_a?(Array) ? user_id.join(',') : user_id
|
14
|
+
api_request :get, "/api/data_sources", {:query => {:user_id => user_id}.merge(opts || {})}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def subscription_url(opts={})
|
19
|
+
url = "#{self.class.client.api_uri}/payments/data_sources/#{id}/orders/new?oauth_token=#{self.class.client.oauth_token}"
|
20
|
+
url = "#{url}&#{opts.to_params}" unless opts.blank?
|
21
|
+
url
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Whatser
|
2
|
+
class Detail < Whatser::Resource
|
3
|
+
attr_accessor :id,:user_id,:poi_id
|
4
|
+
attr_accessor :data,:created_at
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def list(poi_id, opts={})
|
8
|
+
api_request :get, "/api/poi/#{poi_id}/details", {:query => opts}
|
9
|
+
end
|
10
|
+
|
11
|
+
def find(poi_id, id, opts={})
|
12
|
+
api_request :get, "/api/poi/#{poi_id}/details/#{id}", {:query => opts}
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(poi_id, params={})
|
16
|
+
api_request :post, "/api/poi/#{poi_id}/details", {:body => {'detail' => params} }
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete(poi_id, id)
|
20
|
+
api_request :delete, "/api/poi/#{poi_id}/details/#{id}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def save
|
25
|
+
if id.blank?
|
26
|
+
self.class.create(poi_id, to_params)
|
27
|
+
else
|
28
|
+
api_request :put, "/api/poi/#{poi_id}/details/#{id}", {:body => {'detail' => to_params} }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete
|
33
|
+
self.class.delete(poi_id, id)
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_params
|
37
|
+
{:data => data}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Whatser
|
2
|
+
class Follow < Whatser::Resource
|
3
|
+
attr_accessor :id
|
4
|
+
attr_accessor :name,:avatar_pic,:location
|
5
|
+
attr_accessor :promoted,:premium,:collections_count
|
6
|
+
attr_accessor :following,:followed,:foaf_count,:foaf
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def list(opts={})
|
10
|
+
api_request :get, "/api/follows", {:query => opts}
|
11
|
+
end
|
12
|
+
|
13
|
+
def suggested(opts={})
|
14
|
+
api_request :get, "/api/users/suggested", {:query => opts}
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(user_id, opts={})
|
18
|
+
api_request :post, "/api/follows/#{user_id}", {:query => opts, :body => ''}
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(user_id)
|
22
|
+
api_request :delete, "/api/follows/#{user_id}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def ignore(user_id)
|
26
|
+
delete(user_id)
|
27
|
+
end
|
28
|
+
|
29
|
+
def connection(user_id)
|
30
|
+
api_request :get, "/api/users/#{user_id}/connection"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def save
|
35
|
+
self.class.create( id )
|
36
|
+
end
|
37
|
+
|
38
|
+
def delete
|
39
|
+
self.class.ignore( id )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Whatser
|
2
|
+
class Media < Whatser::Resource
|
3
|
+
attr_accessor :id,:user_id,:poi_id
|
4
|
+
attr_accessor :name,:thumb_pic,:small_pic,:mid_pic,:url,:mime,:created_at
|
5
|
+
attr_writer :resource,:remote_resource
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def list(poi_id, opts={})
|
9
|
+
api_request :get, "/api/poi/#{poi_id}/media", {:query => opts}
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(poi_id, id, opts={})
|
13
|
+
api_request :get, "/api/poi/#{poi_id}/media/#{id}", {:query => opts}
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(poi_id, params={})
|
17
|
+
api_request :post, "/api/poi/#{poi_id}/media", {:body => {'media' => params} }
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(poi_id, id)
|
21
|
+
api_request :delete, "/api/poi/#{poi_id}/media/#{id}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def save
|
26
|
+
if id.blank?
|
27
|
+
Whatser::Media.create(poi_id, to_params)
|
28
|
+
else
|
29
|
+
api_request :put, "/api/poi/#{poi_id}/media/#{id}", {:body => {'media' => to_params} }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete
|
34
|
+
Whatser::Media.delete(poi_id, id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_params
|
38
|
+
{:name=>name,:resource=>@resource,:remote_resource=>@remote_resource}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Whatser
|
2
|
+
class Poi < Whatser::Resource
|
3
|
+
attr_accessor :id,:user_id,:gowalla_id,:foursquare_id
|
4
|
+
attr_accessor :name,:lat,:lng,:street,:district,:region,:city,:postal_code,:country
|
5
|
+
attr_accessor :tag_list,:created_at
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def suggested(opts={})
|
9
|
+
api_request :get, "/api/poi/suggested", {:query => opts}
|
10
|
+
end
|
11
|
+
|
12
|
+
def search(opts={})
|
13
|
+
api_request :get, "/api/poi", {:query => opts}
|
14
|
+
end
|
15
|
+
|
16
|
+
def find(id, opts={})
|
17
|
+
api_request :get, "/api/poi/#{id}", {:query => opts}
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(params={})
|
21
|
+
api_request :post, "/api/poi", {:body => {'poi' => params} }
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(poi_id)
|
25
|
+
api_request :delete, "/api/poi/#{poi_id}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def save
|
30
|
+
if id.blank?
|
31
|
+
self.class.create(to_params)
|
32
|
+
else
|
33
|
+
api_request :put, "/api/poi/#{id}", {:body => {'poi' => to_params} }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete
|
38
|
+
Whatser::Poi.delete(id)
|
39
|
+
end
|
40
|
+
|
41
|
+
def tag(tag_name)
|
42
|
+
Whatser::Tag.create(id, tag_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
def tags(opts={})
|
46
|
+
Whatser::Tag.list(id, opts)
|
47
|
+
end
|
48
|
+
|
49
|
+
def media(opts={})
|
50
|
+
Whatser::Media.list(id, opts)
|
51
|
+
end
|
52
|
+
|
53
|
+
def reviews(opts={})
|
54
|
+
Whatser::Review.list(id, opts)
|
55
|
+
end
|
56
|
+
|
57
|
+
def details(opts={})
|
58
|
+
Whatser::Detail.list(id, opts)
|
59
|
+
end
|
60
|
+
|
61
|
+
def foursquare_connected?
|
62
|
+
!foursquare_id.blank?
|
63
|
+
end
|
64
|
+
|
65
|
+
def gowalla_connected?
|
66
|
+
!gowalla_id.blank?
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_params
|
70
|
+
{:name=>name,:lat=>lat,:lng=>lat,:street=>street,:district=>district,
|
71
|
+
:region=>region,:city=>city,:postal_code=>postal_code,:country=>country}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Whatser
|
2
|
+
class Resource
|
3
|
+
attr_accessor :json
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def client
|
7
|
+
@client
|
8
|
+
end
|
9
|
+
|
10
|
+
def set(client)
|
11
|
+
@client = client
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def api_request(verb, path, params={}, opts={})
|
16
|
+
res = client.request(verb, path, params)
|
17
|
+
res.data = convert_data_to_model( res.data, opts)
|
18
|
+
return res
|
19
|
+
end
|
20
|
+
|
21
|
+
def convert_data_to_model(data, opts={})
|
22
|
+
return data if data.blank?
|
23
|
+
opts ||= {}
|
24
|
+
|
25
|
+
data = if data.is_a?(Array)
|
26
|
+
data.inject([]) {|result,d| result << from_hash_to_model(d, opts[:model]) }
|
27
|
+
else
|
28
|
+
from_hash_to_model(data, opts[:model])
|
29
|
+
end
|
30
|
+
data
|
31
|
+
end
|
32
|
+
|
33
|
+
def from_hash_to_model(hash, model=nil)
|
34
|
+
hash ||= {}
|
35
|
+
hash = hash.size == 1 ? hash.first.last : hash
|
36
|
+
mod = model.blank? ? new : model.new
|
37
|
+
hash.each do |k,v|
|
38
|
+
mod.send("#{k}=", v) if mod.respond_to?(k)
|
39
|
+
end
|
40
|
+
mod.json = hash.to_json
|
41
|
+
return mod
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(params={})
|
46
|
+
params.each_pair { |k,v| send("#{k}=", v) if respond_to?(k) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def api_request(verb, path, params={}, opts={})
|
50
|
+
self.class.api_request(verb, path, params, opts)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Whatser
|
2
|
+
class Review < Whatser::Resource
|
3
|
+
attr_accessor :id,:user_id,:poi_id
|
4
|
+
attr_accessor :body,:created_at
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def list(poi_id, opts={})
|
8
|
+
api_request :get, "/api/poi/#{poi_id}/reviews", {:query => opts}
|
9
|
+
end
|
10
|
+
|
11
|
+
def find(poi_id, id, opts={})
|
12
|
+
api_request :get, "/api/poi/#{poi_id}/reviews/#{id}", {:query => opts}
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(poi_id, params={})
|
16
|
+
api_request :post, "/api/poi/#{poi_id}/reviews", {:body => {'review' => params} }
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete(poi_id, id)
|
20
|
+
api_request :delete, "/api/poi/#{poi_id}/reviews/#{id}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def save
|
25
|
+
if id.blank?
|
26
|
+
self.class.create(poi_id, to_params)
|
27
|
+
else
|
28
|
+
api_request :put, "/api/poi/#{poi_id}/reviews/#{id}", {:body => {'review' => to_params} }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete
|
33
|
+
self.class.delete(poi_id, id)
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_params
|
37
|
+
{:body => body}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Whatser
|
2
|
+
class Subscription < Whatser::Resource
|
3
|
+
attr_accessor :id,:data_source_id
|
4
|
+
attr_accessor :data_source_name,:created_at
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def list(params={})
|
8
|
+
api_request :get, "/api/subscriptions", {:query => params}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Whatser
|
2
|
+
class Tag < Whatser::Resource
|
3
|
+
attr_accessor :id,:poi_id
|
4
|
+
attr_accessor :name
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def list(poi_id, opts={})
|
8
|
+
api_request :get, "/api/poi/#{poi_id}/tags", {:query => opts}
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(poi_id, tag_name)
|
12
|
+
api_request :post, "/api/poi/#{poi_id}/tags", {:body => {'tagging' => {'name' => tag_name}} }
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete(poi_id, tag_name)
|
16
|
+
api_request :delete, "/api/poi/#{poi_id}/tags/#{tag_name}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def save
|
21
|
+
self.class.create(poi_id, name)
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete
|
25
|
+
self.class.delete(poi_id, name)
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_params
|
29
|
+
{:name => name}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Whatser
|
2
|
+
class User < Whatser::Resource
|
3
|
+
attr_accessor :id,:facebook_id,:gowalla_id,:foursquare_id,:twitter_id
|
4
|
+
attr_accessor :name,:twitter_name,:avatar_pic,:location,:bio,:email
|
5
|
+
attr_accessor :last_login_at,:promoted,:premium,:collections_count
|
6
|
+
attr_writer :avatar,:remote_avatar,:password,:lat,:lng
|
7
|
+
attr_writer :access_tokens
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def me
|
11
|
+
api_request :get, "/api/users/me"
|
12
|
+
end
|
13
|
+
|
14
|
+
def anonymous
|
15
|
+
api_request :get, "/api/users/anonymous"
|
16
|
+
end
|
17
|
+
|
18
|
+
def search(params={})
|
19
|
+
api_request :get, "/api/users/lookup", {:query => params}
|
20
|
+
end
|
21
|
+
|
22
|
+
def suggested(params={})
|
23
|
+
api_request :get, "/api/users/suggested", {:query => params}
|
24
|
+
end
|
25
|
+
|
26
|
+
def find(id, params={})
|
27
|
+
api_request :get, "/api/users/#{id}/profile", {:query => params}
|
28
|
+
end
|
29
|
+
|
30
|
+
def create(params={})
|
31
|
+
api_request :post, "/api/users", {:body => {'user' => params} }, :auth => :key
|
32
|
+
end
|
33
|
+
|
34
|
+
def invite(emails)
|
35
|
+
api_request :post, "/api/invites", {:query => emails}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def save
|
40
|
+
if id.blank?
|
41
|
+
api_request :post, "/api/users", {:body => {'user' => to_params} }, :auth => :key
|
42
|
+
else
|
43
|
+
api_request :put, "/api/users/me", {:body => {'user' => to_params} }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def connection
|
48
|
+
Whatser::Follow.connection(id)
|
49
|
+
end
|
50
|
+
|
51
|
+
def oauth_token
|
52
|
+
if access_tokens.blank?
|
53
|
+
nil
|
54
|
+
elsif access_tokens.is_a?(Array)
|
55
|
+
access_tokens.first
|
56
|
+
else
|
57
|
+
access_token
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def facebook_connected?
|
62
|
+
!facebook_id.blank?
|
63
|
+
end
|
64
|
+
|
65
|
+
def foursquare_connected?
|
66
|
+
!foursquare_id.blank?
|
67
|
+
end
|
68
|
+
|
69
|
+
def gowalla_connected?
|
70
|
+
!gowalla_id.blank?
|
71
|
+
end
|
72
|
+
|
73
|
+
def twitter_connected?
|
74
|
+
!twitter_id.blank?
|
75
|
+
end
|
76
|
+
|
77
|
+
def to_params
|
78
|
+
{:name=>name,:avatar_pic=>@remote_avatar,:location=>location,:bio=>bio,:email=>email}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/whatser.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
require File.expand_path('../whatser/net/http', __FILE__)
|
5
|
+
require File.expand_path('../whatser/net/oauth', __FILE__)
|
6
|
+
require File.expand_path('../whatser/configuration', __FILE__)
|
7
|
+
require File.expand_path('../whatser/client', __FILE__)
|
8
|
+
require File.expand_path('../whatser/errors', __FILE__)
|
9
|
+
require File.expand_path('../whatser/api/response', __FILE__)
|
10
|
+
|
11
|
+
require File.expand_path('../whatser/resources/resource', __FILE__)
|
12
|
+
require File.expand_path('../whatser/resources/city', __FILE__)
|
13
|
+
require File.expand_path('../whatser/resources/check_in', __FILE__)
|
14
|
+
require File.expand_path('../whatser/resources/collection', __FILE__)
|
15
|
+
require File.expand_path('../whatser/resources/data_source', __FILE__)
|
16
|
+
require File.expand_path('../whatser/resources/detail', __FILE__)
|
17
|
+
require File.expand_path('../whatser/resources/media', __FILE__)
|
18
|
+
require File.expand_path('../whatser/resources/poi', __FILE__)
|
19
|
+
require File.expand_path('../whatser/resources/review', __FILE__)
|
20
|
+
require File.expand_path('../whatser/resources/subscription', __FILE__)
|
21
|
+
require File.expand_path('../whatser/resources/tag', __FILE__)
|
22
|
+
require File.expand_path('../whatser/resources/user', __FILE__)
|
23
|
+
require File.expand_path('../whatser/resources/follow', __FILE__)
|
24
|
+
require File.expand_path('../whatser/resources/activity_feed', __FILE__)
|
25
|
+
|
26
|
+
require File.expand_path('../whatser/api/service', __FILE__)
|
27
|
+
require File.expand_path('../whatser/api/facebook', __FILE__)
|
28
|
+
require File.expand_path('../whatser/api/foursquare', __FILE__)
|
29
|
+
require File.expand_path('../whatser/api/twitter', __FILE__)
|
30
|
+
require File.expand_path('../whatser/api/gowalla', __FILE__)
|
31
|
+
|
32
|
+
module Whatser
|
33
|
+
class << self
|
34
|
+
def client(options={})
|
35
|
+
@client ||= Whatser::Client.new(options)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|