class Supersaas::Users

REF: www.supersaas.com/info/dev/user_api

Public Instance Methods

create(attributes, user_id=nil, webhook=nil) click to toggle source
# File lib/supersaas-api-client/api/users.rb, line 21
def create(attributes, user_id=nil, webhook=nil)
  path = user_path(user_id)
  query = {webhook: webhook}
  params = {
    user: {
      name: validate_present(attributes[:name]),
      email: attributes[:email],
      password: attributes[:password],
      full_name: attributes[:full_name],
      address: attributes[:address],
      mobile: attributes[:mobile],
      phone: attributes[:phone],
      country: attributes[:country],
      field_1: attributes[:field_1],
      field_2: attributes[:field_2],
      super_field: attributes[:super_field],
      credit: attributes[:credit] && validate_number(attributes[:credit]),
      role: attributes[:role] && validate_options(attributes[:role], User::ROLES)
    }
  }
  client.post(path, params, query)
end
delete(user_id) click to toggle source
# File lib/supersaas-api-client/api/users.rb, line 67
def delete(user_id)
  path = user_path(validate_id(user_id))
  client.delete(path)
end
get(user_id) click to toggle source
# File lib/supersaas-api-client/api/users.rb, line 15
def get(user_id)
  path = user_path(user_id)
  res = client.get(path)
  Supersaas::User.new(res)
end
list(form=nil, limit=nil, offset=nil) click to toggle source
# File lib/supersaas-api-client/api/users.rb, line 4
def list(form=nil, limit=nil, offset=nil)
  path = user_path(nil)
  params = {
      form: form ? true : nil,
      limit: limit && validate_number(limit),
      offset: offset && validate_number(offset)
  }
  res = client.get(path, params)
  res.map { |attributes| Supersaas::User.new(attributes) }
end
update(user_id, attributes, webhook=nil) click to toggle source
# File lib/supersaas-api-client/api/users.rb, line 44
def update(user_id, attributes, webhook=nil)
  path = user_path(validate_id(user_id))
  query = {webhook: webhook}
  params = {
    user: {
      name: attributes[:name],
      email: attributes[:email],
      password: attributes[:password],
      full_name: attributes[:full_name],
      address: attributes[:address],
      mobile: attributes[:mobile],
      phone: attributes[:phone],
      country: attributes[:country],
      field_1: attributes[:field_1],
      field_2: attributes[:field_2],
      super_field: attributes[:super_field],
      credit: attributes[:credit] && validate_number(attributes[:credit]),
      role: attributes[:role] && validate_options(attributes[:role], User::ROLES)
    }
  }
  client.put(path, params, query)
end

Private Instance Methods

user_path(user_id) click to toggle source
# File lib/supersaas-api-client/api/users.rb, line 74
def user_path(user_id)
  if user_id.nil? || user_id == ''
    "/users"
  else
    "/users/#{user_id}"
  end
end