Class: RestfulKashflow::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/restful_kashflow/client.rb

Overview

A class for working with and talking to the Kashflow API

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/restful_kashflow/client.rb', line 5

def initialize(options)
  username = options.delete(:username) || raise('No username given to Restful Kashflow Client')
  password = options.delete(:password) || raise('No password given to Restful Kashflow Client')
  memorable_word = options.delete(:memorable_word) || raise('No memorable word given to Restful Kashflow Client')
  environment = options.delete(:environment) || :live
  @customer = {}

  url = options.delete(:url) || url_for_environment(environment)

  @api_service = ApiService.new(username,
                                password,
                                memorable_word,
                                url,
                                options)
end

Instance Method Details

#customer(customer_id = nil) ⇒ Object



25
26
27
# File 'lib/restful_kashflow/client.rb', line 25

def customer(customer_id = nil)
  @customer[customer_id] ||= Services::Customer.new(@api_service, customer_id)
end

#new_customer(name:, email:, first_name:, last_name:) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/restful_kashflow/client.rb', line 29

def new_customer(name: , email:, first_name:, last_name:)
  customer = Services::Customer.create(
    @api_service,
    name,
    email,
    first_name,
    last_name
  )

  puts pp customer
  puts customer.class
  puts customer.first
  puts customer["Code"]
  puts customer["Contacts"].first["Email"]

  puts mandate = Services::Customer.get_mandate(
    api_service: @api_service,
    code: customer["Code"]
  )

  mandate = Services::Customer.create_mandate(
    api_service: @api_service,
    code: customer["Code"],
    email: customer["Contacts"].first["Email"]
  )
  puts mandate
  return { customer: customer, mandate: mandate }
end

#statusObject



21
22
23
# File 'lib/restful_kashflow/client.rb', line 21

def status
  @api_service.status
end