russianpost 0.1.0
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +107 -0
- data/Rakefile +8 -0
- data/lib/russianpost.rb +5 -0
- data/lib/russianpost/client.rb +20 -0
- data/lib/russianpost/operation.rb +56 -0
- data/lib/russianpost/operations_factory.rb +71 -0
- data/lib/russianpost/parcel.rb +23 -0
- data/lib/russianpost/version.rb +3 -0
- data/russianpost.gemspec +24 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e3c78f24b94f6b559a0392383eb33071f10ad954
|
4
|
+
data.tar.gz: b8e33c4b2002fd880b387dbd9f7f2d89ca68d894
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d72fb4308001eb0fedbccb05d6ef7d17785b7ea24cb5c4b3defeec541027391b58933aec3a91347462961a09e1c7435d87b6bba0b0c97907f93246499ba29db
|
7
|
+
data.tar.gz: de9013ea5ff2b270ad4fbf9b66b30c82feddec6d7d2c44558f7a906b45a8a52c307fd96e95befa7e3bc0f6b684f567824ab186a5a8a0fb0769464f5705939d8e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Artem Shitov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# Russian Post API Client
|
2
|
+
|
3
|
+
Thin wrapper around Russian Post package tracking SOAP API. Works on a per-package basis (contrary to the bulk ticket-based API). Use it at your own risk, since the API may appear unstable and require authorization in future.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Initialize a parcel object, passing the package barcode to the constructor:
|
8
|
+
|
9
|
+
parcel = RussianPost::Parcel.new("EC123456789RU")
|
10
|
+
|
11
|
+
Fetch operation history for the parcel:
|
12
|
+
|
13
|
+
parcel.operations
|
14
|
+
|
15
|
+
The `operations` method returns an `Array` of `Operation` structs.
|
16
|
+
|
17
|
+
### Operations API
|
18
|
+
|
19
|
+
Each `Operation` responds to the following methods. If there is no information, methods return `nil`. More thorough documentation coming soon.
|
20
|
+
|
21
|
+
#### Address parameters
|
22
|
+
|
23
|
+
destination_address #=> RussianPost::Address (Struct)
|
24
|
+
destination_address.index #=> String
|
25
|
+
destination_address.description #=> String
|
26
|
+
|
27
|
+
operation_address #=> RussianPost::Address (Struct)
|
28
|
+
operation_address.index #=> String
|
29
|
+
operation_address.description #=> String
|
30
|
+
|
31
|
+
mail_direct #=> RussianPost::Country (Struct)
|
32
|
+
mail_direct.id #=> Fixnum
|
33
|
+
mail_direct.code_2a #=> String
|
34
|
+
mail_direct.code_3a #=> String
|
35
|
+
mail_direct.name_ru #=> String
|
36
|
+
mail_direct.name_en #=> String
|
37
|
+
|
38
|
+
country_from #=> RussianPost::Country (Struct)
|
39
|
+
country_from.id #=> Fixnum
|
40
|
+
country_from.code_2a #=> String
|
41
|
+
country_from.code_3a #=> String
|
42
|
+
country_from.name_ru #=> String
|
43
|
+
country_from.name_en #=> String
|
44
|
+
|
45
|
+
country_oper #=> RussianPost::Country (Struct)
|
46
|
+
country_oper.id #=> Fixnum
|
47
|
+
country_oper.code_2a #=> String
|
48
|
+
country_oper.code_3a #=> String
|
49
|
+
country_oper.name_ru #=> String
|
50
|
+
country_oper.name_en #=> String
|
51
|
+
|
52
|
+
#### Finance parameters
|
53
|
+
|
54
|
+
payment #=> Fixnum
|
55
|
+
value #=> Fixnum
|
56
|
+
mass_rate #=> Fixnum
|
57
|
+
insr_rate #=> Fixnum
|
58
|
+
air_rate #=> Fixnum
|
59
|
+
rate #=> Fixnum
|
60
|
+
|
61
|
+
#### Item parameters
|
62
|
+
|
63
|
+
barcode #=> String
|
64
|
+
internum #=> String
|
65
|
+
valid_ru_type #=> Boolean
|
66
|
+
valid_en_type #=> Boolean
|
67
|
+
complex_item_name #=> String
|
68
|
+
|
69
|
+
mail_rank #=> RussianPost::GenericOperationParameter (Struct)
|
70
|
+
mail_rank.id #=> Fixnum
|
71
|
+
mail_rank.name #=> String
|
72
|
+
|
73
|
+
post_mark #=> RussianPost::GenericOperationParameter (Struct)
|
74
|
+
mail_rank.id #=> Fixnum
|
75
|
+
mail_rank.name #=> String
|
76
|
+
|
77
|
+
mail_type #=> RussianPost::GenericOperationParameter (Struct)
|
78
|
+
mail_type.id #=> Fixnum
|
79
|
+
mail_type.name #=> String
|
80
|
+
|
81
|
+
mail_ctg #=> RussianPost::GenericOperationParameter (Struct)
|
82
|
+
mail_ctg.id #=> Fixnum
|
83
|
+
mail_ctg.name #=> String
|
84
|
+
|
85
|
+
mass #=> Fixnum
|
86
|
+
max_mass_ru #=> Fixnum
|
87
|
+
max_mass_en #=> Fixnum
|
88
|
+
|
89
|
+
#### Operation parameters
|
90
|
+
|
91
|
+
oper_type #=> RussianPost::GenericOperationParameter (Struct)
|
92
|
+
oper_type.id #=> Fixnum
|
93
|
+
oper_type.name #=> String
|
94
|
+
|
95
|
+
oper_attr #=> RussianPost::GenericOperationParameter (Struct)
|
96
|
+
oper_attr.id #=> Fixnum
|
97
|
+
oper_attr.name #=> String
|
98
|
+
|
99
|
+
oper_date #=> DateTime
|
100
|
+
|
101
|
+
#### User parameters
|
102
|
+
send_ctg #=> RussianPost::GenericOperationParameter (Struct)
|
103
|
+
send_ctg.id #=> Fixnum
|
104
|
+
send_ctg.name #=> String
|
105
|
+
|
106
|
+
sndr #=> String
|
107
|
+
rcpn #=> String
|
data/Rakefile
ADDED
data/lib/russianpost.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "savon"
|
2
|
+
|
3
|
+
module RussianPost
|
4
|
+
class Client
|
5
|
+
attr_reader :savon, :endpoint, :namespace
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@endpoint = "http://voh.russianpost.ru:8080/niips-operationhistory-web/OperationHistory"
|
9
|
+
@namespace = "http://russianpost.org/operationhistory/data"
|
10
|
+
@savon = Savon.client(endpoint: endpoint, namespace: namespace)
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(barcode: nil)
|
14
|
+
message = { "wsdl:Barcode" => barcode, "wsdl:MessageType" => "0" }
|
15
|
+
response = savon.call("OperationHistoryRequest", message: message)
|
16
|
+
|
17
|
+
response.to_hash[:operation_history_data][:history_record]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module RussianPost
|
2
|
+
Operation = Struct.new(
|
3
|
+
# address parameters
|
4
|
+
:destination_address, # Address
|
5
|
+
:operation_address, # Address
|
6
|
+
:mail_direct, # Country
|
7
|
+
:country_from, # Country
|
8
|
+
:country_oper, # Country
|
9
|
+
|
10
|
+
# finance parameters
|
11
|
+
:payment, # Fixnum
|
12
|
+
:value, # Fixnum
|
13
|
+
:mass_rate, # Fixnum
|
14
|
+
:insr_rate, # Fixnum
|
15
|
+
:air_rate, # Fixnum
|
16
|
+
:rate, # Fixnum
|
17
|
+
|
18
|
+
# item parameters
|
19
|
+
:barcode, # String
|
20
|
+
:internum, # String
|
21
|
+
:valid_ru_type, # Boolean
|
22
|
+
:valid_en_type, # Boolean
|
23
|
+
:complex_item_name, # String
|
24
|
+
:mail_rank, # GenericOperationParameter
|
25
|
+
:post_mark, # GenericOperationParameter
|
26
|
+
:mail_type, # GenericOperationParameter
|
27
|
+
:mail_ctg, # GenericOperationParameter
|
28
|
+
:mass, # Fixnum
|
29
|
+
:max_mass_ru, # Fixnum
|
30
|
+
:max_mass_en, # Fixnum
|
31
|
+
|
32
|
+
# operation parameters
|
33
|
+
:oper_type, # GenericOperationParameter
|
34
|
+
:oper_attr, # GenericOperationParameter
|
35
|
+
:oper_date, # DateTime
|
36
|
+
|
37
|
+
# user parameters
|
38
|
+
:send_ctg, # GenericOperationParameter
|
39
|
+
:sndr, # String
|
40
|
+
:rcpn) # String
|
41
|
+
|
42
|
+
Country = Struct.new(
|
43
|
+
:id, # Fixnum
|
44
|
+
:code_2a, # String
|
45
|
+
:code_3a, # String
|
46
|
+
:name_ru, # String
|
47
|
+
:name_en) # String
|
48
|
+
|
49
|
+
GenericOperationParameter = Struct.new(
|
50
|
+
:id, # Fixnum
|
51
|
+
:name) # String
|
52
|
+
|
53
|
+
Address = Struct.new(
|
54
|
+
:index, # String
|
55
|
+
:description) # String
|
56
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "russianpost/operation"
|
2
|
+
|
3
|
+
module RussianPost
|
4
|
+
module OperationsFactory
|
5
|
+
class << self
|
6
|
+
def build(operations_hash)
|
7
|
+
operations_hash.map { |o| build_operation(o) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def build_operation(operation_hash)
|
11
|
+
operation = RussianPost::Operation.new
|
12
|
+
ungroup_parameters(operation_hash).each do |key, value|
|
13
|
+
operation[key] = process_param(key, value)
|
14
|
+
end
|
15
|
+
|
16
|
+
operation
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# Initially all parameters are grouped (address parameters, finance
|
23
|
+
# parameters, etc.). This method flattens the structure a bit
|
24
|
+
def ungroup_parameters(operation_hash)
|
25
|
+
operation_hash.values.compact.reduce(Hash.new){ |acc, el| acc.merge(el) }
|
26
|
+
end
|
27
|
+
|
28
|
+
# Methods below convert certain parameters into proper data structures
|
29
|
+
def process_param(key, value)
|
30
|
+
process_fixnum(key, value) ||
|
31
|
+
process_address(key, value) ||
|
32
|
+
process_country(key, value) ||
|
33
|
+
process_generic_param(key, value) ||
|
34
|
+
value
|
35
|
+
end
|
36
|
+
|
37
|
+
def process_fixnum(key, value)
|
38
|
+
if %i(payment value mass_rate insr_rate air_rate rate mass max_mass_ru max_mass_en).include? key
|
39
|
+
value.to_i
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def process_address(key, value)
|
44
|
+
if %i(destination_address operation_address).include? key
|
45
|
+
RussianPost::Address.new(
|
46
|
+
value[:index],
|
47
|
+
value[:description])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def process_country(key, value)
|
52
|
+
if %i(mail_direct country_from country_oper).include? key
|
53
|
+
RussianPost::Country.new(
|
54
|
+
value[:id] ? value[:id].to_i : nil,
|
55
|
+
value[:code_2a],
|
56
|
+
value[:code_3a],
|
57
|
+
value[:name_ru],
|
58
|
+
value[:name_en])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def process_generic_param(key, value)
|
63
|
+
if value.kind_of? Hash
|
64
|
+
RussianPost::GenericOperationParameter.new(
|
65
|
+
value[:id] ? value[:id].to_i : nil,
|
66
|
+
value[:name])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "russianpost/client"
|
2
|
+
require "russianpost/operations_factory"
|
3
|
+
|
4
|
+
module RussianPost
|
5
|
+
class Parcel
|
6
|
+
attr_reader :barcode, :client
|
7
|
+
|
8
|
+
def initialize(barcode, client: Client)
|
9
|
+
@barcode = barcode
|
10
|
+
@client = client.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def operations
|
14
|
+
@operations ||= fetch_operations
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def fetch_operations
|
20
|
+
OperationsFactory.build(client.call(barcode: barcode))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/russianpost.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'russianpost/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "russianpost"
|
8
|
+
spec.version = Russianpost::VERSION
|
9
|
+
spec.authors = ["Artem Shitov"]
|
10
|
+
spec.email = ["inbox@artemshitov.ru"]
|
11
|
+
spec.description = %q{Thin wrapper around Russian Post package tracking SOAP API. Works on a per-package basis (contrary to the bulk ticket-based API). Use it at your own risk, since the API may appear unstable and require authorization in future.}
|
12
|
+
spec.summary = %q{Russian Post package tracking API client}
|
13
|
+
spec.homepage = "https://github.com/artemshitov/russianpost"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "savon"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: russianpost
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Artem Shitov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: savon
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Thin wrapper around Russian Post package tracking SOAP API. Works on
|
56
|
+
a per-package basis (contrary to the bulk ticket-based API). Use it at your own
|
57
|
+
risk, since the API may appear unstable and require authorization in future.
|
58
|
+
email:
|
59
|
+
- inbox@artemshitov.ru
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- .gitignore
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/russianpost.rb
|
70
|
+
- lib/russianpost/client.rb
|
71
|
+
- lib/russianpost/operation.rb
|
72
|
+
- lib/russianpost/operations_factory.rb
|
73
|
+
- lib/russianpost/parcel.rb
|
74
|
+
- lib/russianpost/version.rb
|
75
|
+
- russianpost.gemspec
|
76
|
+
homepage: https://github.com/artemshitov/russianpost
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.0.0
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Russian Post package tracking API client
|
100
|
+
test_files: []
|