pina 0.14.4 → 0.15.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 +4 -4
- data/lib/pina.rb +3 -1
- data/lib/pina/contact.rb +4 -48
- data/lib/pina/document_pairing.rb +2 -15
- data/lib/pina/my_bank_account.rb +4 -51
- data/lib/pina/petty_cash_disburstment.rb +2 -24
- data/lib/pina/petty_cash_income.rb +2 -24
- data/lib/pina/processed_document.rb +4 -42
- data/lib/pina/purchase_invoice.rb +4 -51
- data/lib/pina/receivable.rb +4 -33
- data/lib/pina/resource.rb +104 -0
- data/lib/pina/sales_invoice.rb +4 -51
- data/lib/pina/sales_order.rb +4 -33
- data/lib/pina/stat_processed_document.rb +4 -33
- data/lib/pina/uploaded_document.rb +4 -22
- data/lib/pina/uploaded_document_pairing.rb +2 -4
- data/lib/pina/utils/pagination.rb +39 -13
- data/lib/pina/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da8840d1f9f28b6953ed69d47a55c381e965e1b802e26d19efd54471d135897c
|
4
|
+
data.tar.gz: e862eb284901244fd5434ea8c5690029c6f3ca4ef71fdbeaef617d33632c4cac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6ee26957a842abb416e7939e694b516b02d42aed5d6556029a81945331abe5e0759fa935ae89caca832f1d1ec51b20da9d1e22e631bbd26799bb39217e90177
|
7
|
+
data.tar.gz: dd29354cc030a68320c591abb062e196b58543fe3b3d26c6f2019b2fb1801aac2413e9528e9f44828db1ffcc1e4879523f12ba4db0bc0322512e88922314bee8
|
data/lib/pina.rb
CHANGED
@@ -9,6 +9,7 @@ require 'pina/utils/pagination'
|
|
9
9
|
require 'pina/models/errors'
|
10
10
|
require 'pina/models/error'
|
11
11
|
require 'pina/collections/base'
|
12
|
+
require 'pina/resource'
|
12
13
|
|
13
14
|
require 'pina/contact'
|
14
15
|
require 'pina/sales_invoice'
|
@@ -47,7 +48,7 @@ module Pina
|
|
47
48
|
end
|
48
49
|
|
49
50
|
class Configuration
|
50
|
-
attr_accessor :api_token, :email, :api_host, :use_ssl, :tenant
|
51
|
+
attr_accessor :api_token, :email, :api_host, :use_ssl, :tenant, :default_per_page
|
51
52
|
attr_reader :api_version
|
52
53
|
attr_writer :base_url
|
53
54
|
|
@@ -60,6 +61,7 @@ module Pina
|
|
60
61
|
@email = DEFAULT_EMAIL
|
61
62
|
@tenant = DEFAULT_TENANT
|
62
63
|
@api_host = API_HOST
|
64
|
+
@default_per_page = nil
|
63
65
|
@use_ssl = true
|
64
66
|
@base_url = nil
|
65
67
|
end
|
data/lib/pina/contact.rb
CHANGED
@@ -5,6 +5,10 @@ require 'pina/collections/contact'
|
|
5
5
|
|
6
6
|
module Pina
|
7
7
|
class Contact
|
8
|
+
extend Pina::Resource
|
9
|
+
|
10
|
+
resource_methods :all, :where, :find, :create, :update
|
11
|
+
|
8
12
|
class << self
|
9
13
|
def new(params = nil)
|
10
14
|
Pina::Models::Contact.new(params)
|
@@ -17,54 +21,6 @@ module Pina
|
|
17
21
|
|
18
22
|
response
|
19
23
|
end
|
20
|
-
|
21
|
-
def where(hash, _page = nil)
|
22
|
-
response = Pina::RestAdapter.get(:contacts, hash)
|
23
|
-
|
24
|
-
return Pina::Collections::Contact.new(attributes(response)) if
|
25
|
-
response.ok?
|
26
|
-
|
27
|
-
response
|
28
|
-
end
|
29
|
-
|
30
|
-
def find(id)
|
31
|
-
response = Pina::RestAdapter.get(:contacts, id)
|
32
|
-
|
33
|
-
return Pina::Models::Contact.new(attributes(response)) if response.ok?
|
34
|
-
|
35
|
-
response
|
36
|
-
end
|
37
|
-
|
38
|
-
def all(page = nil)
|
39
|
-
response = Pina::RestAdapter.get(:contacts, page)
|
40
|
-
|
41
|
-
return Pina::Collections::Contact.new(attributes(response)) if
|
42
|
-
response.ok?
|
43
|
-
|
44
|
-
response
|
45
|
-
end
|
46
|
-
|
47
|
-
def create(contact)
|
48
|
-
response = Pina::RestAdapter.post(:contacts, contact)
|
49
|
-
|
50
|
-
return Pina::Models::Contact.new(attributes(response)) if response.ok?
|
51
|
-
|
52
|
-
response
|
53
|
-
end
|
54
|
-
|
55
|
-
def update(id, contact)
|
56
|
-
response = Pina::RestAdapter.patch(:contacts, id, contact)
|
57
|
-
|
58
|
-
return Pina::Models::Contact.new(attributes(response)) if response.ok?
|
59
|
-
|
60
|
-
response
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def attributes(response)
|
66
|
-
response.to_hash.merge(response: response)
|
67
|
-
end
|
68
24
|
end
|
69
25
|
end
|
70
26
|
end
|
@@ -3,21 +3,8 @@ require 'pina/collections/document_pairing'
|
|
3
3
|
|
4
4
|
module Pina
|
5
5
|
class DocumentPairing
|
6
|
-
|
7
|
-
def all(page = nil)
|
8
|
-
response = Pina::RestAdapter.get(:document_pairings, page)
|
6
|
+
extend Pina::Resource
|
9
7
|
|
10
|
-
|
11
|
-
response.ok?
|
12
|
-
|
13
|
-
response
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def attributes(response)
|
19
|
-
response.to_hash.merge(response: response)
|
20
|
-
end
|
21
|
-
end
|
8
|
+
resource_methods :all
|
22
9
|
end
|
23
10
|
end
|
data/lib/pina/my_bank_account.rb
CHANGED
@@ -3,61 +3,14 @@ require 'pina/collections/my_bank_account'
|
|
3
3
|
|
4
4
|
module Pina
|
5
5
|
class MyBankAccount
|
6
|
+
extend Pina::Resource
|
7
|
+
|
8
|
+
resource_methods :all, :where, :find, :create, :update
|
9
|
+
|
6
10
|
class << self
|
7
11
|
def new(params = nil)
|
8
12
|
Pina::Models::MyBankAccount.new(params)
|
9
13
|
end
|
10
|
-
|
11
|
-
def find(id)
|
12
|
-
response = Pina::RestAdapter.get(:my_bank_accounts, id)
|
13
|
-
|
14
|
-
return Pina::Models::MyBankAccount.new(attributes(response)) if
|
15
|
-
response.ok?
|
16
|
-
|
17
|
-
response
|
18
|
-
end
|
19
|
-
|
20
|
-
def all(page = nil)
|
21
|
-
response = Pina::RestAdapter.get(:my_bank_accounts, page)
|
22
|
-
|
23
|
-
return Pina::Collections::MyBankAccount.new(attributes(response)) if
|
24
|
-
response.ok?
|
25
|
-
|
26
|
-
response
|
27
|
-
end
|
28
|
-
|
29
|
-
def where(hash, _page = nil)
|
30
|
-
response = Pina::RestAdapter.get(:my_bank_accounts, hash)
|
31
|
-
|
32
|
-
return Pina::Collections::MyBankAccount.new(attributes(response)) if
|
33
|
-
response.ok?
|
34
|
-
|
35
|
-
response
|
36
|
-
end
|
37
|
-
|
38
|
-
def create(my_bank_account)
|
39
|
-
response = Pina::RestAdapter.post(:my_bank_accounts, my_bank_account)
|
40
|
-
|
41
|
-
return Pina::Models::MyBankAccount.new(attributes(response)) if
|
42
|
-
response.ok?
|
43
|
-
|
44
|
-
response
|
45
|
-
end
|
46
|
-
|
47
|
-
def update(id, my_bank_account)
|
48
|
-
response = Pina::RestAdapter.patch(:my_bank_accounts, id, my_bank_account)
|
49
|
-
|
50
|
-
return Pina::Models::MyBankAccount.new(attributes(response)) if
|
51
|
-
response.ok?
|
52
|
-
|
53
|
-
response
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
def attributes(response)
|
59
|
-
response.to_hash.merge(response: response)
|
60
|
-
end
|
61
14
|
end
|
62
15
|
end
|
63
16
|
end
|
@@ -3,30 +3,8 @@ require 'pina/collections/petty_cash_disburstment'
|
|
3
3
|
|
4
4
|
module Pina
|
5
5
|
class PettyCashDisburstment
|
6
|
-
|
7
|
-
def find(gid)
|
8
|
-
response = Pina::RestAdapter.get(:petty_cash_disburstments, gid)
|
6
|
+
extend Pina::Resource
|
9
7
|
|
10
|
-
|
11
|
-
response.ok?
|
12
|
-
|
13
|
-
response
|
14
|
-
end
|
15
|
-
|
16
|
-
def all
|
17
|
-
response = Pina::RestAdapter.get(:petty_cash_disburstments)
|
18
|
-
|
19
|
-
return Pina::Collections::PettyCashDisburstment.new(attributes(response)) if
|
20
|
-
response.ok?
|
21
|
-
|
22
|
-
response
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def attributes(response)
|
28
|
-
response.to_hash.merge(response: response)
|
29
|
-
end
|
30
|
-
end
|
8
|
+
resource_methods :all, :find
|
31
9
|
end
|
32
10
|
end
|
@@ -3,30 +3,8 @@ require 'pina/collections/petty_cash_income'
|
|
3
3
|
|
4
4
|
module Pina
|
5
5
|
class PettyCashIncome
|
6
|
-
|
7
|
-
def find(gid)
|
8
|
-
response = Pina::RestAdapter.get(:petty_cash_incomes, gid)
|
6
|
+
extend Pina::Resource
|
9
7
|
|
10
|
-
|
11
|
-
response.ok?
|
12
|
-
|
13
|
-
response
|
14
|
-
end
|
15
|
-
|
16
|
-
def all
|
17
|
-
response = Pina::RestAdapter.get(:petty_cash_incomes)
|
18
|
-
|
19
|
-
return Pina::Collections::PettyCashIncome.new(attributes(response)) if
|
20
|
-
response.ok?
|
21
|
-
|
22
|
-
response
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def attributes(response)
|
28
|
-
response.to_hash.merge(response: response)
|
29
|
-
end
|
30
|
-
end
|
8
|
+
resource_methods :all, :find
|
31
9
|
end
|
32
10
|
end
|
@@ -3,52 +3,14 @@ require 'pina/collections/processed_document'
|
|
3
3
|
|
4
4
|
module Pina
|
5
5
|
class ProcessedDocument
|
6
|
+
extend Pina::Resource
|
7
|
+
|
8
|
+
resource_methods :all, :where, :find, :delete
|
9
|
+
|
6
10
|
class << self
|
7
11
|
def new(params = nil)
|
8
12
|
Pina::Models::ProcessedDocument.new(params)
|
9
13
|
end
|
10
|
-
|
11
|
-
def find(id)
|
12
|
-
response = Pina::RestAdapter.get(:processed_documents, id)
|
13
|
-
|
14
|
-
return Pina::Models::ProcessedDocument.new(attributes(response)) if
|
15
|
-
response.ok?
|
16
|
-
|
17
|
-
response
|
18
|
-
end
|
19
|
-
|
20
|
-
def where(hash, _page = nil)
|
21
|
-
response = Pina::RestAdapter.get(:processed_documents, hash)
|
22
|
-
|
23
|
-
return Pina::Collections::ProcessedDocument.new(attributes(response)) if
|
24
|
-
response.ok?
|
25
|
-
|
26
|
-
response
|
27
|
-
end
|
28
|
-
|
29
|
-
def all(page = nil)
|
30
|
-
response = Pina::RestAdapter.get(:processed_documents, page)
|
31
|
-
|
32
|
-
return Pina::Collections::ProcessedDocument.new(attributes(response)) if
|
33
|
-
response.ok?
|
34
|
-
|
35
|
-
response
|
36
|
-
end
|
37
|
-
|
38
|
-
def delete(id)
|
39
|
-
response = Pina::RestAdapter.delete(:processed_documents, id)
|
40
|
-
|
41
|
-
return Pina::Models::ProcessedDocument.new(attributes(response)) if
|
42
|
-
response.ok?
|
43
|
-
|
44
|
-
response
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def attributes(response)
|
50
|
-
response.to_hash.merge(response: response)
|
51
|
-
end
|
52
14
|
end
|
53
15
|
end
|
54
16
|
end
|
@@ -4,61 +4,14 @@ require 'pina/collections/purchase_invoice'
|
|
4
4
|
|
5
5
|
module Pina
|
6
6
|
class PurchaseInvoice
|
7
|
+
extend Pina::Resource
|
8
|
+
|
9
|
+
resource_methods :all, :where, :find, :create, :update
|
10
|
+
|
7
11
|
class << self
|
8
12
|
def new(params = nil)
|
9
13
|
Pina::Models::PurchaseInvoice.new(params)
|
10
14
|
end
|
11
|
-
|
12
|
-
def find(id)
|
13
|
-
response = Pina::RestAdapter.get(:purchase_invoices, id)
|
14
|
-
|
15
|
-
return Pina::Models::PurchaseInvoice.new(attributes(response)) if
|
16
|
-
response.ok?
|
17
|
-
|
18
|
-
response
|
19
|
-
end
|
20
|
-
|
21
|
-
def all(page = nil)
|
22
|
-
response = Pina::RestAdapter.get(:purchase_invoices, page)
|
23
|
-
|
24
|
-
return Pina::Collections::PurchaseInvoice.new(attributes(response)) if
|
25
|
-
response.ok?
|
26
|
-
|
27
|
-
response
|
28
|
-
end
|
29
|
-
|
30
|
-
def where(hash, _page = nil)
|
31
|
-
response = Pina::RestAdapter.get(:purchase_invoices, hash)
|
32
|
-
|
33
|
-
return Pina::Collections::PurchaseInvoice.new(attributes(response)) if
|
34
|
-
response.ok?
|
35
|
-
|
36
|
-
response
|
37
|
-
end
|
38
|
-
|
39
|
-
def create(purchase_invoice)
|
40
|
-
response = Pina::RestAdapter.post(:purchase_invoices, purchase_invoice)
|
41
|
-
|
42
|
-
return Pina::Models::PurchaseInvoice.new(attributes(response)) if
|
43
|
-
response.ok?
|
44
|
-
|
45
|
-
response
|
46
|
-
end
|
47
|
-
|
48
|
-
def update(id, purchase_invoice)
|
49
|
-
response = Pina::RestAdapter.patch(:purchase_invoices, id, purchase_invoice)
|
50
|
-
|
51
|
-
return Pina::Models::PurchaseInvoice.new(attributes(response)) if
|
52
|
-
response.ok?
|
53
|
-
|
54
|
-
response
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def attributes(response)
|
60
|
-
response.to_hash.merge(response: response)
|
61
|
-
end
|
62
15
|
end
|
63
16
|
end
|
64
17
|
end
|
data/lib/pina/receivable.rb
CHANGED
@@ -3,43 +3,14 @@ require 'pina/collections/receivable'
|
|
3
3
|
|
4
4
|
module Pina
|
5
5
|
class Receivable
|
6
|
+
extend Pina::Resource
|
7
|
+
|
8
|
+
resource_methods :all, :where, :find
|
9
|
+
|
6
10
|
class << self
|
7
11
|
def new(params = nil)
|
8
12
|
Pina::Models::Receivable.new(params)
|
9
13
|
end
|
10
|
-
|
11
|
-
def find(id)
|
12
|
-
response = Pina::RestAdapter.get(:receivables, id)
|
13
|
-
|
14
|
-
return Pina::Models::Receivable.new(attributes(response)) if
|
15
|
-
response.ok?
|
16
|
-
|
17
|
-
response
|
18
|
-
end
|
19
|
-
|
20
|
-
def where(hash, _page = nil)
|
21
|
-
response = Pina::RestAdapter.get(:receivables, hash)
|
22
|
-
|
23
|
-
return Pina::Collections::Receivable.new(attributes(response)) if
|
24
|
-
response.ok?
|
25
|
-
|
26
|
-
response
|
27
|
-
end
|
28
|
-
|
29
|
-
def all(page = nil)
|
30
|
-
response = Pina::RestAdapter.get(:receivables, page)
|
31
|
-
|
32
|
-
return Pina::Collections::Receivable.new(attributes(response)) if
|
33
|
-
response.ok?
|
34
|
-
|
35
|
-
response
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def attributes(response)
|
41
|
-
response.to_hash.merge(response: response)
|
42
|
-
end
|
43
14
|
end
|
44
15
|
end
|
45
16
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Pina
|
2
|
+
module Resource
|
3
|
+
def paginate(options = {})
|
4
|
+
@per_page = options.fetch(:per_page)
|
5
|
+
end
|
6
|
+
|
7
|
+
def resource_methods(*methods)
|
8
|
+
methods.each do |method|
|
9
|
+
next unless method
|
10
|
+
|
11
|
+
method_name = "define_#{method}".to_sym
|
12
|
+
next unless respond_to?(method_name, true)
|
13
|
+
|
14
|
+
send(method_name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def per_page
|
19
|
+
@per_page || ::Pina.configuration.default_per_page
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def define_where
|
25
|
+
define_all unless respond_to?(:all)
|
26
|
+
|
27
|
+
singleton_class.class_eval do
|
28
|
+
alias_method :where, :all
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def define_all
|
33
|
+
define_singleton_method(:all) do |params = {}|
|
34
|
+
params[:per_page] = per_page if per_page
|
35
|
+
|
36
|
+
response = Pina::RestAdapter.get(resource_path, params)
|
37
|
+
|
38
|
+
return collection.new(attributes(response)) if response.ok?
|
39
|
+
|
40
|
+
response
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def define_find
|
45
|
+
define_singleton_method(:find) do |id|
|
46
|
+
response = Pina::RestAdapter.get(resource_path, id)
|
47
|
+
|
48
|
+
return model.new(attributes(response)) if response.ok?
|
49
|
+
|
50
|
+
response
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def define_create
|
55
|
+
define_singleton_method(:create) do |entity|
|
56
|
+
response = Pina::RestAdapter.post(resource_path, entity)
|
57
|
+
|
58
|
+
return model.new(attributes(response)) if response.ok?
|
59
|
+
|
60
|
+
response
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def define_update
|
65
|
+
define_singleton_method(:update) do |id, entity|
|
66
|
+
response = Pina::RestAdapter.patch(resource_path, id, entity)
|
67
|
+
|
68
|
+
return model.new(attributes(response)) if response.ok?
|
69
|
+
|
70
|
+
response
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def define_delete
|
75
|
+
define_singleton_method(:delete) do |id|
|
76
|
+
response = Pina::RestAdapter.delete(resource_path, id)
|
77
|
+
|
78
|
+
return model.new(attributes(response)) if response.ok?
|
79
|
+
|
80
|
+
response
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def resource_name
|
85
|
+
name.demodulize
|
86
|
+
end
|
87
|
+
|
88
|
+
def resource_path
|
89
|
+
resource_name.underscore.pluralize
|
90
|
+
end
|
91
|
+
|
92
|
+
def collection
|
93
|
+
Object.const_get("Pina::Collections::#{resource_name}")
|
94
|
+
end
|
95
|
+
|
96
|
+
def model
|
97
|
+
Object.const_get("Pina::Models::#{resource_name}")
|
98
|
+
end
|
99
|
+
|
100
|
+
def attributes(response)
|
101
|
+
response.to_hash.merge(response: response)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/pina/sales_invoice.rb
CHANGED
@@ -4,61 +4,14 @@ require 'pina/collections/sales_invoice'
|
|
4
4
|
|
5
5
|
module Pina
|
6
6
|
class SalesInvoice
|
7
|
+
extend Pina::Resource
|
8
|
+
|
9
|
+
resource_methods :all, :where, :find, :create, :update
|
10
|
+
|
7
11
|
class << self
|
8
12
|
def new(params = nil)
|
9
13
|
Pina::Models::SalesInvoice.new(params)
|
10
14
|
end
|
11
|
-
|
12
|
-
def find(id)
|
13
|
-
response = Pina::RestAdapter.get(:sales_invoices, id)
|
14
|
-
|
15
|
-
return Pina::Models::SalesInvoice.new(attributes(response)) if
|
16
|
-
response.ok?
|
17
|
-
|
18
|
-
response
|
19
|
-
end
|
20
|
-
|
21
|
-
def all(page = nil)
|
22
|
-
response = Pina::RestAdapter.get(:sales_invoices, page)
|
23
|
-
|
24
|
-
return Pina::Collections::SalesInvoice.new(attributes(response)) if
|
25
|
-
response.ok?
|
26
|
-
|
27
|
-
response
|
28
|
-
end
|
29
|
-
|
30
|
-
def where(hash, _page = nil)
|
31
|
-
response = Pina::RestAdapter.get(:sales_invoices, hash)
|
32
|
-
|
33
|
-
return Pina::Collections::SalesInvoice.new(attributes(response)) if
|
34
|
-
response.ok?
|
35
|
-
|
36
|
-
response
|
37
|
-
end
|
38
|
-
|
39
|
-
def create(sales_invoice)
|
40
|
-
response = Pina::RestAdapter.post(:sales_invoices, sales_invoice)
|
41
|
-
|
42
|
-
return Pina::Models::SalesInvoice.new(attributes(response)) if
|
43
|
-
response.ok?
|
44
|
-
|
45
|
-
response
|
46
|
-
end
|
47
|
-
|
48
|
-
def update(id, sales_invoice)
|
49
|
-
response = Pina::RestAdapter.patch(:sales_invoices, id, sales_invoice)
|
50
|
-
|
51
|
-
return Pina::Models::SalesInvoice.new(attributes(response)) if
|
52
|
-
response.ok?
|
53
|
-
|
54
|
-
response
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def attributes(response)
|
60
|
-
response.to_hash.merge(response: response)
|
61
|
-
end
|
62
15
|
end
|
63
16
|
end
|
64
17
|
end
|
data/lib/pina/sales_order.rb
CHANGED
@@ -4,43 +4,14 @@ require 'pina/collections/sales_order'
|
|
4
4
|
|
5
5
|
module Pina
|
6
6
|
class SalesOrder
|
7
|
+
extend Pina::Resource
|
8
|
+
|
9
|
+
resource_methods :all, :where, :find
|
10
|
+
|
7
11
|
class << self
|
8
12
|
def new(params = nil)
|
9
13
|
Pina::Models::SalesOrder.new(params)
|
10
14
|
end
|
11
|
-
|
12
|
-
def find(id)
|
13
|
-
response = Pina::RestAdapter.get(:sales_orders, id)
|
14
|
-
|
15
|
-
return Pina::Models::SalesOrder.new(attributes(response)) if
|
16
|
-
response.ok?
|
17
|
-
|
18
|
-
response
|
19
|
-
end
|
20
|
-
|
21
|
-
def where(hash, _page = nil)
|
22
|
-
response = Pina::RestAdapter.get(:sales_orders, hash)
|
23
|
-
|
24
|
-
return Pina::Collections::SalesOrder.new(attributes(response)) if
|
25
|
-
response.ok?
|
26
|
-
|
27
|
-
response
|
28
|
-
end
|
29
|
-
|
30
|
-
def all(page = nil)
|
31
|
-
response = Pina::RestAdapter.get(:sales_orders, page)
|
32
|
-
|
33
|
-
return Pina::Collections::SalesOrder.new(attributes(response)) if
|
34
|
-
response.ok?
|
35
|
-
|
36
|
-
response
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def attributes(response)
|
42
|
-
response.to_hash.merge(response: response)
|
43
|
-
end
|
44
15
|
end
|
45
16
|
end
|
46
17
|
end
|
@@ -3,43 +3,14 @@ require 'pina/collections/stat_processed_document'
|
|
3
3
|
|
4
4
|
module Pina
|
5
5
|
class StatProcessedDocument
|
6
|
+
extend Pina::Resource
|
7
|
+
|
8
|
+
resource_methods :all, :where, :find
|
9
|
+
|
6
10
|
class << self
|
7
11
|
def new(params = nil)
|
8
12
|
Pina::Models::StatProcessedDocument.new(params)
|
9
13
|
end
|
10
|
-
|
11
|
-
def find(id)
|
12
|
-
response = Pina::RestAdapter.get(:stat_processed_documents, id)
|
13
|
-
|
14
|
-
return Pina::Models::StatProcessedDocument.new(attributes(response)) if
|
15
|
-
response.ok?
|
16
|
-
|
17
|
-
response
|
18
|
-
end
|
19
|
-
|
20
|
-
def where(hash, _page = nil)
|
21
|
-
response = Pina::RestAdapter.get(:stat_processed_documents, hash)
|
22
|
-
|
23
|
-
return Pina::Collections::StatProcessedDocument.new(attributes(response)) if
|
24
|
-
response.ok?
|
25
|
-
|
26
|
-
response
|
27
|
-
end
|
28
|
-
|
29
|
-
def all(page = nil)
|
30
|
-
response = Pina::RestAdapter.get(:stat_processed_documents, page)
|
31
|
-
|
32
|
-
return Pina::Collections::StatProcessedDocument.new(attributes(response)) if
|
33
|
-
response.ok?
|
34
|
-
|
35
|
-
response
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def attributes(response)
|
41
|
-
response.to_hash.merge(response: response)
|
42
|
-
end
|
43
14
|
end
|
44
15
|
end
|
45
16
|
end
|
@@ -3,6 +3,10 @@ require 'pina/collections/uploaded_document'
|
|
3
3
|
|
4
4
|
module Pina
|
5
5
|
class UploadedDocument
|
6
|
+
extend Pina::Resource
|
7
|
+
|
8
|
+
resource_methods :all, :where
|
9
|
+
|
6
10
|
class << self
|
7
11
|
def create(uploaded_document)
|
8
12
|
response = Pina::RestAdapter.post(:uploaded_documents, uploaded_document, multipart: true)
|
@@ -24,24 +28,6 @@ module Pina
|
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
27
|
-
def where(hash, _page = nil)
|
28
|
-
response = Pina::RestAdapter.get(:uploaded_documents, hash)
|
29
|
-
|
30
|
-
return Pina::Collections::UploadedDocument.new(attributes(response)) if
|
31
|
-
response.ok?
|
32
|
-
|
33
|
-
response
|
34
|
-
end
|
35
|
-
|
36
|
-
def all(page = nil)
|
37
|
-
response = Pina::RestAdapter.get(:uploaded_documents, page)
|
38
|
-
|
39
|
-
return Pina::Collections::UploadedDocument.new(attributes(response)) if
|
40
|
-
response.ok?
|
41
|
-
|
42
|
-
response
|
43
|
-
end
|
44
|
-
|
45
31
|
def update(id, uploaded_document)
|
46
32
|
response = Pina::RestAdapter.patch(:uploaded_documents, id, uploaded_document)
|
47
33
|
|
@@ -54,10 +40,6 @@ module Pina
|
|
54
40
|
|
55
41
|
private
|
56
42
|
|
57
|
-
def attributes(response)
|
58
|
-
response.to_hash.merge(response: response)
|
59
|
-
end
|
60
|
-
|
61
43
|
def attributes_for_error(response)
|
62
44
|
response.to_hash.merge(status_code: response.status_code)
|
63
45
|
end
|
@@ -2,6 +2,8 @@ require 'pina/models/uploaded_document_pairing'
|
|
2
2
|
|
3
3
|
module Pina
|
4
4
|
class UploadedDocumentPairing
|
5
|
+
extend Pina::Resource
|
6
|
+
|
5
7
|
class << self
|
6
8
|
def find(id)
|
7
9
|
response = Pina::RestAdapter.get([:uploaded_documents, id, :pairings])
|
@@ -26,10 +28,6 @@ module Pina
|
|
26
28
|
|
27
29
|
private
|
28
30
|
|
29
|
-
def attributes(response)
|
30
|
-
response.to_hash.merge(response: response)
|
31
|
-
end
|
32
|
-
|
33
31
|
def attributes_for_error(response)
|
34
32
|
response.to_hash.merge(status_code: response.status_code)
|
35
33
|
end
|
@@ -2,7 +2,7 @@ module Pina
|
|
2
2
|
module Utils
|
3
3
|
module Pagination
|
4
4
|
def next_page
|
5
|
-
|
5
|
+
paginate(_meta['pagination']['next'])
|
6
6
|
end
|
7
7
|
|
8
8
|
def first_page
|
@@ -10,7 +10,31 @@ module Pina
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def previous_page
|
13
|
-
|
13
|
+
paginate(_meta['pagination']['previous'])
|
14
|
+
end
|
15
|
+
|
16
|
+
def last_page
|
17
|
+
paginate(_meta['pagination']['last'])
|
18
|
+
end
|
19
|
+
|
20
|
+
def paginate(page_url)
|
21
|
+
params = extract_params(page_url)
|
22
|
+
return unless params&.fetch('page')
|
23
|
+
|
24
|
+
resource.all(params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def collect_items
|
28
|
+
resource = self
|
29
|
+
|
30
|
+
[].tap do |collection|
|
31
|
+
loop do
|
32
|
+
collection.push(*resource.items)
|
33
|
+
resource = resource.next_page
|
34
|
+
|
35
|
+
break unless resource
|
36
|
+
end
|
37
|
+
end
|
14
38
|
end
|
15
39
|
|
16
40
|
private
|
@@ -19,20 +43,22 @@ module Pina
|
|
19
43
|
Object.const_get("Pina::#{self.class.to_s.split('::').last}")
|
20
44
|
end
|
21
45
|
|
22
|
-
def
|
23
|
-
|
24
|
-
return unless string
|
46
|
+
def extract_params(url)
|
47
|
+
return unless url
|
25
48
|
|
26
|
-
index =
|
27
|
-
|
28
|
-
end
|
49
|
+
index = url.index('?')
|
50
|
+
return unless index
|
29
51
|
|
30
|
-
|
31
|
-
|
32
|
-
return unless string
|
52
|
+
params_to_hash(url[index + 1..-1])
|
53
|
+
end
|
33
54
|
|
34
|
-
|
35
|
-
|
55
|
+
def params_to_hash(params)
|
56
|
+
{}.tap do |params_hash|
|
57
|
+
params.split('&').each do |element|
|
58
|
+
param = element.split('=')
|
59
|
+
params_hash[param.first] = param.last
|
60
|
+
end
|
61
|
+
end
|
36
62
|
end
|
37
63
|
end
|
38
64
|
end
|
data/lib/pina/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pina
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Hronek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -273,6 +273,7 @@ files:
|
|
273
273
|
- lib/pina/processed_document.rb
|
274
274
|
- lib/pina/purchase_invoice.rb
|
275
275
|
- lib/pina/receivable.rb
|
276
|
+
- lib/pina/resource.rb
|
276
277
|
- lib/pina/rest_adapter.rb
|
277
278
|
- lib/pina/sales_invoice.rb
|
278
279
|
- lib/pina/sales_order.rb
|