Module: Skittles::Client::User

Included in:
Skittles::Client
Defined in:
lib/skittles/client/user.rb

Overview

Define methods related to users.

Instance Method Summary collapse

Instance Method Details

#approve_user(id) ⇒ Hashie::Mash

Approve a pending friend request from another user.

Parameters:

  • id (String)

    The user ID of a pending friend.

Returns:

  • (Hashie::Mash)

    A user object for the approved user.

See Also:

Requires Acting User:

  • Yes



14
15
16
# File 'lib/skittles/client/user.rb', line 14

def approve_user(id)
  post("users/#{id}/approve").user
end

#badges(id) ⇒ Hashie::Mash

Returns badges for a given user.

Parameters:

  • id (String)

    Id for user to view badges for.

Returns:

  • (Hashie::Mash)

    Hierarchical groups of badge ids or, for unlocked badges, badge unlock ids, as they are intended for display.

  • (Hashie::Mash)

    A map of badge ids or badge unlock ids to a badge or a hierarchical groups of badge ids or, for unlocked badges, badge unlock ids, as they are intended for display.

See Also:

Requires Acting User:

  • Yes



24
25
26
# File 'lib/skittles/client/user.rb', line 24

def badges(id)
  get("users/#{id}/badges")
end

#checkins(id = 'self', options = {}) ⇒ Hashie::Mash

Returns a history of checkins for the authenticated user.

Parameters:

  • id (String) (defaults to: 'self')

    For now, only “self” is supported.

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

    A customizable set of options.

Options Hash (options):

  • limit (Integer)

    Number of results to return, up to 500.

  • offset (Integer)

    Used to page through results.

  • sort (String)

    How to sort the returned checkeins. 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:

  • (Hashie::Mash)

    A count of items in check-ins.

See Also:

Requires Acting User:

  • Yes



40
41
42
# File 'lib/skittles/client/user.rb', line 40

def checkins(id = 'self', options = {})
  get("users/#{id}/checkins").checkins
end

#deny_user(id) ⇒ Hashie::Mash

Denies a pending friend request from another user.

Parameters:

  • id (String)

    The user ID of a pending friend.

Returns:

  • (Hashie::Mash)

    A user object for the denied user.

See Also:

Requires Acting User:

  • Yes



50
51
52
# File 'lib/skittles/client/user.rb', line 50

def deny_user(id)
  post("users/#{id}/deny").user
end

#friend_request(id) ⇒ Hashie::Mash

Deprecated.

Use Skittles#send_friend_request

Sends a friend request to another user.

Parameters:

  • id (String)

    The user ID to which a request will be sent.

Returns:

  • (Hashie::Mash)

    A user object for the pending user.

See Also:

Requires Acting User:

  • Yes



61
62
63
64
# File 'lib/skittles/client/user.rb', line 61

def friend_request(id)
  deprecated('friend_request', 'send_friend_request')
  send_friend_request(id)
end

#friend_requestsHashie::Mash

Shows a user the list of users with whom they have a pending friend request.

Returns:

  • (Hashie::Mash)

    An array of compact user objects.

See Also:

Requires Acting User:

  • Yes



72
73
74
# File 'lib/skittles/client/user.rb', line 72

def friend_requests
  get("users/requests").requests
end

#friends(id, options = {}) ⇒ Hashie::Mash

Returns an array of user's friends.

get friends of the acting user.

Parameters:

  • id (String)

    Identity of the user to get friends of. Pass self to

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

    A customizable set of options.

Options Hash (options):

  • limit (Integer)

    Number of results to return, up to 500.

  • offset (Integer)

    Used to page through results.

Returns:

  • (Hashie::Mash)

    A count and items of compact user objects.

See Also:

Requires Acting User:

  • Yes



86
87
88
# File 'lib/skittles/client/user.rb', line 86

def friends(id, options = {})
  get("users/#{id}/friends").friends
end

#leaderboard(neighbors = nil) ⇒ Hashie::Mash

Returns the user's leaderboard.

Parameters:

  • neightbors (Integer)

    Number of friends' scores to return that are adjacent to your score in ranked order. The current user's score is returned as well.

Returns:

  • (Hashie::Mash)

    A count and items containing compact user objects, their respective scores, and their integer rank value relative to the current user.

See Also:

Requires Acting User:

  • Yes



96
97
98
# File 'lib/skittles/client/user.rb', line 96

def leaderboard(neighbors = nil)
  get('users/leaderboard').leaderboard
end

#mayorships(id = 'self') ⇒ Hashie::Mash

Returns a user's mayorships

Returns:

  • (Hashie::Mash)

    A count and items of objects which currently only contain compact venue objects.

See Also:

Requires Acting User:

  • Yes



119
120
121
# File 'lib/skittles/client/user.rb', line 119

def mayorships(id = 'self')
  get("users/#{id}/mayorships").mayorships
end

#send_friend_request(id) ⇒ Hashie::Mash

Sends a friend request to another user.

Parameters:

  • id (String)

    The user ID to which a request will be sent.

Returns:

  • (Hashie::Mash)

    A user object for the pending user.

See Also:

Requires Acting User:

  • Yes



142
143
144
# File 'lib/skittles/client/user.rb', line 142

def send_friend_request(id)
  get("users/#{id}").user
end

#setpings(id, value = false) ⇒ Hashie::Mash

Changes whether the acting user will receive pings (phone notifications) when the specified user checks in.

Parameters:

  • id (String)

    The user ID of a friend.

  • value (Boolean) (defaults to: false)

    True of false.

Returns:

  • (Hashie::Mash)

    A user object for the user.

See Also:

Requires Acting User:

  • Yes



154
155
156
# File 'lib/skittles/client/user.rb', line 154

def setpings(id, value = false)
  post("users/#{id}/setpings", { :value => value }).user
end

#todos(id, sort = 'recent', options = {}) ⇒ Hashie::Mash

Deprecated.

Use Skittles#list_todos

Returns todos from a user.

Parameters:

  • id

    Identity of the user to get todos for. Pass self to get todos of the acting user.

  • sort (defaults to: 'recent')

    One of recent or popular. Nearby requires geolat and geolong to be provided.

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

    A customizable set of options.

Options Hash (options):

  • ll (String)

    Latitude and longitude of the user's location.

Returns:

  • (Hashie::Mash)

    A count and items of todos.

See Also:

Requires Acting User:

  • Yes



168
169
170
171
# File 'lib/skittles/client/user.rb', line 168

def todos(id, sort = 'recent', options = {})
  deprecated("todos", "list_todos")
  get("users/#{id}/todos", { :sort => sort }.merge(options)).todos
end

#unfriend(id) ⇒ Hashie::Mash

Cancels any relationship between the acting user and the specified user.

Parameters:

  • id (String)

    Identity of the user to unfriend.

Returns:

  • (Hashie::Mash)

    A user.

See Also:

Requires Acting User:

  • Yes



221
222
223
# File 'lib/skittles/client/user.rb', line 221

def unfriend(id)
  post("users/#{id}/unfriend").user
end

#update_user_photo(photo) ⇒ Hashie::Mash

Updates the user's profile photo.

Parameters:

  • photo (String)

    Photo under 100KB in multipark MIME encoding with content type image/jpeg, image/gif, or image/png.

Returns:

  • (Hashie::Mash)

    The current user object

See Also:

Requires Acting User:

  • Yes



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/skittles/client/user.rb', line 179

def update_user_photo(photo)
  mime_type = MIME::Types.type_for(photo)[0]
  params = {
    :photo => UploadIO.new(photo, mime_type.to_s, "image.#{mime_type.extensions[0]}"),
    :oauth_token => access_token
  }
  uri = URI.parse("#{endpoint}/users/self/update")
  File.open(photo) do
    req = Net::HTTP::Post::Multipart.new(uri.path, params)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true if uri.scheme == 'https'
    resp = http.start do |net|
      net.request(req)
    end
    
    case resp.code.to_i
    when 200..299
      return Skittles::Utils.parse_json(resp.body).response.user
    when 400..599
      Skittles::Utils.handle_foursquare_error(resp)
    end
  end
end

#user(id = 'self') ⇒ Hashie::Mash

Returns profile information for a given user, including selected badges and mayorships.

Parameters:

  • id (String) (defaults to: 'self')

    Identity of the user to get details for. Pass self to get details of the acting user.

Returns:

  • (Hashie::Mash)

    Profile information for a given user.

See Also:

Requires Acting User:

  • Yes



210
211
212
# File 'lib/skittles/client/user.rb', line 210

def user(id = 'self')
  get("users/#{id}").user
end

#user_lists(id = 'self', options = {}) ⇒ Hashie::Mash

A user's lists.

Parameters:

  • id (String) (defaults to: 'self')

    Identity of the user to get lists for. Pass self to get lists of the acting user.

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

    A customizable set of options.

  • options[String] (Hash)

    a customizable set of options

Options Hash (options):

  • group (String)

    Either created, edited, followed, friends or suggested.

Returns:

  • (Hashie::Mash)

    A user's lists.

See Also:



109
110
111
# File 'lib/skittles/client/user.rb', line 109

def user_lists(id = 'self', options = {})
  get("users/#{id}/lists", options).lists
end

#user_photos(id = 'self', options = {}) ⇒ Hashie::Mash

Returns photos from a user.

Parameters:

  • id (String) (defaults to: 'self')

    Identity of the user to get photos for. Pass self to get photos of the acting user.

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

    A customizable set of options.

Options Hash (options):

  • limit (Integer)

    Number of results to return, up to 500.

  • offset (Integer)

    Used to page through results

Returns:

  • (Hashie::Mash)

    A count and items of photos.

See Also:

Requires Acting User:

  • Yes



132
133
134
# File 'lib/skittles/client/user.rb', line 132

def user_photos(id = 'self', options = {})
  get("/users/#{id}/photos", options).photos
end

#user_search(options = {}) ⇒ Hashie::Mash

Helps a user locate friends.

Parameters:

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

    A customizable set of options.

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 friends of this user 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:

  • (Hashie::Mash)

    An array of compact user objects with Twitter or Facebook information and friend status.

See Also:



237
238
239
# File 'lib/skittles/client/user.rb', line 237

def user_search(options = {})
  get('users/search', options)
end

#user_tips(id, options = {}) ⇒ Hashie::Mash

Deprecated.

User Skittles#list_tips

Returns tips from a user.

Parameters:

  • id (String)

    Identity of the user to get tips from. Pass self to get tips of the acting user.

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

    a customizable set of options

Options Hash (options):

  • A (Hash)

    customizable set of options.

  • sort (String)

    One of recent, nearby, or popular. Nearby requires geolat and geolong to be provided.

  • ll (String)

    Latitude and longitude of the user's location.

  • limit (String)

    Number of results to return, up to 500.

  • offset (String)

    Used to page through results.

Returns:

  • (Hashie::Mash)

    A count and items of tips.

See Also:

Requires Acting User:

  • Yes



253
254
255
256
# File 'lib/skittles/client/user.rb', line 253

def user_tips(id, options = {})
  deprecated("user_tips", "list_tips")
  get("users/#{id}/tips").tips
end

#venuehistory(id = 'self', options = {}) ⇒ Hashie::Mash

Note:

This is an experimental API.

Returns a list of all venues visited by the specified user, along with how many visits and when they were last there.

Parameters:

  • id (String) (defaults to: 'self')

    For now, only “self” is supported.

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

    A customizable set of options.

Options Hash (options):

  • beforeTimestamp (Integer)

    Seconds since epoch.

  • afterTimestamp (Integer)

    Seconds after epoch.

  • categoryId (String)

    Limits returned venues to those in this category.

Returns:

  • (Hashie::Mash)

    A count and items of objects containing a beenHere count, lastHereAt timestamp, and venue compact venues.

See Also:

Requires Acting User:

  • Yes



270
271
272
# File 'lib/skittles/client/user.rb', line 270

def venuehistory(id = 'self', options = {})
  get("users/#{id}/venuehistory", options).venues
end