Class: Carazel
Overview
Define client key constant in the appropriate place depending on usage. CLIENT_KEY = “Your API KEY”
Instance Method Summary collapse
-
#accounts(id) ⇒ Object
Find a user’s connected accounts.
-
#activities(type = nil, limit = nil) ⇒ Object
Find and show activities as well as a given user’s activities.
- #activity(id) ⇒ Object
-
#build_query_string(variables) ⇒ Object
Build query string for queries with multiple combinations of values.
- #checkin(id) ⇒ Object
-
#checkins(id = nil, since = nil, offset = nil) ⇒ Object
Find and show lbs checkins as well as a given user’s lbs checkins.
-
#create_user(email = nil, mobile_number = nil, zip = nil, delivery_sms = nil, delivery_email = nil, birth_date = nil, gender = nil) ⇒ Object
Create a user.
-
#leaderboard(type, limit) ⇒ Object
Leaderboards.
-
#place(id) ⇒ Object
Find and show places.
- #places(lat, lon, term = nil) ⇒ Object
- #reward(id, reward_type) ⇒ Object
-
#rewards(type = nil) ⇒ Object
Find and show rewards as well as a given user’s rewards.
-
#update_user(id, email = nil, mobile_number = nil, zip = nil, delivery_sms = nil, delivery_email = nil, birth_date = nil) ⇒ Object
Update a users info.
- #user(id) ⇒ Object
- #user_activities(id, since, activity_type = nil) ⇒ Object
- #user_checkins(id, since = nil, offset = nil) ⇒ Object
- #user_rewards(id, reward_type = nil) ⇒ Object
-
#users ⇒ Object
Find and show users.
Instance Method Details
#accounts(id) ⇒ Object
Find a user’s connected accounts
101 102 103 104 |
# File 'lib/carazel.rb', line 101 def accounts(id) results = self.class.get("/users/accounts?id=#{id}", :body => {:client_key => CLIENT_KEY}) Hashie::Mash.new(results[0]) rescue nil end |
#activities(type = nil, limit = nil) ⇒ Object
Find and show activities as well as a given user’s activities
61 62 63 64 65 66 67 68 69 |
# File 'lib/carazel.rb', line 61 def activities(type=nil, limit=nil) if type.nil? && limit.nil? results = self.class.get("/activities/search", :body => {:client_key => CLIENT_KEY}) else query = self.build_query_string([['type=',type],['limit=',limit]]) results = self.class.get("/activities/search?#{query}", :body => {:client_key => CLIENT_KEY}) end activities = results.collect{|r| Hashie::Mash.new(r['activity'])} end |
#activity(id) ⇒ Object
71 72 73 74 |
# File 'lib/carazel.rb', line 71 def activity(id) results = self.class.get("/activities/show?id=#{id}", :body => {:client_key => CLIENT_KEY}) Hashie::Mash.new(results.first['activity']) end |
#build_query_string(variables) ⇒ Object
Build query string for queries with multiple combinations of values
125 126 127 |
# File 'lib/carazel.rb', line 125 def build_query_string(variables) variables.reject{|v| v[1].nil?}.collect{|r| r.join('')}.join('&') end |
#checkin(id) ⇒ Object
89 90 91 92 |
# File 'lib/carazel.rb', line 89 def checkin(id) results = self.class.get("/lbs_checkins/show?id=#{id}", :body => {:client_key => CLIENT_KEY}) Hashie::Mash.new(results.first['lbs_checkin']) end |
#checkins(id = nil, since = nil, offset = nil) ⇒ Object
Find and show lbs checkins as well as a given user’s lbs checkins
84 85 86 87 |
# File 'lib/carazel.rb', line 84 def checkins(id=nil, since=nil, offset=nil) query = self.build_query_string([['user_id=',id],['since=',since],['offset=',offset]]) results = self.class.get("/lbs_checkins/search?#{query}", :body => {:client_key => CLIENT_KEY}).collect{|r| Hashie::Mash.new(r['lbs_checkin'])} end |
#create_user(email = nil, mobile_number = nil, zip = nil, delivery_sms = nil, delivery_email = nil, birth_date = nil, gender = nil) ⇒ Object
Create a user
114 115 116 |
# File 'lib/carazel.rb', line 114 def create_user(email=nil, mobile_number=nil, zip=nil, delivery_sms=nil, delivery_email=nil, birth_date=nil, gender=nil) result = self.class.post("/users/create", :body => {:client_key => CLIENT_KEY, :email => email, :mobile_number => mobile_number, :zip => zip, :delivery_sms => delivery_sms, :delivery_email => delivery_email, :age => birth_date, :gender => gender}) end |
#leaderboard(type, limit) ⇒ Object
Leaderboards
119 120 121 |
# File 'lib/carazel.rb', line 119 def leaderboard(type, limit) results = self.class.get("/leaderboards/by_#{type}", :body => {:client_key => CLIENT_KEY, :limit => limit}).collect{|r| Hashie::Mash.new(r['user'])} end |
#place(id) ⇒ Object
Find and show places
49 50 51 52 |
# File 'lib/carazel.rb', line 49 def place(id) results = self.class.get("/places/show?id=#{id}", :body => {:client_key => CLIENT_KEY}) Hashie::Mash.new(results.first['place']) rescue results end |
#places(lat, lon, term = nil) ⇒ Object
54 55 56 57 |
# File 'lib/carazel.rb', line 54 def places(lat,lon,term=nil) query = self.build_query_string([['lat=',lat],['lon=',lon],['query=',term]]) results = self.class.get("/places/search?#{query}", :body => {:client_key => CLIENT_KEY}).collect{|r| Hashie::Mash.new(r['place'])} end |
#reward(id, reward_type) ⇒ Object
35 36 37 38 |
# File 'lib/carazel.rb', line 35 def reward(id, reward_type) results = self.class.get("/rewards/show?id=#{id}&reward_type=#{reward_type}", :body => {:client_key => CLIENT_KEY}) Hashie::Mash.new(results.first['reward']) end |
#rewards(type = nil) ⇒ Object
Find and show rewards as well as a given user’s rewards
26 27 28 29 30 31 32 33 |
# File 'lib/carazel.rb', line 26 def rewards(type=nil) if type.nil? results = self.class.get("/rewards/search", :body => {:client_key => CLIENT_KEY}) else results = self.class.get("/rewards/search?type=type", :body => {:client_key => CLIENT_KEY}) end results.collect{|r| Hashie::Mash.new(r['reward'])} end |
#update_user(id, email = nil, mobile_number = nil, zip = nil, delivery_sms = nil, delivery_email = nil, birth_date = nil) ⇒ Object
Update a users info
108 109 110 |
# File 'lib/carazel.rb', line 108 def update_user(id, email=nil, mobile_number=nil, zip=nil, delivery_sms=nil, delivery_email=nil, birth_date=nil) result = self.class.post("/users/update", :body => {:client_key => CLIENT_KEY, :id => id, :email => email, :mobile_number => mobile_number, :zip => zip, :delivery_sms => delivery_sms, :delivery_email => delivery_email, :age => birth_date}) end |
#user(id) ⇒ Object
19 20 21 22 |
# File 'lib/carazel.rb', line 19 def user(id) results = self.class.get("/users/show?id=#{id}", :body => {:client_key => CLIENT_KEY}) Hashie::Mash.new(results).users rescue results end |
#user_activities(id, since, activity_type = nil) ⇒ Object
76 77 78 79 80 |
# File 'lib/carazel.rb', line 76 def user_activities(id, since, activity_type=nil) query = self.build_query_string([['id=',id],['since=',since],['activity_type=',activity_type]]) results = self.class.get("/users/activities?#{query}", :body => {:client_key => CLIENT_KEY}) Hashie::Mash.new(results[0]).activities rescue results end |
#user_checkins(id, since = nil, offset = nil) ⇒ Object
94 95 96 97 |
# File 'lib/carazel.rb', line 94 def user_checkins(id, since=nil, offset=nil) query = self.build_query_string([['user_id=',id],['since=',since],['offset=',offset]]) results = self.class.get("/lbs_checkins/search?#{query}", :body => {:client_key => CLIENT_KEY}).collect{|r| Hashie::Mash.new(r['lbs_checkin'])} end |
#user_rewards(id, reward_type = nil) ⇒ Object
40 41 42 43 44 |
# File 'lib/carazel.rb', line 40 def user_rewards(id, reward_type=nil) query = self.build_query_string([['id=',id],['reward_type=',reward_type]]) results = self.class.get("/users/rewards?#{query}", :body => {:client_key => CLIENT_KEY}).first Hashie::Mash.new(results).rewards rescue results end |
#users ⇒ Object
Find and show users
14 15 16 17 |
# File 'lib/carazel.rb', line 14 def users results = self.class.get('/users', :body => {:client_key => CLIENT_KEY}) Hashie::Mash.new(results).users end |