Module: Foursquare2::Users

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

Instance Method Summary collapse

Instance Method Details

#check_name(user, query) ⇒ Object

check if the first last name of user match the query



65
66
67
# File 'lib/foursquare2/users.rb', line 65

def check_name user, query
  user.firstName.downcase.match(query.downcase)
end

#leaderboard(options = {}) ⇒ Object

Get user’s leaderboard details

Parameters:

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

Options Hash (options):

  • Integer (Object)

    :neighbors Number of friends’ scores adjacent to your score



9
10
11
12
13
14
# File 'lib/foursquare2/users.rb', line 9

def leaderboard(options={})
  response = connection.get do |req|
    req.url "users/leaderboard", options
  end
  return_error_or_body(response, response.body.response)
end

#search_users(options = {}) ⇒ Object

Search for users

Parameters:

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

Options Hash (options):

  • String (Object)

    :phone - Match on phone number

  • String (Object)

    :email - Match on email

  • String (Object)

    :twitter - Match on twitter username

  • String (Object)

    :twitterSource - Friends of this twitter handle that use foursquare.

  • String (Object)

    :fbid - Match on facebook id.

  • String (Object)

    :name - Match on name



36
37
38
39
40
41
# File 'lib/foursquare2/users.rb', line 36

def search_users(options={})
  response = connection.get do |req|
    req.url "users/search", options
  end
  return_error_or_body(response, response.body.response)
end

#search_users_by_tip(options = {}) ⇒ Object

Search for users by tip

Parameters:

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

Options Hash (options):

  • String (Object)

    :ll - Latitude and longitude in format LAT,LON

  • Integer (Object)

    :limit - The limit of results to return.

  • Integer (Object)

    :offset - Used to page through results.

  • String (Object)

    :filter - Set to ‘friends’ to limit tips to those from friends.

  • String (Object)

    :query - Only find tips matching this term.

  • String (Object)

    :name - Match on name



52
53
54
55
56
57
58
59
60
61
# File 'lib/foursquare2/users.rb', line 52

def search_users_by_tip(options={})
    name = options.delete(:name)
    options[:limit] = 500
    tips = search_tips(options)
    user = []
    tips.each do |tip|
      user << tip['user'] if check_name(tip['user'], name)
    end
    user.uniq
end

#user(user_id, options = {}) ⇒ Object

Get information about a user

Parameters:

  • user_id (Integer)
    • User to get information for.



20
21
22
23
24
25
# File 'lib/foursquare2/users.rb', line 20

def user(user_id, options={})
  response = connection.get do |req|
    req.url "users/#{user_id}", options
  end
  return_error_or_body(response, response.body.response.user)
end

#user_approve_friend(user_id, options = {}) ⇒ Object

Approve friendship with a user.

Parameters:

  • user_id (String)
    • The user to approve friendship with.



230
231
232
233
234
235
# File 'lib/foursquare2/users.rb', line 230

def user_approve_friend(user_id, options={})
  response = connection.post do |req|
    req.url "users/#{user_id}/approve", options
  end
  return_error_or_body(response, response.body.response)
end

#user_badges(user_id, options = {}) ⇒ Object

Get all badges for a given user.

Parameters:

  • user_id (String)
    • The user to retrieve badges for.



81
82
83
84
85
86
# File 'lib/foursquare2/users.rb', line 81

def user_badges(user_id, options={})
  response = connection.get do |req|
    req.url "users/#{user_id}/badges", options
  end
  return_error_or_body(response, response.body.response)
end

#user_checkins(options = {}) ⇒ Object

Get checkins for the authenticated user

Parameters:

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

Options Hash (options):

  • Integer (Object)

    :limit

  • Integer (Object)

    :offest - For paging through results

  • String (Object)

    :sort - “newestfirst” or “oldestfirst”

  • Integer (Object)

    :afterTimestamp - Get all checkins after this epoch time.

  • Integer (Object)

    :beforeTimestamp - Get all checkins before this epoch time.



96
97
98
99
100
101
# File 'lib/foursquare2/users.rb', line 96

def user_checkins(options={})
  response = connection.get do |req|
    req.url "users/self/checkins", options
  end
  return_error_or_body(response, response.body.response.checkins)
end

#user_deny_friend(user_id, options = {}) ⇒ Object

Deny friendship with a user.

Parameters:

  • user_id (String)
    • The user to deny friendship with.



241
242
243
244
245
246
# File 'lib/foursquare2/users.rb', line 241

def user_deny_friend(user_id, options={})
  response = connection.post do |req|
    req.url "users/#{user_id}/deny", options
  end
  return_error_or_body(response, response.body.response)
end

#user_friend_request(user_id, options = {}) ⇒ Object

Request friendship with a user

Parameters:

  • user_id (String)
    • The user to request friendship with.



208
209
210
211
212
213
# File 'lib/foursquare2/users.rb', line 208

def user_friend_request(user_id, options={})
  response = connection.post do |req|
    req.url "users/#{user_id}/request", options
  end
  return_error_or_body(response, response.body.response)
end

#user_friends(user_id, options = {}) ⇒ Object

Get all friends for a given user.

Parameters:

  • user_id (String)
    • The user to retrieve friends for.

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

Options Hash (options):

  • Integer (Object)

    :limit

  • Integer (Object)

    :offest - For paging through results



110
111
112
113
114
115
# File 'lib/foursquare2/users.rb', line 110

def user_friends(user_id, options={})
  response = connection.get do |req|
    req.url "users/#{user_id}/friends", options
  end
  return_error_or_body(response, response.body.response.friends)
end

#user_lists(user_id, options = {}) ⇒ Object

Get the lists for a given user.

Parameters:

  • user_id (String)
    • The user to retrieve lists for.

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

Options Hash (options):

  • String (Object)

    :group - One of: created, edited, followed, friends, or suggestions

  • String (Object)

    :ll - Location of the user, required in order to receive the suggested group.



197
198
199
200
201
202
# File 'lib/foursquare2/users.rb', line 197

def user_lists(user_id, options={})
  response = connection.get do |req|
    req.url "users/#{user_id}/lists", options
  end
  return_error_or_body(response, response.body.response.lists)
end

#user_mayorships(user_id, options = {}) ⇒ Object

Get the mayorships for a given user.

Parameters:

  • user_id (String)
    • The user to retrieve friends for.



183
184
185
186
187
188
# File 'lib/foursquare2/users.rb', line 183

def user_mayorships(user_id, options={})
  response = connection.get do |req|
    req.url "users/#{user_id}/mayorships", options
  end
  return_error_or_body(response, response.body.response.mayorships)
end

#user_photos(options = {}) ⇒ Object



158
159
160
161
162
163
# File 'lib/foursquare2/users.rb', line 158

def user_photos(options={})
  response = connection.get do |req|
    req.url "users/self/photos", options
  end
  return_error_or_body(response, response.body.response.photos)
end

#user_requests(options = {}) ⇒ Object

Get all pending friend requests for the authenticated user



70
71
72
73
74
75
# File 'lib/foursquare2/users.rb', line 70

def user_requests(options={})
  response = connection.get do |req|
    req.url "users/requests", options
  end
  return_error_or_body(response, response.body.response.requests)
end

#user_set_friend_pings(user_id, value) ⇒ Object

Set pings for a friend

Parameters:

  • user_id (String)
    • The user to set pings for

  • value (String)
    • The value of ping setting for this friend, either true or false.



253
254
255
256
257
258
# File 'lib/foursquare2/users.rb', line 253

def user_set_friend_pings(user_id, value)
  response = connection.post do |req|
    req.url "users/#{user_id}/setpings", value
  end
  return_error_or_body(response, response.body.response)
end

#user_tips(user_id, options = {}) ⇒ Object

Get all tips for a given user, optionally filtering by text.

Parameters:

  • user_id (String)
    • The user to retrieve friends for.

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

    a customizable set of options

Options Hash (options):

  • Integer (Object)

    :limit

  • Integer (Object)

    :offest - For paging through results

  • String (Object)

    :sort - One of recent, nearby, popular

  • String (Object)

    :ll - Latitude and longitude in format LAT,LON - required for nearby sort option.



127
128
129
130
131
132
133
134
# File 'lib/foursquare2/users.rb', line 127

def user_tips(user_id, options={})
  response = connection.get do |req|
    req.url "users/#{user_id}/tips", options
  end
  tips = return_error_or_body(response, response.body.response.tips)
  tips = Foursquare2.filter(tips, options[:query]) if options.has_key? :query
  tips
end

#user_todos(user_id, options = {}) ⇒ Object



144
145
146
147
148
149
# File 'lib/foursquare2/users.rb', line 144

def user_todos(user_id, options={})
  response = connection.get do |req|
    req.url "users/#{user_id}/todos", options
  end
  return_error_or_body(response, response.body.response.todos)
end

#user_unfriend(user_id, options = {}) ⇒ Object

Unfriend a user

Parameters:

  • user_id (String)
    • The user to unfriend.



219
220
221
222
223
224
# File 'lib/foursquare2/users.rb', line 219

def user_unfriend(user_id, options={})
  response = connection.post do |req|
    req.url "users/#{user_id}/unfriend", options
  end
  return_error_or_body(response, response.body.response)
end

#user_venue_history(options = {}) ⇒ Object



172
173
174
175
176
177
# File 'lib/foursquare2/users.rb', line 172

def user_venue_history(options={})
  response = connection.get do |req|
    req.url "users/self/venuehistory", options
  end
  return_error_or_body(response, response.body.response.venues)
end

#venuestats(user_id = "self", options = {}) ⇒ Object

Summary of venues visited by a user optional @param [String] user_id - The user to get venue stats for.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • Integer (Object)

    :afterTimestamp - checkins after this epoch time.

  • Integer (Object)

    :beforeTimestamp - checkins before this epoch time.



265
266
267
268
269
270
# File 'lib/foursquare2/users.rb', line 265

def venuestats(user_id="self", options={})
  response = connection.get do |req|
    req.url "users/#{user_id}/venuestats", options
  end
  return_error_or_body(response, response.body.response)
end