unleashed 0.1.11 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cdea89c1db61c6f9af7c6c076d44b61c8c8b544700eaab32b2f0b7adba4f71e
4
- data.tar.gz: a7f23ff31284340aab544858de1a1421bf46a060a550c0b5ff943644b09fcf21
3
+ metadata.gz: 64bf42de94dbe048a5de0a81983e05e92ae7199df7c9f1d31b3af12759af408c
4
+ data.tar.gz: 10dfcd117b381f209e2e740a1a290e264ebb903d4c5121ba926aa01e440d05ed
5
5
  SHA512:
6
- metadata.gz: 9acacc13ac8da33f97fb58da6df5ea72a1f4a7d2b80d663e03e42d34db7542cc0b567c015f794597468aef3a36545bd1c769c04f374b1bb99aa9c85718d7e0f9
7
- data.tar.gz: f9dcd61b442996136c02b2019c52d2d5f6d5eac5e83422e37becee4910aed7c25acb9278a1fac455ebc103fe4f742738c26cabedc4f18e6968bd275feb0198b8
6
+ metadata.gz: 2b4186e4593a6eab6fd8225c3abc7ae16ad3c65e1dece3753d42a76483ae3682d52c142fa3cb66ba46631a001423e65a56e0d928a04de26772b74ca9203735a1
7
+ data.tar.gz: e0f30e55e86a48cf1d37a357de098788a3f7d059d9af542f0fe862891f96c45a9e3f4c3d397444eaa49b950ca33eb44bce9f1525e37051a98e59460deae22411
@@ -2,6 +2,34 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [0.1.17] - 2021-01-14
6
+
7
+ - Update HMAC input.
8
+
9
+ ## [0.1.16] - 2020-04-10
10
+
11
+ - Add new model `Company` and resources.
12
+ - Update README and separate it to some docs.
13
+
14
+ ## [0.1.15] - 2020-02-26
15
+
16
+ - Update and fix bugs for `client`, `currency`, `customer`, `invoice` resources.
17
+ - Show status code in error messge.
18
+ - Print request info to debug easier.
19
+
20
+ ## [0.1.14] - 2020-02-23
21
+
22
+ - Update options, queries, comments of `currencies`, `customers`, `invoices`, `payment terms`.
23
+ - Replace `create` method by `create_or_update` method of `customers`.
24
+
25
+ ## [0.1.13] - 2019-12-05
26
+
27
+ - Update version.
28
+
29
+ ## [0.1.12] - 2019-12-05
30
+
31
+ - Update some cases to show errors.
32
+
5
33
  ## [0.1.11] - 2019-12-04
6
34
 
7
35
  - Add `Payment Term`
data/README.md CHANGED
@@ -70,219 +70,15 @@ options = { api_id: ENV['UNLEASHED_API_ID'], api_key: ENV['UNLEASHED_API_KEY'] }
70
70
  client = Unleashed::Client.new(options)
71
71
  ```
72
72
 
73
- ### Customers
73
+ ## 4. Documentation for Models
74
74
 
75
- #### Create a new Customer
75
+ * [Unleashed::Company](docs/Company.md)
76
+ * [Unleashed::Currency](docs/Currency.md)
77
+ * [Unleashed::Customer](docs/Customer.md)
78
+ * [Unleashed::Invoice](docs/Invoice.md)
79
+ * [Unleashed::PaymentTerm](docs/PaymentTerm.md)
76
80
 
77
- ```ruby
78
- customer = client.customers.create(
79
- Guid: '59f21e05-07fe-4d9d-b460-a09db4c3caa9',
80
- Addresses: [
81
- {
82
- AddressType: 'Shipping',
83
- AddressName: 'Example Address',
84
- StreetAddress: 'Example Address',
85
- StreetAddress2: 'Example Address 2',
86
- Suburb: 'Example Suburb',
87
- City: 'Auckland',
88
- Region: 'Auckland',
89
- Country: 'New Zealand',
90
- PostalCode: '1061',
91
- IsDefault: false,
92
- DeliveryInstruction: 'Have a good day'
93
- }
94
- ],
95
- TaxCode: '',
96
- TaxRate: nil,
97
- CustomerCode: 'UnleashedCustomer',
98
- CustomerName: 'Unleashed Customer',
99
- GSTVATNumber: nil,
100
- BankName: nil,
101
- BankBranch: nil,
102
- BankAccount: nil,
103
- Website: nil,
104
- PhoneNumber: nil,
105
- FaxNumber: nil,
106
- MobileNumber: nil,
107
- DDINumber: nil,
108
- TollFreeNumber: nil,
109
- Email: nil,
110
- EmailCC: nil,
111
- Currency: {
112
- CurrencyCode: 'NZD',
113
- Description: 'New Zealand, Dollars',
114
- Guid: 'c33e4f50-e42b-40cd-9147-4d0e4657cd4d'
115
- },
116
- Notes: nil,
117
- Taxable: true,
118
- SalesPerson: nil,
119
- DiscountRate: 0.0000,
120
- PrintPackingSlipInsteadOfInvoice: false,
121
- PrintInvoice: false,
122
- StopCredit: false,
123
- Obsolete: false,
124
- XeroSalesAccount: nil,
125
- XeroCostOfGoodsAccount: nil,
126
- SellPriceTier: '',
127
- SellPriceTierReference: nil,
128
- CustomerType: 'Cash',
129
- PaymentTerm: '20th Month following',
130
- ContactFirstName: nil,
131
- ContactLastName: nil
132
- )
133
- ```
134
-
135
- #### Update a Customer
136
-
137
- ```ruby
138
- customer = client.customers.update(
139
- Guid: '59f21e05-07fe-4d9d-b460-a09db4c3caa9',
140
- Addresses: [
141
- {
142
- AddressType: 'Shipping',
143
- AddressName: 'Example Address',
144
- StreetAddress: 'Example Address',
145
- StreetAddress2: 'Example Address 2',
146
- Suburb: 'Example Suburb',
147
- City: 'Auckland',
148
- Region: 'Auckland',
149
- Country: 'New Zealand',
150
- PostalCode: '1061',
151
- IsDefault: false,
152
- DeliveryInstruction: 'Have a good day'
153
- }
154
- ],
155
- TaxCode: '',
156
- TaxRate: nil,
157
- CustomerCode: 'UnleashedCustomer',
158
- CustomerName: 'Unleashed Customer',
159
- GSTVATNumber: nil,
160
- BankName: nil,
161
- BankBranch: nil,
162
- BankAccount: nil,
163
- Website: nil,
164
- PhoneNumber: nil,
165
- FaxNumber: nil,
166
- MobileNumber: nil,
167
- DDINumber: nil,
168
- TollFreeNumber: nil,
169
- Email: nil,
170
- EmailCC: nil,
171
- Currency: {
172
- CurrencyCode: 'NZD',
173
- Description: 'New Zealand, Dollars',
174
- Guid: '6cb5d67a-1c96-4fa8-bf59-b23c2d69f22a'
175
- },
176
- Notes: nil,
177
- Taxable: true,
178
- SalesPerson: nil,
179
- DiscountRate: 0.0000,
180
- PrintPackingSlipInsteadOfInvoice: false,
181
- PrintInvoice: false,
182
- StopCredit: false,
183
- Obsolete: false,
184
- XeroSalesAccount: nil,
185
- XeroCostOfGoodsAccount: nil,
186
- SellPriceTier: '',
187
- SellPriceTierReference: nil,
188
- CustomerType: 'Cash',
189
- PaymentTerm: '20th Month following',
190
- ContactFirstName: nil,
191
- ContactLastName: nil
192
- )
193
- ```
194
-
195
- #### Get all customers
196
-
197
- ```ruby
198
- client.customers.all
199
- ```
200
-
201
- #### Get a customer
202
-
203
- ```ruby
204
- client.customers.find('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX')
205
- ```
206
-
207
- #### Get the first customer
208
-
209
- ```ruby
210
- client.customers.first
211
- ```
212
-
213
- #### Get the last customer
214
-
215
- ```ruby
216
- client.customers.last
217
- ```
218
-
219
- ### Invoices
220
-
221
- #### Get all invoices
222
-
223
- ```ruby
224
- client.invoices.all
225
- ```
226
-
227
- #### Get an invoice
228
-
229
- ```ruby
230
- client.invoices.find('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX')
231
- ```
232
-
233
- #### Get the first invoice
234
-
235
- ```ruby
236
- client.invoices.first
237
- ```
238
-
239
- #### Get the last invoice
240
-
241
- ```ruby
242
- client.invoices.last
243
- ```
244
-
245
- ### Currencies
246
-
247
- #### Get all currencies
248
-
249
- ```ruby
250
- client.currencies.all
251
- ```
252
-
253
- #### Get the first currency
254
-
255
- ```ruby
256
- client.currencies.first
257
- ```
258
-
259
- #### Get the last currency
260
-
261
- ```ruby
262
- client.currencies.last
263
- ```
264
-
265
- ### Payment Terms
266
-
267
- #### Get all payment terms
268
-
269
- ```ruby
270
- client.payment_terms.all
271
- ```
272
-
273
- #### Get the first payment term
274
-
275
- ```ruby
276
- client.payment_terms.first
277
- ```
278
-
279
- #### Get the last payment term
280
-
281
- ```ruby
282
- client.payment_terms.last
283
- ```
284
-
285
- ## 4. Contributing
81
+ ## 5. Contributing
286
82
 
287
83
  1. Fork it [https://github.com/nnhansg/unleashed-ruby](https://github.com/nnhansg/unleashed-ruby)
288
84
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -290,10 +86,10 @@ client.payment_terms.last
290
86
  4. Push to the branch (`git push origin my-new-feature`)
291
87
  5. Create a new Pull Request
292
88
 
293
- ## 5. License
89
+ ## 6. License
294
90
 
295
91
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
296
92
 
297
- ## 6. Code of Conduct
93
+ ## 7. Code of Conduct
298
94
 
299
95
  Everyone interacting in the Unleashed project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nnhansg/unleashed-ruby/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,19 @@
1
+ # Unleashed::Company
2
+
3
+ ## Get all companies
4
+
5
+ ```ruby
6
+ client.companies.all
7
+ ```
8
+
9
+ ## Get the first company
10
+
11
+ ```ruby
12
+ client.companies.first
13
+ ```
14
+
15
+ ## Get the last company
16
+
17
+ ```ruby
18
+ client.companies.last
19
+ ```
@@ -0,0 +1,19 @@
1
+ # Unleashed::Currency
2
+
3
+ ## Get all currencies
4
+
5
+ ```ruby
6
+ client.currencies.all
7
+ ```
8
+
9
+ ## Get the first currency
10
+
11
+ ```ruby
12
+ client.currencies.first
13
+ ```
14
+
15
+ ## Get the last currency
16
+
17
+ ```ruby
18
+ client.currencies.last
19
+ ```
@@ -0,0 +1,165 @@
1
+ # Unleashed::Customer
2
+
3
+ ## Create a new Customer
4
+
5
+ ```ruby
6
+ customer = client.customers.create_or_update(
7
+ Guid: '59f21e05-07fe-4d9d-b460-a09db4c3caa9',
8
+ Addresses: [
9
+ {
10
+ AddressType: 'Shipping',
11
+ AddressName: 'Example Address',
12
+ StreetAddress: 'Example Address',
13
+ StreetAddress2: 'Example Address 2',
14
+ Suburb: 'Example Suburb',
15
+ City: 'Auckland',
16
+ Region: 'Auckland',
17
+ Country: 'New Zealand',
18
+ PostalCode: '1061',
19
+ IsDefault: false,
20
+ DeliveryInstruction: 'Have a good day'
21
+ }
22
+ ],
23
+ TaxCode: '',
24
+ TaxRate: nil,
25
+ CustomerCode: 'UnleashedCustomer',
26
+ CustomerName: 'Unleashed Customer',
27
+ GSTVATNumber: nil,
28
+ BankName: nil,
29
+ BankBranch: nil,
30
+ BankAccount: nil,
31
+ Website: nil,
32
+ PhoneNumber: nil,
33
+ FaxNumber: nil,
34
+ MobileNumber: nil,
35
+ DDINumber: nil,
36
+ TollFreeNumber: nil,
37
+ Email: nil,
38
+ EmailCC: nil,
39
+ Currency: {
40
+ CurrencyCode: 'NZD',
41
+ Description: 'New Zealand, Dollars',
42
+ Guid: 'c33e4f50-e42b-40cd-9147-4d0e4657cd4d'
43
+ },
44
+ Notes: nil,
45
+ Taxable: true,
46
+ SalesPerson: nil,
47
+ DiscountRate: 0.0000,
48
+ PrintPackingSlipInsteadOfInvoice: false,
49
+ PrintInvoice: false,
50
+ StopCredit: false,
51
+ Obsolete: false,
52
+ XeroSalesAccount: nil,
53
+ XeroCostOfGoodsAccount: nil,
54
+ SellPriceTier: '',
55
+ SellPriceTierReference: nil,
56
+ CustomerType: 'Cash',
57
+ PaymentTerm: '20th Month following',
58
+ ContactFirstName: nil,
59
+ ContactLastName: nil
60
+ )
61
+ ```
62
+
63
+ ## Update a Customer
64
+
65
+ ```ruby
66
+ customer = client.customers.update(
67
+ Guid: '59f21e05-07fe-4d9d-b460-a09db4c3caa9',
68
+ Addresses: [
69
+ {
70
+ AddressType: 'Shipping',
71
+ AddressName: 'Example Address',
72
+ StreetAddress: 'Example Address',
73
+ StreetAddress2: 'Example Address 2',
74
+ Suburb: 'Example Suburb',
75
+ City: 'Auckland',
76
+ Region: 'Auckland',
77
+ Country: 'New Zealand',
78
+ PostalCode: '1061',
79
+ IsDefault: false,
80
+ DeliveryInstruction: 'Have a good day'
81
+ }
82
+ ],
83
+ TaxCode: '',
84
+ TaxRate: nil,
85
+ CustomerCode: 'UnleashedCustomer',
86
+ CustomerName: 'Unleashed Customer',
87
+ GSTVATNumber: nil,
88
+ BankName: nil,
89
+ BankBranch: nil,
90
+ BankAccount: nil,
91
+ Website: nil,
92
+ PhoneNumber: nil,
93
+ FaxNumber: nil,
94
+ MobileNumber: nil,
95
+ DDINumber: nil,
96
+ TollFreeNumber: nil,
97
+ Email: nil,
98
+ EmailCC: nil,
99
+ Currency: {
100
+ CurrencyCode: 'NZD',
101
+ Description: 'New Zealand, Dollars',
102
+ Guid: '6cb5d67a-1c96-4fa8-bf59-b23c2d69f22a'
103
+ },
104
+ Notes: nil,
105
+ Taxable: true,
106
+ SalesPerson: nil,
107
+ DiscountRate: 0.0000,
108
+ PrintPackingSlipInsteadOfInvoice: false,
109
+ PrintInvoice: false,
110
+ StopCredit: false,
111
+ Obsolete: false,
112
+ XeroSalesAccount: nil,
113
+ XeroCostOfGoodsAccount: nil,
114
+ SellPriceTier: '',
115
+ SellPriceTierReference: nil,
116
+ CustomerType: 'Cash',
117
+ PaymentTerm: '20th Month following',
118
+ ContactFirstName: nil,
119
+ ContactLastName: nil
120
+ )
121
+ ```
122
+
123
+ ## Get all customers
124
+
125
+ ```ruby
126
+ # List all customers
127
+ # /Customers - also returns the first 200 customers because page number 1 is the default.
128
+ #
129
+ # @param options [Hash] Optional options.
130
+ # @option PageSize: Can ask for up to 200 customers. Default: 200
131
+ # @option Page: Page index. Default: 1
132
+ # @option CustomerType: Only returns customers that matches the specified customer type.
133
+ # @option SellPriceTier: Only returns customers that are assigned to the specified sell price tier.
134
+ # @option Currency: Only returns customers with currency code exactly matching the specified value.
135
+ # @option Customer: Returns customers whose customer code or customer name contains the specified value. It is case-sensitive.
136
+ # @option CustomerCode: Only returns customers that start with the specific customer code.
137
+ # @option CustomerName: Only returns customers that start with the specific customer name.
138
+ # @option ContactEmail: Only returns customers that have a contact email that starts with the specified email address.
139
+ # @option ModifiedSince: Only returns customers modified since a specified date.
140
+ # @option IncludeObsolete: Returns all customers, including obsolete, if set to `true`. If set to `false` or if it is not specified then returns only active (ie. non-obsolete) customers.
141
+ # @option XeroContactId: Only returns customers that start with the specific Xero Contact Id.
142
+ # @option OrderBy: Orders the list by `LastModifiedOn` or `CreatedOn` date. By default the list is ordered by `CustomerCode`.
143
+ # @option Sort: Orders the list by `CreatedOn` date sorted in ascending or descending order.
144
+ #
145
+ # @return [Array<Unleashed::Customer>] List all customers.
146
+ client.customers.all
147
+ ```
148
+
149
+ ## Get a customer
150
+
151
+ ```ruby
152
+ client.customers.find('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX')
153
+ ```
154
+
155
+ ## Get the first customer
156
+
157
+ ```ruby
158
+ client.customers.first
159
+ ```
160
+
161
+ ## Get the last customer
162
+
163
+ ```ruby
164
+ client.customers.last
165
+ ```
@@ -0,0 +1,41 @@
1
+ # Invoices
2
+
3
+ ## Get all invoices
4
+
5
+ ```ruby
6
+ # List all invoices
7
+ # /Invoices - also returns the first 200 invoices because page number 1 is the default.
8
+ #
9
+ # @param options [Hash] Optional options.
10
+ # @option Page: Page index. Default: 1
11
+ # @option PageSize: Specifies the page size for pagination. Default page size is 200 invoices.
12
+ # @option CustomerCode: Returns invoices that matches the specific customer code.
13
+ # @option StartDate: Returns invoices created after a specified date, must be UTC format.
14
+ # @option EndDate: Returns invoices created before a specified date, must be UTC format.
15
+ # @option ModifiedSince: Returns invoices created or edited after a specified date, must be UTC format.
16
+ # @option OrderNumber: Returns the invoices associated with the Sales Order Number.
17
+ # @option InvoiceNumber: Returns a single invoice with the specified invoice number. If set, it overrides all other filters.
18
+ # @option InvoiceStatus: Returns invoices with the specified status. Multiple selection can be specified as comma separated.For example: `invoiceStatus=Completed,Parked`. If no invoiceStatus filter is specified, then we exclude “Deleted” by default.
19
+ # @option SerialBatch: False by default. If set to true then the attributes SerialNumbers and BatchNumbers are displayed.
20
+ #
21
+ # @return [Array<Unleashed::Invoice>] List all invoices.
22
+ client.invoices.all
23
+ ```
24
+
25
+ ## Get an invoice
26
+
27
+ ```ruby
28
+ client.invoices.find('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX')
29
+ ```
30
+
31
+ ## Get the first invoice
32
+
33
+ ```ruby
34
+ client.invoices.first
35
+ ```
36
+
37
+ ## Get the last invoice
38
+
39
+ ```ruby
40
+ client.invoices.last
41
+ ```
@@ -0,0 +1,19 @@
1
+ # Payment Terms
2
+
3
+ ## Get all payment terms
4
+
5
+ ```ruby
6
+ client.payment_terms.all
7
+ ```
8
+
9
+ ## Get the first payment term
10
+
11
+ ```ruby
12
+ client.payment_terms.first
13
+ ```
14
+
15
+ ## Get the last payment term
16
+
17
+ ```ruby
18
+ client.payment_terms.last
19
+ ```
@@ -5,11 +5,13 @@ require_relative 'models/customer'
5
5
  require_relative 'models/invoice'
6
6
  require_relative 'models/currency'
7
7
  require_relative 'models/payment_term'
8
+ require_relative 'models/company'
8
9
  require_relative 'resources/base_resource'
9
10
  require_relative 'resources/customer_resource'
10
11
  require_relative 'resources/invoice_resource'
11
12
  require_relative 'resources/currency_resource'
12
13
  require_relative 'resources/payment_term_resource'
14
+ require_relative 'resources/company_resource'
13
15
  require 'json'
14
16
  require 'faraday'
15
17
 
@@ -48,6 +50,16 @@ module Unleashed
48
50
  end
49
51
  end
50
52
 
53
+ def hmac_input(params_hash)
54
+ hmac_input_a = []
55
+
56
+ params_hash.each do |k, v|
57
+ hmac_input_a << "#{k}=#{v}"
58
+ end
59
+
60
+ hmac_input_a.join('&')
61
+ end
62
+
51
63
  # Create a signature for request
52
64
  def signature(params = '')
53
65
  hash = OpenSSL::HMAC.digest('sha256', @api_key, params)
@@ -59,7 +71,8 @@ module Unleashed
59
71
  request.headers['Accept'] = 'application/json'
60
72
  request.headers['Content-Type'] = 'application/json'
61
73
  request.headers['api-auth-id'] = @api_id
62
- request.headers['api-auth-signature'] = signature(request.params.to_query)
74
+ request.headers['api-auth-signature'] = signature(hmac_input(request.params))
75
+ request
63
76
  end
64
77
 
65
78
  # Make a HTTP GET request
@@ -73,12 +86,18 @@ module Unleashed
73
86
  request.params = parameters
74
87
 
75
88
  # Set headers
76
- init_default_headers(request)
89
+ request = init_default_headers(request)
77
90
 
78
91
  # Assign more custom headers
79
92
  headers.each do |key, value|
80
93
  request.headers[key] = value
81
94
  end
95
+
96
+ # Print log
97
+ time = Time.zone.now.strftime('%Y-%m-%d %H:%M:%S %z')
98
+ puts "[#{time}] Client -- : HEADERS #{request.headers}"
99
+ puts "[#{time}] Client -- : GET #{request.path}"
100
+ puts "[#{time}] Client -- : PARAMS #{request.params}"
82
101
  end
83
102
 
84
103
  on_complete(response) unless skip_status_check
@@ -103,6 +122,13 @@ module Unleashed
103
122
  end
104
123
 
105
124
  request.body = parameters.to_json
125
+
126
+ # Print log
127
+ time = Time.zone.now.strftime('%Y-%m-%d %H:%M:%S %z')
128
+ puts "[#{time}] Client -- : HEADERS #{request.headers}"
129
+ puts "[#{time}] Client -- : POST #{request.path}"
130
+ puts "[#{time}] Client -- : PARAMS #{request.params}"
131
+ puts "[#{time}] Client -- : BODY #{request.body}"
106
132
  end
107
133
 
108
134
  on_complete(response) unless skip_status_check
@@ -117,7 +143,8 @@ module Unleashed
117
143
  customers: CustomerResource,
118
144
  invoices: InvoiceResource,
119
145
  currencies: CurrencyResource,
120
- payment_terms: PaymentTermResource
146
+ payment_terms: PaymentTermResource,
147
+ companies: CompanyResource
121
148
  }
122
149
  end
123
150
 
@@ -41,12 +41,12 @@ module Unleashed
41
41
  @response.body
42
42
  else
43
43
  json_response = JSON.parse(@response.body)
44
- message = ''
44
+ message = "[StatusCode=#{@response.status}] - "
45
45
  message << json_response['description'] if json_response.key?('description')
46
46
  message << json_response['Description'] if json_response.key?('Description')
47
47
 
48
- if json_response.key?('errors')
49
- message << json_response['errors'].map { |attribute, content| "#{attribute}: #{content}" }.join(', ')
48
+ if json_response.key?('Items') && json_response['Items'].is_a?(Array)
49
+ message << json_response['Items'].map { |attribute, content| "#{attribute}: #{content}" }.join(', ')
50
50
  end
51
51
 
52
52
  message
@@ -0,0 +1,5 @@
1
+ module Unleashed
2
+ # Manage Companies
3
+ class Company < BaseModel
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ module Unleashed
2
+ # The Companies resource allows Companies to be listed. An individual Company details can be
3
+ # viewed by appending its identifier (a GUID formatted as XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
4
+ # to the URI. Here are some example URIs:
5
+ # /Companies - returns a list of Company related information.
6
+ #
7
+ # @see https://apidocs.unleashedsoftware.com/Companies
8
+ class CompanyResource < BaseResource
9
+ def model
10
+ Unleashed::Company
11
+ end
12
+
13
+ # Lists all information for your company
14
+ # /Companies - returns a list of Company related information.
15
+ #
16
+ # @return [Array<Unleashed::Company>] Lists all information for your company.
17
+ def all
18
+ endpoint = 'Companies'
19
+ response = JSON.parse(@client.get(endpoint).body)
20
+ companies = response.key?('Items') ? response['Items'] : []
21
+ companies.map { |attributes| Unleashed::Company.new(@client, attributes) }
22
+ end
23
+
24
+ # Get a first company in all
25
+ #
26
+ # @return [Unleashed::Company]
27
+ def first
28
+ all.first
29
+ end
30
+
31
+ # Get a last company in all
32
+ #
33
+ # @return [Unleashed::Company]
34
+ def last
35
+ all.last
36
+ end
37
+ end
38
+ end
@@ -10,13 +10,10 @@ module Unleashed
10
10
  # List all currencies
11
11
  # /Currencies - also returns the first 200 currencies because page number 1 is the default.
12
12
  #
13
- # @param options [Hash] Optional options.
14
- # @option options [Integer] :page_size Can ask for up to 200 currencies. default: 10
15
- # @option options [Integer] :page Page index. default: 1
16
- #
17
13
  # @return [Array<Unleashed::Currency>] List all currencies.
18
- def all(options = { page: 1, page_size: 10 })
19
- response = JSON.parse(@client.get('Currencies', options).body)
14
+ def all
15
+ endpoint = 'Currencies'
16
+ response = JSON.parse(@client.get(endpoint).body)
20
17
  currencies = response.key?('Items') ? response['Items'] : []
21
18
  currencies.map { |attributes| Unleashed::Currency.new(@client, attributes) }
22
19
  end
@@ -14,12 +14,29 @@ module Unleashed
14
14
  # /Customers - also returns the first 200 customers because page number 1 is the default.
15
15
  #
16
16
  # @param options [Hash] Optional options.
17
- # @option options [Integer] :page_size Can ask for up to 200 customers. default: 10
18
- # @option options [Integer] :page Page index. default: 1
17
+ # @option PageSize: Can ask for up to 200 customers. Default: 200
18
+ # @option Page: Page index. Default: 1
19
+ # @option CustomerType: Only returns customers that matches the specified customer type.
20
+ # @option SellPriceTier: Only returns customers that are assigned to the specified sell price tier.
21
+ # @option Currency: Only returns customers with currency code exactly matching the specified value.
22
+ # @option Customer: Returns customers whose customer code or customer name contains the specified value. It is case-sensitive.
23
+ # @option CustomerCode: Only returns customers that start with the specific customer code.
24
+ # @option CustomerName: Only returns customers that start with the specific customer name.
25
+ # @option ContactEmail: Only returns customers that have a contact email that starts with the specified email address.
26
+ # @option ModifiedSince: Only returns customers modified since a specified date.
27
+ # @option IncludeObsolete: Returns all customers, including obsolete, if set to `true`. If set to `false` or if it is not specified then returns only active (ie. non-obsolete) customers.
28
+ # @option XeroContactId: Only returns customers that start with the specific Xero Contact Id.
29
+ # @option OrderBy: Orders the list by `LastModifiedOn` or `CreatedOn` date. By default the list is ordered by `CustomerCode`.
30
+ # @option Sort: Orders the list by `CreatedOn` date sorted in ascending or descending order.
19
31
  #
20
32
  # @return [Array<Unleashed::Customer>] List all customers.
21
- def all(options = { page: 1, page_size: 10 })
22
- response = JSON.parse(@client.get('Customers', options).body)
33
+ def all(options = { Page: 1, PageSize: 200 })
34
+ endpoint = 'Customers'
35
+ params = options.dup
36
+
37
+ # Handle Page option
38
+ endpoint << "/#{params[:Page]}" if params[:Page].present?
39
+ response = JSON.parse(@client.get(endpoint, params).body)
23
40
  customers = response.key?('Items') ? response['Items'] : []
24
41
  customers.map { |attributes| Unleashed::Customer.new(@client, attributes) }
25
42
  end
@@ -27,11 +44,12 @@ module Unleashed
27
44
  # Get a single customer
28
45
  # /Customers/E6E8163F-6911-40e9-B740-90E5A0A3A996 - returns details of a particular customer.
29
46
  #
30
- # @param id [String] customer ID.
47
+ # @param guid [String] customer ID.
31
48
  #
32
49
  # @return [Unleashed::Customer]
33
- def find(id)
34
- response = JSON.parse(@client.get("Customers/#{id}").body)
50
+ def find(guid)
51
+ endpoint = "Customers/#{guid}"
52
+ response = JSON.parse(@client.get(endpoint).body)
35
53
  Unleashed::Customer.new(@client, response)
36
54
  end
37
55
 
@@ -52,11 +70,27 @@ module Unleashed
52
70
  # Create a new customer
53
71
  #
54
72
  # @param attributes [Hash] Customer's attributes.
73
+ # attributes = { Guid: "59f21e05-07fe-4d9d-b460-a09db4c3caa9", Addresses: [ { AddressType: "Shipping",
74
+ # AddressName: "Example Address", StreetAddress: "Example Address",
75
+ # StreetAddress2: "Example Address 2", Suburb: "Example Suburb", City: "Auckland",
76
+ # Region: "Auckland", Country: "New Zealand", PostalCode: "1061", IsDefault: false,
77
+ # DeliveryInstruction: "Have a good day" } ], TaxCode: "", TaxRate: nil,
78
+ # CustomerCode: "UnleashedCustomer", CustomerName: "Unleashed Customer", GSTVATNumber: nil,
79
+ # BankName: nil, BankBranch: nil, BankAccount: nil, Website: nil, PhoneNumber: nil, FaxNumber: nil,
80
+ # MobileNumber: nil, DDINumber: nil, TollFreeNumber: nil, Email: nil, EmailCC: nil,
81
+ # Currency: { CurrencyCode: "NZD", Description: "New Zealand, Dollars",
82
+ # Guid: "6cb5d67a-1c96-4fa8-bf59-b23c2d69f22a" }, Notes: nil, Taxable: true, SalesPerson: nil,
83
+ # DiscountRate: 0, PrintPackingSlipInsteadOfInvoice: false, PrintInvoice: false,
84
+ # StopCredit: false, Obsolete: false, XeroSalesAccount: nil, XeroCostOfGoodsAccount: nil,
85
+ # SellPriceTier: "", SellPriceTierReference: nil, CustomerType: "Cash",
86
+ # PaymentTerm: "20th Month following", ContactFirstName: nil, ContactLastName: nil }
55
87
  #
56
88
  # @return [Unleashed::Customer]
57
- def create(attributes)
89
+ def create_or_update(attributes)
58
90
  id = attributes[:Guid].present? ? attributes[:Guid] : ''
59
- response = JSON.parse(@client.post("Customers/#{id}", attributes).body)
91
+ endpoint = 'Customers'
92
+ endpoint << "/#{id}" if id.present?
93
+ response = JSON.parse(@client.post(endpoint, attributes).body)
60
94
  Unleashed::Customer.new(@client, response)
61
95
  end
62
96
  end
@@ -14,12 +14,60 @@ module Unleashed
14
14
  # /Invoices - also returns the first 200 invoices because page number 1 is the default.
15
15
  #
16
16
  # @param options [Hash] Optional options.
17
- # @option options [Integer] :page_size Can ask for up to 200 invoices. default: 10
18
- # @option options [Integer] :page Page index. default: 1
17
+ # @option Page: Page index. Default: 1
18
+ # @option PageSize: Specifies the page size for pagination. Default page size is 200 invoices.
19
+ # @option CustomerCode: Returns invoices that matches the specific customer code.
20
+ # @option StartDate: Returns invoices created after a specified date, must be UTC format.
21
+ # @option EndDate: Returns invoices created before a specified date, must be UTC format.
22
+ # @option ModifiedSince: Returns invoices created or edited after a specified date, must be UTC format.
23
+ # @option OrderNumber: Returns the invoices associated with the Sales Order Number.
24
+ # @option InvoiceNumber: Returns a single invoice with the specified invoice number. If set, it overrides all other filters.
25
+ # @option InvoiceStatus: Returns invoices with the specified status. Multiple selection can be specified as comma separated.For example: `invoiceStatus=Completed,Parked`. If no invoiceStatus filter is specified, then we exclude “Deleted” by default.
26
+ # @option SerialBatch: False by default. If set to true then the attributes SerialNumbers and BatchNumbers are displayed.
19
27
  #
20
28
  # @return [Array<Unleashed::Invoice>] List all invoices.
21
- def all(options = { page: 1, page_size: 10 })
22
- response = JSON.parse(@client.get('Invoices', options).body)
29
+ # { Pagination: { NumberOfItems: 2, PageSize: 200, PageNumber: 1, NumberOfPages: 1 },
30
+ # Items: [ { InvoiceNumber: "SI-137", OrderNumber: "SO-137", QuoteNumber: nil,
31
+ # InvoiceDate: "/Date(1565058456626)/", DueDate: "/Date(1568937600000)/",
32
+ # InvoiceStatus: "Completed", Customer: { CustomerCode: "WADE",
33
+ # CustomerName: "Wade's Apparel & Accessories", CurrencyId: 110,
34
+ # Guid: "b9f21e05-07fe-4d9d-b460-a09db4c3caa9", LastModifiedOn: "/Date(1559778437146)/" },
35
+ # Comments: nil, PostalAddress: nil, DeliveryAddress: { AddressType: nil,
36
+ # AddressName: nil, StreetAddress: nil, StreetAddress2: nil, Suburb: nil, City: nil,
37
+ # Region: nil, Country: nil, PostalCode: nil, IsDefault: false },
38
+ # DeliveryInstruction: "Handle with care.", SubTotal: 25.0, TaxTotal: 5.0, Total: 30.0,
39
+ # BCSubTotal: 25.27, BCTaxTotal: 5.05, BCTotal: 30.32, CreatedBy: "james@JamesInc.com",
40
+ # PaymentTerm: "20th Month following", InvoiceLines: [ { LineNumber: 1, LineType: nil,
41
+ # Product: { Guid: "23280680-a2bd-4873-a390-501e0f3399d1", ProductCode: "NAIL-M",
42
+ # ProductDescription: "Medium Nails" }, OrderQuantity: 1.0, InvoiceQuantity: 1.0,
43
+ # UnitPrice: 25.0, DiscountRate: 0.0, LineTotal: 25.0, Comments: "", TaxRate: 0.2,
44
+ # LineTax: 5.0, BCUnitPrice: 25.2729, SerialNumbers: nil, BatchNumbers: nil,
45
+ # Guid: "866e295f-76fb-49e7-9407-b2ed4e0a5d0d", LastModifiedOn: "/Date(1565058457156)/" } ],
46
+ # Guid: "10a1571d-8c5a-4e5e-bbba-bc3215a27e17", LastModifiedOn: "/Date(1565058457161)/" },
47
+ # { InvoiceNumber: "SI-136", OrderNumber: "SO-136", QuoteNumber: nil,
48
+ # InvoiceDate: "/Date(1565058268231)/", DueDate: "/Date(1568937600000)/",
49
+ # InvoiceStatus: "Completed", Customer: { CustomerCode: "WADE",
50
+ # CustomerName: "Wade's Apparel & Accessories", CurrencyId: 110,
51
+ # Guid: "b9f21e05-07fe-4d9d-b460-a09db4c3caa9", LastModifiedOn: "/Date(1559778437146)/" },
52
+ # Comments: nil, PostalAddress: nil, DeliveryAddress: { AddressType: nil,
53
+ # AddressName: nil, StreetAddress: nil, StreetAddress2: nil, Suburb: nil, City: nil,
54
+ # Region: nil, Country: nil, PostalCode: nil, IsDefault: false },
55
+ # DeliveryInstruction: nil, SubTotal: 25.0, TaxTotal: 5.0, Total: 30.0,
56
+ # BCSubTotal: 25.27, BCTaxTotal: 5.05, BCTotal: 30.32, CreatedBy: "james@JamesInc.com",
57
+ # PaymentTerm: "20th Month following", InvoiceLines: [ { LineNumber: 1, LineType: nil,
58
+ # Product: { Guid: "23280680-a2bd-4873-a390-501e0f3399d1", ProductCode: "NAIL-M",
59
+ # ProductDescription: "Medium Nails" }, OrderQuantity: 1.0, InvoiceQuantity: 1.0,
60
+ # UnitPrice: 25.0, DiscountRate: 0.0, LineTotal: 25.0, Comments: "", TaxRate: 0.2,
61
+ # LineTax: 5.0, BCUnitPrice: 25.2729, SerialNumbers: nil, BatchNumbers: nil,
62
+ # Guid: "2b994962-e446-4b18-b8c7-5f445adde8cc", LastModifiedOn: "/Date(1565058268757)/" } ],
63
+ # Guid: "5cc41e1e-468f-4c01-beb9-a077fc06df46", LastModifiedOn: "/Date(1565058268764)/" } ] }
64
+ def all(options = { Page: 1, PageSize: 200 })
65
+ endpoint = 'Invoices'
66
+ params = options.dup
67
+
68
+ # Handle Page option
69
+ endpoint << "/#{params[:Page]}" if params[:Page].present?
70
+ response = JSON.parse(@client.get(endpoint, params).body)
23
71
  invoices = response.key?('Items') ? response['Items'] : []
24
72
  invoices.map { |attributes| Unleashed::Invoice.new(@client, attributes) }
25
73
  end
@@ -11,13 +11,28 @@ module Unleashed
11
11
  # List all payment_terms
12
12
  # /PaymentTerms - also returns the first 200 payment_terms because page number 1 is the default.
13
13
  #
14
- # @param options [Hash] Optional options.
15
- # @option options [Integer] :page_size Can ask for up to 200 payment_terms. default: 10
16
- # @option options [Integer] :page Page index. default: 1
17
- #
18
- # @return [Array<Unleashed::PaymentTerm>] List all payment_terms.
19
- def all(options = { page: 1, page_size: 10 })
20
- response = JSON.parse(@client.get('PaymentTerms', options).body)
14
+ # @return [Array<Unleashed::PaymentTerm>] List all payment terms.
15
+ # {
16
+ # "Items": [
17
+ # {
18
+ # "Guid": "6223b37e-2ee4-41ed-a215-5f14c53e8f7f",
19
+ # "Type": "DaysOfTheMonthFollowing",
20
+ # "Days": 20,
21
+ # "Obsolete": false,
22
+ # "PaymentTermDescription": "20th Month following"
23
+ # },
24
+ # {
25
+ # "Guid": "6488bee4-ea4c-4a25-ba1b-a86965120e34",
26
+ # "Type": "DaysOfTheMonthFollowing",
27
+ # "Days": 25,
28
+ # "Obsolete": false,
29
+ # "PaymentTermDescription": "25th Month following"
30
+ # }
31
+ # ]
32
+ # }
33
+ def all
34
+ endpoint = 'PaymentTerms'
35
+ response = JSON.parse(@client.get(endpoint).body)
21
36
  payment_terms = response.key?('Items') ? response['Items'] : []
22
37
  payment_terms.map { |attributes| Unleashed::PaymentTerm.new(@client, attributes) }
23
38
  end
@@ -35,16 +50,5 @@ module Unleashed
35
50
  def last
36
51
  all.last
37
52
  end
38
-
39
- # Create a new payment_term
40
- #
41
- # @param attributes [Hash] PaymentTerm's attributes.
42
- #
43
- # @return [Unleashed::PaymentTerm]
44
- def create(attributes)
45
- id = attributes[:Guid].present? ? attributes[:Guid] : ''
46
- response = JSON.parse(@client.post("PaymentTerms/#{id}", attributes).body)
47
- Unleashed::PaymentTerm.new(@client, response)
48
- end
49
53
  end
50
54
  end
@@ -2,7 +2,7 @@ module Unleashed
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 11
5
+ TINY = 17
6
6
 
7
7
  STRING = "#{MAJOR}.#{MINOR}.#{TINY}".freeze
8
8
  end
@@ -13,15 +13,6 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = 'https://github.com/nnhansg/unleashed-ruby'
14
14
  spec.license = 'MIT'
15
15
 
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- # if spec.respond_to?(:metadata)
19
- # spec.metadata['allowed_push_host'] = 'https://github.com'
20
- # else
21
- # raise 'RubyGems 2.0 or newer is required to protect against ' \
22
- # 'public gem pushes.'
23
- # end
24
-
25
16
  spec.metadata['homepage_uri'] = spec.homepage
26
17
  spec.metadata['source_code_uri'] = 'https://github.com/nnhansg/unleashed-ruby/src/master/'
27
18
  spec.metadata['changelog_uri'] = 'https://github.com/nnhansg/unleashed-ruby/src/master/CHANGELOG.md'
@@ -43,6 +34,6 @@ Gem::Specification.new do |spec|
43
34
  spec.add_dependency 'faraday', '>= 0'
44
35
  spec.add_dependency 'json', '>= 0'
45
36
  spec.add_development_dependency 'bundler', '~> 1.16', '>= 1.16.1'
46
- spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'rake', '>= 12.3.3'
47
38
  spec.add_development_dependency 'rspec', '~> 3.0'
48
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unleashed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nhan Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-04 00:00:00.000000000 Z
11
+ date: 2021-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -62,16 +62,16 @@ dependencies:
62
62
  name: rake
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - "~>"
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: '10.0'
67
+ version: 12.3.3
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - "~>"
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: '10.0'
74
+ version: 12.3.3
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rspec
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +107,11 @@ files:
107
107
  - bin/.keep
108
108
  - bin/console
109
109
  - bin/setup
110
+ - docs/Company.md
111
+ - docs/Currency.md
112
+ - docs/Customer.md
113
+ - docs/Invoice.md
114
+ - docs/PaymentTerm.md
110
115
  - lib/.keep
111
116
  - lib/unleashed.rb
112
117
  - lib/unleashed/client.rb
@@ -114,11 +119,13 @@ files:
114
119
  - lib/unleashed/default.rb
115
120
  - lib/unleashed/error.rb
116
121
  - lib/unleashed/models/base_model.rb
122
+ - lib/unleashed/models/company.rb
117
123
  - lib/unleashed/models/currency.rb
118
124
  - lib/unleashed/models/customer.rb
119
125
  - lib/unleashed/models/invoice.rb
120
126
  - lib/unleashed/models/payment_term.rb
121
127
  - lib/unleashed/resources/base_resource.rb
128
+ - lib/unleashed/resources/company_resource.rb
122
129
  - lib/unleashed/resources/currency_resource.rb
123
130
  - lib/unleashed/resources/customer_resource.rb
124
131
  - lib/unleashed/resources/invoice_resource.rb