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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f25804582583d50312fcdabb61739ab523bb1a60
4
- data.tar.gz: d884f42475e9c64231dc79608027d8378c71a3ec
3
+ metadata.gz: 8086e933ce655cad0fbb89201061bdd0874ffba7
4
+ data.tar.gz: ca8eb67058f2b8ae264cf0b615d5c33379a3cd5f
5
5
  SHA512:
6
- metadata.gz: 423ce97c42a91b2f8f964d80457e98b1bd8287ea6af8c8f6aadcb962ca1e9cce25ac995dd270b0253dfc69f00995fe044369145222d4a265002e89c121f9912d
7
- data.tar.gz: b8c07fa4a085b8fe7b0bb1e89ad38ba3a1ebe67045f9bae77298f68468791ca37940d7829892c7029c4dd22ed97092da342932a7b50a549cba15b45704587cfd
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.3.1"
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.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Russianpost
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: russianpost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Shitov