billomat 0.1.4 → 0.3.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.
- checksums.yaml +5 -5
- data/.editorconfig +30 -0
- data/.github/workflows/documentation.yml +38 -0
- data/.github/workflows/test.yml +59 -0
- data/.gitignore +5 -0
- data/.rubocop.yml +53 -0
- data/.simplecov +3 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +48 -0
- data/Dockerfile +29 -0
- data/Envfile +6 -0
- data/Gemfile +3 -1
- data/Makefile +135 -0
- data/README.md +42 -17
- data/Rakefile +74 -3
- data/billomat.gemspec +28 -22
- data/config/docker/.bash_profile +3 -0
- data/config/docker/.bashrc +48 -0
- data/config/docker/.inputrc +17 -0
- data/doc/assets/project.svg +68 -0
- data/docker-compose.yml +9 -0
- data/lib/billomat/actions/cancel.rb +3 -5
- data/lib/billomat/actions/complete.rb +8 -12
- data/lib/billomat/actions/email.rb +6 -10
- data/lib/billomat/actions/pdf.rb +4 -10
- data/lib/billomat/actions/uncancel.rb +3 -6
- data/lib/billomat/actions.rb +0 -1
- data/lib/billomat/configuration.rb +2 -1
- data/lib/billomat/gateway.rb +52 -24
- data/lib/billomat/models/base.rb +26 -27
- data/lib/billomat/models/client.rb +3 -4
- data/lib/billomat/models/contact.rb +18 -0
- data/lib/billomat/models/credit_note.rb +18 -0
- data/lib/billomat/models/credit_note_item.rb +18 -0
- data/lib/billomat/models/invoice.rb +6 -11
- data/lib/billomat/models/invoice_item.rb +3 -3
- data/lib/billomat/models/invoice_payment.rb +3 -4
- data/lib/billomat/models/tag.rb +18 -0
- data/lib/billomat/models/template.rb +18 -0
- data/lib/billomat/models.rb +6 -2
- data/lib/billomat/search.rb +12 -14
- data/lib/billomat/version.rb +1 -1
- data/lib/billomat.rb +15 -18
- metadata +117 -20
- data/.travis.yml +0 -18
- data/doc/assets/logo.png +0 -0
- data/doc/assets/project.png +0 -0
- data/doc/assets/project.xcf +0 -0
data/lib/billomat/models/base.rb
CHANGED
@@ -4,50 +4,49 @@ require 'ostruct'
|
|
4
4
|
|
5
5
|
module Billomat
|
6
6
|
module Models
|
7
|
-
##
|
8
7
|
# This class is the base for all other models (resources).
|
9
8
|
# It handles the communication with the gateway to talk to the API.
|
10
9
|
class Base
|
11
10
|
attr_accessor :data
|
12
11
|
|
13
|
-
|
14
|
-
# Tries to find the resource for the given id
|
12
|
+
# Tries to find the resource for the given id.
|
15
13
|
#
|
16
|
-
# @param [String]
|
17
|
-
# @return [Billomat::Models::Base, nil]
|
14
|
+
# @param id [String] the resource id
|
15
|
+
# @return [Billomat::Models::Base, nil] the found resource or nil
|
18
16
|
def self.find(id)
|
19
17
|
return nil if id.nil?
|
18
|
+
|
20
19
|
resp = Billomat::Gateway.new(:get, "#{base_path}/#{id}").run
|
21
20
|
new(resp[resource_name])
|
22
21
|
end
|
23
22
|
|
24
|
-
|
25
|
-
# Allows to query for a record
|
23
|
+
# Allows to query for a record.
|
26
24
|
#
|
27
|
-
# @param [Hash]
|
28
|
-
# @return [Array<Billomat::Models::Base>]
|
25
|
+
# @param hash [Hash] the query parameters
|
26
|
+
# @return [Array<Billomat::Models::Base>] the found records
|
29
27
|
def self.where(hash = {})
|
30
28
|
Billomat::Search.new(self, hash).run
|
31
29
|
end
|
32
30
|
|
33
31
|
##
|
34
|
-
# Initializes a new model
|
32
|
+
# Initializes a new model.
|
35
33
|
#
|
36
|
-
# @param [Hash]
|
37
|
-
# @return [Billomat::Models::Base]
|
34
|
+
# @param data [Hash] the attributes of the object
|
35
|
+
# @return [Billomat::Models::Base] the record as an object
|
38
36
|
def initialize(data = {})
|
39
37
|
@data = OpenStruct.new(data)
|
40
38
|
end
|
41
39
|
|
42
|
-
##
|
43
40
|
# Persists the current object in the API.
|
44
41
|
# When record is new it calls create, otherwise it saves the object.
|
45
42
|
#
|
46
43
|
# @return [TrueClass]
|
47
44
|
def save
|
48
45
|
return create if id.nil?
|
46
|
+
|
49
47
|
update
|
50
48
|
end
|
49
|
+
alias save! save
|
51
50
|
|
52
51
|
# @return [TrueClass]
|
53
52
|
def create
|
@@ -59,6 +58,7 @@ module Billomat
|
|
59
58
|
|
60
59
|
true
|
61
60
|
end
|
61
|
+
alias create! create
|
62
62
|
|
63
63
|
# @return [TrueClass]
|
64
64
|
def update
|
@@ -68,6 +68,7 @@ module Billomat
|
|
68
68
|
|
69
69
|
true
|
70
70
|
end
|
71
|
+
alias update! update
|
71
72
|
|
72
73
|
# @return [TrueClass]
|
73
74
|
def delete
|
@@ -76,52 +77,50 @@ module Billomat
|
|
76
77
|
|
77
78
|
true
|
78
79
|
end
|
80
|
+
alias delete! delete
|
79
81
|
|
80
|
-
# @return [String, nil]
|
82
|
+
# @return [String, nil] the object's ID
|
81
83
|
def id
|
82
84
|
@data['id'] || nil
|
83
85
|
end
|
84
86
|
|
85
|
-
|
86
|
-
# Wraps the data so the API accepts the request
|
87
|
+
# Wraps the data so the API accepts the request.
|
87
88
|
#
|
88
89
|
# @example
|
89
90
|
# some_invoice.wrapped_data
|
90
91
|
# #=> { "invoice" => { "id" => "12345" } }
|
91
92
|
#
|
92
|
-
# @return [Hash]
|
93
|
+
# @return [Hash] the wrapped data
|
93
94
|
def wrapped_data
|
94
95
|
{ self.class.resource_name => @data.to_h }
|
95
96
|
end
|
96
97
|
|
97
|
-
|
98
|
-
# Returns the object with the right JSON structure
|
98
|
+
# Returns the object with the right JSON structure.
|
99
99
|
#
|
100
|
-
# @return [Hash]
|
101
|
-
def as_json(
|
100
|
+
# @return [Hash] the objects data
|
101
|
+
def as_json(_options = nil)
|
102
102
|
@data.to_h
|
103
103
|
end
|
104
104
|
|
105
|
-
|
106
|
-
# All values in the @data hash can be accessed like a 'normal' method
|
105
|
+
# All values in the @data hash can be accessed like a 'normal' method.
|
107
106
|
#
|
108
107
|
# @example
|
109
108
|
# invoice = Billomat::Models::Invoice.new(invoice_number: '123')
|
110
109
|
# invoice.invoice_number
|
111
110
|
# #=> '123'
|
112
111
|
def method_missing(method, *args, &block)
|
113
|
-
return @data[method] if @data.to_h.
|
112
|
+
return @data[method] if @data.to_h.key?(method)
|
113
|
+
|
114
114
|
super
|
115
115
|
end
|
116
116
|
|
117
|
-
|
118
|
-
# Necessary for method_missing
|
117
|
+
# Necessary for method_missing.
|
119
118
|
#
|
120
119
|
# @param [Symbol] method The method name
|
121
120
|
# @param [TrueClass, FalseClass] include_privat
|
122
121
|
# @return [TrueClass, FalseClass]
|
123
122
|
def respond_to_missing?(method, include_privat = false)
|
124
|
-
@data.to_h.
|
123
|
+
@data.to_h.key?(method.to_s) || super
|
125
124
|
end
|
126
125
|
end
|
127
126
|
end
|
@@ -2,15 +2,14 @@
|
|
2
2
|
|
3
3
|
module Billomat
|
4
4
|
module Models
|
5
|
-
|
6
|
-
# Representation of the client resource
|
5
|
+
# Representation of the client resource.
|
7
6
|
class Client < Base
|
8
|
-
# @return [String]
|
7
|
+
# @return [String] the resource's base path
|
9
8
|
def self.base_path
|
10
9
|
'/clients'
|
11
10
|
end
|
12
11
|
|
13
|
-
# @return [String]
|
12
|
+
# @return [String] the resource's name
|
14
13
|
def self.resource_name
|
15
14
|
'client'
|
16
15
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Billomat
|
4
|
+
module Models
|
5
|
+
# Representation of the client resource.
|
6
|
+
class Contact < Base
|
7
|
+
# @return [String] the resource's base path
|
8
|
+
def self.base_path
|
9
|
+
'/contacts'
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [String] the resource's name
|
13
|
+
def self.resource_name
|
14
|
+
'contact'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Billomat
|
4
|
+
module Models
|
5
|
+
# Representation of the credit note resource
|
6
|
+
class CreditNote < Base
|
7
|
+
# @return [String] the resource's base path
|
8
|
+
def self.base_path
|
9
|
+
'/credit-notes'
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [String] the resource's name
|
13
|
+
def self.resource_name
|
14
|
+
'credit-note'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Billomat
|
4
|
+
module Models
|
5
|
+
# Representation of the credit note item resource
|
6
|
+
class CreditNoteItem < Base
|
7
|
+
# @return [String] the resource's base path
|
8
|
+
def self.base_path
|
9
|
+
'/credit-note-items'
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [String] the resource's name
|
13
|
+
def self.resource_name
|
14
|
+
'credit-note-item'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -2,33 +2,29 @@
|
|
2
2
|
|
3
3
|
module Billomat
|
4
4
|
module Models
|
5
|
-
##
|
6
5
|
# Representation of the invoice resource
|
7
6
|
class Invoice < Base
|
8
|
-
# @return [String]
|
7
|
+
# @return [String] the resource's base path
|
9
8
|
def self.base_path
|
10
9
|
'/invoices'
|
11
10
|
end
|
12
11
|
|
13
|
-
# @return [String]
|
12
|
+
# @return [String] the resource's name
|
14
13
|
def self.resource_name
|
15
14
|
'invoice'
|
16
15
|
end
|
17
16
|
|
18
|
-
|
19
|
-
# Completes the invoice by calling the Complete action
|
17
|
+
# Completes the invoice by calling the Complete action.
|
20
18
|
def complete!
|
21
19
|
Billomat::Actions::Complete.new(id).call
|
22
20
|
end
|
23
21
|
|
24
|
-
|
25
|
-
# Cancels the invoice by calling the Cancel action
|
22
|
+
# Cancels the invoice by calling the Cancel action.
|
26
23
|
def cancel!
|
27
24
|
Billomat::Actions::Cancel.new(id).call
|
28
25
|
end
|
29
26
|
|
30
|
-
|
31
|
-
# Sends the invoice as an email to the given recipient
|
27
|
+
# Sends the invoice as an email to the given recipient.
|
32
28
|
#
|
33
29
|
# @param [String] recipient The email address of the recipient
|
34
30
|
def send_email(recipient)
|
@@ -37,8 +33,7 @@ module Billomat
|
|
37
33
|
Billomat::Actions::Email.new(id, email_params).call
|
38
34
|
end
|
39
35
|
|
40
|
-
|
41
|
-
# Allows to download the invoice as an PDF
|
36
|
+
# Allows to download the invoice as an PDF.
|
42
37
|
def to_pdf
|
43
38
|
Billomat::Actions::Pdf.new(id).call
|
44
39
|
end
|
@@ -3,14 +3,14 @@
|
|
3
3
|
module Billomat
|
4
4
|
module Models
|
5
5
|
##
|
6
|
-
# Representation of the invoice item resource
|
6
|
+
# Representation of the invoice item resource.
|
7
7
|
class InvoiceItem < Base
|
8
|
-
# @return [String]
|
8
|
+
# @return [String] the resource's base path
|
9
9
|
def self.base_path
|
10
10
|
'/invoice-items'
|
11
11
|
end
|
12
12
|
|
13
|
-
# @return [String]
|
13
|
+
# @return [String] the resource's name
|
14
14
|
def self.resource_name
|
15
15
|
'invoice-item'
|
16
16
|
end
|
@@ -2,15 +2,14 @@
|
|
2
2
|
|
3
3
|
module Billomat
|
4
4
|
module Models
|
5
|
-
|
6
|
-
# Representation of the invoice payment resource
|
5
|
+
# Representation of the invoice payment resource.
|
7
6
|
class InvoicePayment < Base
|
8
|
-
# @return [String]
|
7
|
+
# @return [String] the resource's base path
|
9
8
|
def self.base_path
|
10
9
|
'/invoice-payments'
|
11
10
|
end
|
12
11
|
|
13
|
-
# @return [String]
|
12
|
+
# @return [String] the resource's name
|
14
13
|
def self.resource_name
|
15
14
|
'invoice-payment'
|
16
15
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Billomat
|
4
|
+
module Models
|
5
|
+
# Representation of the tag resource.
|
6
|
+
class Tag < Base
|
7
|
+
# @return [String] the resource's base path
|
8
|
+
def self.base_path
|
9
|
+
'/tags'
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [String] the resource's name
|
13
|
+
def self.resource_name
|
14
|
+
'tag'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Billomat
|
4
|
+
module Models
|
5
|
+
# Representation of the template resource.
|
6
|
+
class Template < Base
|
7
|
+
# @return [String] the resource's base path
|
8
|
+
def self.base_path
|
9
|
+
'/templates'
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [String] the resource's name
|
13
|
+
def self.resource_name
|
14
|
+
'template'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/billomat/models.rb
CHANGED
@@ -2,12 +2,16 @@
|
|
2
2
|
|
3
3
|
require 'billomat/models/base'
|
4
4
|
require 'billomat/models/client'
|
5
|
+
require 'billomat/models/credit_note'
|
6
|
+
require 'billomat/models/credit_note_item'
|
5
7
|
require 'billomat/models/invoice'
|
6
8
|
require 'billomat/models/invoice_item'
|
7
9
|
require 'billomat/models/invoice_payment'
|
10
|
+
require 'billomat/models/contact'
|
11
|
+
require 'billomat/models/tag'
|
12
|
+
require 'billomat/models/template'
|
8
13
|
|
9
14
|
module Billomat
|
10
|
-
|
11
|
-
# Models represent a resource in the API, e.g. invoices, clients
|
15
|
+
# Models represent a resource in the API, e.g. invoices, clients.
|
12
16
|
module Models; end
|
13
17
|
end
|
data/lib/billomat/search.rb
CHANGED
@@ -3,11 +3,9 @@
|
|
3
3
|
require 'uri'
|
4
4
|
|
5
5
|
module Billomat
|
6
|
-
|
7
|
-
# This class provides the possibility to query the resources
|
6
|
+
# This class provides the possibility to query the resources.
|
8
7
|
class Search
|
9
|
-
|
10
|
-
# Creates a new search object
|
8
|
+
# Creates a new search object.
|
11
9
|
#
|
12
10
|
# @param [Class] resource The resource class to be queried
|
13
11
|
# @param [Hash] hash The query
|
@@ -16,23 +14,22 @@ module Billomat
|
|
16
14
|
@hash = hash
|
17
15
|
end
|
18
16
|
|
19
|
-
# @return [String]
|
17
|
+
# @return [String] the path including the query
|
20
18
|
def path
|
21
19
|
"#{@resource.base_path}?#{hash_to_query}"
|
22
20
|
end
|
23
21
|
|
24
|
-
|
25
|
-
#
|
26
|
-
# Currently it will always return an empty array when no query is provided
|
22
|
+
# Runs the query and calls the gateway.
|
23
|
+
# Currently it will always return an empty array when no query is provided.
|
27
24
|
#
|
28
25
|
# @return [Array<Billomat::Model::Base>]
|
29
26
|
def run
|
30
|
-
return [] if @hash.reject { |
|
27
|
+
return [] if @hash.reject { |_k, v| v.nil? }.empty?
|
28
|
+
|
31
29
|
to_array(Billomat::Gateway.new(:get, path).run)
|
32
30
|
end
|
33
31
|
|
34
|
-
|
35
|
-
# Corrects the response to always return an array
|
32
|
+
# Corrects the response to always return an array.
|
36
33
|
#
|
37
34
|
# @todo Due to a strange API behaviour we have to fix the reponse here.
|
38
35
|
# This may be fixed in a new API version.
|
@@ -53,21 +50,22 @@ module Billomat
|
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
56
|
-
# @return [String]
|
53
|
+
# @return [String] the name of the resource
|
57
54
|
def name
|
58
55
|
@resource.resource_name
|
59
56
|
end
|
60
57
|
|
61
58
|
# @param [Hash] resp The response from the gateway
|
62
|
-
# @return [Integer]
|
59
|
+
# @return [Integer] the number of records found
|
63
60
|
def count(resp)
|
64
61
|
return 0 if resp.nil?
|
62
|
+
|
65
63
|
resp["#{name}s"]['@total'].to_i
|
66
64
|
end
|
67
65
|
|
68
66
|
private
|
69
67
|
|
70
|
-
# @return [String]
|
68
|
+
# @return [String] the query as www encoded string
|
71
69
|
def hash_to_query
|
72
70
|
URI.encode_www_form(@hash)
|
73
71
|
end
|
data/lib/billomat/version.rb
CHANGED
data/lib/billomat.rb
CHANGED
@@ -7,28 +7,25 @@ require 'billomat/actions'
|
|
7
7
|
require 'billomat/search'
|
8
8
|
require 'billomat/gateway'
|
9
9
|
|
10
|
-
|
11
|
-
# An wrapper for the
|
12
|
-
# <a href="https://billomat.com">Billomat</a>
|
13
|
-
# API
|
10
|
+
# An wrapper for the Billomat API.
|
14
11
|
module Billomat
|
15
12
|
class << self
|
16
13
|
attr_writer :configuration
|
17
|
-
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
# @return [Billomat::Configuration] the global billomat configuration
|
16
|
+
def configuration
|
17
|
+
@configuration ||= Billomat::Configuration.new
|
18
|
+
end
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
20
|
+
# Class method to set and change the global configuration.
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
# Billomat.configure do |config|
|
24
|
+
# config.subdomain = 'your-business-name'
|
25
|
+
# config.api_key = 'a3b148a61cb642389b4f9953f6233f20'
|
26
|
+
# end
|
27
|
+
def configure
|
28
|
+
yield(configuration)
|
29
|
+
end
|
33
30
|
end
|
34
31
|
end
|