Class: QNE::Customers

Inherits:
Base
  • Object
show all
Includes:
QueryBuilder
Defined in:
lib/customers.rb

Constant Summary

Constants included from QueryBuilder

QueryBuilder::OPERATORS

Instance Attribute Summary collapse

Attributes inherited from Base

#conn, #response

Instance Method Summary collapse

Methods included from QueryBuilder

#eq_query, #multi_query, #uri_query, #where

Methods inherited from Base

#initialize, #parse_to_json, #success?

Constructor Details

This class inherits a constructor from QNE::Base

Instance Attribute Details

#customerObject

Returns the value of attribute customer.



12
13
14
# File 'lib/customers.rb', line 12

def customer
  @customer
end

#idObject

Returns the value of attribute id.



12
13
14
# File 'lib/customers.rb', line 12

def id
  @id
end

Instance Method Details

#all(params = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/customers.rb', line 29

def all(params = {})
  @response = QNE::Customer::All.new(
    conn, params: uri_query(params)
  ).call

  parse_to_json(@response.body)
end

#create(request_body) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/customers.rb', line 47

def create(request_body)
  @response = QNE::Customer::Create.new(
    conn, request_body: request_body
  ).call

  parse_to_json(@response.body)
end

#find(id) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/customers.rb', line 16

def find(id)
  @id = id
  finder = QNE::Customer::Find.new(conn, id: id).call

  return unless finder.success?

  define_singleton_method 'show' do
    parse_to_json(finder.body)
  end

  self
end

#find_by(params) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/customers.rb', line 37

def find_by(params)
  @response = QNE::Customer::FindBy.new(
    conn, params: eq_query(params)
  ).call

  body = parse_to_json(@response.body)

  @response.success? ? body.first : body
end

#show(id) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/customers.rb', line 55

def show(id)
  @response = QNE::Customer::Show.new(
    conn, id: id
  ).call

  parse_to_json(@response.body)
end

#update(request_body) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/customers.rb', line 63

def update(request_body)
  @response = QNE::Customer::Update.new(
    conn, request_body: request_body
  ).call

  parse_to_json(@response.body)
end