Class: Foursquared::Client

Inherits:
Object
  • Object
show all
Includes:
Badges, Checkins, Events, Lists, Pages, Photos, Settings, Specials, Tips, Users, Venues, HTTMultiParty
Defined in:
lib/foursquared/client.rb

Overview

The Client class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Tips

#add_tip, #like_tip, #mark_tip_done, #mark_tip_todo, #search_tips, #tip, #tip_dones, #tip_likes, #tip_listed, #unmark_tip_todo

Methods included from Settings

#all_settings, #set_setting, #setting

Methods included from Specials

#flag_special, #special

Methods included from Pages

#like_page, #page, #page_search, #page_venues

Methods included from Events

#add_event, #event, #event_categories

Methods included from Badges

#badge

Methods included from Checkins

#add_checkin, #add_checkin_comment, #checkin, #checkin_likes, #delete_checkin_comment, #like_checkin, #recent_checkins

Methods included from Venues

#add_venue, #explore_venues, #flag_venue, #like_venue, #managed_venues, #propose_venue_edit, #search_venues, #trending_venues, #venue, #venue_categories, #venue_events, #venue_hours, #venue_likes, #venue_lists, #venue_photos

Methods included from Lists

#add_list, #add_list_item, #delete_list_item, #list, #suggest_list_photo, #suggest_list_tip, #suggest_list_venues

Methods included from Photos

#add_photo, #photo

Methods included from Users

#approve_friend_request, #deny_friend_request, #leaderboard, #requests, #search, #send_friend_request, #set_pings, #unfriend, #update_photo, #user, #user_badges, #user_checkins, #user_friends, #user_lists, #user_mayorships, #user_photos, #user_tips, #user_todos

Constructor Details

#initialize(credentials = {}) ⇒ Client

Returns a new instance of Client.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/foursquared/client.rb', line 23

def initialize credentials={}
  @client_id = credentials[:client_id]
  @client_secret = credentials[:client_secret]
  @access_token = credentials[:access_token]
  if @access_token
    self.class.default_params :oauth_token => @access_token
  elsif @client_id and @client_secret
    self.class.default_params :client_id => @client_id
    self.class.default_params :client_secret => @client_secret
  else
    raise "Must provide access_token or client_id and client_secret"
  end
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



6
7
8
# File 'lib/foursquared/client.rb', line 6

def access_token
  @access_token
end

#client_idObject

Returns the value of attribute client_id.



22
23
24
# File 'lib/foursquared/client.rb', line 22

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



22
23
24
# File 'lib/foursquared/client.rb', line 22

def client_secret
  @client_secret
end

Instance Method Details

#get(url, options = {}) ⇒ Object

Do a ‘get’ request

Parameters:

  • url (String)

    the url to get

  • options (Hash) (defaults to: {})

    Additonal options to be passed



40
41
42
43
44
45
46
47
48
# File 'lib/foursquared/client.rb', line 40

def get url, options={}
  options.merge!({:v => Time.now.strftime("%Y%m%d")}) unless options[:v]
  response = self.class.get(url, {:query => options}).parsed_response
  if response["meta"]["code"] == 200
    return response
  else
    raise Foursquared::Error.new(response["meta"])
  end
end

#post(url, options = {}) ⇒ Object

Do a ‘post’ request

Parameters:

  • url (String)

    the url to post

  • options (Hash) (defaults to: {})

    Additonal options to be passed



53
54
55
56
57
58
59
60
61
# File 'lib/foursquared/client.rb', line 53

def post url, options={}
  options.merge!({:v => Time.now.strftime("%Y%m%d")}) unless options[:v]
  response = self.class.post(url, {:body => options}).parsed_response
  if response["meta"]["code"] == 200
    return response
  else
    raise Foursquared::Error.new(response["meta"])
  end
end