posthorn 0.0.5
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 +7 -0
- data/.gitignore +98 -0
- data/.gitlab-ci.yml +21 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +79 -0
- data/Rakefile +7 -0
- data/doc/example_label.png +0 -0
- data/lib/posthorn/address.rb +57 -0
- data/lib/posthorn/configuration.rb +22 -0
- data/lib/posthorn/label.rb +30 -0
- data/lib/posthorn/office.rb +44 -0
- data/lib/posthorn/product_info.rb +5 -0
- data/lib/posthorn/soap_client.rb +32 -0
- data/lib/posthorn/version.rb +3 -0
- data/lib/posthorn.rb +17 -0
- data/posthorn.gemspec +28 -0
- data/spec/address_spec.rb +62 -0
- data/spec/office_spec.rb +48 -0
- data/spec/soap_client_spec.rb +10 -0
- data/spec/spec_helper.rb +10 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0c7cfb6a47a54db8e17f7b6439fb8eee498149f9
|
4
|
+
data.tar.gz: 724d2a078e2c60de907cd197cdb1ed4187b18a1e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e6c71cbd4f1830666e353a0367a48114a756bb3de4f9e5e460b2d33acb4c184e4d3332214de6df4530bf3222b8db6da0fab85defc03ccd0665bdd551ab13d59
|
7
|
+
data.tar.gz: d31e64dbce5574fe35f0b255f50e96d8674b8c125b4b9abcc57c9f5d2ded531205e72a4b85e5fbadfb936530f0c817ef0b70eb0341fd133b142c478497df209b
|
data/.gitignore
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
|
2
|
+
# Created by https://www.gitignore.io/api/ruby,node,osx,linux
|
3
|
+
|
4
|
+
### Ruby ###
|
5
|
+
*.gem
|
6
|
+
*.rbc
|
7
|
+
/.config
|
8
|
+
/coverage/
|
9
|
+
/InstalledFiles
|
10
|
+
/pkg/
|
11
|
+
/spec/reports/
|
12
|
+
/spec/examples.txt
|
13
|
+
/test/tmp/
|
14
|
+
/test/version_tmp/
|
15
|
+
/tmp/
|
16
|
+
Gemfile.lock
|
17
|
+
.rbenv-vars
|
18
|
+
|
19
|
+
# Used by dotenv library to load environment variables.
|
20
|
+
# .env
|
21
|
+
|
22
|
+
## Specific to RubyMotion:
|
23
|
+
.dat*
|
24
|
+
.repl_history
|
25
|
+
build/
|
26
|
+
*.bridgesupport
|
27
|
+
build-iPhoneOS/
|
28
|
+
build-iPhoneSimulator/
|
29
|
+
|
30
|
+
## Specific to RubyMotion (use of CocoaPods):
|
31
|
+
#
|
32
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
33
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
34
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
35
|
+
#
|
36
|
+
# vendor/Pods/
|
37
|
+
|
38
|
+
## Documentation cache and generated files:
|
39
|
+
/.yardoc/
|
40
|
+
/_yardoc/
|
41
|
+
# /doc/
|
42
|
+
/rdoc/
|
43
|
+
|
44
|
+
## Environment normalization:
|
45
|
+
/.bundle/
|
46
|
+
/vendor/bundle
|
47
|
+
/lib/bundler/man/
|
48
|
+
|
49
|
+
# for a library or gem, you might want to ignore these files since the code is
|
50
|
+
# intended to run in multiple environments; otherwise, check them in:
|
51
|
+
# Gemfile.lock
|
52
|
+
# .ruby-version
|
53
|
+
# .ruby-gemset
|
54
|
+
|
55
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
56
|
+
.rvmrc
|
57
|
+
|
58
|
+
### OSX ###
|
59
|
+
*.DS_Store
|
60
|
+
.AppleDouble
|
61
|
+
.LSOverride
|
62
|
+
|
63
|
+
# Icon must end with two \r
|
64
|
+
Icon
|
65
|
+
|
66
|
+
|
67
|
+
# Thumbnails
|
68
|
+
._*
|
69
|
+
|
70
|
+
# Files that might appear in the root of a volume
|
71
|
+
.DocumentRevisions-V100
|
72
|
+
.fseventsd
|
73
|
+
.Spotlight-V100
|
74
|
+
.TemporaryItems
|
75
|
+
.Trashes
|
76
|
+
.VolumeIcon.icns
|
77
|
+
.com.apple.timemachine.donotpresent
|
78
|
+
|
79
|
+
# Directories potentially created on remote AFP share
|
80
|
+
.AppleDB
|
81
|
+
.AppleDesktop
|
82
|
+
Network Trash Folder
|
83
|
+
Temporary Items
|
84
|
+
.apdisk
|
85
|
+
|
86
|
+
|
87
|
+
### Linux ###
|
88
|
+
*~
|
89
|
+
|
90
|
+
# temporary files which can be created if a process still has a handle open of a deleted file
|
91
|
+
.fuse_hidden*
|
92
|
+
|
93
|
+
# KDE directory preferences
|
94
|
+
.directory
|
95
|
+
|
96
|
+
# Linux trash folder which might appear on any partition or disk
|
97
|
+
.Trash-*
|
98
|
+
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
before_script:
|
2
|
+
- ruby -v
|
3
|
+
- which ruby
|
4
|
+
- gem install bundler --no-ri --no-rdoc
|
5
|
+
- bundle install --jobs $(nproc) "${FLAGS[@]}"
|
6
|
+
|
7
|
+
stages:
|
8
|
+
- test
|
9
|
+
- deploy
|
10
|
+
|
11
|
+
|
12
|
+
rspec_job:
|
13
|
+
stage: test
|
14
|
+
script:
|
15
|
+
- bundle exec rspec
|
16
|
+
|
17
|
+
deploy_job:
|
18
|
+
stage: deploy
|
19
|
+
script:
|
20
|
+
- bundle exec rake build
|
21
|
+
- bundle exec gem inabox -g https://gems.aisler.net
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 AISLER B.V.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Posthorn
|
2
|
+
|
3
|
+
Easy access to Deutsche Post 1C4A webservice
|
4
|
+
|
5
|
+
With this Gem it is possible to order pre-paid shipping stickers from the Deutsche Post. Payment is done through the so called "Portokasse", a prepaid wallet service. To use this Gem a registration for the "Portokasse" and the 1C4A webservice is necessary. For more detailed information see (Sorry, only in German language...)
|
6
|
+
|
7
|
+
https://portokasse.deutschepost.de/portokasse/#/
|
8
|
+
|
9
|
+
https://www.deutschepost.de/de/i/internetmarke-porto-drucken/partner-werden.html
|
10
|
+
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'posthorn'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
In case this Gem is used within a Rails application add a new initializer and add the following content
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Posthorn.configure do |c|
|
28
|
+
c.dpwn_key = Rails.application.secrets[:posthorn_dpwn_key]
|
29
|
+
c.partner_id = Rails.application.secrets[:posthorn_partner_id]
|
30
|
+
c.key_phase = 1
|
31
|
+
c.username = Rails.application.secrets[:posthorn_username]
|
32
|
+
c.password = Rails.application.secrets[:posthorn_password]
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
Use the secrets.yml file to securely store all necessary keys and passwords.
|
37
|
+
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
This example will order a single domestic shipping label. The sandbox credentials can be used to run the example without burning real cash. To execute it, Posthorn should be already configured as shown above.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
# Open a new (post-)office
|
45
|
+
office = Office.new
|
46
|
+
|
47
|
+
# Create a new recveiver and sender address, country codes can be ISO3166 Alpha2 codes or Countries Gem instances
|
48
|
+
# see https://github.com/hexorx/countries for details
|
49
|
+
receiver = Address.new(
|
50
|
+
firstname: 'Hans Peter',
|
51
|
+
lastname: 'Wurst',
|
52
|
+
street: 'Carbynstraße',
|
53
|
+
no: '2',
|
54
|
+
city: 'Eschweiler',
|
55
|
+
zip: '52249',
|
56
|
+
country: 'de')
|
57
|
+
|
58
|
+
sender = Address.new(
|
59
|
+
company: 'Your Company',
|
60
|
+
street: 'Charles-de-Gaulle-Straße',
|
61
|
+
no: '20',
|
62
|
+
city: 'Bonn',
|
63
|
+
zip: '53113',
|
64
|
+
country: 'de')
|
65
|
+
|
66
|
+
# Add a new label to the shopping cart
|
67
|
+
# for product_id and price, please referee to Deutsche Post ProdWS database
|
68
|
+
# in this example ID 21 is used which is a large size letter, price is Euro 1.45
|
69
|
+
office.cart << Label.new(sender, receiver, product_id: 21, price: 145)
|
70
|
+
|
71
|
+
# all available page formats can be received with
|
72
|
+
# puts office.page_formats
|
73
|
+
labels = office.checkout!(page_format: 25)
|
74
|
+
IO.write('labels_as_pdf_file.pdf', labels)
|
75
|
+
```
|
76
|
+
|
77
|
+
The output will be a ready to use shipping label as shown below.
|
78
|
+
|
79
|
+

|
data/Rakefile
ADDED
Binary file
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Posthorn
|
2
|
+
class Address
|
3
|
+
attr_accessor :company, :firstname, :lastname, :street, :no, :zip, :city, :country
|
4
|
+
|
5
|
+
def initialize(data)
|
6
|
+
@company = data[:company]
|
7
|
+
@lastname = data[:lastname]
|
8
|
+
@firstname = data[:firstname]
|
9
|
+
|
10
|
+
if data[:no]
|
11
|
+
@no = data[:no]
|
12
|
+
@street = data[:street]
|
13
|
+
else
|
14
|
+
chunks = data[:street].split(' ')
|
15
|
+
@no = chunks[-1]
|
16
|
+
@street = chunks[0..-2].join(' ')
|
17
|
+
end
|
18
|
+
@city = data[:city]
|
19
|
+
@zip = data[:zip]
|
20
|
+
@country = data[:country].is_a?(String) ? ISO3166::Country.new(data[:country]) : data[:country]
|
21
|
+
end
|
22
|
+
|
23
|
+
def company?
|
24
|
+
@company && !@company.blank? && (@company != [@firstname, @lastname].join(' '))
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_h
|
28
|
+
rtn = {
|
29
|
+
name: {}
|
30
|
+
}
|
31
|
+
|
32
|
+
if company?
|
33
|
+
rtn[:name][:companyName] = { company: @company }
|
34
|
+
if @firstname && @lastname
|
35
|
+
rtn[:name][:companyName][:personName] = {
|
36
|
+
firstname: @firstname,
|
37
|
+
lastname: @lastname
|
38
|
+
}
|
39
|
+
end
|
40
|
+
else
|
41
|
+
rtn[:name][:personName] = {
|
42
|
+
firstname: @firstname,
|
43
|
+
lastname: @lastname
|
44
|
+
}
|
45
|
+
end
|
46
|
+
rtn[:address] = {
|
47
|
+
street: @street,
|
48
|
+
houseNo: @no,
|
49
|
+
zip: @zip,
|
50
|
+
city: @city,
|
51
|
+
country: @country.alpha3
|
52
|
+
}
|
53
|
+
|
54
|
+
rtn
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Posthorn
|
2
|
+
def self.configuration
|
3
|
+
@config ||= Configuration.new
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configuration=(c)
|
7
|
+
@config = c
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
class Configuration
|
15
|
+
attr_accessor :dpwn_key, :partner_id, :key_phase, :username, :password
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
# Set default values here
|
19
|
+
@key_phase = 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Posthorn
|
2
|
+
class Label
|
3
|
+
attr_accessor :sender, :receiver, :product_id, :price
|
4
|
+
|
5
|
+
def initialize(sender, receiver, args = {})
|
6
|
+
@sender = sender
|
7
|
+
@receiver = receiver
|
8
|
+
@product_id = args[:product_id] || 11 # Kompaktbrief
|
9
|
+
@price = args[:price] || 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_h(args = {})
|
13
|
+
rtn = {
|
14
|
+
productCode: @product_id,
|
15
|
+
address: {
|
16
|
+
sender: @sender.to_h,
|
17
|
+
receiver: @receiver.to_h
|
18
|
+
},
|
19
|
+
voucherLayout: 'AddressZone',
|
20
|
+
position: {
|
21
|
+
labelX: 1,
|
22
|
+
labelY: 1,
|
23
|
+
page: (args[:page] || 0) + 1
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
rtn
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Posthorn
|
2
|
+
class Office
|
3
|
+
attr_reader :user
|
4
|
+
attr_accessor :cart
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@client = SoapClient.new
|
8
|
+
@user = @client.authenticate
|
9
|
+
@cart = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def page_formats
|
13
|
+
response = @client.call(:retrieve_page_formats)
|
14
|
+
response.body[:retrieve_page_formats_response][:page_format].map do |fmt|
|
15
|
+
OpenStruct.new fmt
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def checkout!(args = {})
|
20
|
+
page = 0
|
21
|
+
price = 0
|
22
|
+
@cart.each { |label| price += label.price }
|
23
|
+
|
24
|
+
message = {
|
25
|
+
userToken: @user.user_token,
|
26
|
+
pageFormatId: args[:page_format] || 25, # Brother 62mm
|
27
|
+
positions: @cart.map.with_index { |label, ix| label.to_h(page: ix) },
|
28
|
+
total: price
|
29
|
+
}
|
30
|
+
|
31
|
+
response = @client.call(:checkout_shopping_cart_pdf, message)
|
32
|
+
data = response.body[:checkout_shopping_cart_pdf_response]
|
33
|
+
@user.wallet_balance = data[:wallet_ballance]
|
34
|
+
|
35
|
+
@cart.clear
|
36
|
+
|
37
|
+
|
38
|
+
request = HTTPI::Request.new
|
39
|
+
request.url = data[:link]
|
40
|
+
request.read_timeout = 240
|
41
|
+
HTTPI.get(request).body
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Posthorn
|
2
|
+
class SoapClient
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
header = {
|
6
|
+
partner_id: Posthorn.configuration.partner_id,
|
7
|
+
request_timestamp: Time.now.strftime('%d%m%Y-%H%M%S'),
|
8
|
+
key_phase: 1
|
9
|
+
}
|
10
|
+
header[:partner_signature] = Digest::MD5.hexdigest(header.values.push(Posthorn.configuration.dpwn_key).join('::'))[0..7]
|
11
|
+
|
12
|
+
|
13
|
+
@base = Savon.client({
|
14
|
+
wsdl: 'https://internetmarke.deutschepost.de/OneClickForAppV3/OneClickForAppServiceV3?wsdl',
|
15
|
+
convert_request_keys_to: :none,
|
16
|
+
soap_header: header
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
def authenticate
|
21
|
+
response = @base.call(:authenticate_user, message: { username: Posthorn.configuration.username, password: Posthorn.configuration.password })
|
22
|
+
user = OpenStruct.new response.body[:authenticate_user_response]
|
23
|
+
user.wallet_balance = user.wallet_balance.to_i
|
24
|
+
|
25
|
+
user
|
26
|
+
end
|
27
|
+
|
28
|
+
def call(method, message = {})
|
29
|
+
@base.call(method, message: message)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/posthorn.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'securerandom'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
require 'savon'
|
6
|
+
require 'countries'
|
7
|
+
require "httpi"
|
8
|
+
|
9
|
+
require 'posthorn/version'
|
10
|
+
require 'posthorn/configuration'
|
11
|
+
require 'posthorn/soap_client'
|
12
|
+
require 'posthorn/office'
|
13
|
+
require 'posthorn/address'
|
14
|
+
require 'posthorn/label'
|
15
|
+
|
16
|
+
module Posthorn
|
17
|
+
end
|
data/posthorn.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'posthorn/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "posthorn"
|
8
|
+
spec.version = Posthorn::VERSION
|
9
|
+
spec.authors = ["Patrick Franken", "AISLER B.V."]
|
10
|
+
spec.email = ["p.franken@aisler.net"]
|
11
|
+
spec.summary = "Easy access to Deutsche Post 1C4A webservice"
|
12
|
+
spec.description = "With this Gem it is possible to order pre-paid shipping stickers from the Deutsche Post. Payment is done through the so called \"Portokasse\", a prepaid wallet service. To use this Gem a registration for the \"Portokasse\" and the 1C4A webservice is necessary."
|
13
|
+
spec.homepage = "http://aisler.net"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'savon', '~> 2'
|
22
|
+
spec.add_runtime_dependency 'countries', '~> 2'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "geminabox"
|
28
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Address do
|
4
|
+
it 'should create company and private addresses', focus: true do
|
5
|
+
address = Address.new(firstname: 'Hans Peter',
|
6
|
+
lastname: 'Wurst',
|
7
|
+
street: 'Schoolstraat',
|
8
|
+
no: '2',
|
9
|
+
city: 'Lemiers',
|
10
|
+
zip: '6295AV',
|
11
|
+
country: 'nl'
|
12
|
+
)
|
13
|
+
|
14
|
+
expect(address.company?).to be_falsey
|
15
|
+
expect(address.to_h[:name][:companyName]).to be_nil
|
16
|
+
expect(address.to_h[:name][:personName]).not_to be_nil
|
17
|
+
|
18
|
+
|
19
|
+
address = Address.new(company: 'Wurst & Co.',
|
20
|
+
firstname: 'Hans Peter',
|
21
|
+
lastname: 'Wurst',
|
22
|
+
street: 'Schoolstraat',
|
23
|
+
no: '2',
|
24
|
+
city: 'Lemiers',
|
25
|
+
zip: '6295AV',
|
26
|
+
country: 'nl'
|
27
|
+
)
|
28
|
+
|
29
|
+
expect(address.company?).to be_truthy
|
30
|
+
expect(address.to_h[:name][:companyName]).not_to be_nil
|
31
|
+
expect(address.to_h[:name][:personName]).to be_nil
|
32
|
+
|
33
|
+
address = Address.new(company: 'Hans Peter Wurst',
|
34
|
+
firstname: 'Hans Peter',
|
35
|
+
lastname: 'Wurst',
|
36
|
+
street: 'Schoolstraat',
|
37
|
+
no: '2',
|
38
|
+
city: 'Lemiers',
|
39
|
+
zip: '6295AV',
|
40
|
+
country: 'nl'
|
41
|
+
)
|
42
|
+
|
43
|
+
expect(address.company?).to be_falsey
|
44
|
+
expect(address.to_h[:name][:companyName]).to be_nil
|
45
|
+
expect(address.to_h[:name][:personName]).not_to be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should create addresses with street and number combined' do
|
49
|
+
address = Address.new(company: 'Wurst & Co.',
|
50
|
+
firstname: 'Hans Peter',
|
51
|
+
lastname: 'Wurst',
|
52
|
+
street: 'Schoolstraat 2',
|
53
|
+
city: 'Lemiers',
|
54
|
+
zip: '6295AV',
|
55
|
+
country: 'nl'
|
56
|
+
)
|
57
|
+
|
58
|
+
expect(address.street).to eq('Schoolstraat')
|
59
|
+
expect(address.no).to eq('2')
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
data/spec/office_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Office do
|
4
|
+
it 'should receive all page formats' do
|
5
|
+
office = Office.new
|
6
|
+
formats = office.page_formats
|
7
|
+
|
8
|
+
expect(formats).to be_an Array
|
9
|
+
expect(formats.length).to eq(108)
|
10
|
+
expect(formats[0].id).to eq('7')
|
11
|
+
expect(formats[0].name).to eq('Herma 8748 CompactLine 105 x 74')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should return user\'s wallet balance' do
|
15
|
+
office = Office.new
|
16
|
+
expect(office.user.wallet_balance).to be_an Fixnum
|
17
|
+
expect(office.user.wallet_balance).to be > 0
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should order national post stamps' do
|
21
|
+
office = Office.new
|
22
|
+
|
23
|
+
receiver = Address.new(
|
24
|
+
company: 'Hans Peter Wurst Inc.',
|
25
|
+
firstname: 'Hans Peter',
|
26
|
+
lastname: 'Wurst',
|
27
|
+
street: 'Schoolstraat',
|
28
|
+
no: '2',
|
29
|
+
city: 'Lemiers',
|
30
|
+
zip: '6295',
|
31
|
+
country: 'de')
|
32
|
+
|
33
|
+
sender = Address.new(
|
34
|
+
company: 'AISLER B.V.',
|
35
|
+
street: 'Schoolstraat',
|
36
|
+
no: '2',
|
37
|
+
city: 'Lemiers',
|
38
|
+
zip: '6295AV',
|
39
|
+
country: 'nl')
|
40
|
+
|
41
|
+
office.cart << Label.new(sender, receiver, product_id: 21, price: 145)
|
42
|
+
expect(office.cart.length).to eq(1)
|
43
|
+
|
44
|
+
labels = office.checkout!(page_format: 25)
|
45
|
+
expect(labels.length).to be >= 100
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SoapClient do
|
4
|
+
it 'should authenticate user and get an user token' do
|
5
|
+
client = SoapClient.new
|
6
|
+
user = client.authenticate
|
7
|
+
expect(user.user_token.length).to be(44)
|
8
|
+
expect(user.wallet_balance).to be_an Fixnum
|
9
|
+
end
|
10
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'posthorn'
|
2
|
+
include Posthorn
|
3
|
+
|
4
|
+
Posthorn.configure do |c|
|
5
|
+
c.dpwn_key = ENV['POSTHORN_DPWN_KEY']
|
6
|
+
c.partner_id = ENV['POSTHORN_PARTNER_ID']
|
7
|
+
c.key_phase = ENV['POSTHORN_KEY_PHASE']
|
8
|
+
c.username = ENV['POSTHORN_USERNAME']
|
9
|
+
c.password = ENV['POSTHORN_PASSWORD']
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: posthorn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patrick Franken
|
8
|
+
- AISLER B.V.
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: savon
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: countries
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '2'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '2'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: geminabox
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
description: With this Gem it is possible to order pre-paid shipping stickers from
|
99
|
+
the Deutsche Post. Payment is done through the so called "Portokasse", a prepaid
|
100
|
+
wallet service. To use this Gem a registration for the "Portokasse" and the 1C4A
|
101
|
+
webservice is necessary.
|
102
|
+
email:
|
103
|
+
- p.franken@aisler.net
|
104
|
+
executables: []
|
105
|
+
extensions: []
|
106
|
+
extra_rdoc_files: []
|
107
|
+
files:
|
108
|
+
- ".gitignore"
|
109
|
+
- ".gitlab-ci.yml"
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- doc/example_label.png
|
115
|
+
- lib/posthorn.rb
|
116
|
+
- lib/posthorn/address.rb
|
117
|
+
- lib/posthorn/configuration.rb
|
118
|
+
- lib/posthorn/label.rb
|
119
|
+
- lib/posthorn/office.rb
|
120
|
+
- lib/posthorn/product_info.rb
|
121
|
+
- lib/posthorn/soap_client.rb
|
122
|
+
- lib/posthorn/version.rb
|
123
|
+
- posthorn.gemspec
|
124
|
+
- spec/address_spec.rb
|
125
|
+
- spec/office_spec.rb
|
126
|
+
- spec/soap_client_spec.rb
|
127
|
+
- spec/spec_helper.rb
|
128
|
+
homepage: http://aisler.net
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.5.1
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: Easy access to Deutsche Post 1C4A webservice
|
152
|
+
test_files:
|
153
|
+
- spec/address_spec.rb
|
154
|
+
- spec/office_spec.rb
|
155
|
+
- spec/soap_client_spec.rb
|
156
|
+
- spec/spec_helper.rb
|