axiomus_api 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e7e56548cb4b9fcbf06900faaa40e7203fea890
4
- data.tar.gz: 3edb5f8eafc6c2fa1d8b5e87c374a337d27cac69
3
+ metadata.gz: ad4f4f35b4f4b4e19262b1f7d25d6fee2c26de68
4
+ data.tar.gz: 87bfb90d97f8c2f159476b8db61c5aae963400b1
5
5
  SHA512:
6
- metadata.gz: 0ff4fa6ae07e2371c0cbb4de8a79324b6a673297d83966e7c34e1544624de3cc52049372d01ade14a1f767c0e1edbbeea5aa5f40fc23abd9f414e18079987940
7
- data.tar.gz: a1a9f6f7590ce9e78de3fab95eedc8566b2097f2846f145fb5f1aec27b59df8fc14488ab980756384d5599375e830b4286771d14d6abc2270c5a48eab2eeaeb4
6
+ metadata.gz: 25f1d85d1a30a776041719c2f632695555bef952638174dc0a3907c9c35e871362a8373545db74569ab7f974ba89edd53cd232a8d5846bb54cde7e738785f717
7
+ data.tar.gz: 0cecac24317941a7014780a2a0d60e7ea50f62085a6beb1a14089bbac628baec19397be80cd4e0fc9987530a4bda4ed8aa48374f79fadb55cad2f3bb3189837f
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  *.sublime*
3
3
  /vendor/bundle
4
4
  /coverage
5
+ .coveralls.yml
data/.travis.yml CHANGED
@@ -5,6 +5,6 @@ rvm:
5
5
  install: "bundle install --path vendor/bundle"
6
6
  cache:
7
7
  directories:
8
- - vendor/bundle
9
- script: "CODECLIMATE_REPO_TOKEN=93631233647d94015cf8e05386117a48a1a23106c2b990e19c96f0f462992e14 bundle exec rspec"
8
+ - vendor/bundle
9
+ script: "bundle exec rspec"
10
10
 
data/Gemfile CHANGED
@@ -4,7 +4,6 @@ gemspec
4
4
 
5
5
  group :test do
6
6
  gem 'rspec'
7
- gem 'coveralls'
8
- gem 'codeclimate-test-reporter', require: nil
7
+ gem 'coveralls', require: false
9
8
  gem 'factory_girl', '~> 4.0'
10
9
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- axiomus_api (0.1)
4
+ axiomus_api (0.1.1)
5
5
  nokogiri (~> 1.6)
6
6
 
7
7
  GEM
@@ -14,8 +14,6 @@ GEM
14
14
  thread_safe (~> 0.1)
15
15
  tzinfo (~> 0.3.37)
16
16
  atomic (1.1.16)
17
- codeclimate-test-reporter (0.3.0)
18
- simplecov (>= 0.7.1, < 1.0.0)
19
17
  coveralls (0.7.0)
20
18
  multi_json (~> 1.3)
21
19
  rest-client
@@ -61,7 +59,6 @@ PLATFORMS
61
59
 
62
60
  DEPENDENCIES
63
61
  axiomus_api!
64
- codeclimate-test-reporter
65
62
  coveralls
66
63
  factory_girl (~> 4.0)
67
64
  rspec
@@ -5,7 +5,7 @@ class AxiomusApi::BaseOrder < AxiomusApi::Base
5
5
  xml_element :order
6
6
 
7
7
  xml_field :contacts, :items
8
- xml_field :description
8
+ xml_field :description, optional: true
9
9
  xml_attribute :inner_id, :okey, optional: true
10
10
  xml_attribute :name, :places
11
11
  xml_field :services, type: AxiomusApi::Services
@@ -2,6 +2,6 @@ require_relative 'base_order'
2
2
 
3
3
  class AxiomusApi::CarryOrder < AxiomusApi::BaseOrder
4
4
 
5
- xml_attribute :office, :incl_delivery_sum, :sms_sender, :sms, optional: true
5
+ xml_attribute :office, :incl_deliv_sum, :sms_sender, :sms, optional: true
6
6
  xml_attribute :b_date, :e_date
7
7
  end
@@ -6,6 +6,6 @@ class AxiomusApi::DpdOrder < AxiomusApi::BaseOrder
6
6
 
7
7
  xml_attribute :d_date, :b_time, :e_time, :post_type
8
8
  xml_field :services, type: AxiomusApi::PostServices
9
- xml_attribute :address, type: AxiomusApi::DpdAddress
9
+ xml_field :address, type: AxiomusApi::DpdAddress
10
10
 
11
11
  end
@@ -5,7 +5,7 @@ require_relative '../services/post_services'
5
5
  class AxiomusApi::EmsOrder < AxiomusApi::BaseOrder
6
6
 
7
7
  xml_attribute :b_date
8
- xml_attribute :incl_delivery_sum, optional: true
8
+ xml_attribute :incl_deliv_sum, optional: true
9
9
  xml_field :address, type: AxiomusApi::EmsAddress
10
10
  xml_field :services, type: AxiomusApi::PostServices
11
11
 
@@ -3,6 +3,6 @@ require_relative 'base_order'
3
3
  class AxiomusApi::Order < AxiomusApi::BaseOrder
4
4
 
5
5
  xml_attribute :address, :d_date, :b_time, :e_time, :city
6
- xml_attribute :incl_delivery_sum, :from_mkad, :garden_ring, :sms_sender, :sms, optional: true
6
+ xml_attribute :incl_deliv_sum, :from_mkad, :garden_ring, :sms_sender, :sms, optional: true
7
7
 
8
8
  end
@@ -5,7 +5,7 @@ require_relative '../services/post_services'
5
5
  class AxiomusApi::PostOrder < AxiomusApi::BaseOrder
6
6
  #уточнить
7
7
  xml_attribute :b_date, :post_type
8
- xml_attribute :incl_delivery_sum, optional: true
8
+ xml_attribute :incl_deliv_sum, optional: true
9
9
  xml_field :address, type: AxiomusApi::PostAddress
10
10
  xml_field :services, type: AxiomusApi::PostServices
11
11
 
@@ -6,7 +6,7 @@ module AxiomusApi::Serializable
6
6
  attribute_fields = serializable_fields.select{|k,v| v[:xml_type] == :attribute}
7
7
 
8
8
  attributes = Hash[attribute_fields.map do |k,v|
9
- [v[:xml_name] || k, self.send(k).to_s]
9
+ [v[:xml_name] || k, normalize_axiomus_xml(self.send(k).to_s)]
10
10
  end].reject{|k,v| v.nil? || v.empty?}
11
11
 
12
12
  builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
@@ -29,11 +29,13 @@ module AxiomusApi::Serializable
29
29
  }
30
30
  end
31
31
 
32
- if xml_header
32
+ xml = if xml_header
33
33
  builder.to_xml
34
34
  else
35
35
  builder.doc.root.to_xml
36
36
  end
37
+
38
+ normalize_axiomus_xml(xml)
37
39
  end
38
40
 
39
41
  private
@@ -47,9 +49,13 @@ module AxiomusApi::Serializable
47
49
  }
48
50
  else
49
51
  xml.send(xml_name) {
50
- xml.text(obj.to_s)
52
+ xml.text(normalize_axiomus_xml(obj.to_s))
51
53
  }
52
54
  end
53
55
  end
54
56
 
57
+ def normalize_axiomus_xml(str)
58
+ str.gsub(/&[^;]+;/, '')
59
+ end
60
+
55
61
  end
@@ -84,9 +84,9 @@ class AxiomusApi::Session
84
84
  logger.info("Request to #{xml_request.mode}")
85
85
  logger.debug("Request body: #{xml_request.to_xml}")
86
86
  response = connection.request(http_request)
87
- response.body.gsub!(/^.*<?xml/, '<?xml')
88
87
  logger.info("Response: #{response.code}")
89
88
  logger.debug("Response raw: #{response.body}")
89
+ response.body.gsub!(/^.*<\?xml/, '<?xml')
90
90
  response
91
91
  end
92
92
 
@@ -1,3 +1,3 @@
1
1
  module AxiomusApi
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
data/spec/factories.rb CHANGED
@@ -14,7 +14,7 @@ FactoryGirl.define do
14
14
  end
15
15
 
16
16
  factory :item, class: AxiomusApi::Item do
17
- name {"Product #{rand(1..1000)}"}
17
+ name {"Product &quot;'\"Awesome\"'&quot; #{rand(1..1000)}"}
18
18
  weight {rand(0.1..10.0)}
19
19
  quantity {rand(1..10)}
20
20
  price {rand(0.5..10000.0)}
@@ -87,6 +87,10 @@ FactoryGirl.define do
87
87
 
88
88
  factory :dpd_address, class: AxiomusApi::DpdAddress, parent: :ems_address do
89
89
  region 'обл Ростовская'
90
+
91
+ trait :without_region do
92
+ region nil
93
+ end
90
94
  end
91
95
 
92
96
  factory :region_courier_address, class: AxiomusApi::RegionCourierAddress do
@@ -103,10 +107,6 @@ FactoryGirl.define do
103
107
  end
104
108
 
105
109
  factory :order, class: AxiomusApi::Order, parent: :base_order do
106
- trait :incl_delivery_sum do
107
- incl_delivery_sum rand(100.0..200.00)
108
- end
109
-
110
110
  sms {rand(1..2) ? generate(:sms) : nil}
111
111
  d_date {Time.now + rand(1..10)*24*60*60}
112
112
  b_time {rand(10..19)}
@@ -115,6 +115,14 @@ FactoryGirl.define do
115
115
  city 0
116
116
  garden_ring {generate :boolean}
117
117
  from_mkad {rand(1..2) == 2 && garden_ring !='yes' && city > 0 ? rand(1..40) : nil}
118
+
119
+ trait :incl_deliv_sum do
120
+ incl_deliv_sum rand(100.0..200.00)
121
+ end
122
+
123
+ trait :with_empty_address do
124
+ address ''
125
+ end
118
126
  end
119
127
 
120
128
  factory :carry_order, class: AxiomusApi::CarryOrder, parent: :base_order do
@@ -164,6 +172,10 @@ FactoryGirl.define do
164
172
  address {build(:post_address)}
165
173
  services {build(:post_services)}
166
174
  contacts {generate(:sms)}
175
+
176
+ trait :with_region_services do
177
+ services {build(:region_services)}
178
+ end
167
179
  end
168
180
 
169
181
  factory :ems_order, class: AxiomusApi::EmsOrder, parent: :base_order do
@@ -195,6 +207,10 @@ FactoryGirl.define do
195
207
  d_date {(Time.now + rand(5..15)*24*60*60).strftime('%Y-%m-%d')}
196
208
  b_time {rand(10..17)}
197
209
  e_time {b_time + 1}
210
+
211
+ trait :without_address do
212
+ address nil
213
+ end
198
214
  end
199
215
 
200
216
  end
@@ -0,0 +1,26 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe 'AxiomusApi::Base' do
4
+
5
+ it 'should raise on wrong xml options' do
6
+ expect do
7
+ class C < AxiomusApi::Base
8
+ xml_field :some_field, unknown_option: 21
9
+ end
10
+ end.to raise_error
11
+ end
12
+
13
+ it 'should raise if no tag name' do
14
+
15
+ class C < AxiomusApi::Base
16
+ xml_field :value
17
+ end
18
+
19
+ c = C.new
20
+ c.value = '32'
21
+
22
+ expect{c.tag_name}.to raise_error
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe 'AxiomusApi::Serializable' do
4
+
5
+ it 'should serialize value as text node' do
6
+
7
+ class Node < AxiomusApi::Base
8
+ xml_element :node
9
+ xml_field :value, xml_type: :text
10
+ xml_attribute :id
11
+ end
12
+
13
+ n = Node.new
14
+ n.id = 1
15
+ n.value = 'Some value'
16
+
17
+ expect(n.to_xml()).to eq('<node id="1">Some value</node>')
18
+
19
+ end
20
+
21
+
22
+ end
@@ -8,16 +8,18 @@ describe 'AxiomusApi::Session' do
8
8
  end
9
9
 
10
10
  ORDER_MODES.each do |method|
11
+ order_class = order_factory_name(method)
12
+
11
13
  describe "##{method}" do
12
14
  it 'should handle successful request' do
13
15
  HttpMocking.enqueue_response(DummyData.order_success_response(method))
14
- response = @session.send(method, build(:base_order))
16
+ response = @session.send(method, build(order_class))
15
17
  expect(response.code).to eq 0
16
18
  end
17
19
 
18
20
  it 'should raise on error' do
19
21
  HttpMocking.enqueue_response(DummyData.order_error_response(method))
20
- expect{@session.send(method, build(:base_order))}.to raise_error(AxiomusApi::Errors::RequestError)
22
+ expect{@session.send(method, build(order_class))}.to raise_error(AxiomusApi::Errors::RequestError)
21
23
  end
22
24
  end
23
25
  end
@@ -44,4 +46,35 @@ describe 'AxiomusApi::Session' do
44
46
  end
45
47
  end
46
48
 
49
+ it 'should accept a block' do
50
+ HttpMocking.enqueue_response(DummyData::REGIONS_SUCCESS_RESPONSE)
51
+ res = nil
52
+
53
+ AxiomusApi.test_session do |s|
54
+ res = s.get_regions
55
+ end
56
+
57
+ expect(res.regions.count).to eq 1
58
+ expect(res.regions.first.code).to eq '21'
59
+ end
60
+
61
+ describe '#send_order_request' do
62
+ it 'should raise on invalid order' do
63
+ order = build(:dpd_order, :without_address)
64
+ HttpMocking.enqueue_response(DummyData.order_success_response(:new_dpd))
65
+ expect{@session.send_order_request(:new_dpd, order)}.to raise_error(AxiomusApi::Errors::ValidationError)
66
+ end
67
+ end
68
+
69
+ describe '#labels_link' do
70
+ it 'should return correct URL' do
71
+ order_nums = []
72
+ 10.times {order_nums << rand(1..10000)}
73
+ url = @session.labels_link(order_nums)
74
+ order_nums.each do |on|
75
+ expect(url).to include(on.to_s)
76
+ end
77
+ end
78
+ end
79
+
47
80
  end
@@ -0,0 +1,36 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe 'AxiomusApi::Validated' do
4
+
5
+ it 'should validate required fields' do
6
+ address = build(:dpd_address, :without_region)
7
+ expect(address).not_to be_valid
8
+ expect(address.validation_errors).to have(1).items
9
+ end
10
+
11
+ it 'should validate empty fields' do
12
+ order = build(:order, :with_empty_address)
13
+ expect(order).not_to be_valid
14
+ expect(order.validation_errors).to have(1).items
15
+ end
16
+
17
+ it 'should validate wrong type fields' do
18
+ order = build(:post_order, :with_region_services)
19
+ expect(order).not_to be_valid
20
+ expect(order.validation_errors).to have(1).items
21
+ end
22
+
23
+ it 'should validate nested fields' do
24
+ order = build(:dpd_order)
25
+ order.address.region = nil
26
+ expect(order).not_to be_valid
27
+ expect(order.validation_errors).to have(1).items
28
+ end
29
+
30
+ it 'should validate correct items' do
31
+ order = build(:post_order)
32
+ expect(order).to be_valid
33
+ expect(order.validation_errors).to have(0).items
34
+ end
35
+
36
+ end
@@ -1,5 +1,7 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
3
  describe 'AxiomusApi' do
4
-
4
+ it 'should assign logger' do
5
+ AxiomusApi.logger = Logger.new($stdout)
6
+ end
5
7
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  require 'coveralls'
2
- require 'codeclimate-test-reporter'
3
- require 'factory_girl'
4
-
5
2
  Coveralls.wear!
6
- CodeClimate::TestReporter.start
3
+
4
+ require 'factory_girl'
7
5
 
8
6
  RSpec.configure do |config|
9
7
  config.include FactoryGirl::Syntax::Methods
@@ -13,6 +11,17 @@ ORDER_MODES = [:new, :update, :new_carry, :update_carry, :new_export, :update_ex
13
11
  :new_self_export, :update_self_export, :new_post, :update_post, :new_dpd, :update_dpd, :new_ems, :update_ems,
14
12
  :new_region_courier, :update_region_courier, :new_region_pickup, :update_region_pickup]
15
13
 
14
+
15
+ def order_factory_name(order_mode)
16
+ match = /_(.+)$/.match(order_mode)
17
+
18
+ if match.nil?
19
+ :order
20
+ else
21
+ "#{match[1]}_order".to_sym
22
+ end
23
+ end
24
+
16
25
  require_relative '../lib/axiomus_api.rb'
17
26
  require_relative 'support/dummy_data.rb'
18
27
  require_relative 'support/http_mocking.rb'
@@ -2,10 +2,6 @@ require 'net/http'
2
2
 
3
3
  module HttpMocking
4
4
 
5
- def self.clear_response_queue
6
- @responses = []
7
- end
8
-
9
5
  def self.enqueue_response(response_body, code = '200', msg='OK')
10
6
  @responses ||= []
11
7
  @responses.push([response_body, code, msg])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: axiomus_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kinderly LTD
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -81,7 +81,10 @@ files:
81
81
  - spec/factories.rb
82
82
  - spec/integration/axiomus_api/session_spec.rb
83
83
  - spec/lib/axiomus_api/base_order_spec.rb
84
+ - spec/lib/axiomus_api/base_spec.rb
85
+ - spec/lib/axiomus_api/serializable_spec.rb
84
86
  - spec/lib/axiomus_api/session_spec.rb
87
+ - spec/lib/axiomus_api/validated_spec.rb
85
88
  - spec/lib/axiomus_api_spec.rb
86
89
  - spec/spec_helper.rb
87
90
  - spec/support/dummy_data.rb