billogram 0.4.1 → 0.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e1cd468bd3eab2cb8de98ae549c52e36f1da713
4
- data.tar.gz: 7ac88f9d37a3c31796f42736ac7721749b00832f
3
+ metadata.gz: 66bc9d6fc1707cc2615a8aa63e3fdd211e68ca4f
4
+ data.tar.gz: 8ad753d1c3b129104bb8c0557e4f92251e264e7d
5
5
  SHA512:
6
- metadata.gz: 846d964585e1c6c635391aaa1e20220c3031ce2e94335028e38630dd20df85e39be6f8179a0a2145cf4552ea0b8fd4cf8d79273b71137f2eada9c2a667499cb7
7
- data.tar.gz: 254c14107ceff556a081b7d03b8331fb8e1307269c7ea6db9d7916256f4a6d671ee0d4a91ec4c015c63d15b292c6e9eaea1009eff5c6c5180a3b93c03a521cf6
6
+ metadata.gz: 829e2453b693f4e409f6d5374656e7ead261a505e21ae6a68d3efffe15c145964bb1ba9959aec4b855f9ffcb8b06042da8e341f1e4fa3962b97fd6197f4ebf40
7
+ data.tar.gz: 45e1132b2af23d470cdb4c0cc94e125bda47142d6ed4e1a89d66900d8a9a183ce9f0046f60375d6b8d3a17b7eab00a4c8b1cca7bec5eb4d74dc7072e55a45121
@@ -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/regional_sweden"
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"
@@ -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.code == 200
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
@@ -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 || class_name}".constantize
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 = extract_attributes(relation)
28
- value = send("build_#{relation.type}", relation, attrs)
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
@@ -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) if respond_to?(key)
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,6 +1,6 @@
1
1
  module Billogram
2
2
  class Address < Resource
3
3
  attr_accessor :street_address, :careof, :use_careof_as_attention, :zipcode,
4
- :city, :country, :name
4
+ :city, :country, :name, :attention
5
5
  end
6
6
  end
@@ -0,0 +1,5 @@
1
+ module Billogram
2
+ class AutomaticReminder < Resource
3
+ attr_accessor :message, :delay_days
4
+ end
5
+ end
@@ -1,6 +1,6 @@
1
1
  module Billogram
2
2
  class Callbacks < Resource
3
- attr_accessor :callback_id, :custom, :signature, :sandbox
3
+ attr_accessor :callback_id, :custom, :signature, :sandbox, :url, :sign_key
4
4
 
5
5
  relation :event, :one
6
6
  relation :invoice, :one
@@ -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,5 +1,7 @@
1
1
  module Billogram
2
2
  class Event < Resource
3
+ include Endpoint
4
+
3
5
  endpoint 'billogram_event'
4
6
 
5
7
  attr_accessor :created_at, :type
@@ -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
- extend Forwardable
21
- delegate perform_request: self
23
+ COMMANDS = [ :sell, :remind, :collect, :writeoff, :resend, :remind, :payment, :credit, :message, :attach ]
22
24
 
23
- def sell
24
- perform_request(command_path(:sell), :post)
25
- end
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
- perform_request(command_path(:send), :post, {method: method})
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 command_path(command)
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,8 @@
1
1
  module Billogram
2
2
  class InvoiceDefaults < Resource
3
3
  attr_accessor :default_message, :default_interest_rate, :default_reminder_fee,
4
- :default_invoice_fee, :automatic_reminders
4
+ :default_invoice_fee
5
+
6
+ relation :automatic_reminders, :many
5
7
  end
6
8
  end
@@ -1,6 +1,9 @@
1
1
  module Billogram
2
2
  class Item < Resource
3
- attr_accessor :item_no, :title, :description, :price, :vat, :unit, :created_at, :updated_at
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
 
@@ -0,0 +1,11 @@
1
+ module Billogram
2
+ class Logotype < Resource
3
+ include Endpoint
4
+
5
+ attr_accessor :content, :file_type
6
+
7
+ def self.upload(*args)
8
+ create(*args)
9
+ end
10
+ end
11
+ end
@@ -1,6 +1,6 @@
1
1
  module Billogram
2
2
  class RegionalSweden < Resource
3
3
  attr_accessor :rotavdrag, :rotavdrag_personal_number, :rotavdrag_description,
4
- :reversed_vat, :rotavdrag_account
4
+ :reversed_vat, :rotavdrag_account, :rotavdrag_sum
5
5
  end
6
6
  end
@@ -0,0 +1,9 @@
1
+ module Billogram
2
+ class Report < Resource
3
+ include Endpoint
4
+
5
+ attr_accessor :filename, :type, :file_type, :info, :created_at, :content
6
+
7
+ alias_method :id, :filename
8
+ end
9
+ end
@@ -1,5 +1,6 @@
1
1
  module Billogram
2
2
  class Settings < Resource
3
+ include Endpoint
3
4
 
4
5
  attr_accessor :name, :org_no
5
6
 
@@ -1,3 +1,3 @@
1
1
  module Billogram
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
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.1
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