Class: Checkdin::Client
- Inherits:
-
Object
- Object
- Checkdin::Client
- Extended by:
- Forwardable
- Includes:
- Activities, Campaigns, Clients, CustomActivities, Leaderboard, PointAccountEntries, Promotions, PushApiSubscriptions, TwitterHashtagStreams, Users, Votes, WonRewards
- Defined in:
- lib/checkdin/client.rb
Constant Summary collapse
- DEFAULT_API_URL =
"https://app.checkd.in/api/v1"
Instance Attribute Summary collapse
-
#api_url ⇒ Object
readonly
Base URL for api requests.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
Instance Method Summary collapse
-
#connection ⇒ Object
Sets up the connection to be used for all requests based on options passed during initialization.
-
#initialize(options = {}) ⇒ Client
constructor
Initialize the client class that will be used for all checkd.in API requests.
-
#return_error_or_body(response) ⇒ Object
Helper method to return errors or desired response data as appropriate.
Methods included from TwitterHashtagStreams
#twitter_hashtag_stream, #twitter_hashtag_streams
Methods included from PointAccountEntries
Methods included from PushApiSubscriptions
#disable_push_api_subscription, #enable_push_api_subscription, #push_api_subscription, #push_api_subscriptions
Methods included from Clients
Methods included from Votes
Methods included from Leaderboard
#campaign_leaderboard, #classification_leaderboard, #leaderboard
Methods included from CustomActivities
Methods included from Users
#blacklist, #blacklisted, #create_user, #create_user_authentication, #create_user_point_redemption, #user, #user_authentication, #user_authentications, #user_point_accounts, #users, #view_user_full_description, #whitelabel_user_lookup, #whitelist
Methods included from Activities
#activities, #activity, #add_vote_on_activity
Methods included from WonRewards
#retract_won_reward, #won_reward, #won_rewards
Methods included from Promotions
#create_promotion, #promotion, #promotion_votes_leaderboard, #promotions
Methods included from Campaigns
Constructor Details
#initialize(options = {}) ⇒ Client
Initialize the client class that will be used for all checkd.in API requests. Requires a valid client_id and client_secret - more info at developer.checkd.in
36 37 38 39 40 41 42 43 |
# File 'lib/checkdin/client.rb', line 36 def initialize(={}) @client_id = .delete(:client_id) @client_secret = .delete(:client_secret) @api_url = .delete(:api_url) || DEFAULT_API_URL @ssl = .delete(:ssl) || {} raise ArgumentError.new("Unexpected argument given: #{.inspect}") unless .blank? end |
Instance Attribute Details
#api_url ⇒ Object (readonly)
Base URL for api requests.
23 24 25 |
# File 'lib/checkdin/client.rb', line 23 def api_url @api_url end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
20 21 22 |
# File 'lib/checkdin/client.rb', line 20 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
20 21 22 |
# File 'lib/checkdin/client.rb', line 20 def client_secret @client_secret end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
21 22 23 |
# File 'lib/checkdin/client.rb', line 21 def ssl @ssl end |
Instance Method Details
#connection ⇒ Object
Sets up the connection to be used for all requests based on options passed during initialization.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/checkdin/client.rb', line 46 def connection @connection ||= begin params = { :client_id => client_id, :client_secret => client_secret } Faraday::Connection.new(:url => api_url, :ssl => ssl, :params => params, :headers => default_headers) do |builder| builder.use Faraday::Request::Multipart builder.use Faraday::Request::UrlEncoded builder.use FaradayMiddleware::Mashify builder.use FaradayMiddleware::ParseJson builder.adapter Faraday.default_adapter end end end |
#return_error_or_body(response) ⇒ Object
Helper method to return errors or desired response data as appropriate.
Added just for convenience to avoid having to traverse farther down the response just to get to returned data.
69 70 71 72 73 74 75 |
# File 'lib/checkdin/client.rb', line 69 def return_error_or_body(response) if response.status / 100 == 2 response.body else raise Checkdin::APIError.new(response.status, response.body) end end |