poczta_polska 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +3 -1
- data/lib/poczta_polska/event.rb +25 -12
- data/lib/poczta_polska/package.rb +55 -19
- data/lib/poczta_polska/version.rb +1 -1
- data/poczta_polska.gemspec +6 -6
- metadata +8 -4
- data/lib/poczta_polska/dynamic_reader.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86453aebbd6ee7866cfdca13cbb3486535cbc214
|
4
|
+
data.tar.gz: 8f98488567ec1af6240e80720509cc079da55709
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42eab5e918c56ef9583431c422a9c46c9dc92153f51ecad1b892d41e4247f24edac40cf5459ab1ffd5460d7975270dad5dddabda5305c010f8acacfaa41001ea
|
7
|
+
data.tar.gz: 7024a795382f937544f44e694667218dd699f2f5ee8012163fdc852e07129f8903f857db9cef24ec9dec5d204ce0ccf786db423385464dfd86bbc133957f62b0
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# PocztaPolska
|
2
2
|
|
3
|
+
[Gem at RubyGems.org](https://rubygems.org/gems/poczta_polska) | [Documentation](http://www.rubydoc.info/gems/poczta_polska)
|
4
|
+
|
3
5
|
With this gem you can monitor Polish Post parcels and registered mail
|
4
6
|
as well as packages shipped by Pocztex. It allows you to see basic data
|
5
7
|
about the consignment as well as all the post offices it has gone through
|
@@ -57,7 +59,7 @@ end
|
|
57
59
|
|
58
60
|
## Contributing
|
59
61
|
|
60
|
-
1. Fork it (
|
62
|
+
1. Fork it (https://github.com/hejmsdz/poczta_polska.rb/fork)
|
61
63
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
64
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
65
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/poczta_polska/event.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'poczta_polska/dynamic_reader'
|
2
1
|
require 'poczta_polska/office'
|
3
2
|
|
4
3
|
module PocztaPolska
|
@@ -8,21 +7,35 @@ module PocztaPolska
|
|
8
7
|
# @return [Hash] Original data from the XML response
|
9
8
|
attr_reader :data
|
10
9
|
|
11
|
-
# Dynamic methods map
|
12
|
-
# @see DynamicReader
|
13
|
-
ATTR_MAP = {
|
14
|
-
time: [:czas, lambda { |time| DateTime.parse(time) }],
|
15
|
-
code: [:kod, :to_sym],
|
16
|
-
name: [:nazwa, :to_s],
|
17
|
-
office: [:jednostka, :nazwa, :to_s],
|
18
|
-
final?: [:konczace, nil]
|
19
|
-
}
|
20
|
-
include DynamicReader
|
21
|
-
|
22
10
|
def initialize(data)
|
23
11
|
@data = data
|
24
12
|
end
|
25
13
|
|
14
|
+
# @return [DateTime] date and time of the event
|
15
|
+
def time
|
16
|
+
DateTime.parse(@data[:czas])
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Symbol] code of the event
|
20
|
+
def code
|
21
|
+
@data[:kod].to_sym
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String] human-readable name of the event
|
25
|
+
def name
|
26
|
+
@data[:nazwa].to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [String] name of the post office
|
30
|
+
def office
|
31
|
+
@data[:jednostka][:nazwa].to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Boolean] whether this is the final event (delivery, receiving in the post office, etc.)
|
35
|
+
def final?
|
36
|
+
@data[:konczace]
|
37
|
+
end
|
38
|
+
|
26
39
|
# Returns detailed information about the post office connected with this event,
|
27
40
|
# only if the {Tracker#check}/{Tracker#check_many} method was called
|
28
41
|
# with +details+ set to +true+.
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'poczta_polska/dynamic_reader'
|
2
1
|
require 'poczta_polska/office'
|
3
2
|
require 'poczta_polska/event'
|
4
3
|
|
@@ -9,28 +8,65 @@ module PocztaPolska
|
|
9
8
|
# @return [Hash] Original data from the XML response
|
10
9
|
attr_reader :data
|
11
10
|
|
12
|
-
# Dynamic methods map
|
13
|
-
# @see DynamicReader
|
14
|
-
ATTR_MAP = {
|
15
|
-
id: [:numer, :to_s],
|
16
|
-
type: [:dane_przesylki, :kod_rodz_przes, :to_sym],
|
17
|
-
type_str: [:dane_przesylki, :rodz_przes, :to_s],
|
18
|
-
country_from: [:dane_przesylki, :kod_kraju_nadania, :to_sym],
|
19
|
-
country_from_str: [:dane_przesylki, :kraj_nadania, :to_s],
|
20
|
-
country_to: [:dane_przesylki, :kod_kraju_przezn, :to_sym],
|
21
|
-
country_to_str: [:dane_przesylki, :kraj_przezn, :to_s],
|
22
|
-
office_from: [:dane_przesylki, :urzad_nadania, :nazwa, :to_s],
|
23
|
-
office_to: [:dane_przesylki, :urzad_przezn, :nazwa, :to_s],
|
24
|
-
mass: [:dane_przesylki, :masa, nil],
|
25
|
-
ready?: [:dane_przesylki, :zakonczono_obsluge, nil]
|
26
|
-
}
|
27
|
-
|
28
|
-
include DynamicReader
|
29
|
-
|
30
11
|
def initialize(data)
|
31
12
|
@data = data
|
32
13
|
end
|
33
14
|
|
15
|
+
# @return [String] package ID
|
16
|
+
def id
|
17
|
+
@data[:numer].to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Symbol] package type code
|
21
|
+
def type
|
22
|
+
@data[:dane_przesylki][:kod_rodz_przes].to_sym
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [String] human-readable package type
|
26
|
+
def type_str
|
27
|
+
@data[:dane_przesylki][:rodz_przes].to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Symbol] origin country code
|
31
|
+
def country_from
|
32
|
+
@data[:dane_przesylki][:kod_kraju_nadania].to_sym
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [String] origin country name
|
36
|
+
def country_from_str
|
37
|
+
@data[:dane_przesylki][:kraj_nadania].to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Symbol] destination country code
|
41
|
+
def country_to
|
42
|
+
@data[:dane_przesylki][:kod_kraju_przezn].to_sym
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [String] destination country name
|
46
|
+
def country_to_str
|
47
|
+
@data[:dane_przesylki][:kraj_przezn].to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [String] origin post office name
|
51
|
+
def office_from
|
52
|
+
@data[:dane_przesylki][:urzad_nadania][:nazwa].to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [String] destination post office name
|
56
|
+
def office_to
|
57
|
+
@data[:dane_przesylki][:urzad_przezn][:nazwa].to_s
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [Float] mass of the package
|
61
|
+
def mass
|
62
|
+
@data[:dane_przesylki][:masa]
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [Boolean] whether the service has been finished (delivered, received in the post office, etc.)
|
66
|
+
def ready?
|
67
|
+
@data[:dane_przesylki][:zakonczono_obsluge]
|
68
|
+
end
|
69
|
+
|
34
70
|
# Returns detailed information about the origin post office,
|
35
71
|
# only if the {Tracker#check}/{Tracker#check_many} method was called
|
36
72
|
# with +details+ set to +true+.
|
data/poczta_polska.gemspec
CHANGED
@@ -10,12 +10,12 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["mikolaj.rozwadowski@outlook.com"]
|
11
11
|
|
12
12
|
spec.summary = "Track Polish Post packages in Ruby"
|
13
|
-
spec.description = "With this gem you can monitor Polish Post parcels and registered mail "
|
14
|
-
"as well as packages shipped by Pocztex. It allows you to see basic data "
|
15
|
-
"about the consignment as well as all the post offices it has gone through "
|
16
|
-
"(including their locations and opening hours). The data is downloaded from "
|
17
|
-
"[a public SOAP API of the Polish Post](http://www.poczta-polska.pl/pliki/webservices/"
|
18
|
-
"Metody%20i%20struktury%20uslugi%20sieciowej%20Poczty%20Polskiej%20SA.pdf) "
|
13
|
+
spec.description = "With this gem you can monitor Polish Post parcels and registered mail " \
|
14
|
+
"as well as packages shipped by Pocztex. It allows you to see basic data " \
|
15
|
+
"about the consignment as well as all the post offices it has gone through " \
|
16
|
+
"(including their locations and opening hours). The data is downloaded from " \
|
17
|
+
"[a public SOAP API of the Polish Post](http://www.poczta-polska.pl/pliki/webservices/" \
|
18
|
+
"Metody%20i%20struktury%20uslugi%20sieciowej%20Poczty%20Polskiej%20SA.pdf) " \
|
19
19
|
"and wrapped into Ruby classes for your convenience."
|
20
20
|
spec.homepage = "https://github.com/hejmsdz/poczta_polska.rb"
|
21
21
|
spec.license = "MIT"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poczta_polska
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikołaj Rozwadowski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: savon
|
@@ -100,7 +100,12 @@ dependencies:
|
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0.8'
|
103
|
-
description:
|
103
|
+
description: With this gem you can monitor Polish Post parcels and registered mail
|
104
|
+
as well as packages shipped by Pocztex. It allows you to see basic data about the
|
105
|
+
consignment as well as all the post offices it has gone through (including their
|
106
|
+
locations and opening hours). The data is downloaded from [a public SOAP API of
|
107
|
+
the Polish Post](http://www.poczta-polska.pl/pliki/webservices/Metody%20i%20struktury%20uslugi%20sieciowej%20Poczty%20Polskiej%20SA.pdf)
|
108
|
+
and wrapped into Ruby classes for your convenience.
|
104
109
|
email:
|
105
110
|
- mikolaj.rozwadowski@outlook.com
|
106
111
|
executables: []
|
@@ -118,7 +123,6 @@ files:
|
|
118
123
|
- bin/setup
|
119
124
|
- examples/example.rb
|
120
125
|
- lib/poczta_polska.rb
|
121
|
-
- lib/poczta_polska/dynamic_reader.rb
|
122
126
|
- lib/poczta_polska/event.rb
|
123
127
|
- lib/poczta_polska/office.rb
|
124
128
|
- lib/poczta_polska/package.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module PocztaPolska
|
2
|
-
# This helper module is +include+d into other classes
|
3
|
-
# and allows to access elements nested in the +@data+ hash.
|
4
|
-
# In order to use it, a class must define a constant hash +ATTR_MAP+.
|
5
|
-
# For the following element in the hash:
|
6
|
-
#
|
7
|
-
# +my_method: [:some, :nested, :value, :to_s]+
|
8
|
-
#
|
9
|
-
# calling +object.my_method+ will return @data[:some][:nested][:value].to_s.
|
10
|
-
# The last element in the array is either a conversion method name, a +Proc+ or +nil+.
|
11
|
-
module DynamicReader
|
12
|
-
# Returns +true+ if the method name is a key in the +ATTR_MAP+ hash.
|
13
|
-
def respond_to_missing?(method, include_private = false)
|
14
|
-
self.class::ATTR_MAP.has_key?(method) || super
|
15
|
-
end
|
16
|
-
|
17
|
-
def method_missing(method)
|
18
|
-
return super unless respond_to_missing?(method)
|
19
|
-
|
20
|
-
keys = self.class::ATTR_MAP[method].dup
|
21
|
-
convert = keys.pop
|
22
|
-
d = @data
|
23
|
-
keys.each { |k| d = d[k] }
|
24
|
-
|
25
|
-
if convert.nil?
|
26
|
-
d
|
27
|
-
elsif convert.is_a?(Proc)
|
28
|
-
convert.call(d)
|
29
|
-
else
|
30
|
-
d.public_send(convert)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|