postnord 0.1.0 → 0.2.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/.simplecov +5 -0
- data/README.md +35 -4
- data/lib/postnord/business_location.rb +5 -5
- data/lib/postnord/client.rb +1 -1
- data/lib/postnord/response.rb +33 -0
- data/lib/postnord/transport.rb +2 -2
- data/lib/postnord/version.rb +1 -1
- data/lib/postnord.rb +3 -1
- data/postnord.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a705b9ebf528ee47ddee8e12713be01d3b89c9b
|
4
|
+
data.tar.gz: aeea9b9165f3106cadca182daa7c3ca5a84b9ed8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7c682cbfeb4626c6defc19fed31ec36586efbe05f06dfa27ee885b470e005480eaf775cd513229b58cce944a534b8ee2094e94ef79dd7eb38bb37e72ed63a2f
|
7
|
+
data.tar.gz: 8bd000418bb6cb58b2fe267288b5e53e792411d9062f85c5f84b2620185605b9f4db40c4e80eb2f6a6e55ccd74b81002599a4d1d60a1822e77dc1ab9bb5b9648
|
data/.simplecov
ADDED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Postnord
|
2
2
|
|
3
|
-
|
3
|
+
Unofficial Postnord gem for tracking shipments, calculating transmit times and finding service points.
|
4
4
|
|
5
|
-
|
5
|
+
For more information and specifications, please visit https://developer.postnord.com/
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,7 +22,38 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
Add configuration to `config/initializers/postnord.rb`:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
POSTNORD_API_KEY = 'CHANGEME'
|
29
|
+
POSTNORD_API_VERSION = 'v1' # default
|
30
|
+
POSTNORD_API_ENDPOINT = 'https://api2.postnord.com/rest' # default
|
31
|
+
POSTNORD_LOCALE = 'en' # default
|
32
|
+
POSTNORD_RETURN_TYPE = 'json' # default
|
33
|
+
```
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
How to fetch a package with the test identifier from [developer documentation](https://developer.postnord.com/docs#!/trackandtrace/findByIdentifier) using a helper method:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
> response = Postnord.find_by_identifier('84971563697SE')
|
41
|
+
> response.code # => 200
|
42
|
+
> response.status # => OK
|
43
|
+
> response.data # => {"TrackingInformationResponse"=>{"shipments"=>[]}}
|
44
|
+
```
|
45
|
+
|
46
|
+
How to calculate transmit time using the class method `call`:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
> response = Postnord::GetTransitTimeInformation.call({dateOfDeparture: '2016-04-01', serviceGroupCode: 'SE', fromAddressPostalCode: '11827', fromAddressCountryCode: 'SE', toAddressPostalCode: '98132', toAddressCountryCode: 'SE', serviceCode:'15'})
|
50
|
+
> response.data # => {"se.posten.loab.lisp.notis.publicapi.serviceapi.TransitTimeResponse"=>{"transitTimes"=>[{"dateOfDeparture"=>"2016-04-01 18:00:00.0 CEST", "latestTimeOfBooking"=>"14:00", "deliveryTime"=>"17:00", "deliveryDate"=>"20160405", "transitTimeInDays"=>4, "possibleDeviation"=>false, "service"=>{"code"=>"15", "groupCode"=>"SE", "name"=>"DPD Företagspaket", "pickup"=>true, "distribution"=>true}, "daysPickup"=>["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"]}]}}
|
51
|
+
```
|
52
|
+
|
53
|
+
Validation of parameters:
|
54
|
+
```ruby
|
55
|
+
> response = Postnord::GetTransitTimeInformation.call({}) # => Postnord::Base::MissingMandatoryParameters: ["serviceGroupCode", "fromAddressPostalCode", "fromAddressCountryCode", "toAddressPostalCode", "toAddressCountryCode"]
|
56
|
+
```
|
26
57
|
|
27
58
|
## Development
|
28
59
|
|
@@ -32,7 +63,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
63
|
|
33
64
|
## Contributing
|
34
65
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/apoex/postnord. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
67
|
|
37
68
|
|
38
69
|
## License
|
@@ -2,7 +2,7 @@ module Postnord
|
|
2
2
|
|
3
3
|
# Classes
|
4
4
|
|
5
|
-
class BusinessLocation
|
5
|
+
class BusinessLocation < Base
|
6
6
|
def self.service
|
7
7
|
'businesslocation'
|
8
8
|
end
|
@@ -12,7 +12,7 @@ module Postnord
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
class FindNearestByCoordinates
|
15
|
+
class FindNearestByCoordinates < BusinessLocation
|
16
16
|
def mandatory_params
|
17
17
|
[
|
18
18
|
'countryCode',
|
@@ -22,7 +22,7 @@ module Postnord
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
class FindByPostalCode
|
25
|
+
class FindByPostalCode < BusinessLocation
|
26
26
|
def mandatory_params
|
27
27
|
[
|
28
28
|
'countryCode',
|
@@ -31,7 +31,7 @@ module Postnord
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
class FindNearestByAddress
|
34
|
+
class FindNearestByAddress < BusinessLocation
|
35
35
|
def mandatory_params
|
36
36
|
[
|
37
37
|
'countryCode',
|
@@ -39,7 +39,7 @@ module Postnord
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
class GetServicePointInformation
|
42
|
+
class GetServicePointInformation < BusinessLocation
|
43
43
|
def mandatory_params
|
44
44
|
[]
|
45
45
|
end
|
data/lib/postnord/client.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Postnord
|
2
|
+
class Response
|
3
|
+
def initialize(data)
|
4
|
+
@data = data
|
5
|
+
@code = data.code
|
6
|
+
@status = data.msg
|
7
|
+
end
|
8
|
+
|
9
|
+
def code
|
10
|
+
@data.code
|
11
|
+
end
|
12
|
+
|
13
|
+
def status
|
14
|
+
@data.status
|
15
|
+
end
|
16
|
+
|
17
|
+
def data
|
18
|
+
if @code == "200"
|
19
|
+
JSON.parse(@data.body)
|
20
|
+
else
|
21
|
+
@data.body
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_h
|
26
|
+
{
|
27
|
+
code: @code,
|
28
|
+
status: @status,
|
29
|
+
data: data,
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/postnord/transport.rb
CHANGED
data/lib/postnord/version.rb
CHANGED
data/lib/postnord.rb
CHANGED
@@ -3,9 +3,11 @@ require 'net/http'
|
|
3
3
|
require 'net/https'
|
4
4
|
require 'json'
|
5
5
|
require 'openssl'
|
6
|
-
require 'byebug'
|
7
6
|
|
8
7
|
require 'postnord/client'
|
8
|
+
require 'postnord/response'
|
9
9
|
require 'postnord/base'
|
10
|
+
require 'postnord/business_location'
|
10
11
|
require 'postnord/shipment'
|
12
|
+
require 'postnord/transport'
|
11
13
|
require 'postnord/version'
|
data/postnord.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postnord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Åhman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- stefan.ahman@apoex.se
|
@@ -61,6 +75,7 @@ extra_rdoc_files: []
|
|
61
75
|
files:
|
62
76
|
- ".gitignore"
|
63
77
|
- ".rspec"
|
78
|
+
- ".simplecov"
|
64
79
|
- ".travis.yml"
|
65
80
|
- Gemfile
|
66
81
|
- LICENSE.txt
|
@@ -72,6 +87,7 @@ files:
|
|
72
87
|
- lib/postnord/base.rb
|
73
88
|
- lib/postnord/business_location.rb
|
74
89
|
- lib/postnord/client.rb
|
90
|
+
- lib/postnord/response.rb
|
75
91
|
- lib/postnord/shipment.rb
|
76
92
|
- lib/postnord/transport.rb
|
77
93
|
- lib/postnord/version.rb
|