Class: Foursquare2::Client
- Inherits:
-
Object
- Object
- Foursquare2::Client
- Extended by:
- Forwardable
- Includes:
- Campaigns, Checkins, Events, Lists, Pages, Photos, Settings, Specials, Tips, Users, Venuegroups, Venues
- Defined in:
- lib/foursquare2/client.rb
Constant Summary collapse
- DEFAULT_CONNECTION_MIDDLEWARE =
[ Faraday::Request::Multipart, Faraday::Request::UrlEncoded, FaradayMiddleware::Mashify, FaradayMiddleware::ParseJson ]
Instance Attribute Summary collapse
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#oauth_token ⇒ Object
readonly
Returns the value of attribute oauth_token.
Instance Method Summary collapse
-
#api_url ⇒ Object
Base URL for api requests.
-
#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 foursquare API requests.
-
#return_error_or_body(response, response_body) ⇒ Object
Helper method to return errors or desired response data as appropriate.
- #ssl ⇒ Object
Methods included from Events
Methods included from Lists
#add_list, #add_list_item, #delete_list_item, #follow_list, #list, #move_list_item, #unfollow_list, #update_list
Methods included from Campaigns
#add_campaign, #campaign, #end_campaign, #list_campaigns
Methods included from Pages
#managed_pages, #page, #page_venues, #search_pages
Methods included from Users
#check_name, #leaderboard, #search_users, #search_users_by_tip, #user, #user_approve_friend, #user_badges, #user_checkins, #user_deny_friend, #user_friend_request, #user_friends, #user_lists, #user_mayorships, #user_photos, #user_requests, #user_set_friend_pings, #user_tips, #user_todos, #user_unfriend, #user_venue_history, #venuestats
Methods included from Specials
#add_special, #search_specials, #special
Methods included from Settings
#setting, #settings, #update_setting
Methods included from Photos
#add_photo, #photo, #venue_photos
Methods included from Tips
#add_tip, #mark_tip_done, #mark_tip_todo, #search_tips, #tip, #unmark_tip, #venue_tips
Methods included from Checkins
#add_checkin, #add_checkin_comment, #add_checkin_post, #add_checkin_reply, #checkin, #delete_checkin_comment, #recent_checkins
Methods included from Venuegroups
#add_venuegroup, #delete_venuegroup, #list_venuegroup, #venuegroup, #venuegroup_update
Methods included from Venues
#add_venue, #edit_venue, #explore_venues, #flag_venue, #herenow, #managed_venue_stats, #managed_venues, #mark_venue_todo, #propose_venue_edit, #search_venues, #search_venues_by_tip, #suggest_completion_venues, #trending_venues, #venue, #venue_categories, #venue_events, #venue_hours, #venue_likes, #venue_links, #venue_listed, #venue_menus, #venue_nextvenues, #venue_similar, #venues_timeseries
Constructor Details
#initialize(options = {}) ⇒ Client
Initialize the client class that will be used for all foursquare API requests. Note that either a valid user oauth token OR a valid client_id + secret is required.
Certain requests will require an oauth token. See developer.foursquare.com/docs/index_docs.html for the full list.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/foursquare2/client.rb', line 41 def initialize(={}) @client_id = [:client_id] || Foursquare2.client_id @client_secret = [:client_secret] || Foursquare2.client_secret @oauth_token = [:oauth_token] @api_version = [:api_version] || Foursquare2.api_version @locale = [:locale] || Foursquare2.locale @ssl = [:ssl] || Foursquare2.ssl || Hash.new @connection_middleware = [:connection_middleware] || Foursquare2.connection_middleware || [] @connection_middleware += DEFAULT_CONNECTION_MIDDLEWARE end |
Instance Attribute Details
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
27 28 29 |
# File 'lib/foursquare2/client.rb', line 27 def api_version @api_version end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
27 28 29 |
# File 'lib/foursquare2/client.rb', line 27 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
27 28 29 |
# File 'lib/foursquare2/client.rb', line 27 def client_secret @client_secret end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
27 28 29 |
# File 'lib/foursquare2/client.rb', line 27 def locale @locale end |
#oauth_token ⇒ Object (readonly)
Returns the value of attribute oauth_token.
27 28 29 |
# File 'lib/foursquare2/client.rb', line 27 def oauth_token @oauth_token end |
Instance Method Details
#api_url ⇒ Object
Base URL for api requests.
75 76 77 |
# File 'lib/foursquare2/client.rb', line 75 def api_url "https://api.foursquare.com/v2" end |
#connection ⇒ Object
Sets up the connection to be used for all requests based on options passed during initialization.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/foursquare2/client.rb', line 58 def connection params = {} params[:client_id] = @client_id if @client_id params[:client_secret] = @client_secret if @client_secret params[:oauth_token] = @oauth_token if @oauth_token params[:v] = @api_version if @api_version params[:locale] = @locale if @locale @connection ||= Faraday::Connection.new(:url => api_url, :ssl => @ssl, :params => params, :headers => default_headers) do |builder| @connection_middleware.each do |middleware| builder.use *middleware end builder.adapter Faraday.default_adapter end end |
#return_error_or_body(response, response_body) ⇒ 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.
83 84 85 86 87 88 89 |
# File 'lib/foursquare2/client.rb', line 83 def return_error_or_body(response, response_body) if response.body['meta'].code == 200 response_body else raise Foursquare2::APIError.new(response.body['meta'], response.body['response']) end end |
#ssl ⇒ Object
52 53 54 |
# File 'lib/foursquare2/client.rb', line 52 def ssl @ssl end |