Class: MfCloud::Invoice::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|@config| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (@config)


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mf_cloud/invoice/client.rb', line 28

def initialize(options = {}, &block)
  @config = MfCloud::Invoice::Configure.new(options)

  yield @config if block_given?

  @conn = Faraday.new(url: "#{MfCloud::Invoice::API_URL}#{@config.api_version}") do |faraday|
    faraday.request :json

    faraday.response :json

    faraday.adapter Faraday.default_adapter
  end
end

Instance Method Details

#billingsObject



54
55
56
# File 'lib/mf_cloud/invoice/client.rb', line 54

def billings
  @_billings ||= MfCloud::Invoice::Api::Billing.new(self)
end

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



90
91
92
93
94
95
96
97
# File 'lib/mf_cloud/invoice/client.rb', line 90

def delete(path, params = {})
  res = @conn.delete do |req|
    req.headers['Authorization'] = "Bearer #{@config.access_token}"
    req.url path, params
  end

  check_response!(res)
end

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



58
59
60
61
62
63
64
65
66
# File 'lib/mf_cloud/invoice/client.rb', line 58

def get(path, params = {})
  res = @conn.get do |req|
    req.headers['Authorization'] = "Bearer #{@config.access_token}"
    req.url path, params
  end

  check_response!(res)
  res.body
end

#itemsObject



50
51
52
# File 'lib/mf_cloud/invoice/client.rb', line 50

def items
  @_items ||= MfCloud::Invoice::Api::Item.new(self)
end

#officeObject



42
43
44
# File 'lib/mf_cloud/invoice/client.rb', line 42

def office
  @_office ||= MfCloud::Invoice::Api::Office.new(self)
end

#partnersObject



46
47
48
# File 'lib/mf_cloud/invoice/client.rb', line 46

def partners
  @_partners ||= MfCloud::Invoice::Api::Partner.new(self)
end

#post(path, params = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/mf_cloud/invoice/client.rb', line 68

def post(path, params = {})
  res = @conn.post do |req|
    req.headers['Authorization'] = "Bearer #{@config.access_token}"
    req.url path
    req.body = params
  end

  check_response!(res)
  res.body
end

#put(path, params = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/mf_cloud/invoice/client.rb', line 79

def put(path, params = {})
  res = @conn.put do |req|
    req.headers['Authorization'] = "Bearer #{@config.access_token}"
    req.url path
    req.body = params
  end

  check_response!(res)
  res.body
end