octobat 2.0.17 → 2.0.22

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
- SHA1:
3
- metadata.gz: cba02a0cbd6ef4f0f6f8687a7addcd59dd96a294
4
- data.tar.gz: b519371775c52b8b6f6a8b30b11fabc9729f0cc1
2
+ SHA256:
3
+ metadata.gz: f103ca1de7b1fa391b9e7d17530d78ada6d6353bd63c5c8e7db09047ef9e3063
4
+ data.tar.gz: 9aa6e8e6c71f51f678e7087f4184154c419d70399254044059d30efdceee2d8e
5
5
  SHA512:
6
- metadata.gz: 06fb388b483d8fe843c6db383abfdea030775ddc4603e02862692a1a81b8d7b478fd79d69a4c422b64bc00a8ad3ff41bd96b21b3304638a806b1de69349f9bc9
7
- data.tar.gz: 732c2061e95830f5a0b94ca642102f1c4d95cdaa68a80c9009030e2506d0dc6500bbd867ef45a6c0b4cd316e0d48d1a90bd9c152740bdcbeb605644c7f313196
6
+ metadata.gz: 5eb46faf6dfcfcc621f2aa8207a42e9c214b8af361bbc657058213e447e9a4b0bab9bcc274ebb68b7a5dc29a1b478568db23eded829becdb7f01f762153b511d
7
+ data.tar.gz: 3fcd9c96dfd1d01d9ba83e6cdaa166ac9604eb67d48d364b3b9c3fe379528c4f02962f531f2d58d204ce8d97973171ddd554f2b61207d86c0031e51d539aa06e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- octobat (2.0.17)
4
+ octobat (2.0.22)
5
5
  rest-client (>= 1.4, < 4.0)
6
6
 
7
7
  GEM
@@ -9,19 +9,21 @@ GEM
9
9
  specs:
10
10
  domain_name (0.5.20190701)
11
11
  unf (>= 0.0.5, < 1.0.0)
12
+ http-accept (1.7.0)
12
13
  http-cookie (1.0.3)
13
14
  domain_name (~> 0.5)
14
- mime-types (3.2.2)
15
+ mime-types (3.3.1)
15
16
  mime-types-data (~> 3.2015)
16
- mime-types-data (3.2019.0331)
17
+ mime-types-data (3.2020.1104)
17
18
  netrc (0.11.0)
18
- rest-client (2.0.2)
19
+ rest-client (2.1.0)
20
+ http-accept (>= 1.7.0, < 2.0)
19
21
  http-cookie (>= 1.0.2, < 2.0)
20
22
  mime-types (>= 1.16, < 4.0)
21
23
  netrc (~> 0.8)
22
24
  unf (0.1.4)
23
25
  unf_ext
24
- unf_ext (0.0.7.6)
26
+ unf_ext (0.0.7.7)
25
27
 
26
28
  PLATFORMS
27
29
  ruby
@@ -30,4 +32,4 @@ DEPENDENCIES
30
32
  octobat!
31
33
 
32
34
  BUNDLED WITH
33
- 1.14.6
35
+ 1.17.3
@@ -1,3 +1,29 @@
1
+ === 2.0.22 2020-11-23
2
+ * 1 minor enhancements:
3
+ * Add support for CustomerBalanceTransaction object
4
+
5
+ === 2.0.21 2020-11-12
6
+ * 3 major enhancements:
7
+ * Add support for Supplier object
8
+ * Add support for SelfBillingInvoice object
9
+ * Add support for PurchaseItem object
10
+
11
+ === 2.0.20 2020-10-05
12
+ * 1 major enhancements:
13
+ * Add support for Beanie::Session object
14
+
15
+ === 2.0.19 2020-05-28
16
+ * 2 major enhancements:
17
+ * Add { opts } param for all nested methods, so you can include headers such as the Connected Octobat Account ID in subrequests
18
+ * Add support for CreditNote#cancel endpoint
19
+
20
+
21
+ === 2.0.18 2020-05-25
22
+ * 3 major enhancements:
23
+ * Add support for multipart encoder (file upload)
24
+ * Add support for File API endpoints
25
+ * Add support for Reporting API endpoints
26
+
1
27
  === 2.0.17 2020-04-27
2
28
  * 1 minor enhancement:
3
29
  * Update Order API endpoints
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.17
1
+ 2.0.22
@@ -17,6 +17,7 @@ require 'octobat/api_operations/delete'
17
17
  require 'octobat/api_operations/list'
18
18
 
19
19
  # Resources
20
+ require 'octobat/multipart_encoder'
20
21
  require 'octobat/util'
21
22
  require 'octobat/octobat_object'
22
23
  require 'octobat/api_resource'
@@ -24,11 +25,15 @@ require 'octobat/singleton_api_resource'
24
25
  require 'octobat/list_object'
25
26
 
26
27
  require 'octobat/customer'
28
+ require 'octobat/supplier'
27
29
  require 'octobat/transaction'
30
+ require 'octobat/customer_balance_transaction'
28
31
  require 'octobat/item'
32
+ require 'octobat/purchase_item'
29
33
  require 'octobat/document'
30
34
  require 'octobat/invoice'
31
35
  require 'octobat/credit_note'
36
+ require 'octobat/self_billing_invoice'
32
37
  require 'octobat/proforma_invoice'
33
38
  require 'octobat/payment_recipient'
34
39
  require 'octobat/payment_recipient_reference'
@@ -51,6 +56,13 @@ require 'octobat/exports_setting'
51
56
  require 'octobat/emails_setting'
52
57
  require 'octobat/tax_id'
53
58
 
59
+ require 'octobat/file_upload'
60
+ require 'octobat/file_link'
61
+ require 'octobat/beanie/session'
62
+ require 'octobat/reporting/report_type'
63
+ require 'octobat/reporting/report_run'
64
+
65
+
54
66
  # Errors
55
67
  require 'octobat/errors/octobat_error'
56
68
  require 'octobat/errors/octobat_lib_error'
@@ -63,6 +75,7 @@ module Octobat
63
75
  #DEFAULT_CA_BUNDLE_PATH = File.dirname(__FILE__) + '/data/ca-certificates.crt'
64
76
  @api_base = 'https://apiv2.octobat.com'
65
77
  #@api_base = 'http://api.octobat.local:3052'
78
+ @uploads_base = "https://files.octobat.com"
66
79
 
67
80
  @max_network_retries = 0
68
81
  @max_network_retry_delay = 2
@@ -75,7 +88,7 @@ module Octobat
75
88
 
76
89
 
77
90
  class << self
78
- attr_accessor :api_key, :api_base, :verify_ssl_certs, :api_version
91
+ attr_accessor :api_key, :api_base, :verify_ssl_certs, :api_version, :uploads_base
79
92
  attr_reader :max_network_retry_delay, :initial_network_retry_delay
80
93
  end
81
94
 
@@ -0,0 +1,13 @@
1
+ module Octobat
2
+ module Beanie
3
+ class Session < APIResource
4
+ include Octobat::APIOperations::Create
5
+ extend Octobat::APIOperations::List
6
+
7
+ def self.url
8
+ '/beanie/sessions'
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -4,20 +4,21 @@ module Octobat
4
4
  include Octobat::APIOperations::Create
5
5
  include Octobat::APIOperations::Update
6
6
 
7
- def activate
8
- response, api_key = Octobat.request(:patch, activate_url, @api_key)
7
+ def activate(params = {}, opts = {})
8
+ response, api_key = Octobat.request(:patch, activate_url, @api_key, params, opts)
9
9
  refresh_from(response, api_key)
10
10
  end
11
11
 
12
- def unactivate
13
- response, api_key = Octobat.request(:patch, unactivate_url, @api_key)
12
+ def unactivate(params = {}, opts = {})
13
+ response, api_key = Octobat.request(:patch, unactivate_url, @api_key, params, opts)
14
14
  refresh_from(response, api_key)
15
15
  end
16
16
 
17
- def delete
18
- response, api_key = Octobat.request(:delete, url, @api_key)
17
+ def delete(params = {}, opts = {})
18
+ response, api_key = Octobat.request(:delete, url, @api_key, params, opts)
19
19
  refresh_from(response, api_key)
20
20
  end
21
+
21
22
 
22
23
  private
23
24
 
@@ -12,30 +12,41 @@ module Octobat
12
12
 
13
13
  instance = self.new(nil, opts)
14
14
 
15
- response, api_key = Octobat.request(:post, url + '/pdf_export', api_key, params)
15
+ response, api_key = Octobat.request(:post, url + '/pdf_export', api_key, params, headers)
16
16
  return true
17
17
  end
18
18
 
19
19
 
20
- def send_by_email(email_data = {})
21
- response, api_key = Octobat.request(:post, send_url, @api_key, email_data)
20
+ def send_by_email(params = {}, opts = {})
21
+ response, api_key = Octobat.request(:post, send_url, @api_key, params, opts)
22
22
  refresh_from(response, api_key)
23
23
  end
24
24
 
25
- def confirm(confirmation_data = {})
26
- response, api_key = Octobat.request(:patch, confirm_url, @api_key, confirmation_data)
25
+ def confirm(params = {}, opts = {})
26
+ response, api_key = Octobat.request(:patch, confirm_url, @api_key, params, opts)
27
27
  refresh_from(response, api_key)
28
28
  end
29
+
30
+
31
+ def cancel(params = {}, opts = {})
32
+ response, api_key = Octobat.request(:patch, cancel_url, @api_key, params, opts)
33
+ refresh_from(response, api_key)
34
+ end
35
+
36
+
29
37
 
30
- def items(params = {})
31
- Item.list(params.merge({credit_note: id }), @api_key)
38
+ def items(params = {}, opts = {})
39
+ Item.list(params.merge({ credit_note: id }), {api_key: @api_key}.merge(opts))
32
40
  end
33
41
 
34
- def transactions(params = {})
35
- Transaction.list(params.merge(credit_note: id), @api_key)
42
+ def transactions(params = {}, opts = {})
43
+ Transaction.list(params.merge(credit_note: id), {api_key: @api_key}.merge(opts))
36
44
  end
37
45
 
38
46
  private
47
+ def cancel_url
48
+ url + '/cancel'
49
+ end
39
50
 
40
51
  def send_url
41
52
  url + '/send'
@@ -4,8 +4,8 @@ module Octobat
4
4
  include Octobat::APIOperations::Create
5
5
  include Octobat::APIOperations::Update
6
6
 
7
- def set_to_default
8
- response, api_key = Octobat.request(:patch, set_to_default_url, @api_key)
7
+ def set_to_default(params = {}, opts = {})
8
+ response, api_key = Octobat.request(:patch, set_to_default_url, @api_key, params, opts)
9
9
  refresh_from(response, api_key)
10
10
  end
11
11
 
@@ -5,16 +5,21 @@ module Octobat
5
5
  include Octobat::APIOperations::Update
6
6
  include Octobat::APIOperations::Delete
7
7
 
8
- def invoices(params = {})
9
- Invoice.all(params.merge({ :customer => id }), @api_key)
8
+ def invoices(params = {}, opts = {})
9
+ Invoice.list(params.merge({ :customer => id }), {api_key: @api_key}.merge(opts))
10
10
  end
11
11
 
12
- def credit_notes(params = {})
13
- CreditNote.all(params.merge({ :customer => id }), @api_key)
12
+ def credit_notes(params = {}, opts = {})
13
+ CreditNote.list(params.merge({ :customer => id }), {api_key: @api_key}.merge(opts))
14
14
  end
15
15
 
16
- def payment_sources(params = {})
17
- PaymentSource.all(params.merge({ :customer => id }), @api_key)
16
+ def payment_sources(params = {}, opts = {})
17
+ PaymentSource.list(params.merge({ :customer => id }), {api_key: @api_key}.merge(opts))
18
18
  end
19
+
20
+ def customer_balance_transactions(params = {}, opts = {})
21
+ CustomerBalanceTransaction.list(params.merge({ :customer => id }), {api_key: @api_key}.merge(opts))
22
+ end
23
+
19
24
  end
20
25
  end
@@ -0,0 +1,50 @@
1
+ module Octobat
2
+ class CustomerBalanceTransaction < APIResource
3
+ extend Octobat::APIOperations::List
4
+ include Octobat::APIOperations::Create
5
+
6
+
7
+ def url
8
+ !parent_obj.nil? ? parentize_url : super
9
+ end
10
+
11
+
12
+ def save_url
13
+ if self[:id] == nil && self.class.respond_to?(:create)
14
+ self.relative_save_url
15
+ else
16
+ url
17
+ end
18
+ end
19
+
20
+
21
+ def parentize_url
22
+ if parent_obj.include?(:customer)
23
+ "#{Customer.url}/#{CGI.escape(parent_obj[:customer])}/customer_balance_transactions/#{CGI.escape(id)}"
24
+ else
25
+ url
26
+ end
27
+ end
28
+
29
+
30
+
31
+ def relative_save_url
32
+ if self[:customer]
33
+ "#{Customer.url}/#{CGI.escape(self[:customer])}/customer_balance_transactions"
34
+ end
35
+ end
36
+
37
+
38
+ def self.url
39
+ if @parent_resource.include?(:customer)
40
+ "#{Customer.url}/#{CGI.escape(@parent_resource[:customer])}/customer_balance_transactions"
41
+ end
42
+ end
43
+
44
+ def self.set_parent_resource(filters)
45
+ @parent_resource = filters.select{|k, v| [:customer].include?(k)}
46
+ end
47
+
48
+
49
+ end
50
+ end
@@ -1,7 +1,6 @@
1
1
  module Octobat
2
2
  class Document < APIResource
3
3
 
4
-
5
4
  def self.csv_export(params = {}, opts={})
6
5
  api_key, headers = Util.parse_opts(opts)
7
6
  api_key ||= @api_key
@@ -9,7 +8,7 @@ module Octobat
9
8
 
10
9
  instance = self.new(nil, opts)
11
10
 
12
- response, api_key = Octobat.request(:post, url + '/csv_export', api_key, params)
11
+ response, api_key = Octobat.request(:post, url + '/csv_export', api_key, params, opts)
13
12
  return true
14
13
  end
15
14
 
@@ -10,7 +10,7 @@ module Octobat
10
10
 
11
11
  instance = self.new(nil, opts)
12
12
 
13
- response, api_key = Octobat.request(:get, url + '/default', api_key, params)
13
+ response, api_key = Octobat.request(:get, url + '/default', api_key, params, opts)
14
14
  instance.refresh_from(response, api_key)
15
15
  instance
16
16
  end
@@ -10,7 +10,7 @@ module Octobat
10
10
 
11
11
  instance = self.new(nil, opts)
12
12
 
13
- response, api_key = Octobat.request(:get, url + '/default', api_key, params)
13
+ response, api_key = Octobat.request(:get, url + '/default', api_key, params, opts)
14
14
  instance.refresh_from(response, api_key)
15
15
  instance
16
16
  end
@@ -4,23 +4,23 @@ module Octobat
4
4
  include Octobat::APIOperations::Create
5
5
  include Octobat::APIOperations::Update
6
6
 
7
- def duplicate(params = {})
8
- response, api_key = Octobat.request(:post, duplicate_url, @api_key, params)
7
+ def duplicate(params = {}, opts = {})
8
+ response, api_key = Octobat.request(:post, duplicate_url, @api_key, params, opts)
9
9
  refresh_from(response, api_key)
10
10
  end
11
11
 
12
- def activate
13
- response, api_key = Octobat.request(:patch, activate_url, @api_key)
12
+ def activate(params = {}, opts = {})
13
+ response, api_key = Octobat.request(:patch, activate_url, @api_key, params, opts)
14
14
  refresh_from(response, api_key)
15
15
  end
16
16
 
17
- def delete
18
- response, api_key = Octobat.request(:delete, url, @api_key)
17
+ def delete(params = {}, opts = {})
18
+ response, api_key = Octobat.request(:delete, url, @api_key, params, opts)
19
19
  refresh_from(response, api_key)
20
20
  end
21
21
 
22
- def preview(params = {})
23
- response, api_key = Octobat.request(:get, preview_url, @api_key, params)
22
+ def preview(params = {}, opts = {})
23
+ response, api_key = Octobat.request(:get, preview_url, @api_key, params, opts)
24
24
  refresh_from(response, api_key)
25
25
  end
26
26
 
@@ -10,7 +10,7 @@ module Octobat
10
10
 
11
11
  instance = self.new(nil, opts)
12
12
 
13
- response, api_key = Octobat.request(:get, url + '/default', api_key, params)
13
+ response, api_key = Octobat.request(:get, url + '/default', api_key, params, opts)
14
14
  instance.refresh_from(response, api_key)
15
15
  instance
16
16
  end
@@ -10,7 +10,7 @@ module Octobat
10
10
 
11
11
  instance = self.new(nil, opts)
12
12
 
13
- response, api_key = Octobat.request(:get, url + '/default', api_key, params)
13
+ response, api_key = Octobat.request(:get, url + '/default', api_key, params, opts)
14
14
  instance.refresh_from(response, api_key)
15
15
  instance
16
16
  end
@@ -0,0 +1,41 @@
1
+ module Octobat
2
+ class FileLink < APIResource
3
+ include Octobat::APIOperations::Create
4
+ extend Octobat::APIOperations::List
5
+
6
+ def self.create(params = {}, opts = {})
7
+ api_key, headers = Util.parse_opts(opts)
8
+ response, api_key = Octobat.request(:post, self.url, api_key, params, headers, Octobat.uploads_base)
9
+ Util.convert_to_octobat_object(response, api_key)
10
+ end
11
+
12
+ def refresh
13
+ response, api_key = Octobat.request(:get, url, @api_key, @retrieve_options, @headers, Octobat.uploads_base)
14
+ refresh_from(response, api_key)
15
+ end
16
+
17
+ def self.list(filters={}, opts={})
18
+ set_parent_resource(filters)
19
+ api_key, headers = Util.parse_opts(opts)
20
+
21
+ api_key ||= @api_key
22
+
23
+ f = filters.select{|request_filter| !@parent_resource.has_key?(request_filter)}
24
+
25
+ response, api_key = Octobat.request(:get, url, api_key, f, headers, Octobat.uploads_base)
26
+ obj = ListObject.construct_from(response, api_key)
27
+
28
+ obj.filters = filters.dup
29
+ obj.cursors[:ending_before] = obj.filters.delete(:ending_before)
30
+ obj.cursors[:starting_after] = obj.filters.delete(:starting_after)
31
+
32
+ obj.filters.delete(:expand)
33
+ obj.parent_resource = @parent_resource
34
+
35
+ obj
36
+ end
37
+
38
+ self.singleton_class.send(:alias_method, :all, :list)
39
+
40
+ end
41
+ end
@@ -0,0 +1,59 @@
1
+ module Octobat
2
+ class FileUpload < APIResource
3
+ include Octobat::APIOperations::Create
4
+ extend Octobat::APIOperations::List
5
+
6
+ def self.url
7
+ "/files"
8
+ end
9
+
10
+
11
+ def self.create(params = {}, opts = {})
12
+ if params[:attachment] && !params[:attachment].is_a?(String)
13
+ unless params[:attachment].respond_to?(:read)
14
+ raise ArgumentError, "attachment must respond to `#read`"
15
+ end
16
+ end
17
+
18
+ api_key, headers = Util.parse_opts(opts)
19
+ headers = headers.merge(content_type: MultipartEncoder::MULTIPART_FORM_DATA)
20
+
21
+ response, api_key = Octobat.request(:post, self.url, api_key, params, headers, Octobat.uploads_base)
22
+ Util.convert_to_octobat_object(response, api_key)
23
+
24
+ end
25
+
26
+ def refresh
27
+ response, api_key = Octobat.request(:get, url, @api_key, @retrieve_options, @headers, Octobat.uploads_base)
28
+ refresh_from(response, api_key)
29
+ end
30
+
31
+
32
+ def self.list(filters={}, opts={})
33
+ set_parent_resource(filters)
34
+ api_key, headers = Util.parse_opts(opts)
35
+
36
+ api_key ||= @api_key
37
+
38
+ f = filters.select{|request_filter| !@parent_resource.has_key?(request_filter)}
39
+
40
+ response, api_key = Octobat.request(:get, url, api_key, f, headers, Octobat.uploads_base)
41
+ obj = ListObject.construct_from(response, api_key)
42
+
43
+ obj.filters = filters.dup
44
+ obj.cursors[:ending_before] = obj.filters.delete(:ending_before)
45
+ obj.cursors[:starting_after] = obj.filters.delete(:starting_after)
46
+
47
+ obj.filters.delete(:expand)
48
+ obj.parent_resource = @parent_resource
49
+
50
+ obj
51
+ end
52
+
53
+ self.singleton_class.send(:alias_method, :all, :list)
54
+
55
+
56
+
57
+
58
+ end
59
+ end
@@ -12,7 +12,7 @@ module Octobat
12
12
 
13
13
  instance = self.new(nil, opts)
14
14
 
15
- response, api_key = Octobat.request(:post, url + '/pdf_export', api_key, params)
15
+ response, api_key = Octobat.request(:post, url + '/pdf_export', api_key, params, opts)
16
16
  return true
17
17
  end
18
18
 
@@ -23,42 +23,42 @@ module Octobat
23
23
 
24
24
  instance = self.new(nil, opts)
25
25
 
26
- response, api_key = Octobat.request(:post, url + '/csv_export', api_key, params)
26
+ response, api_key = Octobat.request(:post, url + '/csv_export', api_key, params, opts)
27
27
  return true
28
28
  end
29
29
 
30
30
 
31
- def send_by_email(email_data = {})
32
- response, api_key = Octobat.request(:post, send_url, @api_key, email_data)
31
+ def send_by_email(params = {}, opts = {})
32
+ response, api_key = Octobat.request(:post, send_url, @api_key, params, opts)
33
33
  refresh_from(response, api_key)
34
34
  end
35
35
 
36
- def confirm(confirmation_data = {})
37
- response, api_key = Octobat.request(:patch, confirm_url, @api_key, confirmation_data)
36
+ def confirm(params = {}, opts = {})
37
+ response, api_key = Octobat.request(:patch, confirm_url, @api_key, params, opts)
38
38
  refresh_from(response, api_key)
39
39
  end
40
40
 
41
- def cancel
42
- response, api_key = Octobat.request(:patch, cancel_url, @api_key)
41
+ def cancel(params = {}, opts = {})
42
+ response, api_key = Octobat.request(:patch, cancel_url, @api_key, params, opts)
43
43
  refresh_from(response, api_key)
44
44
  end
45
45
 
46
- def cancel_and_replace
47
- response, api_key = Octobat.request(:patch, cancel_and_replace_url, @api_key)
46
+ def cancel_and_replace(params = {}, opts = {})
47
+ response, api_key = Octobat.request(:patch, cancel_and_replace_url, @api_key, params, opts)
48
48
  refresh_from(response, api_key)
49
49
  end
50
50
 
51
- def delete
52
- response, api_key = Octobat.request(:delete, url, @api_key)
51
+ def delete(params = {}, opts = {})
52
+ response, api_key = Octobat.request(:delete, url, @api_key, params, opts)
53
53
  refresh_from(response, api_key)
54
54
  end
55
55
 
56
- def items(params = {})
57
- Item.list(params.merge({ :invoice => id }), @api_key)
56
+ def items(params = {}, opts = {})
57
+ Item.list(params.merge({ :invoice => id }), {api_key: @api_key}.merge(opts))
58
58
  end
59
59
 
60
- def transactions(params = {})
61
- Transaction.list(params.merge(invoice: id), @api_key)
60
+ def transactions(params = {}, opts = {})
61
+ Transaction.list(params.merge(invoice: id), {api_key: @api_key}.merge(opts))
62
62
  end
63
63
 
64
64
 
@@ -4,8 +4,8 @@ module Octobat
4
4
  include Octobat::APIOperations::Create
5
5
  include Octobat::APIOperations::Update
6
6
 
7
- def set_to_default
8
- response, api_key = Octobat.request(:patch, set_to_default_url, @api_key)
7
+ def set_to_default(params = {}, opts = {})
8
+ response, api_key = Octobat.request(:patch, set_to_default_url, @api_key, params, opts)
9
9
  refresh_from(response, api_key)
10
10
  end
11
11
 
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+ require "tempfile"
5
+
6
+ module Octobat
7
+ # Encodes parameters into a `multipart/form-data` payload as described by RFC
8
+ # 2388:
9
+ #
10
+ # https://tools.ietf.org/html/rfc2388
11
+ #
12
+ # This is most useful for transferring file-like objects.
13
+ #
14
+ # Parameters should be added with `#encode`. When ready, use `#body` to get
15
+ # the encoded result and `#content_type` to get the value that should be
16
+ # placed in the `Content-Type` header of a subsequent request (which includes
17
+ # a boundary value).
18
+ class MultipartEncoder
19
+ MULTIPART_FORM_DATA = "multipart/form-data"
20
+
21
+ # A shortcut for encoding a single set of parameters and finalizing a
22
+ # result.
23
+ #
24
+ # Returns an encoded body and the value that should be set in the content
25
+ # type header of a subsequent request.
26
+ def self.encode(params)
27
+ encoder = MultipartEncoder.new
28
+ encoder.encode(params)
29
+ encoder.close
30
+ [encoder.body, encoder.content_type]
31
+ end
32
+
33
+ # Gets the object's randomly generated boundary string.
34
+ attr_reader :boundary
35
+
36
+ # Initializes a new multipart encoder.
37
+ def initialize
38
+ # Kind of weird, but required by Rubocop because the unary plus operator
39
+ # is considered faster than `Octobat.new`.
40
+ @body = +""
41
+
42
+ # Chose the same number of random bytes that Go uses in its standard
43
+ # library implementation. Easily enough entropy to ensure that it won't
44
+ # be present in a file we're sending.
45
+ @boundary = SecureRandom.hex(30)
46
+
47
+ @closed = false
48
+ @first_field = true
49
+ end
50
+
51
+ # Gets the encoded body. `#close` must be called first.
52
+ def body
53
+ raise "object must be closed before getting body" unless @closed
54
+
55
+ @body
56
+ end
57
+
58
+ # Finalizes the object by writing the final boundary.
59
+ def close
60
+ raise "object already closed" if @closed
61
+
62
+ @body << "\r\n"
63
+ @body << "--#{@boundary}--"
64
+
65
+ @closed = true
66
+
67
+ nil
68
+ end
69
+
70
+ # Gets the value including boundary that should be put into a multipart
71
+ # request's `Content-Type`.
72
+ def content_type
73
+ "#{MULTIPART_FORM_DATA}; boundary=#{@boundary}"
74
+ end
75
+
76
+ # Encodes a set of parameters to the body.
77
+ #
78
+ # Note that parameters are expected to be a hash, but a "flat" hash such
79
+ # that complex substructures like hashes and arrays have already been
80
+ # appropriately Octobat-encoded. Pass a complex structure through
81
+ # `Util.flatten_params` first before handing it off to this method.
82
+ def encode(params)
83
+ raise "no more parameters can be written to closed object" if @closed
84
+
85
+ params.each do |name, val|
86
+ if val.is_a?(::File) || val.is_a?(::Tempfile)
87
+ write_field(name, val.read, filename: ::File.basename(val.path))
88
+ elsif val.respond_to?(:read)
89
+ write_field(name, val.read, filename: "blob")
90
+ else
91
+ write_field(name, val, filename: nil)
92
+ end
93
+ end
94
+
95
+ nil
96
+ end
97
+
98
+ #
99
+ # private
100
+ #
101
+
102
+ # Escapes double quotes so that the given value can be used in a
103
+ # double-quoted string and replaces any linebreak characters with spaces.
104
+ private def escape(str)
105
+ str.gsub('"', "%22").tr("\n", " ").tr("\r", " ")
106
+ end
107
+
108
+ private def write_field(name, data, filename:)
109
+ if !@first_field
110
+ @body << "\r\n"
111
+ else
112
+ @first_field = false
113
+ end
114
+
115
+ @body << "--#{@boundary}\r\n"
116
+
117
+ if filename
118
+ @body << %(Content-Disposition: form-data) +
119
+ %(; name="#{escape(name.to_s)}") +
120
+ %(; filename="#{escape(filename)}"\r\n)
121
+ @body << %(Content-Type: application/octet-stream\r\n)
122
+ else
123
+ @body << %(Content-Disposition: form-data) +
124
+ %(; name="#{escape(name.to_s)}"\r\n)
125
+ end
126
+
127
+ @body << "\r\n"
128
+ @body << data.to_s
129
+ end
130
+ end
131
+ end
@@ -3,8 +3,8 @@ module Octobat
3
3
  extend Octobat::APIOperations::List
4
4
  include Octobat::APIOperations::Update
5
5
 
6
- def expire
7
- response, api_key = Octobat.request(:patch, expire_url, @api_key)
6
+ def expire(params = {}, opts = {})
7
+ response, api_key = Octobat.request(:patch, expire_url, @api_key, params, opts)
8
8
  refresh_from(response, api_key)
9
9
  end
10
10
 
@@ -2,8 +2,8 @@ module Octobat
2
2
  class Payout < APIResource
3
3
  extend Octobat::APIOperations::List
4
4
 
5
- def balance_transactions(params = {})
6
- BalanceTransaction.list(params.merge({ payout: id }), @api_key)
5
+ def balance_transactions(params = {}, opts = {})
6
+ BalanceTransaction.list(params.merge({ payout: id }), {api_key: @api_key}.merge(opts))
7
7
  end
8
8
 
9
9
  def self.csv_export(params = {}, opts={})
@@ -0,0 +1,52 @@
1
+ module Octobat
2
+ class PurchaseItem < APIResource
3
+ extend Octobat::APIOperations::List
4
+ include Octobat::APIOperations::Create
5
+ include Octobat::APIOperations::Update
6
+ include Octobat::APIOperations::Delete
7
+
8
+
9
+ def url
10
+ !parent_obj.nil? ? parentize_url : super
11
+ end
12
+
13
+
14
+ def save_url
15
+ if self[:id] == nil && self.class.respond_to?(:create)
16
+ self.relative_save_url
17
+ else
18
+ url
19
+ end
20
+ end
21
+
22
+
23
+ def parentize_url
24
+ if parent_obj.include?(:self_billing_invoice)
25
+ "#{SelfBillingInvoice.url}/#{CGI.escape(parent_obj[:self_billing_invoice])}/purchase_items/#{CGI.escape(id)}"
26
+ else
27
+ url
28
+ end
29
+ end
30
+
31
+
32
+
33
+ def relative_save_url
34
+ if self[:self_billing_invoice]
35
+ "#{SelfBillingInvoice.url}/#{CGI.escape(self[:self_billing_invoice])}/purchase_items"
36
+ end
37
+ end
38
+
39
+
40
+ def self.url
41
+ if @parent_resource.include?(:self_billing_invoice)
42
+ "#{SelfBillingInvoice.url}/#{CGI.escape(@parent_resource[:self_billing_invoice])}/purchase_items"
43
+ end
44
+ end
45
+
46
+ def self.set_parent_resource(filters)
47
+ @parent_resource = filters.select{|k, v| [:self_billing_invoice].include?(k)}
48
+ end
49
+
50
+
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+ module Octobat
2
+ module Reporting
3
+ class ReportRun < APIResource
4
+ include Octobat::APIOperations::Create
5
+ extend Octobat::APIOperations::List
6
+
7
+ def self.url
8
+ '/reporting/report_runs'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Octobat
2
+ module Reporting
3
+ class ReportType < APIResource
4
+ extend Octobat::APIOperations::List
5
+
6
+ def self.url
7
+ '/reporting/report_types'
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,77 @@
1
+ module Octobat
2
+ class SelfBillingInvoice < APIResource
3
+ extend Octobat::APIOperations::List
4
+ include Octobat::APIOperations::Create
5
+ include Octobat::APIOperations::Update
6
+
7
+
8
+ # def self.pdf_export(params = {}, opts={})
9
+ # api_key, headers = Util.parse_opts(opts)
10
+ # api_key ||= @api_key
11
+ # opts[:api_key] = api_key
12
+ #
13
+ # instance = self.new(nil, opts)
14
+ #
15
+ # response, api_key = Octobat.request(:post, url + '/pdf_export', api_key, params, opts)
16
+ # return true
17
+ # end
18
+ #
19
+ # def self.csv_export(params = {}, opts={})
20
+ # api_key, headers = Util.parse_opts(opts)
21
+ # api_key ||= @api_key
22
+ # opts[:api_key] = api_key
23
+ #
24
+ # instance = self.new(nil, opts)
25
+ #
26
+ # response, api_key = Octobat.request(:post, url + '/csv_export', api_key, params, opts)
27
+ # return true
28
+ # end
29
+
30
+
31
+ def send_by_email(params = {}, opts = {})
32
+ response, api_key = Octobat.request(:post, send_url, @api_key, params, opts)
33
+ refresh_from(response, api_key)
34
+ end
35
+
36
+ def confirm(params = {}, opts = {})
37
+ response, api_key = Octobat.request(:patch, confirm_url, @api_key, params, opts)
38
+ refresh_from(response, api_key)
39
+ end
40
+
41
+ def cancel(params = {}, opts = {})
42
+ response, api_key = Octobat.request(:patch, cancel_url, @api_key, params, opts)
43
+ refresh_from(response, api_key)
44
+ end
45
+
46
+ def delete(params = {}, opts = {})
47
+ response, api_key = Octobat.request(:delete, url, @api_key, params, opts)
48
+ refresh_from(response, api_key)
49
+ end
50
+
51
+ def purchase_items(params = {}, opts = {})
52
+ PurchaseItem.list(params.merge({ :self_billing_invoice => id }), {api_key: @api_key}.merge(opts))
53
+ end
54
+
55
+ # def transactions(params = {}, opts = {})
56
+ # Transaction.list(params.merge(invoice: id), {api_key: @api_key}.merge(opts))
57
+ # end
58
+
59
+
60
+ private
61
+
62
+ def send_url
63
+ url + '/send'
64
+ end
65
+
66
+ def confirm_url
67
+ url + '/confirm'
68
+ end
69
+
70
+ def cancel_url
71
+ url + '/cancel'
72
+ end
73
+
74
+ end
75
+
76
+
77
+ end
@@ -0,0 +1,8 @@
1
+ module Octobat
2
+ class Supplier < APIResource
3
+ extend Octobat::APIOperations::List
4
+ include Octobat::APIOperations::Create
5
+ include Octobat::APIOperations::Update
6
+ include Octobat::APIOperations::Delete
7
+ end
8
+ end
@@ -9,7 +9,7 @@ module Octobat
9
9
 
10
10
  instance = self.new(nil, opts)
11
11
 
12
- response, api_key = Octobat.request(:post, url + '/for_supplier', api_key, params)
12
+ response, api_key = Octobat.request(:post, url + '/for_supplier', api_key, params, opts)
13
13
  instance.refresh_from(response, api_key)
14
14
  instance
15
15
  end
@@ -4,8 +4,8 @@ module Octobat
4
4
  include Octobat::APIOperations::Create
5
5
  include Octobat::APIOperations::Update
6
6
 
7
- def archive
8
- response, api_key = Octobat.request(:patch, archive_url, @api_key)
7
+ def archive(params = {}, opts = {})
8
+ response, api_key = Octobat.request(:patch, archive_url, @api_key, params, opts)
9
9
  refresh_from(response, api_key)
10
10
  end
11
11
 
@@ -4,13 +4,13 @@ module Octobat
4
4
  include Octobat::APIOperations::Update
5
5
  include Octobat::APIOperations::Create
6
6
 
7
- def activate
8
- response, api_key = Octobat.request(:patch, activate_url, @api_key)
7
+ def activate(params = {}, opts = {})
8
+ response, api_key = Octobat.request(:patch, activate_url, @api_key, params, opts)
9
9
  refresh_from(response, api_key)
10
10
  end
11
11
 
12
- def unactivate
13
- response, api_key = Octobat.request(:patch, unactivate_url, @api_key)
12
+ def unactivate(params = {}, opts = {})
13
+ response, api_key = Octobat.request(:patch, unactivate_url, @api_key, params, opts)
14
14
  refresh_from(response, api_key)
15
15
  end
16
16
 
@@ -4,8 +4,8 @@ module Octobat
4
4
  include Octobat::APIOperations::Create
5
5
  include Octobat::APIOperations::Update
6
6
 
7
- def items(params = {})
8
- Item.list(params.merge({ :transaction => id }), @api_key)
7
+ def items(params = {}, opts = {})
8
+ Item.list(params.merge({ :transaction => id }), {api_key: @api_key}.merge(opts))
9
9
  end
10
10
 
11
11
  def self.csv_export(params = {}, opts={})
@@ -47,7 +47,11 @@ module Octobat
47
47
  'invoice' => Invoice,
48
48
  'credit_note' => CreditNote,
49
49
  'item' => Item,
50
+ 'purchase_item' => PurchaseItem,
50
51
  'customer' => Customer,
52
+ 'customer_balance_transaction' => CustomerBalanceTransaction,
53
+ 'supplier' => Supplier,
54
+ 'self_billing_invoice' => SelfBillingInvoice,
51
55
  'payout' => Payout,
52
56
  'balance_transaction' => BalanceTransaction,
53
57
  'document_template' => DocumentTemplate,
@@ -65,7 +69,12 @@ module Octobat
65
69
  'document_email_template' => DocumentEmailTemplate,
66
70
  'exports_setting' => ExportsSetting,
67
71
  'document' => Document,
68
- 'emails_setting' => EmailsSetting
72
+ 'emails_setting' => EmailsSetting,
73
+ 'file' => FileUpload,
74
+ 'file_link' => FileLink,
75
+ 'beanie.session' => Beanie::Session,
76
+ 'reporting.report_type' => Reporting::ReportType,
77
+ 'reporting.report_run' => Reporting::ReportRun
69
78
  }
70
79
  end
71
80
 
@@ -1,3 +1,3 @@
1
1
  module Octobat
2
- VERSION = '2.0.17'
2
+ VERSION = '2.0.22'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octobat
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.17
4
+ version: 2.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gaultier Laperche
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-20 00:00:00.000000000 Z
11
+ date: 2020-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -61,12 +61,14 @@ files:
61
61
  - lib/octobat/api_operations/update.rb
62
62
  - lib/octobat/api_resource.rb
63
63
  - lib/octobat/balance_transaction.rb
64
+ - lib/octobat/beanie/session.rb
64
65
  - lib/octobat/certificate_blacklist.rb
65
66
  - lib/octobat/checkout.rb
66
67
  - lib/octobat/coupon.rb
67
68
  - lib/octobat/credit_note.rb
68
69
  - lib/octobat/credit_note_numbering_sequence.rb
69
70
  - lib/octobat/customer.rb
71
+ - lib/octobat/customer_balance_transaction.rb
70
72
  - lib/octobat/document.rb
71
73
  - lib/octobat/document_email_template.rb
72
74
  - lib/octobat/document_language.rb
@@ -79,10 +81,13 @@ files:
79
81
  - lib/octobat/errors/octobat_error.rb
80
82
  - lib/octobat/errors/octobat_lib_error.rb
81
83
  - lib/octobat/exports_setting.rb
84
+ - lib/octobat/file_link.rb
85
+ - lib/octobat/file_upload.rb
82
86
  - lib/octobat/invoice.rb
83
87
  - lib/octobat/invoice_numbering_sequence.rb
84
88
  - lib/octobat/item.rb
85
89
  - lib/octobat/list_object.rb
90
+ - lib/octobat/multipart_encoder.rb
86
91
  - lib/octobat/octobat_object.rb
87
92
  - lib/octobat/order.rb
88
93
  - lib/octobat/payment_recipient.rb
@@ -91,7 +96,12 @@ files:
91
96
  - lib/octobat/payout.rb
92
97
  - lib/octobat/product.rb
93
98
  - lib/octobat/proforma_invoice.rb
99
+ - lib/octobat/purchase_item.rb
100
+ - lib/octobat/reporting/report_run.rb
101
+ - lib/octobat/reporting/report_type.rb
102
+ - lib/octobat/self_billing_invoice.rb
94
103
  - lib/octobat/singleton_api_resource.rb
104
+ - lib/octobat/supplier.rb
95
105
  - lib/octobat/tax_evidence.rb
96
106
  - lib/octobat/tax_evidence_request.rb
97
107
  - lib/octobat/tax_id.rb
@@ -120,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
130
  version: '0'
121
131
  requirements: []
122
132
  rubyforge_project:
123
- rubygems_version: 2.4.5
133
+ rubygems_version: 2.7.6.2
124
134
  signing_key:
125
135
  specification_version: 4
126
136
  summary: Ruby bindings for the Octobat API