royal_mail_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/royal_mail_api.rb +22 -0
- data/lib/royal_mail_api/client.rb +14 -0
- data/lib/royal_mail_api/config.rb +14 -0
- data/lib/royal_mail_api/error.rb +61 -0
- data/lib/royal_mail_api/request_handler.rb +60 -0
- data/lib/royal_mail_api/response.rb +72 -0
- data/lib/royal_mail_api/response_handler.rb +9 -0
- data/lib/royal_mail_api/version.rb +3 -0
- data/lib/royal_mail_api/warning.rb +12 -0
- data/lib/royal_mail_api/xml_builder.rb +51 -0
- data/lib/royal_mail_api/xml_parser.rb +20 -0
- data/lib/xml/create_shipment.xml +74 -0
- data/lib/xml/envelope.xml +8 -0
- data/lib/xml/security_header.xml +11 -0
- data/royal_mail_api.gemspec +29 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c01736c6d05427c31f7f0d6f02f8a1ec05df6119
|
4
|
+
data.tar.gz: e3a2d198094f97b39ca060a8fe23dbb2db5e3541
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6c055ad3497eec87ef76a46dc0c6c99f1fd4f5b217d80a341ae2bce54c52bd0f5bddf0627c1323a6fd17d73b1659c508adac2d641f04680bf6aa63008a31950d
|
7
|
+
data.tar.gz: 7f894303cda4f209982b97d7ef9289aa582e65aca1efd7d2538b1e2a74b063bf68e173f093c8fb554b08cd45b1bf2a25454f79e0658ce3f36c4bd68a506d7259
|
data/.gitignore
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
/.env
|
11
|
+
/.DS_Store
|
12
|
+
/lib/.DS_Store
|
13
|
+
/lib/royal_mail_api/.DS_Store
|
14
|
+
/spec/support/fixtures/.DS_Store
|
15
|
+
/spec/support/fixtures/vcr_cassettes
|
16
|
+
/*.gem
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Srikanth Kunkulagunta
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# RoyalMailApi
|
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/royal_mail_api`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'royal_mail_api'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install royal_mail_api
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
in initializers/royal_mail_api.rb
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
RoyalMailApi::Client.configure do |config|
|
29
|
+
config.application_id = 'your Royal Mail application id'
|
30
|
+
config.username = 'your Royal Mail username'
|
31
|
+
config.password = ''your Royal Mail password'
|
32
|
+
config.adapter = library used for http requests (eg. httpclient, excon)
|
33
|
+
config.wsdl = 'path to your wsdl file'
|
34
|
+
config.ssl_ca_cert_file = 'path to your Royal Mail ca cert file'
|
35
|
+
config.ssl_cert_file = 'path to your Royal Mail cert file'
|
36
|
+
config.ssl_cert_key_file = 'path to your Royal Mail key file'
|
37
|
+
config.endpoint = api endpoint for sandbox/production (eg. "https://api.royalmail.com/shipping/onboarding")
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
### to make a request
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
RoyalMailApi::RequestHandler.request(type, attrs)
|
45
|
+
```
|
46
|
+
|
47
|
+
#### types:
|
48
|
+
|
49
|
+
create_shipment
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
attrs = {
|
53
|
+
transaction_id: unique identifier, preferably the id of the delivery in your system,
|
54
|
+
shipping_date: format ('%Y-%m-%d'),
|
55
|
+
user_name: '',
|
56
|
+
email: '',
|
57
|
+
address_line1: '',
|
58
|
+
post_town: '',
|
59
|
+
post_code: '',
|
60
|
+
weight: weight of letter/parcel,
|
61
|
+
country_code: addressee's number's country code,
|
62
|
+
telephone_number: ''
|
63
|
+
}
|
64
|
+
|
65
|
+
RoyalMailApi::RequestHandler.request(:create_shipment, attrs)
|
66
|
+
```
|
67
|
+
|
68
|
+
## Development
|
69
|
+
|
70
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
71
|
+
|
72
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
1. Fork it ( https://github.com/[my-github-username]/royal_mail_api/fork )
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
79
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
80
|
+
5. Create a new Pull Request
|
81
|
+
|
82
|
+
## config adapter
|
83
|
+
To make sure that savon can make the requests you may have to install another library to use as an adapter:
|
84
|
+
|
85
|
+
https://github.com/savonrb/savon/issues/679
|
86
|
+
https://github.com/savonrb/savon/issues/491
|
87
|
+
https://github.com/savonrb/savon/issues/297
|
88
|
+
|
89
|
+
This is a consistent issue, so best to play around.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "royal_mail_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'base64'
|
3
|
+
require 'savon'
|
4
|
+
require 'digest/sha1'
|
5
|
+
require "active_support/core_ext/string"
|
6
|
+
|
7
|
+
require "royal_mail_api/version"
|
8
|
+
require 'royal_mail_api/config'
|
9
|
+
require 'royal_mail_api/request_handler'
|
10
|
+
require 'royal_mail_api/xml_builder'
|
11
|
+
require 'royal_mail_api/xml_parser'
|
12
|
+
require 'royal_mail_api/response_handler'
|
13
|
+
require 'royal_mail_api/response'
|
14
|
+
require 'royal_mail_api/client'
|
15
|
+
require 'royal_mail_api/error'
|
16
|
+
require 'royal_mail_api/warning'
|
17
|
+
|
18
|
+
module RoyalMailApi
|
19
|
+
def self.root
|
20
|
+
File.dirname __dir__
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module RoyalMailApi
|
2
|
+
class Error < StandardError
|
3
|
+
attr_accessor :code, :description
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
raise ArgumentError 'royal mail error must be initialized with a hash' unless args.is_a? Hash
|
7
|
+
raise ArgumentError 'error must contain some information' unless args.present?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class RoyalMailError < Error
|
12
|
+
def initialize(args)
|
13
|
+
super
|
14
|
+
|
15
|
+
@code = args[:error_code]
|
16
|
+
@description = args[:error_description]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class SoapError < Error
|
21
|
+
attr_accessor :parser,
|
22
|
+
:xml,
|
23
|
+
:faultcode,
|
24
|
+
:faultstring
|
25
|
+
|
26
|
+
SOAP_FAULT_DESCRIPTIONS = {
|
27
|
+
"env:VersionMismatch" => "Found an invalid namespace for the SOAP Envelope element.",
|
28
|
+
"env:MustUnderstand" => "An immediate child element of the Header element, with the mustUnderstand attribute set to '1', was not understood.",
|
29
|
+
"env:Client" => "The message was incorrectly formed or contained incorrect information.",
|
30
|
+
"env:Server" => "There was a problem with the server, so the message could not proceed."
|
31
|
+
}
|
32
|
+
|
33
|
+
def initialize(args)
|
34
|
+
super
|
35
|
+
|
36
|
+
@xml = args[:xml]
|
37
|
+
@code = args[:error_code]
|
38
|
+
@parser = RoyalMailApi::XmlParser.new
|
39
|
+
|
40
|
+
set_faultcode
|
41
|
+
set_faultstring
|
42
|
+
set_description
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def set_faultcode
|
48
|
+
@faultcode = parser.parse_text(xml, "faultcode")
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_faultstring
|
52
|
+
@faultstring = parser.parse_text(xml, "faultstring")
|
53
|
+
end
|
54
|
+
|
55
|
+
def set_description
|
56
|
+
desc = SOAP_FAULT_DESCRIPTIONS.fetch(faultcode) { "Sorry, no further information available" }
|
57
|
+
|
58
|
+
@description = "#{faultcode} error: #{desc}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module RoyalMailApi
|
2
|
+
class RequestHandler
|
3
|
+
class << self
|
4
|
+
def request(request, attrs={})
|
5
|
+
begin
|
6
|
+
savon.call(request, xml: build_xml(attrs))
|
7
|
+
rescue Savon::SOAPFault => e
|
8
|
+
raise RoyalMailApi::SoapError.new({
|
9
|
+
xml: e.xml,
|
10
|
+
error_code: e.http.code
|
11
|
+
})
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def build_xml(attrs={})
|
18
|
+
XmlBuilder.new(:create_shipment, attrs.merge(security_attrs)).build
|
19
|
+
end
|
20
|
+
|
21
|
+
def security_attrs
|
22
|
+
# TODO move into own value object
|
23
|
+
|
24
|
+
password = config.password
|
25
|
+
creation_date = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S')
|
26
|
+
nonce = rand(999999).to_s
|
27
|
+
|
28
|
+
hashedpassword = Digest::SHA1.base64digest(password)
|
29
|
+
|
30
|
+
{
|
31
|
+
username: config.username,
|
32
|
+
application_id: config.application_id,
|
33
|
+
creation_date: creation_date,
|
34
|
+
encoded_nonce: Base64.encode64(nonce),
|
35
|
+
password_digest: Digest::SHA1.base64digest(
|
36
|
+
nonce + creation_date + hashedpassword
|
37
|
+
)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def savon
|
42
|
+
Savon.client(
|
43
|
+
adapter: config.adapter,
|
44
|
+
wsdl: config.wsdl,
|
45
|
+
endpoint: config.endpoint,
|
46
|
+
namespace: config.endpoint,
|
47
|
+
ssl_ca_cert_file: config.ssl_ca_cert_file,
|
48
|
+
ssl_cert_file: config.ssl_cert_file,
|
49
|
+
ssl_cert_key_file: config.ssl_cert_key_file,
|
50
|
+
open_timeout: 600,
|
51
|
+
read_timeout: 600
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def config
|
56
|
+
Client.config
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module RoyalMailApi
|
2
|
+
class Response
|
3
|
+
attr_accessor :body,
|
4
|
+
:http,
|
5
|
+
:parser,
|
6
|
+
:errors,
|
7
|
+
:warnings,
|
8
|
+
:shipments
|
9
|
+
|
10
|
+
Shipment = Struct.new(
|
11
|
+
:item_id,
|
12
|
+
:shipment_number,
|
13
|
+
:valid_from
|
14
|
+
)
|
15
|
+
|
16
|
+
def initialize(response)
|
17
|
+
@parser = RoyalMailApi::XmlParser.new
|
18
|
+
set_attrs(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def parse(xml, attr)
|
24
|
+
parser.parse(xml, attr)
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_all(xml, attr)
|
28
|
+
parser.parse_all(xml, attr)
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_text(xml, attr)
|
32
|
+
parser.parse_text(xml, attr)
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_attrs(response)
|
36
|
+
@body = response.xml
|
37
|
+
@http = response.http
|
38
|
+
|
39
|
+
set_errors
|
40
|
+
set_warnings
|
41
|
+
set_shipments
|
42
|
+
end
|
43
|
+
|
44
|
+
def set_errors
|
45
|
+
@errors = parse_all(body, "error").map do |error|
|
46
|
+
RoyalMailApi::RoyalMailError.new({
|
47
|
+
error_code: parse_text(error, "errorCode"),
|
48
|
+
error_description: parse_text(error, "errorDescription")
|
49
|
+
})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_warnings
|
54
|
+
@warnings = parse_all(body, "warning").map do |warning|
|
55
|
+
RoyalMailApi::Warning.new({
|
56
|
+
warning_code: parse_text(warning, "warningCode"),
|
57
|
+
warning_description: parse_text(warning, "warningDescription")
|
58
|
+
})
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def set_shipments
|
63
|
+
@shipments = parse_all(body, "shipment").map do |shipment|
|
64
|
+
Shipment.new(
|
65
|
+
parse_text(shipment, "itemId"),
|
66
|
+
parse_text(shipment, "shipmentNumber"),
|
67
|
+
parse_text(shipment, "validFrom")
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module RoyalMailApi
|
2
|
+
class Warning
|
3
|
+
attr_accessor :code, :description
|
4
|
+
|
5
|
+
def initialize(warning)
|
6
|
+
return unless warning.class.name == 'Hash' && warning.any?
|
7
|
+
|
8
|
+
@code = warning[:warning_code],
|
9
|
+
@description = warning[:warning_description]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
class XmlBuilder < OpenStruct
|
5
|
+
attr_reader :request
|
6
|
+
|
7
|
+
SPECIAL_CHARACTER_MAP = {
|
8
|
+
'"' => """,
|
9
|
+
"&" => "&",
|
10
|
+
"'" => "'",
|
11
|
+
"<" => "<",
|
12
|
+
">" => ">"
|
13
|
+
}
|
14
|
+
|
15
|
+
def initialize(request, attrs={})
|
16
|
+
@request = request
|
17
|
+
super attrs
|
18
|
+
end
|
19
|
+
|
20
|
+
def build
|
21
|
+
envelope
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def xml_path
|
27
|
+
[RoyalMailApi.root, 'lib', 'xml']
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_xml(file)
|
31
|
+
path = File.join(xml_path << file)
|
32
|
+
ERB.new(File.read(path)).result(binding)
|
33
|
+
end
|
34
|
+
|
35
|
+
def header
|
36
|
+
build_xml('security_header.xml')
|
37
|
+
end
|
38
|
+
|
39
|
+
def body
|
40
|
+
build_xml("#{request}.xml")
|
41
|
+
end
|
42
|
+
|
43
|
+
def envelope
|
44
|
+
build_xml('envelope.xml')
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_special_characters(str)
|
48
|
+
return str unless str.is_a? String
|
49
|
+
str.gsub(/["&'<>]/, SPECIAL_CHARACTER_MAP)
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module RoyalMailApi
|
2
|
+
class XmlParser
|
3
|
+
def parse(xml, attr)
|
4
|
+
unless xml.is_a? Nokogiri::XML::Element
|
5
|
+
xml = Nokogiri::XML(xml).remove_namespaces!
|
6
|
+
end
|
7
|
+
|
8
|
+
# xpath method doesn't work for finding SOAP Fault attributes for some reason
|
9
|
+
xml.css(attr)
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse_all(xml, attr)
|
13
|
+
parse(xml, "//#{attr}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_text(xml, attr)
|
17
|
+
parse(xml, attr).text
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
<soapenv:Body>
|
2
|
+
<v2:createShipmentRequest>
|
3
|
+
<v2:integrationHeader>
|
4
|
+
<v1:version>2</v1:version>
|
5
|
+
<v1:identification>
|
6
|
+
<v1:applicationId><%= application_id %></v1:applicationId>
|
7
|
+
<v1:transactionId><%= transaction_id %></v1:transactionId>
|
8
|
+
</v1:identification>
|
9
|
+
</v2:integrationHeader>
|
10
|
+
<v2:requestedShipment>
|
11
|
+
<v2:shipmentType>
|
12
|
+
<code>
|
13
|
+
Delivery
|
14
|
+
</code>
|
15
|
+
</v2:shipmentType>
|
16
|
+
<v2:serviceOccurrence>
|
17
|
+
1
|
18
|
+
</v2:serviceOccurrence>
|
19
|
+
<v2:serviceType>
|
20
|
+
<code>
|
21
|
+
T
|
22
|
+
</code>
|
23
|
+
</v2:serviceType>
|
24
|
+
<v2:serviceOffering>
|
25
|
+
<serviceOfferingCode>
|
26
|
+
<code>
|
27
|
+
TPN
|
28
|
+
</code>
|
29
|
+
</serviceOfferingCode>
|
30
|
+
</v2:serviceOffering>
|
31
|
+
<v2:shippingDate><%= shipping_date %></v2:shippingDate>
|
32
|
+
<v2:recipientContact>
|
33
|
+
<v2:name><%= user_name %></v2:name>
|
34
|
+
<v2:complementaryName></v2:complementaryName>
|
35
|
+
<% if try(:telephone_number) %>
|
36
|
+
<v2:telephoneNumber>
|
37
|
+
<countryCode><%= country_code || '0044' %></countryCode>
|
38
|
+
<telephoneNumber><%= telephone_number %></telephoneNumber>
|
39
|
+
</v2:telephoneNumber>
|
40
|
+
<% end %>
|
41
|
+
<v2:electronicAddress>
|
42
|
+
<electronicAddress><%= email %></electronicAddress>
|
43
|
+
</v2:electronicAddress>
|
44
|
+
</v2:recipientContact>
|
45
|
+
<v2:recipientAddress>
|
46
|
+
<addressLine1><%= address_line1 %></addressLine1>
|
47
|
+
<addressLine2><%= try(:address_line2) %></addressLine2>
|
48
|
+
<postTown><%= post_town %></postTown>
|
49
|
+
<postcode><%= post_code %></postcode>
|
50
|
+
<country>
|
51
|
+
<countryCode>
|
52
|
+
<code>GB</code>
|
53
|
+
</countryCode>
|
54
|
+
</country>
|
55
|
+
</v2:recipientAddress>
|
56
|
+
<v2:items>
|
57
|
+
<v2:item>
|
58
|
+
<v2:numberOfItems>1</v2:numberOfItems>
|
59
|
+
<v2:weight>
|
60
|
+
<unitOfMeasure>
|
61
|
+
<unitOfMeasureCode>
|
62
|
+
<code>g</code>
|
63
|
+
</unitOfMeasureCode>
|
64
|
+
</unitOfMeasure>
|
65
|
+
<value><%= weight %></value>
|
66
|
+
</v2:weight>
|
67
|
+
</v2:item>
|
68
|
+
</v2:items>
|
69
|
+
<v2:customerReference>CustSuppRef1</v2:customerReference>
|
70
|
+
<v2:senderReference>SenderReference1</v2:senderReference>
|
71
|
+
<v2:safePlace><%= try(:safe_place) %></v2:safePlace>
|
72
|
+
</v2:requestedShipment>
|
73
|
+
</v2:createShipmentRequest>
|
74
|
+
</soapenv:Body>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<soapenv:Envelope
|
2
|
+
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
3
|
+
xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
|
4
|
+
xmlns:v2="http://www.royalmailgroup.com/api/ship/V2"
|
5
|
+
xmlns:v1="http://www.royalmailgroup.com/integration/core/V1">
|
6
|
+
<%= header %>
|
7
|
+
<%= body %>
|
8
|
+
</soapenv:Envelope>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<soapenv:Header>
|
2
|
+
<oas:Security xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
|
3
|
+
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
|
4
|
+
<oas:UsernameToken>
|
5
|
+
<oas:Username><%= username %></oas:Username>
|
6
|
+
<oas:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-tokenprofile-1.0#PasswordDigest"><%= password_digest %></oas:Password>
|
7
|
+
<oas:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"><%= encoded_nonce %></oas:Nonce>
|
8
|
+
<wsu:Created><%= creation_date %></wsu:Created>
|
9
|
+
</oas:UsernameToken>
|
10
|
+
</oas:Security>
|
11
|
+
</soapenv:Header>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'royal_mail_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "royal_mail_api"
|
8
|
+
spec.version = RoyalMailApi::VERSION
|
9
|
+
spec.authors = ["Srikanth Kunkulagunta"]
|
10
|
+
spec.email = ["srikanth.kunkulagunta@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{ruby wrapper for Royal Mail's API}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "savon", "~> 2.10"
|
22
|
+
spec.add_dependency "activesupport", "~> 4"
|
23
|
+
spec.add_dependency "httpclient", "~> 2.3"
|
24
|
+
spec.add_development_dependency "vcr", "~> 2.9"
|
25
|
+
spec.add_development_dependency "dotenv", "~> 2.0"
|
26
|
+
spec.add_development_dependency "webmock", "~> 1.21"
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: royal_mail_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Srikanth Kunkulagunta
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: savon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.10'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httpclient
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vcr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.21'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.21'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.9'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.9'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '10.0'
|
125
|
+
description:
|
126
|
+
email:
|
127
|
+
- srikanth.kunkulagunta@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- bin/console
|
140
|
+
- bin/setup
|
141
|
+
- lib/royal_mail_api.rb
|
142
|
+
- lib/royal_mail_api/client.rb
|
143
|
+
- lib/royal_mail_api/config.rb
|
144
|
+
- lib/royal_mail_api/error.rb
|
145
|
+
- lib/royal_mail_api/request_handler.rb
|
146
|
+
- lib/royal_mail_api/response.rb
|
147
|
+
- lib/royal_mail_api/response_handler.rb
|
148
|
+
- lib/royal_mail_api/version.rb
|
149
|
+
- lib/royal_mail_api/warning.rb
|
150
|
+
- lib/royal_mail_api/xml_builder.rb
|
151
|
+
- lib/royal_mail_api/xml_parser.rb
|
152
|
+
- lib/xml/create_shipment.xml
|
153
|
+
- lib/xml/envelope.xml
|
154
|
+
- lib/xml/security_header.xml
|
155
|
+
- royal_mail_api.gemspec
|
156
|
+
homepage: ''
|
157
|
+
licenses:
|
158
|
+
- MIT
|
159
|
+
metadata: {}
|
160
|
+
post_install_message:
|
161
|
+
rdoc_options: []
|
162
|
+
require_paths:
|
163
|
+
- lib
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
requirements: []
|
175
|
+
rubyforge_project:
|
176
|
+
rubygems_version: 2.4.6
|
177
|
+
signing_key:
|
178
|
+
specification_version: 4
|
179
|
+
summary: ruby wrapper for Royal Mail's API
|
180
|
+
test_files: []
|
181
|
+
has_rdoc:
|