dpd_api 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/dpd_api.gemspec +2 -2
- data/lib/dpd_api/base.rb +5 -2
- data/lib/dpd_api/client/response.rb +18 -7
- data/lib/dpd_api/configuration.rb +3 -1
- data/lib/dpd_api/debug/inspector.rb +18 -0
- data/lib/dpd_api/version.rb +1 -1
- data/spec/lib/dpd_api/geography_spec.rb +2 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/support/rspec_helper.rb +5 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: babe69db95fe1be702cd44dee772659e0a13eeaf
|
4
|
+
data.tar.gz: 4c43ed756134fb57e1f290693a0ee24155d9f659
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 618d8cabd267b33ed0c85ca3fdddf73d2f2c5116328b536528f77e2a90130f7b3cf806438e9318267365feb986c4cd0cd71c0f52bfab5d552c9ad08147220d92
|
7
|
+
data.tar.gz: 4e4db970d67dc2cb6393e44c846a867b704218f62005242e3066c054b83519336c75d662cddbf447e496ab00eb90df365f9f676e0280d5bc0c3302c66734f58b
|
data/README.md
CHANGED
@@ -24,6 +24,7 @@ DpdApi.configure do |config|
|
|
24
24
|
config.client_key = 'ASD7686ASD76786786786786AASD'
|
25
25
|
config.client_number = '123456789'
|
26
26
|
config.base_url = Rails.env.production? ? 'http://ws.dpd.ru' : 'http://wstest.dpd.ru'
|
27
|
+
config.debug = Rails.env.production? ? false : true
|
27
28
|
end
|
28
29
|
```
|
29
30
|
|
data/dpd_api.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = DpdApi::VERSION
|
9
9
|
spec.authors = ["Ponomarev Nikolay"]
|
10
10
|
spec.email = ["itsnikolay@gmail.com"]
|
11
|
-
spec.summary = %q{Ruby
|
12
|
-
spec.description = %q{Ruby
|
11
|
+
spec.summary = %q{Ruby / Rails wrapper for Dpd's SOAP API}
|
12
|
+
spec.description = %q{Ruby / Rails wrapper for Dpd's SOAP API}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/lib/dpd_api/base.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'dpd_api/client/response'
|
3
|
+
require 'dpd_api/debug/inspector'
|
3
4
|
|
4
5
|
module DpdApi
|
5
6
|
class Base
|
@@ -11,7 +12,9 @@ module DpdApi
|
|
11
12
|
protected
|
12
13
|
|
13
14
|
def client
|
14
|
-
Client::Response.new(self.url)
|
15
|
+
@client ||= Client::Response.new(self.url)
|
16
|
+
Debug::Inspector.new(@client) if DpdApi.configuration.debug
|
17
|
+
@client
|
15
18
|
end
|
16
19
|
|
17
20
|
def response(method, params = {}, options = {})
|
@@ -1,24 +1,34 @@
|
|
1
|
-
require
|
1
|
+
require 'savon'
|
2
|
+
require 'observer'
|
2
3
|
|
3
4
|
module DpdApi
|
4
5
|
module Client
|
5
6
|
class Response
|
7
|
+
include Observable
|
8
|
+
|
6
9
|
def initialize(url)
|
7
10
|
@url = url
|
8
11
|
@client = Savon.client(wsdl: @url)
|
9
12
|
end
|
10
13
|
|
11
14
|
def response(method, params = {}, options = {})
|
15
|
+
changed
|
12
16
|
builder = ResourceBuilder.new(@client, method, params, options)
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
result = begin
|
18
|
+
builder.resources
|
19
|
+
rescue Savon::SOAPFault => error
|
20
|
+
{ errors: error.to_s }
|
21
|
+
end
|
22
|
+
notify_observers(@url, builder.merged_params, builder.response_body, result)
|
23
|
+
result
|
16
24
|
end
|
17
25
|
|
18
26
|
private
|
19
27
|
|
20
28
|
class ResourceBuilder
|
21
|
-
|
29
|
+
attr_reader :merged_params, :response_body
|
30
|
+
|
31
|
+
def initialize(client, method, params = {}, options = {})
|
22
32
|
@client = client
|
23
33
|
@method = method
|
24
34
|
@namespace = options.delete(:namespace)
|
@@ -27,13 +37,14 @@ module DpdApi
|
|
27
37
|
|
28
38
|
def resources
|
29
39
|
namespace = "#{@method}_response".to_sym
|
30
|
-
|
40
|
+
@response_body = response.body
|
41
|
+
resources = @response_body[namespace][:return]
|
31
42
|
resources.is_a?(Array) ? resources : [] << resources
|
32
43
|
end
|
33
44
|
|
34
45
|
private
|
35
46
|
|
36
|
-
def merge_auth_params(params)
|
47
|
+
def merge_auth_params(params = {})
|
37
48
|
auth_params = DpdApi.configuration.auth_params.clone
|
38
49
|
auth_params.deep_merge!(params)
|
39
50
|
end
|
@@ -13,7 +13,8 @@ module DpdApi
|
|
13
13
|
class Configuration
|
14
14
|
attr_accessor :client_key,
|
15
15
|
:client_number,
|
16
|
-
:base_url
|
16
|
+
:base_url,
|
17
|
+
:debug
|
17
18
|
|
18
19
|
attr_reader :auth_params
|
19
20
|
|
@@ -21,6 +22,7 @@ module DpdApi
|
|
21
22
|
@client_key = '123'
|
22
23
|
@client_number = '234'
|
23
24
|
@base_url = 'http://wstest.dpd.ru'
|
25
|
+
@debug = false
|
24
26
|
end
|
25
27
|
|
26
28
|
def auth_params
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'observer'
|
2
|
+
|
3
|
+
module Debug
|
4
|
+
class Inspector
|
5
|
+
def initialize(client)
|
6
|
+
client.add_observer(self)
|
7
|
+
end
|
8
|
+
|
9
|
+
def update(url, params, response_body, result)
|
10
|
+
p '--------------------------'
|
11
|
+
p "SENDING REQUEST TO: #{url}"
|
12
|
+
p "WITH PARAMS: #{params}"
|
13
|
+
p "GETTING RESPONSE: #{response_body}"
|
14
|
+
p "RESULT: #{result}"
|
15
|
+
p '--------------------------'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/dpd_api/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -4,9 +4,11 @@ require "codeclimate-test-reporter"
|
|
4
4
|
CodeClimate::TestReporter.start
|
5
5
|
|
6
6
|
require 'dpd_api'
|
7
|
-
require
|
7
|
+
require 'savon/mock/spec_helper'
|
8
|
+
require_relative 'support/rspec_helper'
|
8
9
|
|
9
10
|
RSpec.configure do |config|
|
10
11
|
config.filter_run focus: true
|
11
12
|
config.run_all_when_everything_filtered = true
|
13
|
+
config.include RspecHelper
|
12
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dpd_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ponomarev Nikolay
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Ruby
|
69
|
+
description: Ruby / Rails wrapper for Dpd's SOAP API
|
70
70
|
email:
|
71
71
|
- itsnikolay@gmail.com
|
72
72
|
executables: []
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/dpd_api/calculator.rb
|
87
87
|
- lib/dpd_api/client/response.rb
|
88
88
|
- lib/dpd_api/configuration.rb
|
89
|
+
- lib/dpd_api/debug/inspector.rb
|
89
90
|
- lib/dpd_api/geography.rb
|
90
91
|
- lib/dpd_api/label_print.rb
|
91
92
|
- lib/dpd_api/nl.rb
|
@@ -116,6 +117,7 @@ files:
|
|
116
117
|
- spec/lib/dpd_api/order_spec.rb
|
117
118
|
- spec/lib/dpd_api/tracing_spec.rb
|
118
119
|
- spec/spec_helper.rb
|
120
|
+
- spec/support/rspec_helper.rb
|
119
121
|
homepage: ''
|
120
122
|
licenses:
|
121
123
|
- MIT
|
@@ -139,7 +141,7 @@ rubyforge_project:
|
|
139
141
|
rubygems_version: 2.2.2
|
140
142
|
signing_key:
|
141
143
|
specification_version: 4
|
142
|
-
summary: Ruby
|
144
|
+
summary: Ruby / Rails wrapper for Dpd's SOAP API
|
143
145
|
test_files:
|
144
146
|
- spec/fixtures/dpd_api/calculator/service_cost.xml
|
145
147
|
- spec/fixtures/dpd_api/calculator/service_cost_by_parcels.xml
|
@@ -165,3 +167,4 @@ test_files:
|
|
165
167
|
- spec/lib/dpd_api/order_spec.rb
|
166
168
|
- spec/lib/dpd_api/tracing_spec.rb
|
167
169
|
- spec/spec_helper.rb
|
170
|
+
- spec/support/rspec_helper.rb
|