Module: Foursquared::Users

Included in:
Client
Defined in:
lib/foursquared/users.rb

Overview

Users module

Instance Method Summary collapse

Instance Method Details

#approve_friend_request(user_id) ⇒ Foursquared::Response::User

Approves a pending friend request from another user.

Parameters:

  • user_id (String, Integer)

    The request user’s id

Returns:



29
30
31
32
# File 'lib/foursquared/users.rb', line 29

def approve_friend_request user_id
  response = post("/users/#{user_id}/approve")["response"]
  @user = Foursquared::Response::User.new(self,response["user"])
end

#deny_friend_request(user_id) ⇒ Foursquared::Response::User

Denies a pending friend request from another user.

Parameters:

  • user_id (String, Integer)

    The request user’s id

Returns:



37
38
39
40
# File 'lib/foursquared/users.rb', line 37

def deny_friend_request user_id
  response = post("/users/#{user_id}/deny")["response"]
  @user = Foursquared::Response::User.new(self,response["user"])
end

#leaderboard(options = {}) ⇒ Hash

Returns the user’s leaderboard.

Parameters:

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

    the optional options to be passed with the request

Options Hash (options):

  • :neighbors (Integer)

    Number of friends’ scores to return that are adjacent to your score, in ranked order.

Returns:

  • (Hash)

    the user’s leaderboard.



18
19
20
21
22
23
24
# File 'lib/foursquared/users.rb', line 18

def leaderboard options={}
  @leaderboard = get("/users/leaderboard", options)["response"]["leaderboard"]
  @leaderboard["items"].each do |item|
    item["user"] = Foursquared::Response::User.new(self,item["user"])
  end
  @leaderboard
end

#requestsArray

Pending friend requests

Returns:

  • (Array)

    User objects



60
61
62
63
# File 'lib/foursquared/users.rb', line 60

def requests
  response = get("/users/requests")["response"]
  @requests = response["requests"].collect{|request| Foursquared::Response::User.new(self,request)}
end

#search(options = {}) ⇒ Hash

Find users

Parameters:

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

Options Hash (options):

  • :phone (String)

    A comma-delimited list of phone numbers to look for.

  • :email (String)

    A comma-delimited list of email addresses to look for.

  • :twitter (String)

    A comma-delimited list of Twitter handles to look for.

  • :twitterSource (String)

    A single Twitter handle. Results will be users that this handle follows on Twitter who use Foursquare.

  • :fbid (String)

    A comma-delimited list of Facebook ID’s to look for.

  • :name (String)

    A single string to search for in users’ names.

Returns:

  • (Hash)


74
75
76
77
78
# File 'lib/foursquared/users.rb', line 74

def search options={}
  response = get("/users/search", options)["response"]
  response["results"].map!{|result| Foursquared::Response::User.new(self,result)}
  response
end

#send_friend_request(user_id) ⇒ Foursquared::Response::User

Send a Friend/Follow Request

Parameters:

  • user_id (String, Integer)

    The request user’s/page’s id

Returns:



45
46
47
48
# File 'lib/foursquared/users.rb', line 45

def send_friend_request user_id
  response = post("/users/#{user_id}/request")["response"]
  @user = Foursquared::Response::User.new(self,response["user"])
end

#set_pings(user_id, options = {}) ⇒ Foursquared::Response::User

Set whether to receive pings about a user

Parameters:

  • user_id (String, Integer)

    User ID of a friend

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

Options Hash (options):

  • :value (Boolean)

    True or false.

Returns:



85
86
87
88
# File 'lib/foursquared/users.rb', line 85

def set_pings user_id, options={}
  response = post("/users/#{user_id}/setpings", options)["response"]
  @user = Foursquared::Response::User.new(self,response["user"])
end

#unfriend(user_id) ⇒ Foursquared::Response::User

Removes a friend, unfollows a celebrity, or cancels a pending friend request.

Parameters:

  • user_id (String, Integer)

    The request user’s id

Returns:



53
54
55
56
# File 'lib/foursquared/users.rb', line 53

def unfriend user_id
  response = post("/users/#{user_id}/unfriend")["response"]
  @user = Foursquared::Response::User.new(self,response["user"])
end

#update_photo(image_filename) ⇒ Foursquared::Response::User

Update user’s photo

Parameters:

  • image_filename (String)

    The location of the photo to be uploaded

Returns:



93
94
95
96
# File 'lib/foursquared/users.rb', line 93

def update_photo image_filename
  response = post("/users/self/update", options={:photo => File.read(image_filename)})["response"]
  @user = Foursquared::Response::User.new(self, response["user"])
end

#user(user_id = "self") ⇒ Foursquared::Response::User

Return profile information for a given user

Parameters:

  • user_id (String, Integer) (defaults to: "self")

    user’s id

Returns:



9
10
11
12
# File 'lib/foursquared/users.rb', line 9

def user user_id="self"
  @user = get("/users/#{user_id}")["response"]["user"]
  Foursquared::Response::User.new(self,@user)
end

#user_badges(user_id = "self") ⇒ Hash

Badges for a user

Parameters:

  • user_id (String, Integer) (defaults to: "self")

Returns:

  • (Hash)


191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/foursquared/users.rb', line 191

def user_badges user_id="self"
  response = get("/users/#{user_id}/badges")["response"]
  if response["sets"] and response["sets"]["groups"]
    response["sets"]["groups"].map!{|group| Foursquared::Response::BadgeGroup.new(self, group)}
  end

  if response["badges"]
    response["badges"].each_key do |badge_id|
      response["badges"][badge_id] = badge(badge_id)
    end
  end
  response
end

#user_checkins(user_id = "self", options = {}) ⇒ Hash

Checkins by a user

Parameters:

  • user_id (String, Integer) (defaults to: "self")
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :limit (Integer)

    Number of results to return, up to 250.

  • :offset (Integer)

    The number of results to skip. Used to page through results.

  • :sort (String)

    How to sort the returned checkins. Can be “newestfirst” or “oldestfirst”.

  • :afterTimestamp (Integer)

    Retrieve the first results to follow these seconds since epoch

  • :beforeTimestamp (Integer)

    Retrieve the first results prior to these seconds since epoch

Returns:

  • (Hash)

    A count and items of check-ins.



107
108
109
110
111
# File 'lib/foursquared/users.rb', line 107

def user_checkins user_id="self", options={}
  response = get("/users/#{user_id}/checkins",options)["response"]["checkins"]
  response["items"].map!{|checkin| Foursquared::Response::Checkin.new(self, checkin)} if response["items"]
  response
end

#user_friends(user_id = "self", options = {}) ⇒ Hash

List friends

Parameters:

  • user_id (String, Integer) (defaults to: "self")
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :limit (Integer)

    Number of results to return, up to 500.

  • :offset (Integer)

    Used to page through results.

Returns:

  • (Hash)

    A count and items of friends.



119
120
121
122
123
# File 'lib/foursquared/users.rb', line 119

def user_friends user_id="self", options={}
  response = get("/users/#{user_id}/friends"), options["response"]["friends"]
  response["items"].map!{|friend| Foursquared::Response::User.new(self, friend)} if response["items"]
  response
end

#user_lists(user_id = "self", options = {}) ⇒ Hash

Return the user’s lists

Parameters:

  • user_id (String, Integer) (defaults to: "self")
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :group (String)

    “edited”, “created”, “followed”, “friends” or “suggested”

  • :ll (String)

    Location of the user eg: 40.7,-74

Returns:

  • (Hash)


131
132
133
134
135
136
137
138
# File 'lib/foursquared/users.rb', line 131

def user_lists user_id="self", options={}
  response = get("/users/#{user_id}/lists", options)["response"]
  @lists = response["lists"]
  @lists["groups"].each do |group|
    group["items"].map!{|item| Foursquared::Response::List.new(self, item)}
  end
  @lists
end

#user_mayorships(user_id = "self") ⇒ Hash

List user’s mayorships

Parameters:

  • user_id (String, Integer) (defaults to: "self")

Returns:

  • (Hash)


143
144
145
146
147
148
# File 'lib/foursquared/users.rb', line 143

def user_mayorships user_id="self"
  response = get("/users/#{user_id}/mayorships")["response"]
  @mayorships = response["mayorships"]
  @mayorships["items"].each{|item| item["venue"] = Foursquared::Response::Venue.new(self, item["venue"])}
  @mayorships
end

#user_photos(user_id = "self", options = {}) ⇒ Hash

Photos from a User

Parameters:

  • user_id (String, Integer) (defaults to: "self")
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :limit (Integer)

    Number of results to return, up to 500.

  • :offset (Integer)

    The number of results to skip. Used to page through results.

Returns:

  • (Hash)

    A count and items of photos.



156
157
158
159
160
# File 'lib/foursquared/users.rb', line 156

def user_photos user_id="self", options={}
  response = get("/users/#{user_id}/photos",options)["response"]
  @photos = response["photos"]
  @photos["items"].map!{|item| Foursquared::Response::Photo.new(self, item)}
end

#user_tips(user_id = "self", options = {}) ⇒ Foursquared::Response::List

Tips from a User

Parameters:

  • user_id (String, Integer) (defaults to: "self")
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :limit (Object)

    Number of results to return, up to 200.

  • :offset (Object)

    The number of results to skip. Used to page through results.

  • :llBounds (Object)

    Restricts the returned results to the input bounding box.

  • :categoryId (Object)

    Restricts the returned results to venues matching the input category id.

Returns:



170
171
172
173
# File 'lib/foursquared/users.rb', line 170

def user_tips user_id="self", options={}
  response = get("/lists/#{user_id}/tips", options)["response"]
  Foursquared::Response::List.new(self, response["list"])
end

#user_todos(user_id = "self", options = {}) ⇒ Foursquared::Response::List

Todos from a User

Parameters:

  • user_id (String, Integer) (defaults to: "self")
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :limit (Object)

    Number of results to return, up to 200.

  • :offset (Object)

    The number of results to skip. Used to page through results.

  • :llBounds (Object)

    Restricts the returned results to the input bounding box.

  • :categoryId (Object)

    Restricts the returned results to venues matching the input category id.

Returns:



183
184
185
186
# File 'lib/foursquared/users.rb', line 183

def user_todos user_id="self", options={}
  response = get("/lists/#{user_id}/todos", options)["response"]
  Foursquared::Response::List.new(self, response["list"])
end