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.

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.

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.

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.

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.

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.

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.

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.

Options Hash (options):

  • limit (Integer)

    Number of results to return, up to 500.

  • offset (Integer)

    Used to page through results.

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.


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


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.

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.

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.

Options Hash (options):

  • ll (String)

    Latitude and longitude of the user's location.

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.

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.

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.

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.

Options Hash (options):

  • group (String)

    Either created, edited, followed, friends or suggested.

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.

Options Hash (options):

  • limit (Integer)

    Number of results to return, up to 500.

  • offset (Integer)

    Used to page through results

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.

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.

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.

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.

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.

Options Hash (options):

  • beforeTimestamp (Integer)

    Seconds since epoch.

  • afterTimestamp (Integer)

    Seconds after epoch.

  • categoryId (String)

    Limits returned venues to those in this category.

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