rs.ge 0.1.6 → 0.1.7

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: 7546bf9f1d2d511ed338bc862dd77c8d10e99b04
4
- data.tar.gz: 69662fd8244f94fdd104b983d7810f0aa486d064
3
+ metadata.gz: 7cbef5c1a418b73e5e5ad907d96f8df8f7baf14e
4
+ data.tar.gz: 24e83d6a07bf96835bf75ef1eb768f4c880f9347
5
5
  SHA512:
6
- metadata.gz: 447892ce8317a536843abf69cf2eb4aad5e9603dc21121c59e1596c79eb551a82e5d7ea1b1fdb8f15029b03257340b0e523b6c457cda78f16b070eebfed80301
7
- data.tar.gz: d96847c6ff14c964d904210af20a1069eaae2d82b83ab1d837ddeb2e18781c43e8a01ad5bed168ef610634af5d0b12143af3f4e71b96f2cdfe42ed38c8b174c2
6
+ metadata.gz: b963482f324fda9ec7159cafdcf6292fe99a894da6871d1794a67aab186ec72878666776f4e24cc3b7ca01ccf48164f01053cd1cacaa61995f9466d01527610c
7
+ data.tar.gz: 8d11ea84b08172274404c2c35580140aa6e4764f6e6e0f5b8611b3dffb2283f4bdbfaf532290d0227358b26167c43bc4ec676dc34637388f0a9b39a51edc1fb8
@@ -246,13 +246,15 @@ class RS::Waybill < RS::Validable
246
246
 
247
247
  # Initialize this waybill from given hash.
248
248
  def init_from_hash(hash)
249
- items_hash = hash[:goods_list][:goods]
250
- items_hash = [items_hash] if items_hash.instance_of? Hash
251
249
  self.items = []
252
- items_hash.each do |item_hash|
253
- item = RS::WaybillItem.new
254
- item.init_from_hash(item_hash)
255
- self.items << item
250
+ if hash[:goods_list].present?
251
+ items_hash = hash[:goods_list][:goods]
252
+ items_hash = [items_hash] if items_hash.instance_of? Hash
253
+ items_hash.each do |item_hash|
254
+ item = RS::WaybillItem.new
255
+ item.init_from_hash(item_hash)
256
+ self.items << item
257
+ end
256
258
  end
257
259
  self.id = hash[:id].to_i
258
260
  self.type = hash[:type].to_i
@@ -271,6 +273,8 @@ class RS::Waybill < RS::Validable
271
273
  self.delivery_date = hash[:delivery_date] # delivery date
272
274
  self.status = hash[:status].to_i
273
275
  self.seller_id = hash[:seler_un_id].to_i
276
+ self.seller_tin = hash[:seller_tin]
277
+ self.seller_name = hash[:seller_name]
274
278
  self.activate_date = hash[:activate_date]
275
279
  self.parent_id = hash[:par_id] ? hash[:par_id].to_i : nil
276
280
  self.total = hash[:full_amount].to_f
@@ -2,7 +2,6 @@
2
2
  require 'singleton'
3
3
 
4
4
  module RS
5
-
6
5
  class WaybillRequest < BaseRequest
7
6
  include Singleton
8
7
 
@@ -43,6 +42,64 @@ module RS
43
42
  wb.init_from_hash(response.to_hash[:get_waybill_response][:get_waybill_result][:waybill])
44
43
  end
45
44
 
45
+ # Get waybills (seller's point of view).
46
+ def get_waybills(opts = {})
47
+ validate_presence_of(opts, :su, :sp)
48
+ message = { 'su' => opts[:su], 'sp' => opts[:sp] }
49
+ waybill_search_params(opts, message)
50
+ response = waybill_client.request 'get_waybills' do
51
+ soap.body = message
52
+ end
53
+ waybill_data = response.to_hash[:get_waybills_response][:get_waybills_result][:waybill_list][:waybill]
54
+ extract_waybills(waybill_data)
55
+ end
56
+
57
+ # Get waybills (buyer's point of view).
58
+ def get_buyer_waybills(opts = {})
59
+ validate_presence_of(opts, :su, :sp)
60
+ message = { 'su' => opts[:su], 'sp' => opts[:sp] }
61
+ waybill_search_params(opts, message)
62
+ response = waybill_client.request 'get_buyer_waybills' do
63
+ soap.body = message
64
+ end
65
+ waybill_data = response.to_hash[:get_buyer_waybills_response][:get_buyer_waybills_result][:waybill_list][:waybill]
66
+ extract_waybills(waybill_data)
67
+ end
68
+
69
+ def extract_waybills(waybill_data)
70
+ waybills = []
71
+ if waybill_data.is_a?(Array)
72
+ waybill_data.each do |data|
73
+ wb = RS::Waybill.new
74
+ wb.init_from_hash(data)
75
+ waybills << wb
76
+ end
77
+ elsif waybill_data.is_a?(Hash)
78
+ wb = RS::Waybill.new
79
+ wb.init_from_hash(waybill_data)
80
+ waybills << wb
81
+ end
82
+ waybills
83
+ end
84
+
85
+ def waybill_search_params(opts, message)
86
+ message['itypes'] = opts[:types].join(',') if opts[:types].present?
87
+ message['buyer_tin'] = opts[:buyer_tin] if opts[:buyer_tin].present?
88
+ message['statuses'] = opts[:statuses].join(',') if opts[:statuses].present?
89
+ message['car_number'] = opts[:vehicle] if opts[:vehicle].present?
90
+ message['begin_date_s'] = opts[:begin_date_1] if opts[:begin_date_1].present?
91
+ message['begin_date_e'] = opts[:begin_date_2] if opts[:begin_date_2].present?
92
+ message['create_date_s'] = opts[:create_date_1] if opts[:create_date_1].present?
93
+ message['create_date_e'] = opts[:create_date_2] if opts[:create_date_2].present?
94
+ message['driver_tin'] = opts[:driver_tin] if opts[:driver_tin].present?
95
+ message['delivery_date_s'] = opts[:delivery_date_1] if opts[:delivery_date_1].present?
96
+ message['delivery_date_e'] = opts[:delivery_date_2] if opts[:delivery_date_2].present?
97
+ message['full_amount'] = opts[:amount] if opts[:amount].present?
98
+ message['waybill_number'] = opts[:number] if opts[:number].present?
99
+ message['close_date_s'] = opts[:close_date_1] if opts[:close_date_1]
100
+ message['close_date_e'] = opts[:close_date_2] if opts[:close_date_2]
101
+ end
102
+
46
103
  # Activate waybill.
47
104
  def activate_waybill(opts)
48
105
  validate_presence_of(opts, :id, :su, :sp)
@@ -110,7 +167,6 @@ module RS
110
167
  nil
111
168
  end
112
169
  end
113
-
114
170
  end
115
171
 
116
172
  class << self
@@ -122,5 +178,4 @@ module RS
122
178
  RS::WaybillRequest.instance
123
179
  end
124
180
  end
125
-
126
181
  end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module RS
3
- VERSION = '0.1.6'
3
+ VERSION = '0.1.7'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rs.ge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Kurashvili
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-05 00:00:00.000000000 Z
11
+ date: 2013-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec