russianpost 0.3.1 → 0.4.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 +4 -4
- data/README.md +20 -1
- data/lib/russianpost/parcel.rb +20 -0
- data/lib/russianpost/version.rb +1 -1
- data/test/russianpost/parcel_test.rb +36 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8086e933ce655cad0fbb89201061bdd0874ffba7
|
|
4
|
+
data.tar.gz: ca8eb67058f2b8ae264cf0b615d5c33379a3cd5f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 426c67bbe5a25b333a19e521f22ad159cfe328f992df927d1c128e50f584e51232246b49615c535205ddd6baf38e7f24b2bf4b8904b107f9da85755ab0b9420c
|
|
7
|
+
data.tar.gz: f6862f03ba823fd8dc6d8467b06dc2cbbf93277faa58c2827417bbc2b82b45eff94198d1abaca6084f91bf335f5e8a6ae2e2e00371ce88d7de4f9505f2064561
|
data/README.md
CHANGED
|
@@ -12,7 +12,7 @@ To install gem stand-alone:
|
|
|
12
12
|
|
|
13
13
|
To use gem in a Rails app, add the following to your `Gemfile`:
|
|
14
14
|
|
|
15
|
-
gem "russianpost", "~> 0.
|
|
15
|
+
gem "russianpost", "~> 0.4.0"
|
|
16
16
|
|
|
17
17
|
This gem uses [Savon](http://savonrb.com/), which in turn uses [HTTPI](https://github.com/savonrb/httpi) internally. HTTPI chooses the best HTTP library of those you have installed. For the fastest results, make sure you add [Curb](https://github.com/taf2/curb) to your `Gemfile`:
|
|
18
18
|
|
|
@@ -33,6 +33,25 @@ Fetch operation history for the parcel:
|
|
|
33
33
|
|
|
34
34
|
The `operations` method returns an `Array` of `Operation` structs.
|
|
35
35
|
|
|
36
|
+
### Parcel info
|
|
37
|
+
|
|
38
|
+
RussianPost makes guesses about current state of the parcel.
|
|
39
|
+
|
|
40
|
+
# Current parcel location
|
|
41
|
+
parcel.location
|
|
42
|
+
|
|
43
|
+
# Mass
|
|
44
|
+
parcel.mass
|
|
45
|
+
|
|
46
|
+
# Rank
|
|
47
|
+
parcel.rank
|
|
48
|
+
|
|
49
|
+
# Recipient
|
|
50
|
+
parcel.recipient
|
|
51
|
+
|
|
52
|
+
# Type
|
|
53
|
+
parcel.type
|
|
54
|
+
|
|
36
55
|
### Operations API
|
|
37
56
|
|
|
38
57
|
Each `Operation` responds to the following methods. If there is no information, methods return `nil`. More thorough documentation coming soon.
|
data/lib/russianpost/parcel.rb
CHANGED
|
@@ -15,6 +15,26 @@ module RussianPost
|
|
|
15
15
|
@operations ||= fetch_operations
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def location
|
|
19
|
+
operations.last.operation_address
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def mass
|
|
23
|
+
operations.map{ |o| o.mass }.max
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def rank
|
|
27
|
+
operations.map{ |o| o.mail_rank }.compact.last
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def recipient
|
|
31
|
+
operations.map{ |o| o.rcpn }.compact.last
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def type
|
|
35
|
+
operations.last.mail_type
|
|
36
|
+
end
|
|
37
|
+
|
|
18
38
|
private
|
|
19
39
|
|
|
20
40
|
def fetch_operations
|
data/lib/russianpost/version.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
1
3
|
require "test_helper"
|
|
2
4
|
require "russianpost/parcel"
|
|
3
5
|
|
|
@@ -24,3 +26,37 @@ class ParcelTest < MiniTest::Unit::TestCase
|
|
|
24
26
|
end
|
|
25
27
|
end
|
|
26
28
|
end
|
|
29
|
+
|
|
30
|
+
class ParcelMetaTest < MiniTest::Unit::TestCase
|
|
31
|
+
attr_reader :parcel
|
|
32
|
+
|
|
33
|
+
def setup
|
|
34
|
+
VCR.use_cassette :valid_barcode do
|
|
35
|
+
@parcel = RussianPost::Parcel.new("RD025500807SE")
|
|
36
|
+
parcel.operations
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_knows_current_location
|
|
41
|
+
location = RussianPost::Address.new("127576", "Москва 576")
|
|
42
|
+
assert_equal location, parcel.location
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_knows_parcel_mass
|
|
46
|
+
assert_equal 281, parcel.mass
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_knows_type
|
|
50
|
+
type = RussianPost::GenericOperationParameter.new(5, "Мелкий пакет")
|
|
51
|
+
assert_equal type, parcel.type
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_knows_rank
|
|
55
|
+
rank = RussianPost::GenericOperationParameter.new(0, "Без разряда")
|
|
56
|
+
assert_equal rank, parcel.rank
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_knows_recipient
|
|
60
|
+
assert_equal "ЕЛЕНА", parcel.recipient
|
|
61
|
+
end
|
|
62
|
+
end
|