dpd_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +468 -0
  7. data/Rakefile +2 -0
  8. data/dpd_api.gemspec +26 -0
  9. data/lib/dpd_api/base.rb +36 -0
  10. data/lib/dpd_api/calculator.rb +21 -0
  11. data/lib/dpd_api/configuration.rb +33 -0
  12. data/lib/dpd_api/geography.rb +26 -0
  13. data/lib/dpd_api/label_print.rb +32 -0
  14. data/lib/dpd_api/nl.rb +32 -0
  15. data/lib/dpd_api/order.rb +56 -0
  16. data/lib/dpd_api/tracing.rb +26 -0
  17. data/lib/dpd_api/version.rb +3 -0
  18. data/lib/dpd_api.rb +14 -0
  19. data/spec/fixtures/dpd_api/calculator/service_cost.xml +55 -0
  20. data/spec/fixtures/dpd_api/calculator/service_cost_by_parcels.xml +55 -0
  21. data/spec/fixtures/dpd_api/calculator/service_cost_by_parcels_fault.xml +15 -0
  22. data/spec/fixtures/dpd_api/calculator/service_cost_fault.xml +15 -0
  23. data/spec/fixtures/dpd_api/geography/cities_cash_pay.xml +23 -0
  24. data/spec/fixtures/dpd_api/geography/parcel_shops.xml +39 -0
  25. data/spec/fixtures/dpd_api/geography/terminals_self_delivery.xml +35 -0
  26. data/spec/fixtures/dpd_api/order/add_parcels.xml +0 -0
  27. data/spec/fixtures/dpd_api/order/cancel_order.xml +11 -0
  28. data/spec/fixtures/dpd_api/order/create_address.xml +11 -0
  29. data/spec/fixtures/dpd_api/order/create_order.xml +14 -0
  30. data/spec/fixtures/dpd_api/order/invoice_file.xml +0 -0
  31. data/spec/fixtures/dpd_api/order/order_status.xml +12 -0
  32. data/spec/fixtures/dpd_api/order/remove_parcels.xml +0 -0
  33. data/spec/fixtures/dpd_api/order/update_address.xml +11 -0
  34. data/spec/fixtures/dpd_api/tracing/states_by_client_order.xml +0 -0
  35. data/spec/fixtures/dpd_api/tracing/states_by_client_parcel.xml +0 -0
  36. data/spec/fixtures/dpd_api/tracing/states_by_dpd_order.xml +0 -0
  37. data/spec/lib/dpd_api/calculator_spec.rb +99 -0
  38. data/spec/lib/dpd_api/configuration_spec.rb +23 -0
  39. data/spec/lib/dpd_api/geography_spec.rb +53 -0
  40. data/spec/lib/dpd_api/order_spec.rb +200 -0
  41. data/spec/lib/dpd_api/tracing_spec.rb +58 -0
  42. data/spec/spec_helper.rb +7 -0
  43. metadata +165 -0
data/lib/dpd_api/nl.rb ADDED
@@ -0,0 +1,32 @@
1
+ module DpdApi
2
+ class Nl < Base
3
+ # TODO: Implement namespace
4
+ class << self
5
+ def get_nl_amount(params = {})
6
+ method = :get_nl_amount
7
+ namespace = :arg0
8
+ response(method, params, namespace: namespace)
9
+ end
10
+
11
+ def get_nl_invoice(params = {})
12
+ method = :get_nl_invoice
13
+ namespace = :arg0
14
+ response(method, params, namespace: namespace)
15
+ end
16
+
17
+ def response(method, params = {}, namespace: nil)
18
+ params = @auth_params.clone.deep_merge!(params)
19
+ request = namespace ? { namespace => params } : params
20
+ response = @client.call(method, message: request)
21
+ namespace = "#{method}_response".to_sym
22
+ response.body[namespace][:return]
23
+ end
24
+
25
+ protected
26
+
27
+ def url
28
+ "#{DpdApi.configuration.base_url}/services/nl?wsdl"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,56 @@
1
+ module DpdApi
2
+ class Order < Base
3
+ class << self
4
+ def create_order(params = {})
5
+ method = :create_order
6
+ response(method, params)
7
+ end
8
+
9
+ def cancel_order(params = {})
10
+ method = :cancel_order
11
+ response(method, params)
12
+ end
13
+
14
+ def order_status(params = {})
15
+ method = :get_order_status
16
+ response(method, params)
17
+ end
18
+
19
+ def create_address(params = {})
20
+ method = :create_address
21
+ response(method, params)
22
+ end
23
+
24
+ def update_address(params = {})
25
+ method = :update_address
26
+ response(method, params)
27
+ end
28
+
29
+ # TODO: add :save for file
30
+ #
31
+ #f = File.new("/tmp/file.pdf", "w")
32
+ #f.write(Base64.decode64(invoice[:file]).force_encoding('UTF-8'))
33
+ #f.close
34
+ def invoice_file(params = {})
35
+ method = :get_invoice_file
36
+ response(method, params)
37
+ end
38
+
39
+ def add_parcels(params = {})
40
+ method = :add_parcels
41
+ response(method, params)
42
+ end
43
+
44
+ def remove_parcels(params = {})
45
+ method = :remove_parcels
46
+ response(method, params)
47
+ end
48
+
49
+ protected
50
+
51
+ def url
52
+ "#{DpdApi.configuration.base_url}/services/order2?wsdl"
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,26 @@
1
+ module DpdApi
2
+ class Tracing < Base
3
+ class << self
4
+ def states_by_client_order(params = {})
5
+ method = :get_states_by_client_order
6
+ response(method, params)
7
+ end
8
+
9
+ def states_by_client_parcel(params = {})
10
+ method = :get_states_by_client_parcel
11
+ response(method, params)
12
+ end
13
+
14
+ def states_by_dpd_order(params = {})
15
+ method = :get_states_by_dpd_order
16
+ response(method, params)
17
+ end
18
+
19
+ protected
20
+
21
+ def url
22
+ "#{DpdApi.configuration.base_url}/services/tracing1-1?wsdl"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module DpdApi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/dpd_api.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "dpd_api/version"
2
+
3
+ require "savon"
4
+
5
+ require 'dpd_api/configuration'
6
+ require 'dpd_api/base'
7
+ require 'dpd_api/geography'
8
+ require 'dpd_api/calculator'
9
+ require 'dpd_api/order'
10
+ require 'dpd_api/tracing'
11
+ require 'dpd_api/nl'
12
+ require 'dpd_api/label_print'
13
+
14
+ DpdApi.configure {}
@@ -0,0 +1,55 @@
1
+ <?xml version = "1.0" encoding = "UTF-8" ?>
2
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <S:Body>
4
+ <ns2:getServiceCost2Response xmlns:ns2="http://dpd.ru/ws/calculator/2012-03-20">
5
+ <return>
6
+ <serviceCode>TEN</serviceCode>
7
+ <serviceName>DPD 10:00</serviceName>
8
+ <cost>551.65</cost>
9
+ <days>4</days>
10
+ </return>
11
+ <return>
12
+ <serviceCode>DPT</serviceCode>
13
+ <serviceName>DPD 13:00</serviceName>
14
+ <cost>486.75</cost>
15
+ <days>4</days>
16
+ </return>
17
+ <return>
18
+ <serviceCode>NDY</serviceCode>
19
+ <serviceName>DPD EXPRESS</serviceName>
20
+ <cost>1328.83</cost>
21
+ <days>4</days>
22
+ </return>
23
+ <return>
24
+ <serviceCode>BZP</serviceCode>
25
+ <serviceName>DPD 18:00</serviceName>
26
+ <cost>421.85</cost>
27
+ <days>4</days>
28
+ </return>
29
+ <return>
30
+ <serviceCode>CUR</serviceCode>
31
+ <serviceName>DPD CLASSIC domestic</serviceName>
32
+ <cost>1022.18</cost>
33
+ <days>4</days>
34
+ </return>
35
+ <return>
36
+ <serviceCode>ECN</serviceCode>
37
+ <serviceName>DPD ECONOMY</serviceName>
38
+ <cost>324.5</cost>
39
+ <days>5</days>
40
+ </return>
41
+ <return>
42
+ <serviceCode>CSM</serviceCode>
43
+ <serviceName>DPD Consumer</serviceName>
44
+ <cost>448.4</cost>
45
+ <days>4</days>
46
+ </return>
47
+ <return>
48
+ <serviceCode>PCL</serviceCode>
49
+ <serviceName>DPD CLASSIC Parcel</serviceName>
50
+ <cost>177.0</cost>
51
+ <days>4</days>
52
+ </return>
53
+ </ns2:getServiceCost2Response>
54
+ </S:Body>
55
+ </S:Envelope>
@@ -0,0 +1,55 @@
1
+ <?xml version = "1.0" encoding = "UTF-8" ?>
2
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <S:Body>
4
+ <ns2:getServiceCostByParcels2Response xmlns:ns2="http://dpd.ru/ws/calculator/2012-03-20">
5
+ <return>
6
+ <serviceCode>TEN</serviceCode>
7
+ <serviceName>DPD 10:00</serviceName>
8
+ <cost>551.65</cost>
9
+ <days>4</days>
10
+ </return>
11
+ <return>
12
+ <serviceCode>DPT</serviceCode>
13
+ <serviceName>DPD 13:00</serviceName>
14
+ <cost>486.75</cost>
15
+ <days>4</days>
16
+ </return>
17
+ <return>
18
+ <serviceCode>NDY</serviceCode>
19
+ <serviceName>DPD EXPRESS</serviceName>
20
+ <cost>1328.83</cost>
21
+ <days>4</days>
22
+ </return>
23
+ <return>
24
+ <serviceCode>BZP</serviceCode>
25
+ <serviceName>DPD 18:00</serviceName>
26
+ <cost>421.85</cost>
27
+ <days>4</days>
28
+ </return>
29
+ <return>
30
+ <serviceCode>CUR</serviceCode>
31
+ <serviceName>DPD CLASSIC domestic</serviceName>
32
+ <cost>1022.18</cost>
33
+ <days>4</days>
34
+ </return>
35
+ <return>
36
+ <serviceCode>ECN</serviceCode>
37
+ <serviceName>DPD ECONOMY</serviceName>
38
+ <cost>324.5</cost>
39
+ <days>5</days>
40
+ </return>
41
+ <return>
42
+ <serviceCode>CSM</serviceCode>
43
+ <serviceName>DPD Consumer</serviceName>
44
+ <cost>448.4</cost>
45
+ <days>4</days>
46
+ </return>
47
+ <return>
48
+ <serviceCode>PCL</serviceCode>
49
+ <serviceName>DPD CLASSIC Parcel</serviceName>
50
+ <cost>177.0</cost>
51
+ <days>4</days>
52
+ </return>
53
+ </ns2:getServiceCostByParcels2Response>
54
+ </S:Body>
55
+ </S:Envelope>
@@ -0,0 +1,15 @@
1
+ <?xml version = "1.0" encoding = "UTF-8" ?>
2
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <S:Body>
4
+ <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
5
+ <faultcode>S:Server</faultcode>
6
+ <faultstring>Населенный пункт cityId=0 не найден</faultstring>
7
+ <detail>
8
+ <ns2:ServiceCostFault2 xmlns:ns2="http://dpd.ru/ws/calculator/2012-03-20">
9
+ <code>no-data-found</code>
10
+ <message>Населенный пункт cityId=0 не найден</message>
11
+ </ns2:ServiceCostFault2>
12
+ </detail>
13
+ </S:Fault>
14
+ </S:Body>
15
+ </S:Envelope>
@@ -0,0 +1,15 @@
1
+ <?xml version = "1.0" encoding = "UTF-8" ?>
2
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <S:Body>
4
+ <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
5
+ <faultcode>S:Server</faultcode>
6
+ <faultstring>Населенный пункт cityId=0 не найден</faultstring>
7
+ <detail>
8
+ <ns2:ServiceCostFault2 xmlns:ns2="http://dpd.ru/ws/calculator/2012-03-20">
9
+ <code>no-data-found</code>
10
+ <message>Населенный пункт cityId=0 не найден</message>
11
+ </ns2:ServiceCostFault2>
12
+ </detail>
13
+ </S:Fault>
14
+ </S:Body>
15
+ </S:Envelope>
@@ -0,0 +1,23 @@
1
+ <?xml version = "1.0" encoding = "UTF-8" ?>
2
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <S:Body>
4
+ <ns2:getCitiesCashPayResponse xmlns:ns2="http://dpd.ru/ws/geography/2012-04-17">
5
+ <return>
6
+ <cityId>48951627</cityId>
7
+ <countryCode>RU</countryCode>
8
+ <countryName>Россия</countryName>
9
+ <regionCode>42</regionCode>
10
+ <regionName>Кемеровская</regionName>
11
+ <cityName>Кемерово</cityName>
12
+ </return>
13
+ <return>
14
+ <cityId>48994107</cityId>
15
+ <countryCode>RU</countryCode>
16
+ <countryName>Россия</countryName>
17
+ <regionCode>66</regionCode>
18
+ <regionName>Свердловская</regionName>
19
+ <cityName>Екатеринбург</cityName>
20
+ </return>
21
+ </ns2:getCitiesCashPayResponse>
22
+ </S:Body>
23
+ </S:Envelope>
@@ -0,0 +1,39 @@
1
+ <?xml version = "1.0" encoding = "UTF-8" ?>
2
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <S:Body>
4
+ <ns2:getParcelShopsResponse xmlns:ns2="http://dpd.ru/ws/geography/2012-04-17">
5
+ <return>
6
+ <parcelShop>
7
+ <code>01A</code>
8
+ <parcelShopType>ПВП</parcelShopType>
9
+ <address>
10
+ <countryCode>RU</countryCode>
11
+ <regionCode>61</regionCode>
12
+ <regionName>Ростовская</regionName>
13
+ <cityCode>61000001000</cityCode>
14
+ <cityName>Ростов-на-Дону</cityName>
15
+ <addressString>344038, Ростовская обл., г. Ростов-на-Дону, пр-т Ленина, д. 115</addressString>
16
+ </address>
17
+ <geoCoordinates>
18
+ <geoX>47.249054</geoX>
19
+ <geoY>39.722657</geoY>
20
+ </geoCoordinates>
21
+ <limits>
22
+ <maxWeight>31</maxWeight>
23
+ <maxLength>100</maxLength>
24
+ <maxWidth>100</maxWidth>
25
+ <maxHeight>100</maxHeight>
26
+ </limits>
27
+ <workingTime>
28
+ <weekDays>Пн,Вт,Ср,Чт,Пт,Сб</weekDays>
29
+ <workTime>09:00 - 20:00</workTime>
30
+ </workingTime>
31
+ <workingTime>
32
+ <weekDays>Вс</weekDays>
33
+ <workTime>выходной</workTime>
34
+ </workingTime>
35
+ </parcelShop>
36
+ </return>
37
+ </ns2:getParcelShopsResponse>
38
+ </S:Body>
39
+ </S:Envelope>
@@ -0,0 +1,35 @@
1
+ <?xml version = "1.0" encoding = "UTF-8" ?>
2
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <S:Body>
4
+ <ns2:getTerminalsSelfDelivery2Response xmlns:ns2="http://dpd.ru/ws/geography/2012-04-17">
5
+ <return>
6
+ <terminal>
7
+ <terminalCode>ABA</terminalCode>
8
+ <terminalName>Абакан - терминал</terminalName>
9
+ <terminalAddress>655004, Хакасия респ., г. Абакан, ул. Игарская, д. 10</terminalAddress>
10
+ <geoCoordinates>
11
+ <geoX>53.710113</geoX>
12
+ <geoY>91.392873</geoY>
13
+ </geoCoordinates>
14
+ <workingTime>
15
+ <weekDays>Пн,Вт,Ср,Чт,Пт</weekDays>
16
+ <workTime>08:00 - 19:30</workTime>
17
+ </workingTime>
18
+ <workingTime>
19
+ <weekDays>Сб,Вс</weekDays>
20
+ <workTime>08:00 - 18:30</workTime>
21
+ </workingTime>
22
+ </terminal>
23
+ <city>
24
+ <cityId>195851995</cityId>
25
+ <countryCode>RU</countryCode>
26
+ <countryName>Россия</countryName>
27
+ <regionCode>19</regionCode>
28
+ <regionName>Хакасия</regionName>
29
+ <cityCode>19000001000</cityCode>
30
+ <cityName>Абакан</cityName>
31
+ </city>
32
+ </return>
33
+ </ns2:getTerminalsSelfDelivery2Response>
34
+ </S:Body>
35
+ </S:Envelope>
File without changes
@@ -0,0 +1,11 @@
1
+ <?xml version = "1.0" encoding = "UTF-8" ?>
2
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <S:Body>
4
+ <ns2:cancelOrderResponse xmlns:ns2="http://dpd.ru/ws/order2/2012-04-04">
5
+ <return>
6
+ <orderNumberInternal>1234567</orderNumberInternal>
7
+ <status>Canceled</status>
8
+ </return>
9
+ </ns2:cancelOrderResponse>
10
+ </S:Body>
11
+ </S:Envelope>
@@ -0,0 +1,11 @@
1
+ <?xml version = "1.0" encoding = "UTF-8" ?>
2
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <S:Body>
4
+ <ns2:createAddressResponse xmlns:ns2="http://dpd.ru/ws/order2/2012-04-04">
5
+ <return>
6
+ <code>78</code>
7
+ <status>OK</status>
8
+ </return>
9
+ </ns2:createAddressResponse>
10
+ </S:Body>
11
+ </S:Envelope>
@@ -0,0 +1,14 @@
1
+ <?xml version = "1.0" encoding = "UTF-8" ?>
2
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <S:Body>
4
+ <ns2:createOrderResponse xmlns:ns2="http://dpd.ru/ws/order2/2012-04-04">
5
+ <return>
6
+ <orderNumberInternal>12345678</orderNumberInternal>
7
+ <status>OrderPending</status>
8
+ <errorMessage>Заказ обрабатывается нашими сотрудниками. Не повторяйте оформление данного заказа.
9
+ ---------------------
10
+ 2884657523 Нет разрешения на загрузку посылок!</errorMessage>
11
+ </return>
12
+ </ns2:createOrderResponse>
13
+ </S:Body>
14
+ </S:Envelope>
File without changes
@@ -0,0 +1,12 @@
1
+ <?xml version = "1.0" encoding = "UTF-8" ?>
2
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <S:Body>
4
+ <ns2:getOrderStatusResponse xmlns:ns2="http://dpd.ru/ws/order2/2012-04-04">
5
+ <return>
6
+ <orderNumberInternal>1234567</orderNumberInternal>
7
+ <status>OrderError</status>
8
+ <errorMessage>2884657523 Нет разрешения на загрузку посылок!</errorMessage>
9
+ </return>
10
+ </ns2:getOrderStatusResponse>
11
+ </S:Body>
12
+ </S:Envelope>
File without changes
@@ -0,0 +1,11 @@
1
+ <?xml version = "1.0" encoding = "UTF-8" ?>
2
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <S:Body>
4
+ <ns2:updateAddressResponse xmlns:ns2="http://dpd.ru/ws/order2/2012-04-04">
5
+ <return>
6
+ <code>78</code>
7
+ <status>OK</status>
8
+ </return>
9
+ </ns2:updateAddressResponse>
10
+ </S:Body>
11
+ </S:Envelope>
@@ -0,0 +1,99 @@
1
+ require "spec_helper"
2
+
3
+ describe DpdApi::Calculator do
4
+ include Savon::SpecHelper
5
+ before(:all) { savon.mock! }
6
+ after(:all) { savon.unmock! }
7
+
8
+ let(:auth) do
9
+ { request: {
10
+ auth: {
11
+ client_number: "234",
12
+ client_key: "123"
13
+ } } }
14
+ end
15
+ let(:message) { auth.clone.deep_merge!({ request: params }) }
16
+
17
+ context ".service_cost" do
18
+ let(:fixture) { File.read("spec/fixtures/dpd_api/calculator/service_cost.xml") }
19
+ let(:params) do
20
+ { pickup: { city_id: 195851995 },
21
+ delivery: { city_id: 48951627 },
22
+ self_pickup: false,
23
+ self_delivery: false,
24
+ weight: 1, }
25
+ end
26
+
27
+ it "is success" do
28
+ savon.expects(:get_service_cost2).with(message: message).returns(fixture)
29
+
30
+ response = described_class.service_cost(params)
31
+ expect(response.first).to have_key(:service_code) # 'TEN'
32
+ expect(response.first).to have_key(:service_name) # 'DPD 10:00'
33
+ expect(response.first).to have_key(:cost) # '551.65'
34
+ expect(response.first).to have_key(:days) # '4'
35
+ end
36
+ end
37
+
38
+ context ".serivce_cost" do
39
+ let(:fixture) { File.read("spec/fixtures/dpd_api/calculator/service_cost_fault.xml") }
40
+ let(:params) do
41
+ { pickup: { city_id: '0' },
42
+ delivery: { city_id: '0' },
43
+ self_pickup: false,
44
+ self_delivery: false,
45
+ weight: 1, }
46
+ end
47
+
48
+ it "is fault" do
49
+ savon.expects(:get_service_cost2).with(message: message).returns(fixture)
50
+
51
+ response = described_class.service_cost(params)
52
+ expect(response).to have_key(:errors)
53
+ end
54
+ end
55
+
56
+ context ".service_cost_by_parcels" do
57
+ let(:fixture) { File.read("spec/fixtures/dpd_api/calculator/service_cost_by_parcels.xml") }
58
+ let(:params) do
59
+ { pickup: { city_id: 195851995 },
60
+ delivery: { city_id: 48951627 },
61
+ self_pickup: true,
62
+ self_delivery: true,
63
+ parcel: {
64
+ weight: 0.5,
65
+ length: 0.5,
66
+ width: 0.5,
67
+ height: 0.5,
68
+ },
69
+ parcel: {
70
+ weight: 1,
71
+ length: 1,
72
+ width: 1,
73
+ height: 1,
74
+ } }
75
+ end
76
+
77
+ it "is success" do
78
+ savon.expects(:get_service_cost_by_parcels2).with(message: message).returns(fixture)
79
+
80
+ response = described_class.service_cost_by_parcels(params)
81
+ expect(response.first).to have_key(:service_code)
82
+ expect(response.first).to have_key(:service_name)
83
+ expect(response.first).to have_key(:cost)
84
+ expect(response.first).to have_key(:days)
85
+ end
86
+ end
87
+
88
+ context ".service_cost_by_parcels" do
89
+ let(:fixture) { File.read("spec/fixtures/dpd_api/calculator/service_cost_by_parcels_fault.xml") }
90
+ let(:params) { { pickup: { city_id: 0 } } }
91
+
92
+ it "is fails" do
93
+ savon.expects(:get_service_cost_by_parcels2).with(message: message).returns(fixture)
94
+
95
+ response = described_class.service_cost_by_parcels(params)
96
+ expect(response).to have_key(:errors)
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe DpdApi do
4
+ let(:client_key) { '123' }
5
+ let(:client_number) { '234' }
6
+ let(:base_url) { 'http://wstest.dpd.ru' }
7
+ let(:auth_params) do
8
+ {
9
+ auth: {
10
+ client_number: client_number,
11
+ client_key: client_key
12
+ }
13
+ }
14
+ end
15
+ let(:configuration) { described_class.configuration }
16
+
17
+ it ".configuration" do
18
+ expect(configuration.client_key).to eq client_key
19
+ expect(configuration.client_number).to eq client_number
20
+ expect(configuration.base_url).to eq base_url
21
+ expect(configuration.auth_params).to eq auth_params
22
+ end
23
+ end
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ describe DpdApi::Geography do
4
+ include Savon::SpecHelper
5
+ before(:all) { savon.mock! }
6
+ after(:all) { savon.unmock! }
7
+
8
+ let(:auth) do
9
+ { request: {
10
+ auth: {
11
+ client_number: "234",
12
+ client_key: "123"
13
+ } } }
14
+ end
15
+ let(:message) { auth }
16
+
17
+ context ".cities_cash_pay" do
18
+ let(:fixture) { File.read("spec/fixtures/dpd_api/geography/cities_cash_pay.xml") }
19
+
20
+ it "is success" do
21
+ savon.expects(:get_cities_cash_pay).with(message: message).returns(fixture)
22
+
23
+ response = described_class.cities_cash_pay
24
+ expect(response.first).to have_key(:city_id)
25
+ expect(response.first).to have_key(:country_code)
26
+ expect(response.first).to have_key(:region_code)
27
+ expect(response.first).to have_key(:region_name)
28
+ expect(response.first).to have_key(:city_name)
29
+ end
30
+ end
31
+
32
+ context ".terminals_self_delivery" do
33
+ let(:fixture) { File.read("spec/fixtures/dpd_api/geography/terminals_self_delivery.xml") }
34
+
35
+ it "is success" do
36
+ savon.expects(:get_terminals_self_delivery2).with(message: message).returns(fixture)
37
+
38
+ response = described_class.terminals_self_delivery
39
+ expect(response.first).to have_key(:terminal)
40
+ end
41
+ end
42
+
43
+ context ".parcel_shops" do
44
+ let(:fixture) { File.read("spec/fixtures/dpd_api/geography/parcel_shops.xml") }
45
+
46
+ it "is success" do
47
+ savon.expects(:get_parcel_shops).with(message: message).returns(fixture)
48
+
49
+ response = described_class.parcel_shops
50
+ expect(response.first).to have_key(:parcel_shop)
51
+ end
52
+ end
53
+ end