Module: Toolhound::Client::Users

Defined in:
lib/toolhound-ruby/client/users.rb

Overview

Methods for the Users API

Instance Method Summary collapse

Instance Method Details

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



61
62
63
# File 'lib/toolhound-ruby/client/users.rb', line 61

def delete_user(user, options = {})
  delete "users/#{user}", options
end

#edit_user(user, options = {}) ⇒ Object Also known as: update_user

Edit a user

Examples:

Update a user

@client.edit_user('some_id', {
  email: "[email protected]",
  name: "Markus Klooth"
})

Parameters:

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

    User information.

Options Hash (options):

  • :email (String)

    Email of user

  • :name (String)

    Name of user

  • :nickname (String)

    Nickname of user

  • :role (Integer)

    Set to admin or not

  • :phone_number (String)

    Phone number of user

  • :image (String)

    URL of image of user

  • :language (String)

    Code “en”, “de”, “es”

Returns:

  • Sawyer::Resource

    Edited user info



51
52
53
# File 'lib/toolhound-ruby/client/users.rb', line 51

def edit_user(user, options = {})
  patch "update_user/#{user}", options
end

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



56
57
58
# File 'lib/toolhound-ruby/client/users.rb', line 56

def update_email(user, options = {})

end

#user(user = nil, options = {}) ⇒ Sawyer::Resource

Get a single user

Examples:

Nearmiss.user("31817811-dce4-48c4-aa5f-f49603c5abee") or Nearmiss.user("[email protected]")

Parameters:

  • user (String) (defaults to: nil)

    Nearmiss user email or id.

Returns:

  • (Sawyer::Resource)


24
25
26
27
28
29
30
31
# File 'lib/toolhound-ruby/client/users.rb', line 24

def user(user=nil, options = {})
  if user.nil?
    get "me", options
  else
    get "users/#{user}", options
  end
  # get User.path(user), options
end

#users(options = {}) ⇒ Array<Sawyer::Resource> Also known as: list_users

Note:

Logged in user must be an admin to see all users

List users

Returns:

  • (Array<Sawyer::Resource>)

    List of projects



13
14
15
# File 'lib/toolhound-ruby/client/users.rb', line 13

def users(options = {})
  paginate "users", options
end

#validate_credentials(options = {}) ⇒ Boolean

Validate user username and password

Parameters:

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

    User credentials

Options Hash (options):

  • :email (String)

    Nearmiss login email

  • :password (String)

    Nearmiss password

Returns:

  • (Boolean)

    True if credentials are valid



71
72
73
74
75
# File 'lib/toolhound-ruby/client/users.rb', line 71

def validate_credentials(options = {})
  !self.class.new(options).user.nil?
rescue Toolhound::Unauthorized
  false
end