billogram 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/billogram.rb +5 -1
- data/lib/billogram/client.rb +1 -1
- data/lib/billogram/endpoint.rb +53 -0
- data/lib/billogram/relation.rb +2 -14
- data/lib/billogram/relation_builder.rb +2 -14
- data/lib/billogram/resource.rb +1 -46
- data/lib/billogram/resources/address.rb +1 -1
- data/lib/billogram/resources/automatic_reminder.rb +5 -0
- data/lib/billogram/resources/callbacks.rb +1 -1
- data/lib/billogram/resources/customer.rb +3 -2
- data/lib/billogram/resources/event.rb +2 -0
- data/lib/billogram/resources/invoice.rb +12 -39
- data/lib/billogram/resources/invoice_defaults.rb +3 -1
- data/lib/billogram/resources/item.rb +4 -1
- data/lib/billogram/resources/logotype.rb +11 -0
- data/lib/billogram/resources/regional_sweden.rb +1 -1
- data/lib/billogram/resources/report.rb +9 -0
- data/lib/billogram/resources/settings.rb +1 -0
- data/lib/billogram/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66bc9d6fc1707cc2615a8aa63e3fdd211e68ca4f
|
4
|
+
data.tar.gz: 8ad753d1c3b129104bb8c0557e4f92251e264e7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 829e2453b693f4e409f6d5374656e7ead261a505e21ae6a68d3efffe15c145964bb1ba9959aec4b855f9ffcb8b06042da8e341f1e4fa3962b97fd6197f4ebf40
|
7
|
+
data.tar.gz: 45e1132b2af23d470cdb4c0cc94e125bda47142d6ed4e1a89d66900d8a9a183ce9f0046f60375d6b8d3a17b7eab00a4c8b1cca7bec5eb4d74dc7072e55a45121
|
data/lib/billogram.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require "httparty"
|
2
2
|
require "billogram/client"
|
3
|
+
require "billogram/endpoint"
|
3
4
|
require "billogram/error"
|
4
5
|
require "billogram/relation"
|
5
6
|
require "billogram/relation_builder"
|
6
7
|
require "billogram/resource"
|
7
8
|
require "billogram/request"
|
8
9
|
require "billogram/resources/address"
|
10
|
+
require "billogram/resources/automatic_reminder"
|
9
11
|
require "billogram/resources/bookkeeping"
|
10
12
|
require "billogram/resources/callbacks"
|
11
13
|
require "billogram/resources/contact"
|
@@ -19,8 +21,10 @@ require "billogram/resources/international_bank_account"
|
|
19
21
|
require "billogram/resources/invoice"
|
20
22
|
require "billogram/resources/invoice_defaults"
|
21
23
|
require "billogram/resources/item"
|
22
|
-
require "billogram/resources/
|
24
|
+
require "billogram/resources/logotype"
|
23
25
|
require "billogram/resources/payment"
|
26
|
+
require "billogram/resources/regional_sweden"
|
27
|
+
require "billogram/resources/report"
|
24
28
|
require "billogram/resources/settings"
|
25
29
|
require "billogram/resources/tax"
|
26
30
|
require "billogram/version"
|
data/lib/billogram/client.rb
CHANGED
@@ -25,7 +25,7 @@ module Billogram
|
|
25
25
|
|
26
26
|
def handle_request(method, *args)
|
27
27
|
response = self.class.send(method, *args)
|
28
|
-
return response.parsed_response["data"] if response.
|
28
|
+
return response.parsed_response["data"] if response.success?
|
29
29
|
raise Billogram::Error.from_response(response)
|
30
30
|
end
|
31
31
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Billogram
|
2
|
+
module Endpoint
|
3
|
+
def self.included(base)
|
4
|
+
base.include(InstanceMethods)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
def update(attributes)
|
10
|
+
self.class.perform_request(:put, "#{endpoint}/#{id}", attributes)
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete
|
14
|
+
self.class.perform_request(:delete, "#{endpoint}/#{id}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def endpoint
|
18
|
+
self.class.endpoint
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module ClassMethods
|
23
|
+
attr_writer :default_search_options
|
24
|
+
|
25
|
+
def default_search_options
|
26
|
+
@default_search_options ||= { page: 1, page_size: 50 }
|
27
|
+
end
|
28
|
+
|
29
|
+
def endpoint(value = nil)
|
30
|
+
@endpoint = value if value
|
31
|
+
@endpoint || name.demodulize.underscore
|
32
|
+
end
|
33
|
+
|
34
|
+
def search(options = {})
|
35
|
+
query = default_search_options.merge(options)
|
36
|
+
perform_request(:get, "#{endpoint}", query)
|
37
|
+
end
|
38
|
+
|
39
|
+
def fetch(id = nil)
|
40
|
+
perform_request(:get, "#{endpoint}/#{id}")
|
41
|
+
end
|
42
|
+
|
43
|
+
def create(attributes)
|
44
|
+
perform_request(:post, "#{endpoint}", attributes)
|
45
|
+
end
|
46
|
+
|
47
|
+
def perform_request(type, url, params = {})
|
48
|
+
response = Request.new(type, url, params).execute
|
49
|
+
build_objects(response)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/billogram/relation.rb
CHANGED
@@ -3,25 +3,13 @@ module Billogram
|
|
3
3
|
attr_reader :name, :type, :class_override
|
4
4
|
|
5
5
|
def initialize(name, type, class_override: nil)
|
6
|
-
@name = name
|
6
|
+
@name = name.to_s
|
7
7
|
@type = type
|
8
8
|
@class_override = class_override
|
9
9
|
end
|
10
10
|
|
11
11
|
def relation_class
|
12
|
-
"Billogram::#{class_override ||
|
13
|
-
end
|
14
|
-
|
15
|
-
def class_name
|
16
|
-
@class_name ||= send("class_name_for_#{type}").classify
|
17
|
-
end
|
18
|
-
|
19
|
-
def class_name_for_one
|
20
|
-
name.to_s
|
21
|
-
end
|
22
|
-
|
23
|
-
def class_name_for_many
|
24
|
-
name.to_s.singularize
|
12
|
+
"Billogram::#{class_override || name.classify}".constantize
|
25
13
|
end
|
26
14
|
end
|
27
15
|
end
|
@@ -15,27 +15,15 @@ module Billogram
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def extract_attributes(relation)
|
19
|
-
attributes.delete(relation.name.to_s)
|
20
|
-
end
|
21
|
-
|
22
18
|
def resource_relations
|
23
19
|
resource.class.relations
|
24
20
|
end
|
25
21
|
|
26
22
|
def build_relation(relation)
|
27
|
-
if attrs =
|
28
|
-
value =
|
23
|
+
if attrs = attributes.delete(relation.name)
|
24
|
+
value = relation.relation_class.build_objects(attrs)
|
29
25
|
resource.public_send("#{relation.name}=", value)
|
30
26
|
end
|
31
27
|
end
|
32
|
-
|
33
|
-
def build_one(relation, attrs)
|
34
|
-
relation.relation_class.new(attrs)
|
35
|
-
end
|
36
|
-
|
37
|
-
def build_many(relation, attrs)
|
38
|
-
attrs.map{|item| relation.relation_class.new(item) }
|
39
|
-
end
|
40
28
|
end
|
41
29
|
end
|
data/lib/billogram/resource.rb
CHANGED
@@ -2,39 +2,11 @@ require "active_support/core_ext/string/inflections.rb"
|
|
2
2
|
|
3
3
|
module Billogram
|
4
4
|
class Resource
|
5
|
-
DEFAULT_SEARCH_OPTIONS = { page: 1, page_size: 50 }
|
6
|
-
|
7
5
|
class << self
|
8
6
|
def relations
|
9
7
|
@relations ||= []
|
10
8
|
end
|
11
9
|
|
12
|
-
def endpoint(value = nil)
|
13
|
-
@endpoint = value if value
|
14
|
-
@endpoint || name.demodulize.underscore
|
15
|
-
end
|
16
|
-
|
17
|
-
def search(options = {})
|
18
|
-
query = DEFAULT_SEARCH_OPTIONS.merge(options)
|
19
|
-
perform_request(:get, "#{endpoint}", query)
|
20
|
-
end
|
21
|
-
|
22
|
-
def fetch(id = nil)
|
23
|
-
perform_request(:get, "#{endpoint}/#{id}")
|
24
|
-
end
|
25
|
-
|
26
|
-
def create(attributes)
|
27
|
-
perform_request(:post, "#{endpoint}", attributes)
|
28
|
-
end
|
29
|
-
|
30
|
-
def update(id, attributes)
|
31
|
-
perform_request(:put, "#{endpoint}/#{id}", attributes)
|
32
|
-
end
|
33
|
-
|
34
|
-
def delete(id)
|
35
|
-
perform_request(:delete, "#{endpoint}/#{id}")
|
36
|
-
end
|
37
|
-
|
38
10
|
def relation(name, type, class_override: nil)
|
39
11
|
relations << Relation.new(name, type, class_override: class_override)
|
40
12
|
attr_accessor name
|
@@ -47,33 +19,16 @@ module Billogram
|
|
47
19
|
else data
|
48
20
|
end
|
49
21
|
end
|
50
|
-
|
51
|
-
def perform_request(type, url, params = {})
|
52
|
-
response = Request.new(type, url, params).execute
|
53
|
-
build_objects(response)
|
54
|
-
end
|
55
22
|
end
|
56
23
|
|
57
24
|
def initialize(attributes = {})
|
58
25
|
Hash(attributes).each do |key, value|
|
59
|
-
public_send("#{key}=", value)
|
26
|
+
public_send("#{key}=", value)
|
60
27
|
end
|
61
28
|
|
62
29
|
RelationBuilder.new(self, attributes).call
|
63
30
|
end
|
64
31
|
|
65
|
-
def update(attributes)
|
66
|
-
self.class.update(id, attributes)
|
67
|
-
end
|
68
|
-
|
69
|
-
def delete
|
70
|
-
self.class.delete(id)
|
71
|
-
end
|
72
|
-
|
73
|
-
def endpoint
|
74
|
-
self.class.endpoint
|
75
|
-
end
|
76
|
-
|
77
32
|
def to_json(*args)
|
78
33
|
instance_variables
|
79
34
|
.map{|var| ["#{var}"[1..-1], instance_variable_get(var)]}
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module Billogram
|
2
2
|
class Customer < Resource
|
3
|
+
include Endpoint
|
4
|
+
|
3
5
|
attr_accessor :customer_no, :name, :notes, :org_no, :vat_no, :created_at,
|
4
|
-
:updated_at, :company_type
|
6
|
+
:updated_at, :company_type, :phone, :email
|
5
7
|
|
6
8
|
alias_method :id, :customer_no
|
7
9
|
|
8
10
|
relation :address, :one
|
9
11
|
relation :contact, :one
|
10
12
|
relation :delivery_address, :one, class_override: "Address"
|
11
|
-
|
12
13
|
end
|
13
14
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module Billogram
|
2
2
|
class Invoice < Resource
|
3
|
+
include Endpoint
|
4
|
+
|
3
5
|
endpoint 'billogram'
|
6
|
+
|
4
7
|
attr_accessor :id, :invoice_no, :ocr_number, :invoice_date, :due_date, :due_days,
|
5
8
|
:invoice_fee, :invoice_fee_vat, :reminder_fee, :interest_rate,
|
6
9
|
:interest_fee, :currency, :delivery_method, :state, :url, :flags,
|
@@ -17,53 +20,23 @@ module Billogram
|
|
17
20
|
relation :items, :many
|
18
21
|
relation :events, :many
|
19
22
|
|
20
|
-
|
21
|
-
delegate perform_request: self
|
23
|
+
COMMANDS = [ :sell, :remind, :collect, :writeoff, :resend, :remind, :payment, :credit, :message, :attach ]
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
def collect
|
28
|
-
perform_request(command_path(:collect), :post)
|
29
|
-
end
|
30
|
-
|
31
|
-
def writeoff
|
32
|
-
perform_request(command_path(:writeoff), :post)
|
25
|
+
COMMANDS.each do |command|
|
26
|
+
define_method command do |*args|
|
27
|
+
send_command(command, *args)
|
28
|
+
end
|
33
29
|
end
|
34
30
|
|
35
31
|
def send!(method: )
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
def resend(method: )
|
40
|
-
perform_request(command_path(:resend), :post, {method: method})
|
41
|
-
end
|
42
|
-
|
43
|
-
def remind(method: )
|
44
|
-
perform_request(command_path(:remind), :post, {method: method})
|
45
|
-
end
|
46
|
-
|
47
|
-
def payment(amount: )
|
48
|
-
perform_request(command_path(:payment), :post, {amount: amount})
|
49
|
-
end
|
50
|
-
|
51
|
-
def credit(options = {})
|
52
|
-
perform_request(command_path(:credit), :post, options)
|
53
|
-
end
|
54
|
-
|
55
|
-
def message(message: )
|
56
|
-
perform_request(command_path(:message), :post, {message: message})
|
57
|
-
end
|
58
|
-
|
59
|
-
def attach(options = {})
|
60
|
-
perform_request(command_path(:attach), :post, options)
|
32
|
+
send_command(:send, {method: method})
|
61
33
|
end
|
62
34
|
|
63
35
|
private
|
64
36
|
|
65
|
-
def
|
66
|
-
"#{endpoint}/#{id}/command/#{command}"
|
37
|
+
def send_command(command, options = {})
|
38
|
+
path = "#{endpoint}/#{id}/command/#{command}"
|
39
|
+
self.class.perform_request(:post, path, options)
|
67
40
|
end
|
68
41
|
end
|
69
42
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module Billogram
|
2
2
|
class Item < Resource
|
3
|
-
|
3
|
+
include Endpoint
|
4
|
+
|
5
|
+
attr_accessor :item_no, :title, :description, :price, :vat, :unit,
|
6
|
+
:created_at, :updated_at, :count, :discount
|
4
7
|
|
5
8
|
alias_method :id, :item_no
|
6
9
|
|
data/lib/billogram/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: billogram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Birman
|
@@ -142,12 +142,14 @@ files:
|
|
142
142
|
- bin/setup
|
143
143
|
- lib/billogram.rb
|
144
144
|
- lib/billogram/client.rb
|
145
|
+
- lib/billogram/endpoint.rb
|
145
146
|
- lib/billogram/error.rb
|
146
147
|
- lib/billogram/relation.rb
|
147
148
|
- lib/billogram/relation_builder.rb
|
148
149
|
- lib/billogram/request.rb
|
149
150
|
- lib/billogram/resource.rb
|
150
151
|
- lib/billogram/resources/address.rb
|
152
|
+
- lib/billogram/resources/automatic_reminder.rb
|
151
153
|
- lib/billogram/resources/bookkeeping.rb
|
152
154
|
- lib/billogram/resources/callbacks.rb
|
153
155
|
- lib/billogram/resources/contact.rb
|
@@ -161,8 +163,10 @@ files:
|
|
161
163
|
- lib/billogram/resources/invoice.rb
|
162
164
|
- lib/billogram/resources/invoice_defaults.rb
|
163
165
|
- lib/billogram/resources/item.rb
|
166
|
+
- lib/billogram/resources/logotype.rb
|
164
167
|
- lib/billogram/resources/payment.rb
|
165
168
|
- lib/billogram/resources/regional_sweden.rb
|
169
|
+
- lib/billogram/resources/report.rb
|
166
170
|
- lib/billogram/resources/settings.rb
|
167
171
|
- lib/billogram/resources/tax.rb
|
168
172
|
- lib/billogram/version.rb
|