billogram 0.4.0 → 0.4.1
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 +1 -2
- data/lib/billogram/error.rb +2 -15
- data/lib/billogram/request.rb +26 -0
- data/lib/billogram/resource.rb +10 -22
- data/lib/billogram/resources/customer.rb +3 -0
- data/lib/billogram/resources/invoice.rb +3 -1
- data/lib/billogram/resources/item.rb +2 -0
- data/lib/billogram/resources/regional_sweden.rb +2 -1
- data/lib/billogram/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e1cd468bd3eab2cb8de98ae549c52e36f1da713
|
4
|
+
data.tar.gz: 7ac88f9d37a3c31796f42736ac7721749b00832f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 846d964585e1c6c635391aaa1e20220c3031ce2e94335028e38630dd20df85e39be6f8179a0a2145cf4552ea0b8fd4cf8d79273b71137f2eada9c2a667499cb7
|
7
|
+
data.tar.gz: 254c14107ceff556a081b7d03b8331fb8e1307269c7ea6db9d7916256f4a6d671ee0d4a91ec4c015c63d15b292c6e9eaea1009eff5c6c5180a3b93c03a521cf6
|
data/lib/billogram.rb
CHANGED
@@ -4,6 +4,7 @@ require "billogram/error"
|
|
4
4
|
require "billogram/relation"
|
5
5
|
require "billogram/relation_builder"
|
6
6
|
require "billogram/resource"
|
7
|
+
require "billogram/request"
|
7
8
|
require "billogram/resources/address"
|
8
9
|
require "billogram/resources/bookkeeping"
|
9
10
|
require "billogram/resources/callbacks"
|
@@ -24,8 +25,6 @@ require "billogram/resources/settings"
|
|
24
25
|
require "billogram/resources/tax"
|
25
26
|
require "billogram/version"
|
26
27
|
|
27
|
-
require "billogram/inflections"
|
28
|
-
|
29
28
|
module Billogram
|
30
29
|
class << self
|
31
30
|
attr_accessor :username, :password, :base_uri
|
data/lib/billogram/error.rb
CHANGED
@@ -8,12 +8,7 @@ module Billogram
|
|
8
8
|
class InternalServerError < Error; end
|
9
9
|
|
10
10
|
def self.from_response(response)
|
11
|
-
|
12
|
-
body = response.body.to_s
|
13
|
-
headers = response.headers
|
14
|
-
message = error_message(response)
|
15
|
-
|
16
|
-
if klass = case status
|
11
|
+
if klass = case response.code.to_i
|
17
12
|
when 400 then BadRequest
|
18
13
|
when 401 then Unauthorized
|
19
14
|
when 403 then Forbidden
|
@@ -21,15 +16,7 @@ module Billogram
|
|
21
16
|
when 500 then InternalServerError
|
22
17
|
else Billogram::Error
|
23
18
|
end
|
24
|
-
klass.new(message)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def self.error_message(response)
|
31
|
-
if data = response["data"]
|
32
|
-
data.fetch("message", "")
|
19
|
+
klass.new(response["data"]["message"])
|
33
20
|
end
|
34
21
|
end
|
35
22
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Billogram
|
2
|
+
class Request
|
3
|
+
attr_reader :url, :type, :params
|
4
|
+
|
5
|
+
def initialize(type, url, params = {})
|
6
|
+
@url = url
|
7
|
+
@type = type
|
8
|
+
@params = params
|
9
|
+
end
|
10
|
+
|
11
|
+
def content
|
12
|
+
case type
|
13
|
+
when :post, :put
|
14
|
+
{ body: params.to_json }
|
15
|
+
when :get
|
16
|
+
{ query: params }
|
17
|
+
when :delete
|
18
|
+
{}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute
|
23
|
+
Billogram.client.send(type, url, content)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/billogram/resource.rb
CHANGED
@@ -2,7 +2,7 @@ require "active_support/core_ext/string/inflections.rb"
|
|
2
2
|
|
3
3
|
module Billogram
|
4
4
|
class Resource
|
5
|
-
|
5
|
+
DEFAULT_SEARCH_OPTIONS = { page: 1, page_size: 50 }
|
6
6
|
|
7
7
|
class << self
|
8
8
|
def relations
|
@@ -15,24 +15,24 @@ module Billogram
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def search(options = {})
|
18
|
-
query =
|
19
|
-
perform_request("#{endpoint}",
|
18
|
+
query = DEFAULT_SEARCH_OPTIONS.merge(options)
|
19
|
+
perform_request(:get, "#{endpoint}", query)
|
20
20
|
end
|
21
21
|
|
22
22
|
def fetch(id = nil)
|
23
|
-
perform_request("#{endpoint}/#{id}"
|
23
|
+
perform_request(:get, "#{endpoint}/#{id}")
|
24
24
|
end
|
25
25
|
|
26
26
|
def create(attributes)
|
27
|
-
perform_request("#{endpoint}",
|
27
|
+
perform_request(:post, "#{endpoint}", attributes)
|
28
28
|
end
|
29
29
|
|
30
30
|
def update(id, attributes)
|
31
|
-
perform_request("#{endpoint}/#{id}",
|
31
|
+
perform_request(:put, "#{endpoint}/#{id}", attributes)
|
32
32
|
end
|
33
33
|
|
34
34
|
def delete(id)
|
35
|
-
|
35
|
+
perform_request(:delete, "#{endpoint}/#{id}")
|
36
36
|
end
|
37
37
|
|
38
38
|
def relation(name, type, class_override: nil)
|
@@ -48,17 +48,9 @@ module Billogram
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def perform_request(
|
52
|
-
|
53
|
-
|
54
|
-
query = { body: params.to_json }
|
55
|
-
when :get
|
56
|
-
query = { query: params }
|
57
|
-
else nil
|
58
|
-
end
|
59
|
-
|
60
|
-
response = Billogram.client.send(type, url, query)
|
61
|
-
build_objects(response) unless type == :delete
|
51
|
+
def perform_request(type, url, params = {})
|
52
|
+
response = Request.new(type, url, params).execute
|
53
|
+
build_objects(response)
|
62
54
|
end
|
63
55
|
end
|
64
56
|
|
@@ -78,10 +70,6 @@ module Billogram
|
|
78
70
|
self.class.delete(id)
|
79
71
|
end
|
80
72
|
|
81
|
-
def perform_request(*args)
|
82
|
-
self.class.perform_request(*args)
|
83
|
-
end
|
84
|
-
|
85
73
|
def endpoint
|
86
74
|
self.class.endpoint
|
87
75
|
end
|
@@ -3,8 +3,11 @@ module Billogram
|
|
3
3
|
attr_accessor :customer_no, :name, :notes, :org_no, :vat_no, :created_at,
|
4
4
|
:updated_at, :company_type
|
5
5
|
|
6
|
+
alias_method :id, :customer_no
|
7
|
+
|
6
8
|
relation :address, :one
|
7
9
|
relation :contact, :one
|
8
10
|
relation :delivery_address, :one, class_override: "Address"
|
11
|
+
|
9
12
|
end
|
10
13
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Billogram
|
2
2
|
class Invoice < Resource
|
3
3
|
endpoint 'billogram'
|
4
|
-
|
5
4
|
attr_accessor :id, :invoice_no, :ocr_number, :invoice_date, :due_date, :due_days,
|
6
5
|
:invoice_fee, :invoice_fee_vat, :reminder_fee, :interest_rate,
|
7
6
|
:interest_fee, :currency, :delivery_method, :state, :url, :flags,
|
@@ -18,6 +17,9 @@ module Billogram
|
|
18
17
|
relation :items, :many
|
19
18
|
relation :events, :many
|
20
19
|
|
20
|
+
extend Forwardable
|
21
|
+
delegate perform_request: self
|
22
|
+
|
21
23
|
def sell
|
22
24
|
perform_request(command_path(:sell), :post)
|
23
25
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Billogram
|
2
2
|
class RegionalSweden < Resource
|
3
|
-
attr_accessor :rotavdrag, :rotavdrag_personal_number, :rotavdrag_description,
|
3
|
+
attr_accessor :rotavdrag, :rotavdrag_personal_number, :rotavdrag_description,
|
4
|
+
:reversed_vat, :rotavdrag_account
|
4
5
|
end
|
5
6
|
end
|
data/lib/billogram/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Birman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- lib/billogram/error.rb
|
146
146
|
- lib/billogram/relation.rb
|
147
147
|
- lib/billogram/relation_builder.rb
|
148
|
+
- lib/billogram/request.rb
|
148
149
|
- lib/billogram/resource.rb
|
149
150
|
- lib/billogram/resources/address.rb
|
150
151
|
- lib/billogram/resources/bookkeeping.rb
|