octobat 0.0.12 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +2 -1
  4. data/Gemfile.lock +20 -10
  5. data/History.txt +33 -0
  6. data/VERSION +1 -1
  7. data/lib/octobat.rb +95 -19
  8. data/lib/octobat/api_operations/delete.rb +1 -0
  9. data/lib/octobat/api_operations/list.rb +16 -9
  10. data/lib/octobat/api_operations/update.rb +7 -4
  11. data/lib/octobat/api_resource.rb +5 -2
  12. data/lib/octobat/{payment_mode.rb → checkout.rb} +1 -1
  13. data/lib/octobat/coupon.rb +32 -0
  14. data/lib/octobat/credit_note.rb +35 -0
  15. data/lib/octobat/credit_note_numbering_sequence.rb +13 -0
  16. data/lib/octobat/customer.rb +10 -2
  17. data/lib/octobat/document.rb +17 -0
  18. data/lib/octobat/document_email_template.rb +19 -0
  19. data/lib/octobat/document_language.rb +19 -0
  20. data/lib/octobat/document_template.rb +33 -0
  21. data/lib/octobat/emails_setting.rb +19 -0
  22. data/lib/octobat/errors/api_connection_error.rb +1 -1
  23. data/lib/octobat/errors/api_error.rb +1 -1
  24. data/lib/octobat/errors/authentication_error.rb +1 -1
  25. data/lib/octobat/errors/invalid_request_error.rb +2 -4
  26. data/lib/octobat/errors/octobat_error.rb +31 -5
  27. data/lib/octobat/errors/octobat_lib_error.rb +20 -0
  28. data/lib/octobat/exports_setting.rb +19 -0
  29. data/lib/octobat/invoice.rb +61 -12
  30. data/lib/octobat/invoice_numbering_sequence.rb +18 -0
  31. data/lib/octobat/item.rb +64 -0
  32. data/lib/octobat/list_object.rb +12 -4
  33. data/lib/octobat/octobat_object.rb +13 -4
  34. data/lib/octobat/payment_recipient.rb +7 -0
  35. data/lib/octobat/{numbering_sequence.rb → payment_recipient_reference.rb} +1 -1
  36. data/lib/octobat/payment_source.rb +16 -0
  37. data/lib/octobat/{invoice_item.rb → tax_evidence.rb} +1 -1
  38. data/lib/octobat/tax_evidence_request.rb +5 -0
  39. data/lib/octobat/tax_region_setting.rb +27 -0
  40. data/lib/octobat/transaction.rb +11 -0
  41. data/lib/octobat/util.rb +28 -10
  42. data/lib/octobat/version.rb +1 -1
  43. data/octobat.gemspec +3 -3
  44. metadata +33 -45
@@ -3,12 +3,13 @@ module Octobat
3
3
  include Enumerable
4
4
  include Octobat::APIOperations::List
5
5
 
6
- attr_accessor :filters, :cursors
6
+ attr_accessor :filters, :cursors, :parent_resource
7
7
 
8
8
  def initialize(*args)
9
9
  super
10
10
  self.filters = {}
11
11
  self.cursors = {}
12
+ self.parent_resource = {}
12
13
  end
13
14
 
14
15
  def [](k)
@@ -28,10 +29,12 @@ module Octobat
28
29
  self.data.empty?
29
30
  end
30
31
 
31
- def retrieve(id, api_key=nil)
32
+ def retrieve(id, opts={})
33
+ api_key, headers = Util.parse_opts(opts)
32
34
  api_key ||= @api_key
35
+
33
36
  response, api_key = Octobat.request(:get, "#{url}/#{CGI.escape(id)}", api_key)
34
- Util.convert_to_octobat_object(response, api_key)
37
+ Util.convert_to_octobat_object(response, api_key, self.parent_resource)
35
38
  end
36
39
 
37
40
  def create(params={}, opts={})
@@ -45,7 +48,7 @@ module Octobat
45
48
  def next_page_params(params={}, opts={})
46
49
  return nil if !has_more
47
50
  last_id = data.last.id
48
-
51
+
49
52
  params = filters.merge({
50
53
  starting_after: last_id
51
54
  }).merge(params)
@@ -61,5 +64,10 @@ module Octobat
61
64
  }).merge(params)
62
65
  end
63
66
 
67
+
68
+ def url
69
+ self.request_url
70
+ end
71
+
64
72
  end
65
73
  end
@@ -2,7 +2,7 @@ module Octobat
2
2
  class OctobatObject
3
3
  include Enumerable
4
4
 
5
- attr_accessor :api_key
5
+ attr_accessor :api_key, :parent_obj
6
6
  @@permanent_attributes = Set.new([:api_key, :id])
7
7
 
8
8
  # The default :id method is deprecated and isn't useful to us
@@ -10,7 +10,7 @@ module Octobat
10
10
  undef :id
11
11
  end
12
12
 
13
- def initialize(id=nil, api_key=nil)
13
+ def initialize(id=nil, opts={})
14
14
  # parameter overloading!
15
15
  if id.kind_of?(Hash)
16
16
  @retrieve_options = id.dup
@@ -20,7 +20,10 @@ module Octobat
20
20
  @retrieve_options = {}
21
21
  end
22
22
 
23
- @api_key = api_key
23
+ @api_key = opts[:api_key]
24
+
25
+ @retrieve_options.merge!(opts.clone).delete(:api_key)
26
+
24
27
  @values = {}
25
28
  # This really belongs in APIResource, but not putting it there allows us
26
29
  # to have a unified inspect method
@@ -30,7 +33,7 @@ module Octobat
30
33
  end
31
34
 
32
35
  def self.construct_from(values, api_key=nil)
33
- self.new(values[:id], api_key).refresh_from(values, api_key)
36
+ self.new(values[:id], api_key: api_key).refresh_from(values, api_key)
34
37
  end
35
38
 
36
39
  def to_s(*args)
@@ -63,6 +66,12 @@ module Octobat
63
66
  end
64
67
  values.each do |k, v|
65
68
  @values[k] = Util.convert_to_octobat_object(v, api_key)
69
+
70
+ case @values[k]
71
+ when ListObject
72
+ @values[k].parent_resource = {self.object.to_sym => self.id}
73
+ end
74
+
66
75
  @transient_values.delete(k)
67
76
  @unsaved_values.delete(k)
68
77
  end
@@ -0,0 +1,7 @@
1
+ module Octobat
2
+ class PaymentRecipient < APIResource
3
+ extend Octobat::APIOperations::List
4
+ include Octobat::APIOperations::Create
5
+ include Octobat::APIOperations::Update
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  module Octobat
2
- class NumberingSequence < APIResource
2
+ class PaymentRecipientReference < APIResource
3
3
  extend Octobat::APIOperations::List
4
4
  end
5
5
  end
@@ -0,0 +1,16 @@
1
+ module Octobat
2
+ class PaymentSource < APIResource
3
+ extend Octobat::APIOperations::List
4
+ include Octobat::APIOperations::Create
5
+
6
+ def self.url
7
+ if @parent_resource.include?(:customer)
8
+ "#{Customer.url}/#{CGI.escape(@parent_resource[:customer])}/payment_sources"
9
+ end
10
+ end
11
+
12
+ def self.parent_resource(filters)
13
+ @parent_resource = filters.select{|k, v| [:customer].include?(k)}
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  module Octobat
2
- class InvoiceItem < APIResource
2
+ class TaxEvidence < APIResource
3
3
  include Octobat::APIOperations::Create
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ module Octobat
2
+ class TaxEvidenceRequest < APIResource
3
+ include Octobat::APIOperations::Create
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ module Octobat
2
+ class TaxRegionSetting < APIResource
3
+ extend Octobat::APIOperations::List
4
+ include Octobat::APIOperations::Update
5
+ include Octobat::APIOperations::Create
6
+
7
+ def activate
8
+ response, api_key = Octobat.request(:patch, activate_url, @api_key)
9
+ refresh_from(response, api_key)
10
+ end
11
+
12
+ def unactivate
13
+ response, api_key = Octobat.request(:patch, unactivate_url, @api_key)
14
+ refresh_from(response, api_key)
15
+ end
16
+
17
+ private
18
+
19
+ def activate_url
20
+ url + '/activate'
21
+ end
22
+
23
+ def unactivate_url
24
+ url + '/unactivate'
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Octobat
2
+ class Transaction < APIResource
3
+ extend Octobat::APIOperations::List
4
+ include Octobat::APIOperations::Create
5
+ include Octobat::APIOperations::Update
6
+
7
+ def items(params = {})
8
+ Item.list(params.merge({ :transaction => id }), @api_key)
9
+ end
10
+ end
11
+ end
data/lib/octobat/util.rb CHANGED
@@ -17,7 +17,7 @@ module Octobat
17
17
  h
18
18
  end
19
19
  end
20
-
20
+
21
21
  def self.objects_to_ids(h)
22
22
  case h
23
23
  when APIResource
@@ -39,23 +39,39 @@ module Octobat
39
39
  'list' => ListObject,
40
40
 
41
41
  # business objects
42
- 'payment_mode' => PaymentMode,
43
- 'payment' => Payment,
44
- 'numbering_sequence' => NumberingSequence,
42
+ 'payment_recipient' => PaymentRecipient,
43
+ 'payment_recipient_reference' => PaymentRecipientReference,
44
+ 'payment_source' => PaymentSource,
45
+ 'invoice_numbering_sequence' => InvoiceNumberingSequence,
45
46
  'credit_note_numbering_sequence' => CreditNoteNumberingSequence,
46
47
  'invoice' => Invoice,
47
- 'invoice_item' => InvoiceItem,
48
- 'customer' => Customer
48
+ 'credit_note' => CreditNote,
49
+ 'item' => Item,
50
+ 'customer' => Customer,
51
+ 'document_template' => DocumentTemplate,
52
+ 'document_language' => DocumentLanguage,
53
+ 'checkout' => Checkout,
54
+ 'coupon' => Coupon,
55
+ 'tax_region_setting' => TaxRegionSetting,
56
+ 'transaction' => Transaction,
57
+ 'tax_evidence' => TaxEvidence,
58
+ 'tax_evidence_request' => TaxEvidenceRequest,
59
+ 'document_email_template' => DocumentEmailTemplate,
60
+ 'exports_setting' => ExportsSetting,
61
+ 'document' => Document,
62
+ 'emails_setting' => EmailsSetting
49
63
  }
50
64
  end
51
65
 
52
- def self.convert_to_octobat_object(resp, api_key)
66
+ def self.convert_to_octobat_object(resp, api_key, parent_resource = nil)
53
67
  case resp
54
68
  when Array
55
- resp.map { |i| convert_to_octobat_object(i, api_key) }
69
+ resp.map { |i| convert_to_octobat_object(i, api_key, parent_resource) }
56
70
  when Hash
57
71
  # Try converting to a known object class. If none available, fall back to generic OctobatObject
58
- object_classes.fetch(resp[:object], OctobatObject).construct_from(resp, api_key)
72
+ obj = object_classes.fetch(resp[:object], OctobatObject).construct_from(resp, api_key)
73
+ obj.parent_obj = parent_resource if parent_resource && obj.respond_to?(:parent_obj)
74
+ obj
59
75
  else
60
76
  resp
61
77
  end
@@ -132,7 +148,9 @@ module Octobat
132
148
  when String
133
149
  return opts, {}
134
150
  when Hash
135
- headers = {}
151
+ headers = opts.clone
152
+ headers.delete(:api_key)
153
+
136
154
  if opts[:idempotency_key]
137
155
  headers[:idempotency_key] = opts[:idempotency_key]
138
156
  end
@@ -1,3 +1,3 @@
1
1
  module Octobat
2
- VERSION = '0.0.12'
2
+ VERSION = '2.0.0'
3
3
  end
data/octobat.gemspec CHANGED
@@ -12,9 +12,9 @@ spec = Gem::Specification.new do |s|
12
12
  s.homepage = 'https://www.octobat.com/api'
13
13
  s.license = 'MIT'
14
14
 
15
- s.add_dependency('rest-client', '~> 1.4')
16
- s.add_dependency('mime-types', '>= 1.25', '< 3.0')
17
- s.add_dependency('json', '~> 1.8.1')
15
+ s.add_dependency('rest-client', '>= 1.4', '< 4.0')
16
+ #s.add_dependency('mime-types', '>= 1.25', '< 3.0')
17
+ #s.add_dependency('json', '~> 1.8.1')
18
18
 
19
19
  #s.add_development_dependency('mocha', '~> 0.13.2')
20
20
  #s.add_development_dependency('shoulda', '~> 3.4.0')
metadata CHANGED
@@ -1,63 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octobat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gaultier Laperche
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-13 00:00:00.000000000 Z
11
+ date: 2017-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.4'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.4'
27
- - !ruby/object:Gem::Dependency
28
- name: mime-types
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '1.25'
34
- - - "<"
20
+ - - <
35
21
  - !ruby/object:Gem::Version
36
- version: '3.0'
22
+ version: '4.0'
37
23
  type: :runtime
38
24
  prerelease: false
39
25
  version_requirements: !ruby/object:Gem::Requirement
40
26
  requirements:
41
- - - ">="
27
+ - - '>='
42
28
  - !ruby/object:Gem::Version
43
- version: '1.25'
44
- - - "<"
45
- - !ruby/object:Gem::Version
46
- version: '3.0'
47
- - !ruby/object:Gem::Dependency
48
- name: json
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: 1.8.1
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
29
+ version: '1.4'
30
+ - - <
59
31
  - !ruby/object:Gem::Version
60
- version: 1.8.1
32
+ version: '4.0'
61
33
  description: Octobat is the easiest way to generate invoices online. See https://www.octobat.com
62
34
  for details.
63
35
  email:
@@ -67,8 +39,8 @@ executables:
67
39
  extensions: []
68
40
  extra_rdoc_files: []
69
41
  files:
70
- - ".gitignore"
71
- - ".travis.yml"
42
+ - .gitignore
43
+ - .travis.yml
72
44
  - CONTRIBUTORS
73
45
  - Gemfile
74
46
  - Gemfile.lock
@@ -89,21 +61,37 @@ files:
89
61
  - lib/octobat/api_operations/update.rb
90
62
  - lib/octobat/api_resource.rb
91
63
  - lib/octobat/certificate_blacklist.rb
64
+ - lib/octobat/checkout.rb
65
+ - lib/octobat/coupon.rb
66
+ - lib/octobat/credit_note.rb
92
67
  - lib/octobat/credit_note_numbering_sequence.rb
93
68
  - lib/octobat/customer.rb
69
+ - lib/octobat/document.rb
70
+ - lib/octobat/document_email_template.rb
71
+ - lib/octobat/document_language.rb
72
+ - lib/octobat/document_template.rb
73
+ - lib/octobat/emails_setting.rb
94
74
  - lib/octobat/errors/api_connection_error.rb
95
75
  - lib/octobat/errors/api_error.rb
96
76
  - lib/octobat/errors/authentication_error.rb
97
77
  - lib/octobat/errors/invalid_request_error.rb
98
78
  - lib/octobat/errors/octobat_error.rb
79
+ - lib/octobat/errors/octobat_lib_error.rb
80
+ - lib/octobat/exports_setting.rb
99
81
  - lib/octobat/invoice.rb
100
- - lib/octobat/invoice_item.rb
82
+ - lib/octobat/invoice_numbering_sequence.rb
83
+ - lib/octobat/item.rb
101
84
  - lib/octobat/list_object.rb
102
- - lib/octobat/numbering_sequence.rb
103
85
  - lib/octobat/octobat_object.rb
104
86
  - lib/octobat/payment.rb
105
- - lib/octobat/payment_mode.rb
87
+ - lib/octobat/payment_recipient.rb
88
+ - lib/octobat/payment_recipient_reference.rb
89
+ - lib/octobat/payment_source.rb
106
90
  - lib/octobat/singleton_api_resource.rb
91
+ - lib/octobat/tax_evidence.rb
92
+ - lib/octobat/tax_evidence_request.rb
93
+ - lib/octobat/tax_region_setting.rb
94
+ - lib/octobat/transaction.rb
107
95
  - lib/octobat/util.rb
108
96
  - lib/octobat/version.rb
109
97
  - octobat.gemspec
@@ -117,17 +105,17 @@ require_paths:
117
105
  - lib
118
106
  required_ruby_version: !ruby/object:Gem::Requirement
119
107
  requirements:
120
- - - ">="
108
+ - - '>='
121
109
  - !ruby/object:Gem::Version
122
110
  version: '0'
123
111
  required_rubygems_version: !ruby/object:Gem::Requirement
124
112
  requirements:
125
- - - ">="
113
+ - - '>='
126
114
  - !ruby/object:Gem::Version
127
115
  version: '0'
128
116
  requirements: []
129
117
  rubyforge_project:
130
- rubygems_version: 2.4.4
118
+ rubygems_version: 2.0.14.1
131
119
  signing_key:
132
120
  specification_version: 4
133
121
  summary: Ruby bindings for the Octobat API