Class: SpyriApi::Users

Inherits:
Object
  • Object
show all
Defined in:
lib/spyri_api/users.rb

Constant Summary collapse

BASEPATH =
'/users'.freeze
SEARCHABLE_ATTRIBUTES =
[:email, :name, :phone_number, :erp_id].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client) ⇒ Users

Returns a new instance of Users.



11
12
13
# File 'lib/spyri_api/users.rb', line 11

def initialize(api_client)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



9
10
11
# File 'lib/spyri_api/users.rb', line 9

def api_client
  @api_client
end

Instance Method Details

#create(user_object) ⇒ Object



29
30
31
32
# File 'lib/spyri_api/users.rb', line 29

def create(user_object)
  path = BASEPATH
  @api_client.call_api(:POST, path, body: { user: user_object })
end

#get(id) ⇒ Object



24
25
26
27
# File 'lib/spyri_api/users.rb', line 24

def get(id)
  path = "#{BASEPATH}/#{id}"
  @api_client.call_api(:GET, path)
end

#search(opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/spyri_api/users.rb', line 15

def search(opts = {})
  query_params = {}
  SEARCHABLE_ATTRIBUTES.each do |key|
    query_params[key.to_s] = opts[key] if !opts[key].nil?
  end
  path = BASEPATH
  @api_client.call_api(:GET, path, query_params: query_params)
end

#update(id, user_object) ⇒ Object



34
35
36
37
# File 'lib/spyri_api/users.rb', line 34

def update(id, user_object)
  path = "#{BASEPATH}/#{id}"
  @api_client.call_api(:PATCH, path, body: { user: user_object })
end