Class: Supersaas::Users

Inherits:
BaseApi show all
Defined in:
lib/supersaas-api-client/api/users.rb

Overview

Constant Summary

Constants inherited from BaseApi

BaseApi::DATETIME_REGEX, BaseApi::INTEGER_REGEX, BaseApi::PROMOTION_REGEX

Instance Attribute Summary

Attributes inherited from BaseApi

#client

Instance Method Summary collapse

Methods inherited from BaseApi

#initialize

Constructor Details

This class inherits a constructor from Supersaas::BaseApi

Instance Method Details

#create(attributes, user_id = nil, webhook = nil, duplicate = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/supersaas-api-client/api/users.rb', line 23

def create(attributes, user_id = nil, webhook = nil, duplicate = nil)
  path = user_path(user_id)
  query = { webhook: webhook }
  query.merge!(duplicate: validate_duplicate(duplicate)) if duplicate
  params = {
    user: {
      name: validate_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],
      timezone: attributes[:timezone],
      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) ⇒ Object



74
75
76
77
# File 'lib/supersaas-api-client/api/users.rb', line 74

def delete(user_id)
  path = user_path(user_id)
  client.delete(path)
end

#field_listObject



79
80
81
82
83
# File 'lib/supersaas-api-client/api/users.rb', line 79

def field_list
  path = '/field_list'
  res = client.get(path)
  res.map { |attributes| Supersaas::FieldList.new(attributes) }
end

#get(user_id) ⇒ Object



17
18
19
20
21
# File 'lib/supersaas-api-client/api/users.rb', line 17

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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/supersaas-api-client/api/users.rb', line 6

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, notfound = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/supersaas-api-client/api/users.rb', line 48

def update(user_id, attributes, webhook = nil, notfound = nil)
  path = user_path(user_id)
  query = { webhook: webhook }
  query.merge!(notfound: validate_notfound(notfound)) if notfound
  params = {
    user: {
      name: validate_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],
      timezone: attributes[:timezone],
      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)
    }
  }
  params[:user].compact!
  client.put(path, params, query)
end