Class: Plancast::Client
- Inherits:
-
Object
- Object
- Plancast::Client
- Includes:
- HTTParty
- Defined in:
- lib/plancast/client.rb
Instance Attribute Summary collapse
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
-
#attend(details = {}) ⇒ Hashie::Mash
Add an attendance for a particular plan for the authenticated user and return information about it.
-
#destroy_comment(comment_id) ⇒ Hashie::Mash
Delete a comment for the authenticated user and return its previous information.
-
#destroy_subscription(options = {}) ⇒ Hashie::Mash
Unsubscribe the authenticated user from a target user and returns information about the target user.
-
#discover_friends(query = {}) ⇒ Hashie::Mash
Return the users connected to the authenticated user on a given network (Facebook or Twitter).
-
#home(query = {}) ⇒ Hashie::Mash
Return plans on the session user’s homepage (their own plans plus those of their subscriptions).
-
#initialize(username, password) ⇒ Client
constructor
Create the API client.
-
#parse_when(q) ⇒ Hashie::Mash
Parse a string for datetime information and returns the result if successful.
-
#parse_where(where) ⇒ Hashie::Mash
Parse a string for location information and returns the result if successful.
-
#plan(query = {}) ⇒ Hashie::Mash
Return the details for a given plan.
-
#plans(query = {}) ⇒ Hashie::Mash
Return a given user’s plans.
-
#search_plans(query = {}) ⇒ Hashie::Mash
Return up to 25 plans that match the given keyword(s).
-
#search_users(q, options = {}) ⇒ Hashie::Mash
Return up to 25 users that match the given keyword(s).
-
#subscribers(query = {}) ⇒ Hashie::Mash
Return the users who are subscribed to a given user.
-
#subscriptions(query = {}) ⇒ Hashie::Mash
Return the users to which a given user is subscribed.
-
#unattend(options = {}) ⇒ Hashie::Mash
Delete an attendance for the authenticated user and returns its previous information.
-
#update(details = {}) ⇒ Hashie::Mash
Create a new plan or update the details of an existing plan.
-
#update_comment(details = {}) ⇒ Hashie::Mash
Create a new comment on a plan and return information about it.
-
#update_subscription(options = {}) ⇒ Hashie::Mash
Subscribe the authenticated user to a target user and returns information about the target user.
-
#user(query = {}) ⇒ Hashie::Mash
Return information about a given user.
-
#verify_credentials ⇒ Hashie::Mash
Verify account credentials and gets information about the authenticated user.
Constructor Details
#initialize(username, password) ⇒ Client
Create the API client
15 16 17 18 |
# File 'lib/plancast/client.rb', line 15 def initialize(username, password) @username = username self.class.basic_auth username, password end |
Instance Attribute Details
#username ⇒ Object (readonly)
Returns the value of attribute username.
7 8 9 |
# File 'lib/plancast/client.rb', line 7 def username @username end |
Class Method Details
.get(*args) ⇒ Object
268 |
# File 'lib/plancast/client.rb', line 268 def self.get(*args); handle_response super end |
.handle_response(response) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/plancast/client.rb', line 273 def self.handle_response(response) case response.code when 401; raise Unauthorized.new when 403; raise RateLimitExceeded.new when 404; raise NotFound.new when 400...500; raise ClientError.new when 500...600; raise ServerError.new(response.code) else; response end if response.is_a?(Array) response.map{|item| Hashie::Mash.new(item)} else Hashie::Mash.new(response) end end |
.post(*args) ⇒ Object
270 |
# File 'lib/plancast/client.rb', line 270 def self.post(*args); handle_response super end |
Instance Method Details
#attend(details = {}) ⇒ Hashie::Mash
Add an attendance for a particular plan for the authenticated user and return information about it
231 232 233 |
# File 'lib/plancast/client.rb', line 231 def attend(details={}) self.class.post("/plans/attend.json", :body => details) end |
#destroy_comment(comment_id) ⇒ Hashie::Mash
Delete a comment for the authenticated user and return its previous information
262 263 264 |
# File 'lib/plancast/client.rb', line 262 def destroy_comment(comment_id) self.class.post("/comments/destroy.json", :body => {:comment_id => comment_id}) end |
#destroy_subscription(options = {}) ⇒ Hashie::Mash
Unsubscribe the authenticated user from a target user and returns information about the target user
69 70 71 |
# File 'lib/plancast/client.rb', line 69 def destroy_subscription(={}) self.class.post("/subscriptions/destroy.json", :body => ) end |
#discover_friends(query = {}) ⇒ Hashie::Mash
Return the users connected to the authenticated user on a given network (Facebook or Twitter)
94 95 96 |
# File 'lib/plancast/client.rb', line 94 def discover_friends(query={}) self.class.get("/users/discover_friends.json", :query => query) end |
#home(query = {}) ⇒ Hashie::Mash
Return plans on the session user’s homepage (their own plans plus those of their subscriptions).
135 136 137 |
# File 'lib/plancast/client.rb', line 135 def home(query = {}) self.class.get("/plans/home.json", :query => query) end |
#parse_when(q) ⇒ Hashie::Mash
Parse a string for datetime information and returns the result if successful
172 173 174 175 176 177 |
# File 'lib/plancast/client.rb', line 172 def parse_when(q) date = self.class.get("/plans/parse_when.json", :query => {:when => q}) date.start = Time.at(date.start) date.stop = Time.at(date.stop) date end |
#parse_where(where) ⇒ Hashie::Mash
Parse a string for location information and returns the result if successful
188 189 190 191 192 |
# File 'lib/plancast/client.rb', line 188 def parse_where(where) locations = self.class.get("/plans/parse_where.json", :query => {:where => where}) locations.each{|l| l.latitude = l.latitude.to_f; l.longitude = l.longitude.to_f} locations end |
#plan(query = {}) ⇒ Hashie::Mash
Return the details for a given plan
148 149 150 |
# File 'lib/plancast/client.rb', line 148 def plan(query = {}) self.class.get("/plans/show.json", :query => query) end |
#plans(query = {}) ⇒ Hashie::Mash
Return a given user’s plans
121 122 123 |
# File 'lib/plancast/client.rb', line 121 def plans(query = {}) self.class.get("/plans/user.json", :query => query) end |
#search_plans(query = {}) ⇒ Hashie::Mash
Return up to 25 plans that match the given keyword(s).
160 161 162 |
# File 'lib/plancast/client.rb', line 160 def search_plans(query={}) self.class.get("/plans/search.json", :query => query) end |
#search_users(q, options = {}) ⇒ Hashie::Mash
Return up to 25 users that match the given keyword(s).
105 106 107 |
# File 'lib/plancast/client.rb', line 105 def search_users(q, ={}) self.class.get("/users/search.json", :query => .merge({:q => q})) end |
#subscribers(query = {}) ⇒ Hashie::Mash
Return the users who are subscribed to a given user
82 83 84 |
# File 'lib/plancast/client.rb', line 82 def subscribers(query={}) self.class.get("/users/subscribers.json", :query => query) end |
#subscriptions(query = {}) ⇒ Hashie::Mash
Return the users to which a given user is subscribed
49 50 51 |
# File 'lib/plancast/client.rb', line 49 def subscriptions(query={}) self.class.get("/users/subscriptions.json", :query => query) end |
#unattend(options = {}) ⇒ Hashie::Mash
Delete an attendance for the authenticated user and returns its previous information
240 241 242 |
# File 'lib/plancast/client.rb', line 240 def unattend(={}) self.class.post("/plans/destroy.json", :body => ) end |
#update(details = {}) ⇒ Hashie::Mash
Create a new plan or update the details of an existing plan. Returns up-to-date information about the plan in either case.
213 214 215 |
# File 'lib/plancast/client.rb', line 213 def update(details={}) self.class.post("/plans/update.json", :body => details) end |
#update_comment(details = {}) ⇒ Hashie::Mash
Create a new comment on a plan and return information about it
253 254 255 |
# File 'lib/plancast/client.rb', line 253 def update_comment(details={}) self.class.post("/comments/update.json", :body => details) end |
#update_subscription(options = {}) ⇒ Hashie::Mash
Subscribe the authenticated user to a target user and returns information about the target user. If the target user has enabled account protection, a subscription request will be sent.
59 60 61 |
# File 'lib/plancast/client.rb', line 59 def update_subscription(={}) self.class.post("/subscriptions/update.json", :body => ) end |
#user(query = {}) ⇒ Hashie::Mash
Return information about a given user.
36 37 38 |
# File 'lib/plancast/client.rb', line 36 def user(query={}) self.class.get("/users/show.json", :query => query) end |
#verify_credentials ⇒ Hashie::Mash
Verify account credentials and gets information about the authenticated user
23 24 25 |
# File 'lib/plancast/client.rb', line 23 def verify_credentials self.class.get("/account/verify_credentials.json") end |