pixi_client 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -2
- data/lib/pixi_client.rb +2 -0
- data/lib/pixi_client/configuration.rb +7 -1
- data/lib/pixi_client/error.rb +4 -0
- data/lib/pixi_client/railtie.rb +11 -0
- data/lib/pixi_client/requests.rb +1 -0
- data/lib/pixi_client/requests/base.rb +3 -1
- data/lib/pixi_client/requests/get_item_stock.rb +23 -0
- data/lib/pixi_client/version.rb +1 -1
- data/lib/tasks/pixi_client.rake +24 -0
- data/spec/lib/pixi_client/configuration_spec.rb +44 -4
- data/spec/lib/pixi_client/error_spec.rb +15 -0
- data/spec/lib/pixi_client/requests/get_item_stock_spec.rb +47 -0
- data/spec/lib/pixi_client_spec.rb +2 -0
- metadata +11 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79ab279f8283d407ffc3a8f93124c1f52b6e2bfb
|
4
|
+
data.tar.gz: 246c56375ce95f560cecd12aa669aacfc9be98ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c647a3c2a06b0c04589df953e2e4169a50e44b71c16f8a2c1520ed246a43c04435300de8007b137324bf3738c65c6d4556ebefedeef868a551e7e58a8d25969
|
7
|
+
data.tar.gz: d134a39d8621b889ee016cb458f4697efb4e2761254c308cc2f3a3a2e31e0fce72512a4b6d0d9542439eeb1bca4c3cdb90116752130ec1fd7fd9f45a48b82437
|
data/README.md
CHANGED
@@ -46,9 +46,23 @@ Or install it yourself as:
|
|
46
46
|
|
47
47
|
### Configuration
|
48
48
|
|
49
|
-
#### Rails
|
49
|
+
#### Rails (with cached wsdl document)
|
50
50
|
|
51
|
-
|
51
|
+
|
52
|
+
run ```bundle exec rake pixi_client:download_wsdl``` in your Rails app root and add the following initializer to the project.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
PixiClient.configure do |config|
|
56
|
+
config.endpoint = <your_pixi_endpoing_url>
|
57
|
+
config.username = <your_pixi_username>
|
58
|
+
config.password = <your_pixi_password>
|
59
|
+
config.wsdl = "#{Rails.root}/config/pixi_client.wsdl"
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
#### Rails (with remote wsdl document)
|
64
|
+
|
65
|
+
If you don't want to cache the ```wsdl``` you can omit that variable in the initializer. The gem will then download the wdsl document at each request and your configuration will look like:
|
52
66
|
|
53
67
|
```ruby
|
54
68
|
PixiClient.configure do |config|
|
@@ -58,6 +72,7 @@ PixiClient.configure do |config|
|
|
58
72
|
end
|
59
73
|
```
|
60
74
|
|
75
|
+
|
61
76
|
### Example of usage
|
62
77
|
|
63
78
|
To have a list of the implemented requests, have a look to the lib/requests folder.
|
data/lib/pixi_client.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'pixi_client/version'
|
2
|
+
require 'pixi_client/error'
|
2
3
|
require 'pixi_client/configuration'
|
3
4
|
require 'pixi_client/response_parser'
|
4
5
|
require 'pixi_client/response'
|
5
6
|
require 'pixi_client/requests'
|
7
|
+
require 'pixi_client/railtie' if defined?(Rails)
|
6
8
|
|
7
9
|
module PixiClient
|
8
10
|
class << self
|
@@ -1,5 +1,11 @@
|
|
1
1
|
module PixiClient
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :endpoint, :username, :password
|
3
|
+
attr_accessor :endpoint, :username, :password, :wsdl
|
4
|
+
|
5
|
+
def wsdl_document
|
6
|
+
wsdl || endpoint || raise(PixiClient::Error.new("A 'wsdl' or 'endpoint' must be configured"))
|
7
|
+
wsdl ? wsdl : endpoint + '?wsdl'
|
8
|
+
end
|
9
|
+
|
4
10
|
end
|
5
11
|
end
|
data/lib/pixi_client/requests.rb
CHANGED
@@ -9,6 +9,7 @@ require 'pixi_client/requests/get_invoice'
|
|
9
9
|
require 'pixi_client/requests/get_item_info'
|
10
10
|
require 'pixi_client/requests/get_order_comments'
|
11
11
|
require 'pixi_client/requests/set_stock_multiple'
|
12
|
+
require 'pixi_client/requests/get_item_stock'
|
12
13
|
require 'pixi_client/requests/get_item_stock_bins'
|
13
14
|
require 'pixi_client/requests/get_items_info'
|
14
15
|
require 'pixi_client/requests/get_items_on_stock_bin'
|
@@ -15,7 +15,9 @@ module PixiClient
|
|
15
15
|
|
16
16
|
def client
|
17
17
|
@client ||= Savon.client(
|
18
|
-
wsdl: PixiClient.configuration.
|
18
|
+
wsdl: PixiClient.configuration.wsdl_document,
|
19
|
+
open_timeout: 300,
|
20
|
+
read_timeout: 300,
|
19
21
|
ssl_verify_mode: :none,
|
20
22
|
basic_auth: [PixiClient.configuration.username, PixiClient.configuration.password]
|
21
23
|
)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PixiClient
|
2
|
+
module Requests
|
3
|
+
class GetItemStock < Base
|
4
|
+
include Itemable
|
5
|
+
|
6
|
+
attr_accessor :item_id_key, :item_id
|
7
|
+
|
8
|
+
def initialize(item_id_key, item_id)
|
9
|
+
self.item_id_key = item_id_key
|
10
|
+
self.item_id = item_id
|
11
|
+
end
|
12
|
+
|
13
|
+
def message
|
14
|
+
{ item_id_key_to_param => item_id, 'LocationStock' => 1}
|
15
|
+
end
|
16
|
+
|
17
|
+
def api_method
|
18
|
+
:pixi_get_item_stock
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
data/lib/pixi_client/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
namespace :pixi_client do
|
5
|
+
desc 'Create the file config/pixi_client.wsdl'
|
6
|
+
task :download_wsdl do
|
7
|
+
config = YAML.load_file(File.join([Rails.root, 'config', 'pixi.yml']))[Rails.env]
|
8
|
+
|
9
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE # needed due to the context
|
10
|
+
|
11
|
+
File.open('config/pixi_client.wsdl', "wb") do |wsdl_file|
|
12
|
+
# the following "open" is provided by open-uri
|
13
|
+
open(config['url'] + '?wsdl',
|
14
|
+
http_basic_authentication: [config['username'], config['password']]) do |document|
|
15
|
+
wsdl_file.write(document.read)
|
16
|
+
puts 'file downloaded in config/pixi_client.wsdl'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
task :install => [:download_wsdl] do
|
23
|
+
end
|
24
|
+
end
|
@@ -11,6 +11,12 @@ describe PixiClient::Configuration do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
describe '#wsdl' do
|
15
|
+
it 'should be nil' do
|
16
|
+
expect(subject.wsdl).to be_nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
14
20
|
describe '#username' do
|
15
21
|
it 'should be nil' do
|
16
22
|
expect(subject.username).to be_nil
|
@@ -22,12 +28,39 @@ describe PixiClient::Configuration do
|
|
22
28
|
expect(subject.password).to be_nil
|
23
29
|
end
|
24
30
|
end
|
31
|
+
|
32
|
+
describe '#wsdl_document' do
|
33
|
+
it 'should raise an error' do
|
34
|
+
expect {
|
35
|
+
subject.wsdl_document
|
36
|
+
}.to raise_error(PixiClient::Error, "A 'wsdl' or 'endpoint' must be configured")
|
37
|
+
end
|
38
|
+
end
|
25
39
|
end
|
26
40
|
|
27
|
-
describe '#
|
28
|
-
|
29
|
-
|
30
|
-
|
41
|
+
describe '#wsdl_document' do
|
42
|
+
context 'when and endpoint is set' do
|
43
|
+
it 'returns the remote wsdl document' do
|
44
|
+
subject.endpoint = 'endpoint_url'
|
45
|
+
subject.wsdl = nil
|
46
|
+
expect(subject.wsdl_document).to eq('endpoint_url?wsdl')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
context 'when and wsdl file is set' do
|
50
|
+
it 'returns the local wsdl document' do
|
51
|
+
subject.endpoint = nil
|
52
|
+
subject.wsdl = 'path/to/endpoint.xml'
|
53
|
+
expect(subject.wsdl_document).to eq('path/to/endpoint.xml')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
context 'when no wsdl or file is set' do
|
57
|
+
it 'raises an error' do
|
58
|
+
subject.endpoint = nil
|
59
|
+
subject.wsdl = nil
|
60
|
+
expect {
|
61
|
+
subject.wsdl_document
|
62
|
+
}.to raise_error(PixiClient::Error, "A 'wsdl' or 'endpoint' must be configured")
|
63
|
+
end
|
31
64
|
end
|
32
65
|
end
|
33
66
|
|
@@ -38,6 +71,13 @@ describe PixiClient::Configuration do
|
|
38
71
|
end
|
39
72
|
end
|
40
73
|
|
74
|
+
describe '#wsdl=' do
|
75
|
+
it 'sets the wsdl' do
|
76
|
+
subject.wsdl = 'wsdl_set'
|
77
|
+
expect(subject.wsdl).to eq 'wsdl_set'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
41
81
|
describe '#password=' do
|
42
82
|
it 'sets the password' do
|
43
83
|
subject.password = 'random-password'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PixiClient::Error do
|
4
|
+
|
5
|
+
subject { PixiClient::Error.new }
|
6
|
+
|
7
|
+
it 'should accept a message' do
|
8
|
+
begin
|
9
|
+
raise PixiClient::Error.new('Something happend')
|
10
|
+
rescue => e
|
11
|
+
expect(e.class).to eq(PixiClient::Error)
|
12
|
+
expect(e.message).to eq('Something happend')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PixiClient::Requests::GetItemStock do
|
4
|
+
|
5
|
+
subject { PixiClient::Requests::GetItemStock.new(:ean, 1) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
set_default_config
|
9
|
+
end
|
10
|
+
|
11
|
+
it { is_expected.to be_a_kind_of(PixiClient::Requests::Base) }
|
12
|
+
|
13
|
+
describe '#api_method' do
|
14
|
+
it 'should return :pixi_get_item_stock' do
|
15
|
+
expect(subject.api_method).to eq :pixi_get_item_stock
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'call behaviour' do
|
20
|
+
let(:expected_response) { double(body: { pixi_get_item_stock_response: { pixi_get_item_stock_result: sql_row_set_response_mock } }) }
|
21
|
+
let(:double_client) { double }
|
22
|
+
|
23
|
+
before do
|
24
|
+
allow(subject).to receive(:client).and_return(double_client)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should call the client with the appropriate parameters' do
|
28
|
+
expect(double_client).to receive(:call)
|
29
|
+
.with(:pixi_get_item_stock, attributes: { xmlns: PixiClient.configuration.endpoint }, message: { 'EAN' => 1, "LocationStock"=>1 })
|
30
|
+
.and_return(expected_response)
|
31
|
+
|
32
|
+
subject.call
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should instanciate an instance of Response with the response body' do
|
36
|
+
expect(double_client).to receive(:call).and_return(expected_response)
|
37
|
+
expect(PixiClient::Response).to receive(:new).with(:pixi_get_item_stock, expected_response.body)
|
38
|
+
subject.call
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should return an instance of Response' do
|
42
|
+
expect(double_client).to receive(:call).and_return(expected_response)
|
43
|
+
expect(subject.call).to be_an_instance_of(PixiClient::Response)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -6,6 +6,7 @@ describe PixiClient do
|
|
6
6
|
configuration.endpoint = 'endpoint'
|
7
7
|
configuration.username = 'username'
|
8
8
|
configuration.password = 'random-password'
|
9
|
+
configuration.wsdl = 'some/path/somewhere.wsdl'
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
@@ -14,6 +15,7 @@ describe PixiClient do
|
|
14
15
|
expect(PixiClient.configuration.endpoint).to eq 'endpoint'
|
15
16
|
expect(PixiClient.configuration.username).to eq 'username'
|
16
17
|
expect(PixiClient.configuration.password).to eq 'random-password'
|
18
|
+
expect(PixiClient.configuration.wsdl).to eq 'some/path/somewhere.wsdl'
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixi_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- heragu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: savon
|
@@ -180,6 +180,8 @@ files:
|
|
180
180
|
- Rakefile
|
181
181
|
- lib/pixi_client.rb
|
182
182
|
- lib/pixi_client/configuration.rb
|
183
|
+
- lib/pixi_client/error.rb
|
184
|
+
- lib/pixi_client/railtie.rb
|
183
185
|
- lib/pixi_client/requests.rb
|
184
186
|
- lib/pixi_client/requests/add_comment_to_order.rb
|
185
187
|
- lib/pixi_client/requests/base.rb
|
@@ -189,6 +191,7 @@ files:
|
|
189
191
|
- lib/pixi_client/requests/get_changed_items.rb
|
190
192
|
- lib/pixi_client/requests/get_invoice.rb
|
191
193
|
- lib/pixi_client/requests/get_item_info.rb
|
194
|
+
- lib/pixi_client/requests/get_item_stock.rb
|
192
195
|
- lib/pixi_client/requests/get_item_stock_bins.rb
|
193
196
|
- lib/pixi_client/requests/get_items_info.rb
|
194
197
|
- lib/pixi_client/requests/get_items_on_stock_bin.rb
|
@@ -210,11 +213,13 @@ files:
|
|
210
213
|
- lib/pixi_client/response.rb
|
211
214
|
- lib/pixi_client/response_parser.rb
|
212
215
|
- lib/pixi_client/version.rb
|
216
|
+
- lib/tasks/pixi_client.rake
|
213
217
|
- pixi_client.gemspec
|
214
218
|
- spec/fixtures/get_order_nr_external_by_box_nr.xml
|
215
219
|
- spec/fixtures/pixi_get_changed_item_stock.xml
|
216
220
|
- spec/integration/pixi_get_changed_item_stock_spec.rb
|
217
221
|
- spec/lib/pixi_client/configuration_spec.rb
|
222
|
+
- spec/lib/pixi_client/error_spec.rb
|
218
223
|
- spec/lib/pixi_client/requests/add_comment_to_order_spec.rb
|
219
224
|
- spec/lib/pixi_client/requests/cancel_order_line_spec.rb
|
220
225
|
- spec/lib/pixi_client/requests/cancel_order_spec.rb
|
@@ -223,6 +228,7 @@ files:
|
|
223
228
|
- spec/lib/pixi_client/requests/get_invoice_spec.rb
|
224
229
|
- spec/lib/pixi_client/requests/get_item_info_spec.rb
|
225
230
|
- spec/lib/pixi_client/requests/get_item_stock_bins_spec.rb
|
231
|
+
- spec/lib/pixi_client/requests/get_item_stock_spec.rb
|
226
232
|
- spec/lib/pixi_client/requests/get_items_info_spec.rb
|
227
233
|
- spec/lib/pixi_client/requests/get_items_on_stock_bin_spec.rb
|
228
234
|
- spec/lib/pixi_client/requests/get_items_stock_history_spec.rb
|
@@ -265,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
265
271
|
version: '0'
|
266
272
|
requirements: []
|
267
273
|
rubyforge_project:
|
268
|
-
rubygems_version: 2.
|
274
|
+
rubygems_version: 2.5.1
|
269
275
|
signing_key:
|
270
276
|
specification_version: 4
|
271
277
|
summary: SOAP Pixi* API client
|
@@ -274,6 +280,7 @@ test_files:
|
|
274
280
|
- spec/fixtures/pixi_get_changed_item_stock.xml
|
275
281
|
- spec/integration/pixi_get_changed_item_stock_spec.rb
|
276
282
|
- spec/lib/pixi_client/configuration_spec.rb
|
283
|
+
- spec/lib/pixi_client/error_spec.rb
|
277
284
|
- spec/lib/pixi_client/requests/add_comment_to_order_spec.rb
|
278
285
|
- spec/lib/pixi_client/requests/cancel_order_line_spec.rb
|
279
286
|
- spec/lib/pixi_client/requests/cancel_order_spec.rb
|
@@ -282,6 +289,7 @@ test_files:
|
|
282
289
|
- spec/lib/pixi_client/requests/get_invoice_spec.rb
|
283
290
|
- spec/lib/pixi_client/requests/get_item_info_spec.rb
|
284
291
|
- spec/lib/pixi_client/requests/get_item_stock_bins_spec.rb
|
292
|
+
- spec/lib/pixi_client/requests/get_item_stock_spec.rb
|
285
293
|
- spec/lib/pixi_client/requests/get_items_info_spec.rb
|
286
294
|
- spec/lib/pixi_client/requests/get_items_on_stock_bin_spec.rb
|
287
295
|
- spec/lib/pixi_client/requests/get_items_stock_history_spec.rb
|