Module: TheCity::API::Users

Includes:
Utils
Included in:
Client
Defined in:
lib/the_city/api/users.rb

Instance Method Summary collapse

Instance Method Details

#me(options = {}) ⇒ TheCity::User Also known as: current_user

Returns the user associated with the current access token

Parameters:

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

    A customizable set of options.

Options Hash (options):

  • :force_download (Boolean)

    Forces the request to hit the server and flush the cached response

Returns:

See Also:



36
37
38
39
# File 'lib/the_city/api/users.rb', line 36

def me(options={})
  @me = nil if options.delete(:force_download)
  @me ||= object_from_response(TheCity::User, :get, "/me", options, {:current_user => true, :client => self})
end

#permissions(options = {}) ⇒ TheCity::Permissions

Returns the permissions for the current user

Parameters:

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

    A customizable set of options.

Returns:

See Also:



51
52
53
54
# File 'lib/the_city/api/users.rb', line 51

def permissions(*args)
  arguments = TheCity::Arguments.new(args)
  object_from_response(TheCity::Permissions, :get, "/me/permissions", arguments.options)
end

#user(id) ⇒ TheCity::User #user(id, options = {}) ⇒ TheCity::User

Returns The requested user.

Overloads:

  • #user(id) ⇒ TheCity::User

    Parameters:

    • id (Integer)

      The id of the user.

  • #user(id, options = {}) ⇒ TheCity::User

    Parameters:

    • id (Integer)

      The id of the user.

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

      A customizable set of options.

    Options Hash (options):

    • :force_download (Boolean)

      Forces the request to hit the server and flush the cached response

Returns:

Raises:

See Also:



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

def user(*args)
  @users ||= {}
  arguments = TheCity::Arguments.new(args)
  uid = args.shift
  @users[uid] = nil if arguments.options.delete(:force_download)
  @users[uid] ||= object_from_response(TheCity::User, :get, "/users/#{uid}", arguments.options, {:client => self})
end

#user?(user) ⇒ Boolean

Returns true if the specified user exists

Parameters:

  • user (Integer, String, TheCity::User)

    A City user id, or object.

Returns:

  • (Boolean)

    true if the user exists, otherwise false.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/the_city/api/users.rb', line 61

def user?(user)
  user_id = case user
  when ::Integer
    user
  when ::String
    user.to_i
  when TheCity::User
    user.id
  end
  get("/users/#{user_id}")
  true
rescue TheCity::Error::NotFound
  false
end