unleashed 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +120 -0
- data/lib/unleashed/client.rb +35 -1
- data/lib/unleashed/error.rb +1 -0
- data/lib/unleashed/models/currency.rb +5 -0
- data/lib/unleashed/resources/currency_resource.rb +38 -0
- data/lib/unleashed/resources/customer_resource.rb +11 -0
- data/lib/unleashed/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf3ba61a8bff2e77aa0ace253add4da5afbda0061714a9c88845ece3ae649dd4
|
4
|
+
data.tar.gz: ba46eed20ad77d7b8d26f299067e54be7e374380803aaf13a84c759e6b2511e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac418597461705c6773100bba898c13f9b26736da7d6a629124d4fcbfb6c9616b3ff74c5e221f91499d467b06ef116a8e5e5d01ad966129c655f2a52450ad946
|
7
|
+
data.tar.gz: db6da8431dd8462425306858a923d8709304aa1abd6c7252550fb8b16ba249deb5e75d85f9f9ef7b70d34108506cd01753ff4c2ef4f935aee8d70a474af4118b
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,25 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## [0.1.9] - 2019-11-29
|
6
|
+
|
7
|
+
- Add `attr_reader` attributes applying for all models.
|
8
|
+
- Update configuration of dependencies.
|
9
|
+
- Add first, last methods for `invoice` model.
|
10
|
+
|
11
|
+
## [0.1.7] - 2019-11-13
|
12
|
+
|
13
|
+
- Show messages when having any error.
|
14
|
+
|
15
|
+
## [0.1.6] - 2019-11-13
|
16
|
+
|
17
|
+
- Add some methods to `Customer`
|
18
|
+
- Update readme.
|
19
|
+
|
20
|
+
## [0.1.5] - 2019-11-11
|
21
|
+
|
22
|
+
- Some small updates.
|
23
|
+
|
5
24
|
## [0.1.4] - 2019-11-11
|
6
25
|
|
7
26
|
- Add `Customer` resource
|
data/README.md
CHANGED
@@ -64,6 +64,126 @@ client = Unleashed::Client.new(options)
|
|
64
64
|
|
65
65
|
### Customers
|
66
66
|
|
67
|
+
#### Create a new Customer
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
customer = client.customers.create(
|
71
|
+
Guid: '59f21e05-07fe-4d9d-b460-a09db4c3caa9',
|
72
|
+
Addresses: [
|
73
|
+
{
|
74
|
+
AddressType: 'Shipping',
|
75
|
+
AddressName: 'Example Address',
|
76
|
+
StreetAddress: 'Example Address',
|
77
|
+
StreetAddress2: 'Example Address 2',
|
78
|
+
Suburb: 'Example Suburb',
|
79
|
+
City: 'Auckland',
|
80
|
+
Region: 'Auckland',
|
81
|
+
Country: 'New Zealand',
|
82
|
+
PostalCode: '1061',
|
83
|
+
IsDefault: false,
|
84
|
+
DeliveryInstruction: 'Have a good day'
|
85
|
+
}
|
86
|
+
],
|
87
|
+
TaxCode: '',
|
88
|
+
TaxRate: nil,
|
89
|
+
CustomerCode: 'UnleashedCustomer',
|
90
|
+
CustomerName: 'Unleashed Customer',
|
91
|
+
GSTVATNumber: nil,
|
92
|
+
BankName: nil,
|
93
|
+
BankBranch: nil,
|
94
|
+
BankAccount: nil,
|
95
|
+
Website: nil,
|
96
|
+
PhoneNumber: nil,
|
97
|
+
FaxNumber: nil,
|
98
|
+
MobileNumber: nil,
|
99
|
+
DDINumber: nil,
|
100
|
+
TollFreeNumber: nil,
|
101
|
+
Email: nil,
|
102
|
+
EmailCC: nil,
|
103
|
+
Currency: {
|
104
|
+
CurrencyCode: 'NZD',
|
105
|
+
Description: 'New Zealand, Dollars',
|
106
|
+
Guid: 'c33e4f50-e42b-40cd-9147-4d0e4657cd4d'
|
107
|
+
},
|
108
|
+
Notes: nil,
|
109
|
+
Taxable: true,
|
110
|
+
SalesPerson: nil,
|
111
|
+
DiscountRate: 0.0000,
|
112
|
+
PrintPackingSlipInsteadOfInvoice: false,
|
113
|
+
PrintInvoice: false,
|
114
|
+
StopCredit: false,
|
115
|
+
Obsolete: false,
|
116
|
+
XeroSalesAccount: nil,
|
117
|
+
XeroCostOfGoodsAccount: nil,
|
118
|
+
SellPriceTier: '',
|
119
|
+
SellPriceTierReference: nil,
|
120
|
+
CustomerType: 'Cash',
|
121
|
+
PaymentTerm: '20th Month following',
|
122
|
+
ContactFirstName: nil,
|
123
|
+
ContactLastName: nil
|
124
|
+
)
|
125
|
+
```
|
126
|
+
|
127
|
+
#### Update a Customer
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
customer = client.customers.update(
|
131
|
+
Guid: '59f21e05-07fe-4d9d-b460-a09db4c3caa9',
|
132
|
+
Addresses: [
|
133
|
+
{
|
134
|
+
AddressType: 'Shipping',
|
135
|
+
AddressName: 'Example Address',
|
136
|
+
StreetAddress: 'Example Address',
|
137
|
+
StreetAddress2: 'Example Address 2',
|
138
|
+
Suburb: 'Example Suburb',
|
139
|
+
City: 'Auckland',
|
140
|
+
Region: 'Auckland',
|
141
|
+
Country: 'New Zealand',
|
142
|
+
PostalCode: '1061',
|
143
|
+
IsDefault: false,
|
144
|
+
DeliveryInstruction: 'Have a good day'
|
145
|
+
}
|
146
|
+
],
|
147
|
+
TaxCode: '',
|
148
|
+
TaxRate: nil,
|
149
|
+
CustomerCode: 'UnleashedCustomer',
|
150
|
+
CustomerName: 'Unleashed Customer',
|
151
|
+
GSTVATNumber: nil,
|
152
|
+
BankName: nil,
|
153
|
+
BankBranch: nil,
|
154
|
+
BankAccount: nil,
|
155
|
+
Website: nil,
|
156
|
+
PhoneNumber: nil,
|
157
|
+
FaxNumber: nil,
|
158
|
+
MobileNumber: nil,
|
159
|
+
DDINumber: nil,
|
160
|
+
TollFreeNumber: nil,
|
161
|
+
Email: nil,
|
162
|
+
EmailCC: nil,
|
163
|
+
Currency: {
|
164
|
+
CurrencyCode: 'NZD',
|
165
|
+
Description: 'New Zealand, Dollars',
|
166
|
+
Guid: '6cb5d67a-1c96-4fa8-bf59-b23c2d69f22a'
|
167
|
+
},
|
168
|
+
Notes: nil,
|
169
|
+
Taxable: true,
|
170
|
+
SalesPerson: nil,
|
171
|
+
DiscountRate: 0.0000,
|
172
|
+
PrintPackingSlipInsteadOfInvoice: false,
|
173
|
+
PrintInvoice: false,
|
174
|
+
StopCredit: false,
|
175
|
+
Obsolete: false,
|
176
|
+
XeroSalesAccount: nil,
|
177
|
+
XeroCostOfGoodsAccount: nil,
|
178
|
+
SellPriceTier: '',
|
179
|
+
SellPriceTierReference: nil,
|
180
|
+
CustomerType: 'Cash',
|
181
|
+
PaymentTerm: '20th Month following',
|
182
|
+
ContactFirstName: nil,
|
183
|
+
ContactLastName: nil
|
184
|
+
)
|
185
|
+
```
|
186
|
+
|
67
187
|
#### Get all customers
|
68
188
|
|
69
189
|
```ruby
|
data/lib/unleashed/client.rb
CHANGED
@@ -10,6 +10,16 @@ require 'json'
|
|
10
10
|
require 'faraday'
|
11
11
|
|
12
12
|
module Unleashed
|
13
|
+
class CustomParamsEncoder
|
14
|
+
def self.encode(params)
|
15
|
+
Faraday::NestedParamsEncoder.encode(params).gsub(/\+/, '%20')
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.decode(query)
|
19
|
+
Faraday::NestedParamsEncoder.decode(query)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
13
23
|
# Client for the Unleashed API
|
14
24
|
#
|
15
25
|
# @see https://apidocs.unleashedsoftware.com
|
@@ -29,7 +39,7 @@ module Unleashed
|
|
29
39
|
#
|
30
40
|
# @return [Faraday::Connection]
|
31
41
|
def connection
|
32
|
-
Faraday.new(url: @api_endpoint) do |faraday|
|
42
|
+
Faraday.new(url: @api_endpoint, request: { params_encoder: CustomParamsEncoder }) do |faraday|
|
33
43
|
faraday.adapter :net_http
|
34
44
|
end
|
35
45
|
end
|
@@ -71,6 +81,30 @@ module Unleashed
|
|
71
81
|
response
|
72
82
|
end
|
73
83
|
|
84
|
+
# Make a HTTP POST request
|
85
|
+
#
|
86
|
+
# @param url [String] The path, relative to {#api_endpoint}
|
87
|
+
# @param parameters [Hash] Query params for request
|
88
|
+
# @return [Faraday::Response]
|
89
|
+
def post(url, parameters = {}, headers = {}, skip_status_check = false)
|
90
|
+
response = connection.post do |request|
|
91
|
+
request.url "#{api_endpoint}#{url}"
|
92
|
+
|
93
|
+
# Set headers
|
94
|
+
init_default_headers(request)
|
95
|
+
|
96
|
+
# Assign more custom headers
|
97
|
+
headers.each do |key, value|
|
98
|
+
request.headers[key] = value
|
99
|
+
end
|
100
|
+
|
101
|
+
request.body = parameters.to_json
|
102
|
+
end
|
103
|
+
|
104
|
+
on_complete(response) unless skip_status_check
|
105
|
+
response
|
106
|
+
end
|
107
|
+
|
74
108
|
# Available resources for {Client}
|
75
109
|
#
|
76
110
|
# @return [Hash]
|
data/lib/unleashed/error.rb
CHANGED
@@ -43,6 +43,7 @@ module Unleashed
|
|
43
43
|
json_response = JSON.parse(@response.body)
|
44
44
|
message = ''
|
45
45
|
message << json_response['description'] if json_response.key?('description')
|
46
|
+
message << json_response['Description'] if json_response.key?('Description')
|
46
47
|
|
47
48
|
if json_response.key?('errors')
|
48
49
|
message << json_response['errors'].map { |attribute, content| "#{attribute}: #{content}" }.join(', ')
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Unleashed
|
2
|
+
# Resource for the Currencies API
|
3
|
+
# The Currencies resource allows Currencies to be listed, viewed.
|
4
|
+
# @see https://apidocs.unleashedsoftware.com/Sandbox
|
5
|
+
class CurrencyResource < BaseResource
|
6
|
+
def model
|
7
|
+
Unleashed::Currency
|
8
|
+
end
|
9
|
+
|
10
|
+
# List all currencies
|
11
|
+
# /Currencies - also returns the first 200 currencies because page number 1 is the default.
|
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
|
+
# @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)
|
20
|
+
currencies = response.key?('Items') ? response['Items'] : []
|
21
|
+
currencies.map { |attributes| Unleashed::Currency.new(@client, attributes) }
|
22
|
+
end
|
23
|
+
|
24
|
+
# Get a first currency in all
|
25
|
+
#
|
26
|
+
# @return [Unleashed::Currency]
|
27
|
+
def first
|
28
|
+
all.first
|
29
|
+
end
|
30
|
+
|
31
|
+
# Get a last currency in all
|
32
|
+
#
|
33
|
+
# @return [Unleashed::Currency]
|
34
|
+
def last
|
35
|
+
all.last
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -48,5 +48,16 @@ module Unleashed
|
|
48
48
|
def last
|
49
49
|
all.last
|
50
50
|
end
|
51
|
+
|
52
|
+
# Create a new customer for a marketplace
|
53
|
+
#
|
54
|
+
# @param attributes [Hash] Customer's attributes.
|
55
|
+
#
|
56
|
+
# @return [Unleashed::Customer]
|
57
|
+
def create(attributes)
|
58
|
+
id = attributes[:Guid].present? ? attributes[:Guid] : ''
|
59
|
+
response = JSON.parse(@client.post("Customers/#{id}", attributes).body)
|
60
|
+
Unleashed::Customer.new(@client, response)
|
61
|
+
end
|
51
62
|
end
|
52
63
|
end
|
data/lib/unleashed/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.10
|
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-
|
11
|
+
date: 2019-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -114,9 +114,11 @@ files:
|
|
114
114
|
- lib/unleashed/default.rb
|
115
115
|
- lib/unleashed/error.rb
|
116
116
|
- lib/unleashed/models/base_model.rb
|
117
|
+
- lib/unleashed/models/currency.rb
|
117
118
|
- lib/unleashed/models/customer.rb
|
118
119
|
- lib/unleashed/models/invoice.rb
|
119
120
|
- lib/unleashed/resources/base_resource.rb
|
121
|
+
- lib/unleashed/resources/currency_resource.rb
|
120
122
|
- lib/unleashed/resources/customer_resource.rb
|
121
123
|
- lib/unleashed/resources/invoice_resource.rb
|
122
124
|
- lib/unleashed/version.rb
|