pina 0.3.1 → 0.5.1

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: 23b08d7071b89683e9435a5a42b8f4f51cb5eccd
4
- data.tar.gz: e5648493ce1f0a9505d9dc806bbdbe0d4163e4fb
3
+ metadata.gz: e50f2ed2015bf16a54f12d20aff18b67ad7e66d6
4
+ data.tar.gz: d2e5434617fb9156bcddbc1d6cb467b6c2293445
5
5
  SHA512:
6
- metadata.gz: 607bb57906cee481c9cba39cc107a1c1bff8353150434c2187e1eae44a8c93db43e67d052aeb29814f8d8415f80a874e09512936024d27cdef35b7bb503c3e47
7
- data.tar.gz: 0e7b22d010ec4e5bdc19db8f09c505871a31f18da886009bc6ba56564154316b6763e5de6bfeb9aa58eb25d503b4685cfb4b89021fea0252174c8989cf2e5139
6
+ metadata.gz: 37b7cf897b2b4d62c6071eadba1435bce7b4eae43cb10905ed88aa63b75eba7a2635e045d3d496b7a887cd1d8ebd5d87815067fe16d4df5bf9eb8a51197fab3d
7
+ data.tar.gz: b1a154831bf26d55da0685d3ea584fe53a21f32225b721eb872908d4d930de3f3454f2516f5d082637d61b38bd159308c29c064ea04c798c1e102dd2ca2c1255
data/.travis.yml CHANGED
@@ -2,8 +2,6 @@ language: ruby
2
2
  rvm:
3
3
  - 2.3.0
4
4
  - 2.2.3
5
- - 2.2
6
- - 2.1
7
5
  env:
8
6
  - secure: TENANT=test
9
7
  before_install: gem install bundler -v 1.10.6
data/README.md CHANGED
@@ -39,7 +39,9 @@ end
39
39
 
40
40
  Now you can start querying REST API.
41
41
 
42
- ### All contacts
42
+ ### Contacts
43
+
44
+ #### All contacts
43
45
 
44
46
  ```ruby
45
47
  Pina::Contact.all
@@ -60,27 +62,30 @@ contacts.previous_page
60
62
  contacts.first_page
61
63
  ```
62
64
 
63
- ### Fetching specific contact
65
+ #### Fetching specific contact
64
66
 
65
67
  ```ruby
66
68
  Pina::Contact.find('contact_name')
67
69
  ```
68
70
 
69
- ### Create new contact
71
+ #### Create new contact
70
72
 
71
73
  ```ruby
72
74
  contact = Pina::Models::Contact.new
73
75
  Pina::Contact.create(contact)
74
76
  ```
75
77
 
76
- ### Update existing contact
78
+ #### Update existing contact
77
79
 
78
80
  ```ruby
79
81
  contact = Pina::Contact.find('existing')
80
82
  contact.email = 'brand_new@email.com'
81
83
  Pina::Contact.update('existing', contact)
82
84
  ```
83
- ### All sales invoices
85
+
86
+ ### Sales Invoices
87
+
88
+ #### All sales invoices
84
89
 
85
90
  ```ruby
86
91
  Pina::SalesInvoice.all
@@ -101,26 +106,93 @@ invoices.previous_page
101
106
  invoices.first_page
102
107
  ```
103
108
 
104
- ### Fetching specific sales invoice
109
+ #### Fetching specific sales invoice
105
110
 
106
111
  ```ruby
107
112
  Pina::SalesInvoice.find(invoice_id)
108
113
  ```
109
114
 
110
- ### Create new sales invoice
115
+ #### Create new sales invoice
111
116
 
112
117
  ```ruby
113
118
  invoice = Pina::Models::SalesInvoice.new
114
119
  Pina::SalesInvoice.create(invoice)
115
120
  ```
116
121
 
117
- ### Update existing sales invoice
122
+ #### Update existing sales invoice
118
123
 
119
124
  ```ruby
120
125
  invoice = Pina::SalesInvoice.find(2016000001)
121
126
  invoice.status = :confirmed
122
127
  Pina::SalesInvoice.update(2016000001, invoice)
123
128
  ```
129
+
130
+ ### Sales Orders
131
+
132
+ #### All sales orders
133
+
134
+ ```ruby
135
+ Pina::SalesOrder.all
136
+ ```
137
+
138
+ Gets all sales orders from your database. Results are paginated and you can access
139
+ first, next or previous page like this:
140
+
141
+ ```ruby
142
+ orders = Pina::SalesOrder.all
143
+ orders.next_page
144
+ ```
145
+
146
+ ```ruby
147
+ orders = Pina::SalesOrder.all
148
+ orders.previous_page
149
+
150
+ orders.first_page
151
+ ```
152
+
153
+ #### Fetching specific sales order
154
+
155
+ ```ruby
156
+ Pina::SalesOrder.find(order_id)
157
+ ```
158
+
159
+ ### Receivables
160
+
161
+ #### All receivables
162
+
163
+ ```ruby
164
+ Pina::Receivable.all
165
+ ```
166
+
167
+ Gets all receivables from your database. Results are paginated and you can access
168
+ first, next or previous page like this:
169
+
170
+ ```ruby
171
+ receivables = Pina::Receivable.all
172
+ receivables.next_page
173
+ ```
174
+
175
+ ```ruby
176
+ invoices = Pina::Receivable.all
177
+ invoices.previous_page
178
+
179
+ invoices.first_page
180
+ ```
181
+
182
+ #### Fetching specific receivable
183
+
184
+ ```ruby
185
+ Pina::Receivable.find(invoice_id)
186
+ ```
187
+
188
+ NOTE: receivables are being calculated from your DB, they do not correspond
189
+ with any table in your database, you can access related invoice simply:
190
+
191
+ ```ruby
192
+ receivable = Pina::Receivable.find(invoice_id)
193
+ receivable.invoice
194
+ ```
195
+
124
196
  ## Development
125
197
 
126
198
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/bin/console CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'irb'
4
4
  require 'irb/completion'
5
5
 
6
+ require 'bundler/setup'
6
7
  require 'pina'
7
8
  require 'dotenv'
8
9
  Dotenv.load
data/lib/pina.rb CHANGED
@@ -5,19 +5,16 @@ require 'typhoeus'
5
5
  require 'virtus'
6
6
  require 'uri'
7
7
 
8
+ require 'pina/utils/pagination'
9
+
10
+ require 'pina/collections/base'
11
+
8
12
  require 'pina/contact'
9
13
  require 'pina/sales_invoice'
10
14
  require 'pina/version'
11
15
  require 'pina/rest_adapter'
12
-
13
- require 'pina/utils/pagination'
14
-
15
- require 'pina/models/address'
16
- require 'pina/models/contact'
17
- require 'pina/models/contact_list'
18
- require 'pina/models/sales_item'
19
- require 'pina/models/sales_invoice'
20
- require 'pina/models/sales_invoice_list'
16
+ require 'pina/sales_order'
17
+ require 'pina/receivable'
21
18
 
22
19
  module Pina
23
20
  class ConfigurationNotSet < StandardError; end
@@ -0,0 +1,11 @@
1
+ module Pina
2
+ module Collections
3
+ class Base
4
+ include Virtus.model
5
+ include Pina::Utils::Pagination
6
+
7
+ attribute :_meta
8
+ attribute :response
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Pina
2
+ module Collections
3
+ class Contact < Base
4
+ attribute :items, Array[::Pina::Models::Contact]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Pina
2
+ module Collections
3
+ class Receivable < Base
4
+ attribute :items, Array[::Pina::Models::Receivable]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Pina
2
+ module Collections
3
+ class SalesInvoice < Base
4
+ attribute :items, Array[::Pina::Models::SalesInvoice]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Pina
2
+ module Collections
3
+ class SalesOrder < Base
4
+ attribute :items, Array[::Pina::Models::SalesOrder]
5
+ end
6
+ end
7
+ end
data/lib/pina/contact.rb CHANGED
@@ -1,3 +1,7 @@
1
+ require 'pina/models/address'
2
+ require 'pina/models/contact'
3
+ require 'pina/collections/contact'
4
+
1
5
  module Pina
2
6
  class Contact
3
7
  class << self
@@ -8,7 +12,7 @@ module Pina
8
12
  def find_by(hash)
9
13
  response = where(hash)
10
14
 
11
- return response.items.first if response.is_a? Pina::Models::ContactList
15
+ return response.items.first if response.is_a? Pina::Collections::Contact
12
16
 
13
17
  response
14
18
  end
@@ -16,7 +20,7 @@ module Pina
16
20
  def where(hash, page = nil)
17
21
  response = Pina::RestAdapter.get(:contacts, hash)
18
22
 
19
- return Pina::Models::ContactList.new(attributes(response)) if
23
+ return Pina::Collections::Contact.new(attributes(response)) if
20
24
  response.ok?
21
25
 
22
26
  response
@@ -33,7 +37,7 @@ module Pina
33
37
  def all(page = nil)
34
38
  response = Pina::RestAdapter.get(:contacts, page)
35
39
 
36
- return Pina::Models::ContactList.new(attributes(response)) if
40
+ return Pina::Collections::Contact.new(attributes(response)) if
37
41
  response.ok?
38
42
 
39
43
  response
@@ -0,0 +1,24 @@
1
+ module Pina
2
+ module Models
3
+ class Receivable
4
+ include Virtus.model
5
+
6
+ attribute :invoice_id
7
+ attribute :invoice
8
+ attribute :contact_id
9
+ attribute :total_amount
10
+ attribute :total_amount_in_currency
11
+ attribute :paid_amount
12
+ attribute :paid_amount_in_currency
13
+ attribute :paid_amount_currency_ids
14
+ attribute :last_payment_time
15
+
16
+ def invoice_id=(value)
17
+ return unless value
18
+
19
+ self.invoice = Pina::SalesInvoice.find(value)
20
+ super
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,106 @@
1
+ module Pina
2
+ module Models
3
+ class SalesOrder
4
+ include Virtus.model
5
+
6
+ attribute :created_at
7
+ attribute :updated_at
8
+ attribute :creator
9
+ attribute :creator_id
10
+ attribute :modifier
11
+ attribute :modifier_id
12
+ attribute :contact
13
+ attribute :contact_id
14
+ attribute :accounting_address
15
+ attribute :accounting_address_id
16
+ attribute :buyer_address
17
+ attribute :buyer_address_id
18
+ attribute :document_recipient_address
19
+ attribute :document_recipient_address_id
20
+ attribute :delivery_address
21
+ attribute :delivery_address_id
22
+ attribute :contact
23
+ attribute :currency
24
+ attribute :currency_id
25
+ attribute :date_of_receipt
26
+ attribute :delivery_method
27
+ attribute :department
28
+ attribute :department_id
29
+ attribute :percent_discount
30
+ attribute :external_id
31
+ attribute :fullfilled_on
32
+ attribute :group_id
33
+ attribute :invoicing_method
34
+ attribute :status
35
+ attribute :order
36
+ attribute :order_id
37
+ attribute :contract
38
+ attribute :shipper_id
39
+ attribute :shipping_method
40
+ attribute :specific_symbol
41
+ attribute :payment_method
42
+ attribute :complete_upon_execution
43
+ attribute :items, Array[::Pina::Models::SalesItem]
44
+
45
+ def self.to_s
46
+ 'sales_order'
47
+ end
48
+
49
+ def accounting_address=(value)
50
+ return unless value
51
+
52
+ self.accounting_address_id = value.values[0]
53
+ super
54
+ end
55
+
56
+ def buyer_address=(value)
57
+ return unless value
58
+
59
+ self.buyer_address_id = value.values[0]
60
+ super
61
+ end
62
+
63
+ def delivery_address=(value)
64
+ return unless value
65
+
66
+ self.delivery_address_id = value.values[0]
67
+ super
68
+ end
69
+
70
+ def department=(value)
71
+ return unless value
72
+
73
+ self.department_id = value.values[0]
74
+ super
75
+ end
76
+
77
+ def contact=(value)
78
+ return unless value
79
+
80
+ self.contact_id = value.values[0]
81
+ super
82
+ end
83
+
84
+ def order=(value)
85
+ return unless value
86
+
87
+ self.order_id = value.values[0]
88
+ super
89
+ end
90
+
91
+ def creator=(value)
92
+ return unless value
93
+
94
+ self.creator_id = value.values[0]
95
+ super
96
+ end
97
+
98
+ def modifier=(value)
99
+ return unless value
100
+
101
+ self.modifier_id = value.values[0]
102
+ super
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,45 @@
1
+ require 'pina/models/receivable'
2
+ require 'pina/collections/receivable'
3
+
4
+ module Pina
5
+ class Receivable
6
+ class << self
7
+ def new(params = nil)
8
+ Pina::Models::Receivable.new(params)
9
+ 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
+ end
44
+ end
45
+ end
@@ -1,3 +1,7 @@
1
+ require 'pina/models/sales_item'
2
+ require 'pina/models/sales_invoice'
3
+ require 'pina/collections/sales_invoice'
4
+
1
5
  module Pina
2
6
  class SalesInvoice
3
7
  class << self
@@ -17,7 +21,7 @@ module Pina
17
21
  def all(page = nil)
18
22
  response = Pina::RestAdapter.get(:sales_invoices, page)
19
23
 
20
- return Pina::Models::SalesInvoiceList.new(attributes(response)) if
24
+ return Pina::Collections::SalesInvoice.new(attributes(response)) if
21
25
  response.ok?
22
26
 
23
27
  response
@@ -0,0 +1,46 @@
1
+ require 'pina/models/sales_item'
2
+ require 'pina/models/sales_order'
3
+ require 'pina/collections/sales_order'
4
+
5
+ module Pina
6
+ class SalesOrder
7
+ class << self
8
+ def new(params = nil)
9
+ Pina::Models::SalesOrder.new(params)
10
+ 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
+ end
45
+ end
46
+ end
@@ -2,19 +2,23 @@ module Pina
2
2
  module Utils
3
3
  module Pagination
4
4
  def next_page
5
- RESOURCE.all(extract_next_page)
5
+ resource.all(extract_next_page)
6
6
  end
7
7
 
8
8
  def first_page
9
- RESOURCE.all
9
+ resource.all
10
10
  end
11
11
 
12
12
  def previous_page
13
- RESOURCE.all(extract_prev_page)
13
+ resource.all(extract_prev_page)
14
14
  end
15
15
 
16
16
  private
17
17
 
18
+ def resource
19
+ Object.const_get("Pina::#{self.class.to_s.split('::').last}")
20
+ end
21
+
18
22
  def extract_next_page
19
23
  string = _meta['pagination']['next']
20
24
  return unless string
data/lib/pina/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pina
2
- VERSION = '0.3.1'
2
+ VERSION = '0.5.1'
3
3
  end
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.3.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Hronek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-08 00:00:00.000000000 Z
11
+ date: 2016-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -197,15 +197,22 @@ files:
197
197
  - Rakefile
198
198
  - bin/console
199
199
  - lib/pina.rb
200
+ - lib/pina/collections/base.rb
201
+ - lib/pina/collections/contact.rb
202
+ - lib/pina/collections/receivable.rb
203
+ - lib/pina/collections/sales_invoice.rb
204
+ - lib/pina/collections/sales_order.rb
200
205
  - lib/pina/contact.rb
201
206
  - lib/pina/models/address.rb
202
207
  - lib/pina/models/contact.rb
203
- - lib/pina/models/contact_list.rb
208
+ - lib/pina/models/receivable.rb
204
209
  - lib/pina/models/sales_invoice.rb
205
- - lib/pina/models/sales_invoice_list.rb
206
210
  - lib/pina/models/sales_item.rb
211
+ - lib/pina/models/sales_order.rb
212
+ - lib/pina/receivable.rb
207
213
  - lib/pina/rest_adapter.rb
208
214
  - lib/pina/sales_invoice.rb
215
+ - lib/pina/sales_order.rb
209
216
  - lib/pina/utils/pagination.rb
210
217
  - lib/pina/version.rb
211
218
  - pina.gemspec
@@ -1,41 +0,0 @@
1
- module Pina
2
- module Models
3
- class ContactList
4
- include Virtus.model
5
-
6
- attribute :items, Array[Contact]
7
- attribute :_meta
8
- attribute :response
9
-
10
- def next_page
11
- Pina::Contact.all(extract_next_page)
12
- end
13
-
14
- def first_page
15
- Pina::Contact.all
16
- end
17
-
18
- def previous_page
19
- Pina::Contact.all(extract_prev_page)
20
- end
21
-
22
- private
23
-
24
- def extract_next_page
25
- string = _meta['pagination']['next']
26
- return unless string
27
-
28
- index = string.index('?')
29
- string[index..-1]
30
- end
31
-
32
- def extract_prev_page
33
- string = _meta['pagination']['prev']
34
- return unless string
35
-
36
- index = string.index('?')
37
- string[index..-1]
38
- end
39
- end
40
- end
41
- end
@@ -1,41 +0,0 @@
1
- module Pina
2
- module Models
3
- class SalesInvoiceList
4
- include Virtus.model
5
-
6
- attribute :items, Array[SalesInvoice]
7
- attribute :_meta
8
- attribute :response
9
-
10
- def next_page
11
- Pina::SalesInvoice.all(extract_next_page)
12
- end
13
-
14
- def first_page
15
- Pina::SalesInvoice.all
16
- end
17
-
18
- def previous_page
19
- Pina::SalesInvoice.all(extract_prev_page)
20
- end
21
-
22
- private
23
-
24
- def extract_next_page
25
- string = _meta['pagination']['next']
26
- return unless string
27
-
28
- index = string.index('?')
29
- string[index..-1]
30
- end
31
-
32
- def extract_prev_page
33
- string = _meta['pagination']['prev']
34
- return unless string
35
-
36
- index = string.index('?')
37
- string[index..-1]
38
- end
39
- end
40
- end
41
- end