brightpearl_api 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.travis.yml +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +383 -0
- data/Rakefile +10 -0
- data/brightpearl_api.gemspec +27 -0
- data/lib/brightpearl_api/client.rb +87 -0
- data/lib/brightpearl_api/configuration.rb +61 -0
- data/lib/brightpearl_api/service.rb +68 -0
- data/lib/brightpearl_api/services/contact.rb +18 -0
- data/lib/brightpearl_api/services/order.rb +48 -0
- data/lib/brightpearl_api/services/product.rb +68 -0
- data/lib/brightpearl_api/services/warehouse.rb +112 -0
- data/lib/brightpearl_api/version.rb +3 -0
- data/lib/brightpearl_api.rb +20 -0
- data/spec/spec_helper.rb +2 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f410dbbc703592d57a6682f4f9f4c82a6b77314a
|
4
|
+
data.tar.gz: afa11400aff3eb3861ae03852e663528af910c45
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 984c93efc23fd0e2466d38a0f6c6f7118650704cad0fc3efc4e063d1264c3ee36942fe82484fb5568a2ad65fed3d9c58f3d5b1ee988a4367d03b64e3c0afc744
|
7
|
+
data.tar.gz: f3d290f29838ac2155065f1c99148c912356c9bad8e748b46c402d1c1ee9580c66fcec063ec06039b2536b1146b01b0fb196763cd5b6cea633453752db906d39
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format documentation
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kunwar Aditya Raghuwanshi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,383 @@
|
|
1
|
+
# BrightpearlApi
|
2
|
+
|
3
|
+
Gem for connecting to your brightpearl account via their API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'brightpearl_api'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install brightpearl_api
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Initialize
|
22
|
+
|
23
|
+
Refer [Brightpearl Documentation](http://www.brightpearl.com/developer/latest/tutorial/getting-started.html) for values.
|
24
|
+
|
25
|
+
In ```config/initializers/brightpearl_api.rb```
|
26
|
+
|
27
|
+
With Environment Variables set
|
28
|
+
|
29
|
+
```(ENV['BRIGHTPEARL_EMAIL'], ENV['BRIGHTPEARL_PASSWORD'], ENV['BRIGHTPEARL_VERSION'], ENV['BRIGHTPEARL_DATACENTER'], ENV['BRIGHTPEARL_ACCOUNT'])```
|
30
|
+
|
31
|
+
```
|
32
|
+
BrightpearlApi.configure do
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
Else
|
37
|
+
|
38
|
+
```
|
39
|
+
BrightpearlApi.configure do |c|
|
40
|
+
c.email = 'someone@example.com'
|
41
|
+
c.password = 'something'
|
42
|
+
c.version = '2.0.0'
|
43
|
+
c.datacenter = 'ws-usw'
|
44
|
+
c.account = 'myaccount'
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Then, anywhere
|
49
|
+
|
50
|
+
```
|
51
|
+
s = BrightpearlApi::Service.new
|
52
|
+
```
|
53
|
+
|
54
|
+
### API
|
55
|
+
|
56
|
+
__All Post calls have to be passed a block which constructs a body hash__
|
57
|
+
|
58
|
+
#### Multi Purpose
|
59
|
+
|
60
|
+
*Four functions (get_resource, create_resource, update_resource, delete_resource) take the service name and resource name as parameters. get_resource also takes an optional idset parameter which can be an int, range or array. It'll try to get all resources if idset is not provided and the API supports it.*
|
61
|
+
|
62
|
+
*Range URI's can be retrived via get_resource_range which also takes an optional range*
|
63
|
+
|
64
|
+
```
|
65
|
+
s.get_resource('product', 'product', 100)
|
66
|
+
s.get_resource('product', 'product', 100..200)
|
67
|
+
s.create_resource('contact', 'contact') do |body|
|
68
|
+
hash = {
|
69
|
+
salutation: "Ms.",
|
70
|
+
firstName: "Pink",
|
71
|
+
lastName: "Melody",
|
72
|
+
postAddressIds: {
|
73
|
+
DEF: 141,
|
74
|
+
BIL: 141,
|
75
|
+
DEL: 141
|
76
|
+
}
|
77
|
+
}
|
78
|
+
body.merge!(hash)
|
79
|
+
end
|
80
|
+
|
81
|
+
s.create_resource('contact', 'postal-address') do |body|
|
82
|
+
hash = {
|
83
|
+
addressLine1: "Brightpearl, First Floor",
|
84
|
+
addressLine2: "New Bond House",
|
85
|
+
addressLine3: "Bond Street",
|
86
|
+
addressLine4: "Bristol",
|
87
|
+
postalCode: "BS2 9AG",
|
88
|
+
countryIsoCode: "GBR"
|
89
|
+
}
|
90
|
+
body.merge!(hash)
|
91
|
+
end
|
92
|
+
|
93
|
+
s.create_resource('order', 'order') do |body|
|
94
|
+
hash = {
|
95
|
+
orderTypeCode: "SO",
|
96
|
+
reference: "order#001",
|
97
|
+
priceListId: 2,
|
98
|
+
invoices: [
|
99
|
+
{
|
100
|
+
taxDate: "2012-06-08T12:57:25+00:00"
|
101
|
+
}
|
102
|
+
],
|
103
|
+
placedOn: "2011-09-29T11:12:24.000+01:00",
|
104
|
+
orderStatus: {
|
105
|
+
orderStatusId: 1
|
106
|
+
},
|
107
|
+
delivery: {
|
108
|
+
deliveryDate: "2011-09-29T11:12:24.000+01:00",
|
109
|
+
shippingMethodId: 2
|
110
|
+
},
|
111
|
+
currency: {
|
112
|
+
orderCurrencyCode: "GBP"
|
113
|
+
},
|
114
|
+
parties: {
|
115
|
+
customer: {
|
116
|
+
contactId: 204
|
117
|
+
}
|
118
|
+
},
|
119
|
+
assignment: {
|
120
|
+
current: {
|
121
|
+
channelId: 1,
|
122
|
+
leadSourceId: 1,
|
123
|
+
projectId: 1,
|
124
|
+
staffOwnerContactId: 501,
|
125
|
+
teamId: 2
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
body.merge!(hash)
|
130
|
+
end
|
131
|
+
|
132
|
+
s.create_resource('product', 'product') do |body|
|
133
|
+
hash = {
|
134
|
+
brandId: 74,
|
135
|
+
financialDetails: {
|
136
|
+
taxCode: {
|
137
|
+
id: 7
|
138
|
+
}
|
139
|
+
},
|
140
|
+
salesChannels: [
|
141
|
+
{
|
142
|
+
salesChannelName: "Brightpearl",
|
143
|
+
productName: "Product B",
|
144
|
+
productCondition: "new",
|
145
|
+
categories: [
|
146
|
+
{
|
147
|
+
categoryCode: "276"
|
148
|
+
}
|
149
|
+
]
|
150
|
+
}
|
151
|
+
]
|
152
|
+
}
|
153
|
+
body.merge!(hash)
|
154
|
+
end
|
155
|
+
|
156
|
+
s.get_resource_range('contact', 'contact', 100..200)
|
157
|
+
s.get_resource_range('order', 'order')
|
158
|
+
|
159
|
+
```
|
160
|
+
|
161
|
+
#### Supported Service - Resource Pairs
|
162
|
+
|
163
|
+
| Service | Resource |
|
164
|
+
| ------------ | ---------------------- |
|
165
|
+
| contact | contact |
|
166
|
+
| contact | postal-address |
|
167
|
+
| order | order |
|
168
|
+
| order | order-status |
|
169
|
+
| product | brand |
|
170
|
+
| product | brightpearl-category |
|
171
|
+
| product | channel |
|
172
|
+
| product | option |
|
173
|
+
| product | price-list |
|
174
|
+
| product | product |
|
175
|
+
| product | product-price |
|
176
|
+
| product | product-type |
|
177
|
+
| product | season |
|
178
|
+
| warehouse | fulfilment-source |
|
179
|
+
| warehouse | product-availability |
|
180
|
+
| warehouse | shipping-method |
|
181
|
+
| warehouse | warehouse |
|
182
|
+
|
183
|
+
#### Contact
|
184
|
+
|
185
|
+
```
|
186
|
+
s.associate_tag(idset, tag_id)
|
187
|
+
```
|
188
|
+
|
189
|
+
#### Order
|
190
|
+
|
191
|
+
```
|
192
|
+
s.order_acknowledgement(order_id, reference)
|
193
|
+
s.create_order_note(order_id)
|
194
|
+
s.get_order_row(order_id, row_id)
|
195
|
+
|
196
|
+
s.create_order_row(order_id) do |body|
|
197
|
+
hash = {
|
198
|
+
#...
|
199
|
+
}
|
200
|
+
body.merge!(hash)
|
201
|
+
end
|
202
|
+
|
203
|
+
s.update_order_row(order_id, row_id) do |body|
|
204
|
+
hash = {
|
205
|
+
#...
|
206
|
+
}
|
207
|
+
body.merge!(hash)
|
208
|
+
end
|
209
|
+
|
210
|
+
s.update_order_status(order_id) do |body|
|
211
|
+
hash = {
|
212
|
+
#...
|
213
|
+
}
|
214
|
+
body.merge!(hash)
|
215
|
+
end
|
216
|
+
```
|
217
|
+
|
218
|
+
#### Product
|
219
|
+
|
220
|
+
```
|
221
|
+
s.create_brand(name, description)
|
222
|
+
s.create_category(name, parentId)
|
223
|
+
s.get_option_value(idset)
|
224
|
+
s.create_option_value(option_id, optionValueName)
|
225
|
+
|
226
|
+
s.update_product_price(1001) do |body|
|
227
|
+
hash = {
|
228
|
+
priceLists: [
|
229
|
+
{
|
230
|
+
priceListId: 1,
|
231
|
+
quantityPrice: {
|
232
|
+
1: "1",
|
233
|
+
5: "9.555",
|
234
|
+
15: "9",
|
235
|
+
25: "8",
|
236
|
+
50: "7.5",
|
237
|
+
200: "7"
|
238
|
+
}
|
239
|
+
},
|
240
|
+
{
|
241
|
+
priceListId: 2,
|
242
|
+
quantityPrice: {
|
243
|
+
1: "1",
|
244
|
+
5: "9.555",
|
245
|
+
15: "9",
|
246
|
+
25: "8",
|
247
|
+
50: "7.5",
|
248
|
+
200: "7"
|
249
|
+
}
|
250
|
+
}
|
251
|
+
]
|
252
|
+
}
|
253
|
+
body.merge!(hash)
|
254
|
+
end
|
255
|
+
|
256
|
+
s.create_product_type(name)
|
257
|
+
s.product_type_association(product_id_set, option_id_set)
|
258
|
+
s.create_season(name, description)
|
259
|
+
```
|
260
|
+
|
261
|
+
#### Warehouse
|
262
|
+
|
263
|
+
```
|
264
|
+
s.asset_value_correction(warehouse_id) do |body|
|
265
|
+
hash = {
|
266
|
+
#...
|
267
|
+
}
|
268
|
+
body.merge!(hash)
|
269
|
+
end
|
270
|
+
|
271
|
+
s.get_default_location(warehouse_id)
|
272
|
+
s.get_quarantine_location(warehouse_id)
|
273
|
+
s.get_location(warehouse_id, location_id_set)
|
274
|
+
s.delete_location(warehouse_id, location_id)
|
275
|
+
|
276
|
+
s.create_location(warehouse_id) do |body|
|
277
|
+
hash = {
|
278
|
+
#...
|
279
|
+
}
|
280
|
+
body.merge!(hash)
|
281
|
+
end
|
282
|
+
|
283
|
+
s.get_drop_ship_note(sales_id_set, drop_ship_note_id_set)
|
284
|
+
|
285
|
+
s.create_drop_ship_note(sales_order_id) do |body|
|
286
|
+
hash = {
|
287
|
+
#...
|
288
|
+
}
|
289
|
+
body.merge!(hash)
|
290
|
+
end
|
291
|
+
|
292
|
+
s.create_drop_ship_note_event(drop_ship_note_id) do |body|
|
293
|
+
hash = {
|
294
|
+
#...
|
295
|
+
}
|
296
|
+
body.merge!(hash)
|
297
|
+
end
|
298
|
+
|
299
|
+
s.goods_in_note_correction(batch_id) do |body|
|
300
|
+
hash = {
|
301
|
+
#...
|
302
|
+
}
|
303
|
+
body.merge!(hash)
|
304
|
+
end
|
305
|
+
|
306
|
+
s.create_goods_in_note(order_id) do |body|
|
307
|
+
hash = {
|
308
|
+
#...
|
309
|
+
}
|
310
|
+
body.merge!(hash)
|
311
|
+
end
|
312
|
+
|
313
|
+
s.delete_goods_in_note(goods_in_note_id)
|
314
|
+
s.delete_goods_out_note(order_id, goods_out_note_id)
|
315
|
+
s.get_goods_out_note(order_id_set, goods_out_note_id_set)
|
316
|
+
|
317
|
+
s.create_goods_out_note(order_id) do |body|
|
318
|
+
hash = {
|
319
|
+
"warehouses: [
|
320
|
+
{
|
321
|
+
releaseDate: "2011-07-15T10:39:40.000+01:00",
|
322
|
+
warehouseId: 2,
|
323
|
+
transfer: false,
|
324
|
+
products: [
|
325
|
+
{
|
326
|
+
productId: 1008,
|
327
|
+
salesOrderRowId: 4,
|
328
|
+
quantity: 5
|
329
|
+
},
|
330
|
+
{
|
331
|
+
productId: 1007,
|
332
|
+
salesOrderRowId: 5,
|
333
|
+
quantity: 14
|
334
|
+
}
|
335
|
+
]
|
336
|
+
}
|
337
|
+
],
|
338
|
+
priority: false,
|
339
|
+
shippingMethodId: 4
|
340
|
+
}
|
341
|
+
body.merge!(hash)
|
342
|
+
end
|
343
|
+
|
344
|
+
s.update_goods_out_note(goods_out_note_id) do |body|
|
345
|
+
hash = {
|
346
|
+
#...
|
347
|
+
}
|
348
|
+
body.merge!(hash)
|
349
|
+
end
|
350
|
+
|
351
|
+
s.create_goods_out_note_event(goods_out_note_id) do |body|
|
352
|
+
hash = {
|
353
|
+
#...
|
354
|
+
}
|
355
|
+
body.merge!(hash)
|
356
|
+
end
|
357
|
+
|
358
|
+
s.create_internal_transfer(warehouse_id) do |body|
|
359
|
+
hash = {
|
360
|
+
#...
|
361
|
+
}
|
362
|
+
body.merge!(hash)
|
363
|
+
end
|
364
|
+
|
365
|
+
s.quarantine_release(warehouse_id) do |body|
|
366
|
+
hash = {
|
367
|
+
#...
|
368
|
+
}
|
369
|
+
body.merge!(hash)
|
370
|
+
end
|
371
|
+
```
|
372
|
+
|
373
|
+
## TODO
|
374
|
+
|
375
|
+
Resource Search
|
376
|
+
|
377
|
+
## Contributing
|
378
|
+
|
379
|
+
1. Fork it ( http://github.com/kitwalker12/brightpearl_api/fork )
|
380
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
381
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
382
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
383
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
# Default directory to look in is `/specs`
|
5
|
+
# Run with `rake spec`
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
7
|
+
task.rspec_opts = ['--color', '--format', 'nested']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :spec
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'brightpearl_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "brightpearl_api"
|
8
|
+
spec.version = BrightpearlApi::VERSION
|
9
|
+
spec.authors = ["Kunwar Aditya Raghuwanshi"]
|
10
|
+
spec.email = ["adi.version1@gmail.com"]
|
11
|
+
spec.summary = %q{Brightpearl API Library}
|
12
|
+
spec.description = %q{Gem for connecting to your brightpearl account via their API}
|
13
|
+
spec.homepage = "http://github.com/kitwalker12/brightpearl_api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "activesupport"
|
24
|
+
spec.add_development_dependency "httparty"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module BrightpearlApi
|
5
|
+
class Client
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
@@token = false
|
9
|
+
|
10
|
+
def self.instance
|
11
|
+
@@instance ||= new
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(type, path, data = {})
|
15
|
+
api_call(type, path, data)
|
16
|
+
rescue AuthException => e
|
17
|
+
reset_token
|
18
|
+
api_call(type, path, data)
|
19
|
+
end
|
20
|
+
|
21
|
+
def api_call(type, path, data = {})
|
22
|
+
token = authenticate
|
23
|
+
|
24
|
+
uri = configuration.uri(path)
|
25
|
+
options = {
|
26
|
+
:headers => {
|
27
|
+
'Content-Type' => 'application/json',
|
28
|
+
'Accept' => 'json',
|
29
|
+
'brightpearl-auth' => token
|
30
|
+
},
|
31
|
+
:body => data.to_json
|
32
|
+
}
|
33
|
+
if type == :get
|
34
|
+
response = HTTParty.get(uri, options)
|
35
|
+
elsif type == :post
|
36
|
+
response = HTTParty.post(uri, options)
|
37
|
+
elsif type == :put
|
38
|
+
response = HTTParty.put(uri, options)
|
39
|
+
elsif type == :options
|
40
|
+
response = HTTParty.options(uri, options)
|
41
|
+
elsif type == :delete
|
42
|
+
response = HTTParty.delete(uri, options)
|
43
|
+
end
|
44
|
+
check_response(response)
|
45
|
+
return response["response"]
|
46
|
+
end
|
47
|
+
|
48
|
+
def authenticate
|
49
|
+
return @@token unless @@token.blank?
|
50
|
+
options = {
|
51
|
+
:headers => {
|
52
|
+
'Content-Type' => 'application/json',
|
53
|
+
'Accept' => 'json'
|
54
|
+
},
|
55
|
+
:body => {
|
56
|
+
:apiAccountCredentials => {
|
57
|
+
:emailAddress => configuration.email,
|
58
|
+
:password => configuration.password
|
59
|
+
}
|
60
|
+
}.to_json
|
61
|
+
}
|
62
|
+
response = HTTParty.post(configuration.auth_uri, options)
|
63
|
+
check_response(response)
|
64
|
+
@@token = response["response"]
|
65
|
+
end
|
66
|
+
|
67
|
+
def reset_token
|
68
|
+
@@token = false
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def configuration
|
74
|
+
BrightpearlApi.configuration
|
75
|
+
end
|
76
|
+
|
77
|
+
def check_response(response)
|
78
|
+
if(!response['errors'].blank?)
|
79
|
+
reset_token
|
80
|
+
raise BrightpearlException, "#{response.to_json}"
|
81
|
+
end
|
82
|
+
if (response['response'].is_a? String) && (response['response'].include? 'Not authenticated')
|
83
|
+
raise AuthException, "#{response.to_json}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module BrightpearlApi
|
4
|
+
class Configuration
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
attr_accessor :email, :password, :version, :datacenter, :account
|
8
|
+
|
9
|
+
def self.instance
|
10
|
+
@@instance ||= new
|
11
|
+
end
|
12
|
+
|
13
|
+
def init(args = {})
|
14
|
+
@email = default_email
|
15
|
+
@password = default_password
|
16
|
+
@version = default_version
|
17
|
+
@datacenter = default_datacenter
|
18
|
+
@account = default_account
|
19
|
+
args.each_pair do |option, value|
|
20
|
+
self.send("#{option}=", value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid?
|
25
|
+
result = true
|
26
|
+
[:email, :password, :version, :datacenter, :account].each do |value|
|
27
|
+
result = false if self.send(value).blank?
|
28
|
+
end
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
def uri(path)
|
33
|
+
"https://" + @datacenter + ".brightpearl.com/" + @version + "/" + @account + path
|
34
|
+
end
|
35
|
+
|
36
|
+
def auth_uri
|
37
|
+
uri('/authorise').sub("/" + @version, "")
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def default_email
|
42
|
+
ENV['BRIGHTPEARL_EMAIL']
|
43
|
+
end
|
44
|
+
|
45
|
+
def default_password
|
46
|
+
ENV['BRIGHTPEARL_PASSWORD']
|
47
|
+
end
|
48
|
+
|
49
|
+
def default_version
|
50
|
+
ENV['BRIGHTPEARL_VERSION']
|
51
|
+
end
|
52
|
+
|
53
|
+
def default_datacenter
|
54
|
+
ENV['BRIGHTPEARL_DATACENTER']
|
55
|
+
end
|
56
|
+
|
57
|
+
def default_account
|
58
|
+
ENV['BRIGHTPEARL_ACCOUNT']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'brightpearl_api/services/contact'
|
2
|
+
require 'brightpearl_api/services/order'
|
3
|
+
require 'brightpearl_api/services/product'
|
4
|
+
require 'brightpearl_api/services/warehouse'
|
5
|
+
|
6
|
+
module BrightpearlApi
|
7
|
+
class Service
|
8
|
+
include Contact
|
9
|
+
include Order
|
10
|
+
include Product
|
11
|
+
include Warehouse
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
raise BrightpearlException, "Configuration is invalid" unless Configuration.instance.valid?
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(type, path, data = {})
|
18
|
+
Client.instance.call(type, path, data)
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_idset(idset)
|
22
|
+
id_set = nil
|
23
|
+
case idset
|
24
|
+
when Range
|
25
|
+
id_set = "#{idset.min.to_int}-#{idset.max.to_int}"
|
26
|
+
when Array
|
27
|
+
id_set = idset.collect{ |x| x.to_int }.join(',')
|
28
|
+
else
|
29
|
+
id_set = idset.to_int
|
30
|
+
end
|
31
|
+
id_set
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_resource(service, resource)
|
35
|
+
body = {}
|
36
|
+
yield(body)
|
37
|
+
call(:post, "/#{service}-service/#{resource}/", body)
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_resource(service, resource, idset = nil)
|
41
|
+
if !idset.nil?
|
42
|
+
id_set = parse_idset(idset)
|
43
|
+
call(:get, "/#{service}-service/#{resource}/#{id_set}")
|
44
|
+
else
|
45
|
+
call(:get, "/#{service}-service/#{resource}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def update_resource(service, resource, resource_id)
|
50
|
+
body = {}
|
51
|
+
yield(body)
|
52
|
+
call(:put, "/#{service}-service/#{resource}/#{resource_id.to_int}", body)
|
53
|
+
end
|
54
|
+
|
55
|
+
def delete_resource(service, resource, resource_id)
|
56
|
+
call(:delete, "/#{service}-service/#{resource}/#{resource_id.to_int}")
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_resource_range(service, resource, idset = nil)
|
60
|
+
if !idset.nil?
|
61
|
+
id_set = parse_idset(idset)
|
62
|
+
call(:options, "/#{service}-service/#{resource}/#{id_set}")
|
63
|
+
else
|
64
|
+
call(:options, "/#{service}-service/#{resource}")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module BrightpearlApi
|
2
|
+
class Service
|
3
|
+
module Contact
|
4
|
+
def self.included(klass)
|
5
|
+
klass.class_eval do
|
6
|
+
def contact_search
|
7
|
+
# TODO
|
8
|
+
end
|
9
|
+
|
10
|
+
def associate_tag(idset, tag_id)
|
11
|
+
id_set = parse_idset(idset)
|
12
|
+
call(:post, "/contact-service/contact/#{id_set}/tag/#{tag_id.to_int}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module BrightpearlApi
|
2
|
+
class Service
|
3
|
+
module Order
|
4
|
+
def self.included(klass)
|
5
|
+
klass.class_eval do
|
6
|
+
def order_search
|
7
|
+
# TODO
|
8
|
+
end
|
9
|
+
|
10
|
+
def order_acknowledgement(order_id, reference)
|
11
|
+
body = {
|
12
|
+
reference: "#{reference}"
|
13
|
+
}
|
14
|
+
call(:put, "/order-service/order/#{order_id.to_int}/acknowledgement", body)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_order_note(order_id)
|
18
|
+
body = {}
|
19
|
+
yield(body)
|
20
|
+
call(:post, "/order-service/order/#{order_id.to_int}/note", body)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_order_row(order_id, row_id)
|
24
|
+
call(:get, "/order-service/order/#{order_id.to_int}/row/#{row_id.to_int}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_order_row(order_id)
|
28
|
+
body = {}
|
29
|
+
yield(body)
|
30
|
+
call(:post, "/order-service/order/#{order_id.to_int}/row", body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def update_order_row(order_id, row_id)
|
34
|
+
body = {}
|
35
|
+
yield(body)
|
36
|
+
call(:put, "/order-service/order/#{order_id.to_int}/row/#{row_id.to_int}", body)
|
37
|
+
end
|
38
|
+
|
39
|
+
def update_order_status(order_id)
|
40
|
+
body = {}
|
41
|
+
yield(body)
|
42
|
+
call(:put, "/order-service/order/#{order_id.to_int}/status", body)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module BrightpearlApi
|
2
|
+
class Service
|
3
|
+
module Product
|
4
|
+
def self.included(klass)
|
5
|
+
klass.class_eval do
|
6
|
+
def create_brand(name, description)
|
7
|
+
body = {
|
8
|
+
name: name,
|
9
|
+
description: description
|
10
|
+
}
|
11
|
+
call(:post, "/product-service/brand/", body)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_category(name, parentId = 0)
|
15
|
+
body = {
|
16
|
+
name: name,
|
17
|
+
parentId: parentId
|
18
|
+
}
|
19
|
+
call(:post, "/product-service/brightpearl-category/", body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_option_value(idset)
|
23
|
+
id_set = parse_idset(idset)
|
24
|
+
call(:get, "/product-service/option/#{id_set}/value")
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_option_value(option_id, optionValueName)
|
28
|
+
body = {
|
29
|
+
optionValueName: optionValueName
|
30
|
+
}
|
31
|
+
call(:post, "/product-service/option/#{option_id.to_int}/value", body)
|
32
|
+
end
|
33
|
+
|
34
|
+
def product_search
|
35
|
+
# TODO
|
36
|
+
end
|
37
|
+
|
38
|
+
def update_product_price(product_id)
|
39
|
+
body = {}
|
40
|
+
yield(body)
|
41
|
+
call(:put, "/product-service/product-service/#{product_id.to_int}/price-list", body)
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_product_type(name)
|
45
|
+
body = {
|
46
|
+
name: name
|
47
|
+
}
|
48
|
+
call(:post, "/product-service/product-type/", body)
|
49
|
+
end
|
50
|
+
|
51
|
+
def product_type_association(product_id_set, option_id_set)
|
52
|
+
pid = parse_idset(product_id_set)
|
53
|
+
oid = parse_idset(option_id_set)
|
54
|
+
call(:post, "/product-service/product-type/#{pid}/option-association/#{oid}")
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_season(name, description)
|
58
|
+
body = {
|
59
|
+
name: name,
|
60
|
+
description: description
|
61
|
+
}
|
62
|
+
call(:post, "/product-service/season/", body)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module BrightpearlApi
|
2
|
+
class Service
|
3
|
+
module Warehouse
|
4
|
+
def self.included(klass)
|
5
|
+
klass.class_eval do
|
6
|
+
def asset_value_correction(warehouse_id)
|
7
|
+
body = {}
|
8
|
+
yield(body)
|
9
|
+
call(:post, "/warehouse-service/warehouse/#{warehouse_id.to_int}/asset-value-correction", body)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_default_location(warehouse_id)
|
13
|
+
call(:get, "/warehouse-service/warehouse/#{warehouse_id.to_int}/location/default")
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_quarantine_location(warehouse_id)
|
17
|
+
call(:get, "/warehouse-service/warehouse/#{warehouse_id.to_int}/location/quarantine")
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_location(warehouse_id, location_id_set = nil)
|
21
|
+
lid = location_id_set.nil? ? "" : parse_idset(location_id_set)
|
22
|
+
call(:get, "/warehouse-service/warehouse/#{warehouse_id.to_int}/location/#{lid}")
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_location(warehouse_id)
|
26
|
+
body = {}
|
27
|
+
yield(body)
|
28
|
+
call(:post, "/warehouse-service/warehouse/#{warehouse_id.to_int}/location/", body)
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete_location(warehouse_id, location_id)
|
32
|
+
call(:delete, "/warehouse-service/warehouse/#{warehouse_id.to_int}/location/#{location_id.to_int}")
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_drop_ship_note(sales_id_set, drop_ship_note_id_set = nil)
|
36
|
+
sid = parse_idset(sales_id_set)
|
37
|
+
did = drop_ship_note_id_set.nil? ? "" : parse_idset(drop_ship_note_id_set)
|
38
|
+
call(:get, "/warehouse-service/order/#{sid}/goods-note/drop-ship/#{did}")
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_drop_ship_note(sales_order_id)
|
42
|
+
body = {}
|
43
|
+
yield(body)
|
44
|
+
call(:post, "/warehouse-service/order/#{sales_order_id.to_int}/goods-note/drop-ship", body)
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_drop_ship_note_event(drop_ship_note_id)
|
48
|
+
body = {}
|
49
|
+
yield(body)
|
50
|
+
call(:post, "/warehouse-service/goods-note/drop-ship/#{drop_ship_note_id.to_int}/event", body)
|
51
|
+
end
|
52
|
+
|
53
|
+
def goods_in_note_correction(batch_id)
|
54
|
+
body = {}
|
55
|
+
yield(body)
|
56
|
+
call(:post, "/warehouse-service/goods-note/goods-in/#{batch_id.to_int}/correction", body)
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_goods_in_note(order_id)
|
60
|
+
body = {}
|
61
|
+
yield(body)
|
62
|
+
call(:post, "/warehouse-service/order/#{order_id.to_int}/goods-note/goods-in", body)
|
63
|
+
end
|
64
|
+
|
65
|
+
def delete_goods_in_note(goods_in_note_id)
|
66
|
+
call(:delete, "/warehouse-service/goods-note/goods-in/#{goods_in_note_id.to_int}")
|
67
|
+
end
|
68
|
+
|
69
|
+
def delete_goods_out_note(order_id, goods_out_note_id)
|
70
|
+
call(:delete, "/warehouse-service/order/#{order_id.to_int}/goods-note/goods-out/#{goods_out_note_id.to_int}")
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_goods_out_note(order_id_set, goods_out_note_id_set = nil)
|
74
|
+
oid = parse_idset(order_id_set)
|
75
|
+
gid = goods_out_note_id.nil? ? "" : parse_idset(goods_out_note_id_set)
|
76
|
+
call(:get, "/warehouse-service/order/#{oid}/goods-note/goods-out/#{gid}")
|
77
|
+
end
|
78
|
+
|
79
|
+
def create_goods_out_note(order_id)
|
80
|
+
body = {}
|
81
|
+
yield(body)
|
82
|
+
call(:post, "/warehouse-service/order/#{order_id.to_int}/goods-note/goods-out", body)
|
83
|
+
end
|
84
|
+
|
85
|
+
def update_goods_out_note(goods_out_note_id)
|
86
|
+
body = {}
|
87
|
+
yield(body)
|
88
|
+
call(:put, "/warehouse-service/goods-note/goods-out/#{goods_out_note_id.to_int}", body)
|
89
|
+
end
|
90
|
+
|
91
|
+
def create_goods_out_note_event(goods_out_note_id)
|
92
|
+
body = {}
|
93
|
+
yield(body)
|
94
|
+
call(:post, "/warehouse-service/goods-note/goods-out/#{goods_out_note_id.to_int}/event", body)
|
95
|
+
end
|
96
|
+
|
97
|
+
def create_internal_transfer(warehouse_id)
|
98
|
+
body = {}
|
99
|
+
yield(body)
|
100
|
+
call(:post, "/warehouse-service/warehouse/#{warehouse_id.to_int}/internal-transfer", body)
|
101
|
+
end
|
102
|
+
|
103
|
+
def quarantine_release(warehouse_id)
|
104
|
+
body = {}
|
105
|
+
yield(body)
|
106
|
+
call(:post, "/warehouse-service/warehouse/#{warehouse_id.to_int}/quarantine/release", body)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "active_support/all"
|
2
|
+
require "brightpearl_api/version"
|
3
|
+
require 'brightpearl_api/configuration'
|
4
|
+
require 'brightpearl_api/client'
|
5
|
+
require 'brightpearl_api/service'
|
6
|
+
|
7
|
+
module BrightpearlApi
|
8
|
+
class << self
|
9
|
+
attr_accessor :configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
class AuthException < StandardError; end
|
13
|
+
class BrightpearlException < StandardError; end
|
14
|
+
|
15
|
+
def self.configure
|
16
|
+
Configuration.instance.init
|
17
|
+
self.configuration ||= Configuration.instance
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brightpearl_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kunwar Aditya Raghuwanshi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Gem for connecting to your brightpearl account via their API
|
98
|
+
email:
|
99
|
+
- adi.version1@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- .travis.yml
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- brightpearl_api.gemspec
|
112
|
+
- lib/brightpearl_api.rb
|
113
|
+
- lib/brightpearl_api/client.rb
|
114
|
+
- lib/brightpearl_api/configuration.rb
|
115
|
+
- lib/brightpearl_api/service.rb
|
116
|
+
- lib/brightpearl_api/services/contact.rb
|
117
|
+
- lib/brightpearl_api/services/order.rb
|
118
|
+
- lib/brightpearl_api/services/product.rb
|
119
|
+
- lib/brightpearl_api/services/warehouse.rb
|
120
|
+
- lib/brightpearl_api/version.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
homepage: http://github.com/kitwalker12/brightpearl_api
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.2.2
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Brightpearl API Library
|
146
|
+
test_files:
|
147
|
+
- spec/spec_helper.rb
|