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



63
64
65
# File 'lib/foursquare2/users.rb', line 63

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



34
35
36
37
38
39
# File 'lib/foursquare2/users.rb', line 34

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



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

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) ⇒ Object

Get information about a user

Parameters:

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



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

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

#user_approve_friend(user_id) ⇒ Object

Approve friendship with a user.

Parameters:

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



210
211
212
213
214
215
# File 'lib/foursquare2/users.rb', line 210

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

#user_badges(user_id) ⇒ Object

Get all badges for a given user.

Parameters:

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



77
78
79
80
# File 'lib/foursquare2/users.rb', line 77

def user_badges(user_id)
  response = connection.get("users/#{user_id}/badges")
  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.



90
91
92
93
94
95
# File 'lib/foursquare2/users.rb', line 90

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) ⇒ Object

Deny friendship with a user.

Parameters:

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



221
222
223
224
225
226
# File 'lib/foursquare2/users.rb', line 221

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

#user_friend_request(user_id) ⇒ Object

Request friendship with a user

Parameters:

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



188
189
190
191
192
193
# File 'lib/foursquare2/users.rb', line 188

def user_friend_request(user_id)
  response = connection.post do |req|
    req.url "users/#{user_id}/request"
  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



104
105
106
107
108
109
# File 'lib/foursquare2/users.rb', line 104

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.



177
178
179
180
181
182
# File 'lib/foursquare2/users.rb', line 177

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) ⇒ Object

Get the mayorships for a given user.

Parameters:

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



163
164
165
166
167
168
# File 'lib/foursquare2/users.rb', line 163

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

#user_requestsObject

Get all pending friend requests for the authenticated user



68
69
70
71
# File 'lib/foursquare2/users.rb', line 68

def user_requests
  response = connection.get("users/requests")
  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.



233
234
235
236
237
238
# File 'lib/foursquare2/users.rb', line 233

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.



121
122
123
124
125
126
127
128
# File 'lib/foursquare2/users.rb', line 121

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



138
139
140
141
142
143
# File 'lib/foursquare2/users.rb', line 138

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) ⇒ Object

Unfriend a user

Parameters:

  • user_id (String)
    • The user to unfriend.



199
200
201
202
203
204
# File 'lib/foursquare2/users.rb', line 199

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

#user_venue_history(options = {}) ⇒ Object



152
153
154
155
156
157
# File 'lib/foursquare2/users.rb', line 152

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.



245
246
247
248
249
250
# File 'lib/foursquare2/users.rb', line 245

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