postnord 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 625ad1e48069d8cbc99a4b6c526e0a48bce29fd4
4
- data.tar.gz: 42047c6e4d7275f2149d5a7bb50387eb6fc181ab
3
+ metadata.gz: 4a705b9ebf528ee47ddee8e12713be01d3b89c9b
4
+ data.tar.gz: aeea9b9165f3106cadca182daa7c3ca5a84b9ed8
5
5
  SHA512:
6
- metadata.gz: 4d3608f020020a0657c1843baed46704dc4d43d8cab00589de24743e8c6bd42347bfae361dad31ae25fd166ad20cbf2811ea758e5bb7d09da24155608db8c83e
7
- data.tar.gz: c5a26090a77829f2c95cb8bee2e7db2a3595348a73d3a8c1a931254334ff960ea736c610891cefc84b6917f9c7d41cdf6aa422556a15b907e9b21cbd9902b8e5
6
+ metadata.gz: b7c682cbfeb4626c6defc19fed31ec36586efbe05f06dfa27ee885b470e005480eaf775cd513229b58cce944a534b8ee2094e94ef79dd7eb38bb37e72ed63a2f
7
+ data.tar.gz: 8bd000418bb6cb58b2fe267288b5e53e792411d9062f85c5f84b2620185605b9f4db40c4e80eb2f6a6e55ccd74b81002599a4d1d60a1822e77dc1ab9bb5b9648
data/.simplecov ADDED
@@ -0,0 +1,5 @@
1
+ SimpleCov.start do
2
+ add_group 'business_location', 'postnord/business_location'
3
+ add_group 'shipment', 'postnord/shipment'
4
+ add_group 'transport', 'postnord/transport'
5
+ end
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Postnord
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/postnord`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Unofficial Postnord gem for tracking shipments, calculating transmit times and finding service points.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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/[USERNAME]/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.
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
@@ -28,7 +28,7 @@ module Postnord
28
28
  http.request(req)
29
29
  end
30
30
 
31
- JSON.parse(res.body)
31
+ Response.new(res)
32
32
  end
33
33
 
34
34
  private
@@ -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
@@ -12,8 +12,8 @@ module Postnord
12
12
  end
13
13
  end
14
14
 
15
- class GetTransitTimeInformation
16
- def mandatory_params
15
+ class GetTransitTimeInformation < Transport
16
+ def self.mandatory_params
17
17
  [
18
18
  'serviceGroupCode',
19
19
  'fromAddressPostalCode',
@@ -1,3 +1,3 @@
1
1
  module Postnord
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.12"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "simplecov"
24
25
  end
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.1.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-05-13 00:00:00.000000000 Z
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