Class: FsApi::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Client

Returns a new instance of Client.



6
7
8
9
# File 'lib/fs_api/client.rb', line 6

def initialize(username, password)
  @username = username
  @password = password
end

Instance Attribute Details

#_last_responseObject (readonly)

Returns the value of attribute _last_response.



3
4
5
# File 'lib/fs_api/client.rb', line 3

def _last_response
  @_last_response
end

#errorsObject

Returns the value of attribute errors.



4
5
6
# File 'lib/fs_api/client.rb', line 4

def errors
  @errors
end

#passwordObject (readonly)

Returns the value of attribute password.



3
4
5
# File 'lib/fs_api/client.rb', line 3

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



3
4
5
# File 'lib/fs_api/client.rb', line 3

def username
  @username
end

Instance Method Details

#base_urlObject



11
12
13
# File 'lib/fs_api/client.rb', line 11

def base_url
  "https://www.factuursturen.nl:443/api/v1"
end

#clientsObject



66
67
68
# File 'lib/fs_api/client.rb', line 66

def clients
  FsApi::Service::Client.new(self)
end

#delete(path, headers = {}) ⇒ Object



56
57
58
59
60
# File 'lib/fs_api/client.rb', line 56

def delete(path, headers={})
  uri = uri_for_path(path)
  http = Net::HTTP::Delete.new(uri.request_uri, self.headers.merge(headers))
  perform(http)
end

#get(path, headers = {}) ⇒ Object



36
37
38
39
40
# File 'lib/fs_api/client.rb', line 36

def get(path, headers={})
  uri = uri_for_path(path)
  http = Net::HTTP::Get.new(uri.request_uri, self.headers.merge(headers))
  perform(http)
end

#headersObject



25
26
27
28
29
30
# File 'lib/fs_api/client.rb', line 25

def headers
  {
    'Accept' => 'application/json',
    'Content-Type' => 'application/json'
  }
end

#httpObject



15
16
17
18
19
20
21
22
23
# File 'lib/fs_api/client.rb', line 15

def http
  @http ||= begin
    uri = uri_for_path(base_url)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = uri.scheme == 'https'
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    http
  end
end

#invoicesObject



62
63
64
# File 'lib/fs_api/client.rb', line 62

def invoices
  FsApi::Service::Invoice.new(self)
end

#invoices_paymentsObject



74
75
76
# File 'lib/fs_api/client.rb', line 74

def invoices_payments
  FsApi::Service::InvoicesPayment.new(self)
end

#post(path, body = nil, headers = {}) ⇒ Object



49
50
51
52
53
54
# File 'lib/fs_api/client.rb', line 49

def post(path, body=nil, headers={})
  uri = uri_for_path(path)
  http = Net::HTTP::Post.new(uri.request_uri, self.headers.merge(headers))
  http.body = body
  perform(http)
end

#productsObject



70
71
72
# File 'lib/fs_api/client.rb', line 70

def products
  FsApi::Service::Product.new(self)
end

#put(path, body = nil, headers = {}) ⇒ Object



42
43
44
45
46
47
# File 'lib/fs_api/client.rb', line 42

def put(path, body=nil, headers={})
  uri = uri_for_path(path)
  http = Net::HTTP::Put.new(uri.request_uri, self.headers.merge(headers))
  http.body = body
  perform(http)
end

#saved_invoicesObject



78
79
80
# File 'lib/fs_api/client.rb', line 78

def saved_invoices
  FsApi::Service::InvoicesSaved.new(self)
end

#uri_for_path(path) ⇒ Object



32
33
34
# File 'lib/fs_api/client.rb', line 32

def uri_for_path(path)
  URI.parse(File.join(base_url, path))
end