moneybird 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 944b2c8d8441278203f58d084b530147a0f23886
4
- data.tar.gz: 1c7a0f696c363928717f41f4294544a853a1cf73
3
+ metadata.gz: e95396ed4efb40b6b353de2fd52324137c0dc7ef
4
+ data.tar.gz: 23d23d0f007276daff2a3254ade2cccab9963246
5
5
  SHA512:
6
- metadata.gz: b527b144d9dcf62f37832b35e20f21875e00c223e865b738719bc73b9e6ada95c02b4bb57b603fdd5acac91d3d3d6d14e0f9ac5d7a476f58c618c1ec9bc9813a
7
- data.tar.gz: 686f076396deeaa72a11445db74375eb3fee3d8c48adc0004c1a18114ffc9ec82ed5f8212902b451004caa3976c698d975b87af4a11276851c988c4e95010f93
6
+ metadata.gz: 940f204d739c8a1bc9cb41754ba9a5c15bf228375b7ad3c8173598754b0dc537eee24973b34eb5712a9a19014677bc9ddba131ed15d5770dde8011e24b892d24
7
+ data.tar.gz: 40c9db3585dac07505fe6e6b91cd166da5abb48d8a7064cbc1f97840ffb9f1d9fc38dfe9aaa51fe2a047728f8e9fb52b28c14ca1c0acfc13ce584a3b75ee28c2
@@ -2,6 +2,7 @@
2
2
  require 'active_support'
3
3
  require 'active_support/core_ext/object/json'
4
4
  require 'active_support/core_ext/string/inflections'
5
+ require 'faraday'
5
6
 
6
7
  require 'logger'
7
8
  require 'uri'
@@ -21,33 +22,14 @@ require "moneybird/traits/save"
21
22
  require "moneybird/traits/delete"
22
23
  require "moneybird/client"
23
24
  require "moneybird/resource"
24
- require "moneybird/resource/invoice/details"
25
- require "moneybird/resource/generic/note"
26
- require "moneybird/resource/generic/event"
27
25
  require "moneybird/webhook"
28
26
 
29
- resources = %w(
30
- administration
31
- contact
32
- document_style
33
- estimate
34
- financial_account
35
- financial_mutation
36
- identity
37
- ledger_account
38
- product
39
- recurring_sales_invoice
40
- sales_invoice
41
- tax_rate
42
- webhook
43
- workflow
44
- )
45
-
46
- resources.each do |resource|
47
- require "moneybird/service/#{resource}"
48
- require "moneybird/resource/#{resource}"
27
+ Dir[File.join(File.dirname(__FILE__), 'moneybird/service', '**/*.rb')].each do |service|
28
+ require service
49
29
  end
50
30
 
51
-
31
+ Dir[File.join(File.dirname(__FILE__), 'moneybird/resource', '**/*.rb')].each do |resource|
32
+ require resource
33
+ end
52
34
 
53
35
  require "moneybird/version"
@@ -2,7 +2,7 @@ module Moneybird
2
2
  class Client
3
3
  attr_reader :bearer_token, :_last_response
4
4
  attr_accessor :errors
5
- attr_writer :http
5
+ attr_writer :http, :faraday_adapter
6
6
 
7
7
  def initialize(bearer_token)
8
8
  @bearer_token = bearer_token
@@ -16,11 +16,18 @@ module Moneybird
16
16
  @version ||= 'v2'
17
17
  end
18
18
 
19
+ def faraday_adapter
20
+ @faraday_adapter ||= Faraday.default_adapter
21
+ end
22
+
19
23
  def http
20
24
  @http ||= begin
21
25
  uri = uri_for_path(base_url)
22
- http = Net::HTTP.new(uri.host, uri.port)
23
- http.use_ssl = uri.scheme == 'https'
26
+ http = Faraday.new(:url => uri) do |faraday|
27
+ faraday.request :url_encoded
28
+ faraday.response :logger
29
+ faraday.adapter faraday_adapter
30
+ end
24
31
  http
25
32
  end
26
33
  end
@@ -39,37 +46,26 @@ module Moneybird
39
46
 
40
47
  def get(path, headers={})
41
48
  uri = uri_for_path(path)
42
- http = Net::HTTP::Get.new(uri.request_uri, self.headers.merge(headers))
43
- perform(http)
49
+ @_last_response = http.get(uri.request_uri, nil, self.headers.merge(headers))
44
50
  end
45
51
 
46
52
  def patch(path, body=nil, headers={})
47
53
  uri = uri_for_path(path)
48
- http = Net::HTTP::Patch.new(uri.request_uri, self.headers.merge(headers))
49
- http.body = body
50
- perform(http)
54
+ @_last_response = http.patch(uri.request_uri, body, self.headers.merge(headers))
51
55
  end
52
56
 
53
57
  def post(path, body=nil, headers={})
54
58
  uri = uri_for_path(path)
55
- http = Net::HTTP::Post.new(uri.request_uri, self.headers.merge(headers))
56
- http.body = body
57
- perform(http)
59
+ @_last_response = http.post(uri.request_uri, body, self.headers.merge(headers))
58
60
  end
59
61
 
60
62
  def delete(path, headers={})
61
63
  uri = uri_for_path(path)
62
- http = Net::HTTP::Delete.new(uri.request_uri, self.headers.merge(headers))
63
- perform(http)
64
+ @_last_response = http.delete(uri.request_uri, nil, self.headers.merge(headers))
64
65
  end
65
66
 
66
67
  def administrations
67
68
  Moneybird::Service::Administration.new(self).all
68
69
  end
69
-
70
- private
71
- def perform(request)
72
- @_last_response = http.request(request)
73
- end
74
70
  end
75
71
  end
@@ -16,6 +16,10 @@ module Moneybird::Resource
16
16
  Moneybird::Service::LedgerAccount.new(@client, id)
17
17
  end
18
18
 
19
+ def purchase_invoices
20
+ Moneybird::Service::PurchaseInvoice.new(@client, id)
21
+ end
22
+
19
23
  def sales_invoices
20
24
  Moneybird::Service::SalesInvoice.new(@client, id)
21
25
  end
@@ -45,6 +45,8 @@ module Moneybird::Resource
45
45
  events
46
46
  email_ubl
47
47
  sales_invoices_url
48
+ invoice_workflow_id
49
+ estimate_workflow_id
48
50
  )
49
51
 
50
52
  def notes=(notes)
@@ -0,0 +1,23 @@
1
+ module Moneybird::Resource::Invoice
2
+ class Payment
3
+ include Moneybird::Resource
4
+ extend Moneybird::Resource::ClassMethods
5
+
6
+ has_attributes %i(
7
+ administration_id
8
+ created_at
9
+ credit_invoice_id
10
+ financial_account_id
11
+ financial_mutation_id
12
+ id
13
+ invoice_id
14
+ invoice_type
15
+ payment_date
16
+ payment_transaction_id
17
+ price
18
+ price_base
19
+ updated_at
20
+ user_id
21
+ )
22
+ end
23
+ end
@@ -0,0 +1,56 @@
1
+ module Moneybird::Resource
2
+ class PurchaseInvoice
3
+ include Moneybird::Resource
4
+ extend Moneybird::Resource::ClassMethods
5
+
6
+ has_attributes %i(
7
+ administration_id
8
+ attachments
9
+ contact
10
+ contact_id
11
+ created_at
12
+ currency
13
+ date
14
+ details
15
+ due_date
16
+ entry_number
17
+ events
18
+ exchange_rate
19
+ id
20
+ notes
21
+ origin
22
+ paid_at
23
+ payments
24
+ prices_are_incl_tax
25
+ reference
26
+ revenue_invoice
27
+ state
28
+ tax_number
29
+ total_price_excl_tax
30
+ total_price_excl_tax_base
31
+ total_price_incl_tax
32
+ total_price_incl_tax_base
33
+ updated_at
34
+ )
35
+
36
+ def notes=(notes)
37
+ @notes ||= notes.map{ |note| Moneybird::Resource::Generic::Note.build(note) }
38
+ end
39
+
40
+ def contact=(attributes)
41
+ @contact = Moneybird::Resource::Contact.build(attributes)
42
+ end
43
+
44
+ def details=(line_items)
45
+ @details = line_items.map{ |line_item| Moneybird::Resource::Invoice::Details.build(line_item) }
46
+ end
47
+
48
+ def events=(events)
49
+ @events ||= events.map{ |event| Moneybird::Resource::Generic::Event.build(event) }
50
+ end
51
+
52
+ def payments=(payments)
53
+ @payments ||= payments.map{ |payment| Moneybird::Resource::Invoice::Payment.build(payment) }
54
+ end
55
+ end
56
+ end
@@ -18,7 +18,7 @@ module Moneybird::Service
18
18
  def find_by_customer_id(customer_id)
19
19
  result = client.get("#{path}/customer_id/#{customer_id}")
20
20
 
21
- if result.code.to_i == GET_SUCCESS_CODE
21
+ if result.status.to_i == GET_SUCCESS_CODE
22
22
  build(JSON.parse(result.body))
23
23
  end
24
24
  end
@@ -0,0 +1,18 @@
1
+ module Moneybird::Service
2
+ class PurchaseInvoice
3
+ include Moneybird::Traits::AdministrationService
4
+ include Moneybird::Traits::Service
5
+ include Moneybird::Traits::Find
6
+ include Moneybird::Traits::FindAll
7
+ include Moneybird::Traits::Save
8
+ include Moneybird::Traits::Delete
9
+
10
+ def resource_class
11
+ Moneybird::Resource::PurchaseInvoice
12
+ end
13
+
14
+ def path
15
+ "#{administration_id}/documents/purchase_invoices"
16
+ end
17
+ end
18
+ end
@@ -5,7 +5,7 @@ module Moneybird
5
5
 
6
6
  def delete(resource)
7
7
  client.delete(resource_path(resource))
8
- if client._last_response.code.to_i != DELETE_SUCCESS_CODE
8
+ if client._last_response.status.to_i != DELETE_SUCCESS_CODE
9
9
  resource.errors = client._last_response.body
10
10
  return false
11
11
  end
@@ -6,7 +6,7 @@ module Moneybird
6
6
  def find(id)
7
7
  result = client.get("#{path}/#{id}")
8
8
 
9
- if result.code.to_i == GET_SUCCESS_CODE
9
+ if result.status.to_i == GET_SUCCESS_CODE
10
10
  build(JSON.parse(result.body))
11
11
  end
12
12
  end
@@ -6,7 +6,7 @@ module Moneybird
6
6
  def all
7
7
  result = client.get(path)
8
8
 
9
- if result.code.to_i == GET_SUCCESS_CODE
9
+ if result.status.to_i == GET_SUCCESS_CODE
10
10
  JSON.parse(result.body).map do |resource|
11
11
  build(resource)
12
12
  end
@@ -11,7 +11,7 @@ module Moneybird
11
11
  def save(resource)
12
12
  if resource.persisted?
13
13
  client.patch(resource_path(resource), resource.to_json)
14
- if client._last_response.code.to_i == UPDATE_SUCCESS_CODE
14
+ if client._last_response.status.to_i == UPDATE_SUCCESS_CODE
15
15
  resource.attributes = JSON.parse(client._last_response.body)
16
16
  else
17
17
  resource.errors = client._last_response.body
@@ -19,7 +19,7 @@ module Moneybird
19
19
  end
20
20
  else
21
21
  client.post(resource_path(resource), resource.to_json)
22
- if client._last_response.code.to_i == CREATE_SUCCESS_CODE
22
+ if client._last_response.status.to_i == CREATE_SUCCESS_CODE
23
23
  resource.attributes = JSON.parse(client._last_response.body)
24
24
  else
25
25
  resource.errors = client._last_response.body
@@ -1,3 +1,3 @@
1
1
  module Moneybird
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "activesupport", '>= 3.0'
22
+ spec.add_dependency "activesupport", '>= 0.12'
23
+ spec.add_dependency "faraday"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.11"
25
26
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moneybird
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten van Vliet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-25 00:00:00.000000000 Z
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '0.12'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '0.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -113,8 +127,10 @@ files:
113
127
  - lib/moneybird/resource/generic/note.rb
114
128
  - lib/moneybird/resource/identity.rb
115
129
  - lib/moneybird/resource/invoice/details.rb
130
+ - lib/moneybird/resource/invoice/payment.rb
116
131
  - lib/moneybird/resource/ledger_account.rb
117
132
  - lib/moneybird/resource/product.rb
133
+ - lib/moneybird/resource/purchase_invoice.rb
118
134
  - lib/moneybird/resource/recurring_sales_invoice.rb
119
135
  - lib/moneybird/resource/sales_invoice.rb
120
136
  - lib/moneybird/resource/tax_rate.rb
@@ -129,6 +145,7 @@ files:
129
145
  - lib/moneybird/service/identity.rb
130
146
  - lib/moneybird/service/ledger_account.rb
131
147
  - lib/moneybird/service/product.rb
148
+ - lib/moneybird/service/purchase_invoice.rb
132
149
  - lib/moneybird/service/recurring_sales_invoice.rb
133
150
  - lib/moneybird/service/sales_invoice.rb
134
151
  - lib/moneybird/service/tax_rate.rb