postat 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fbc5fb921e2c840e64f5898d80641eadfd0aeee0
4
+ data.tar.gz: 6cc55eef198ebdfe38491975df306432cc1f354a
5
+ SHA512:
6
+ metadata.gz: bd81648edd06753ab585c64c398090d29c13c4f9eda9c31101fd9831c3ff46d334fab4adcdb11d6249a8cded9fde8e1d96136fe119b8e0001a768b58686ba0a6
7
+ data.tar.gz: 9a00e643428e73be9c73611552525c681079db95ed7cdb27f0a31e8889798e840c3798f5138599336c8e66384961ee74a1d35875c5664293e1b7c2cd56224665
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ spec/config.yml
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+ gem 'savon', '~> 2.11.1'
3
+
4
+ group :dev do # not development <-> would add unneeded development dependencies in gemspec
5
+ gem 'rake'
6
+ gem 'rspec', '~>2'
7
+ gem 'rubocop'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ akami (1.3.1)
5
+ gyoku (>= 0.4.0)
6
+ nokogiri
7
+ ast (2.3.0)
8
+ builder (3.2.3)
9
+ diff-lcs (1.1.2)
10
+ gyoku (1.3.1)
11
+ builder (>= 2.1.2)
12
+ httpi (2.4.2)
13
+ rack
14
+ socksify
15
+ mini_portile2 (2.3.0)
16
+ nokogiri (1.8.1)
17
+ mini_portile2 (~> 2.3.0)
18
+ nori (2.6.0)
19
+ parallel (1.12.0)
20
+ parser (2.4.0.0)
21
+ ast (~> 2.2)
22
+ powerpack (0.1.1)
23
+ rack (2.0.3)
24
+ rainbow (2.2.2)
25
+ rake
26
+ rake (0.8.7)
27
+ rspec (2.5.0)
28
+ rspec-core (~> 2.5.0)
29
+ rspec-expectations (~> 2.5.0)
30
+ rspec-mocks (~> 2.5.0)
31
+ rspec-core (2.5.1)
32
+ rspec-expectations (2.5.0)
33
+ diff-lcs (~> 1.1.2)
34
+ rspec-mocks (2.5.0)
35
+ rubocop (0.51.0)
36
+ parallel (~> 1.10)
37
+ parser (>= 2.3.3.1, < 3.0)
38
+ powerpack (~> 0.1)
39
+ rainbow (>= 2.2.2, < 3.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (~> 1.0, >= 1.0.1)
42
+ ruby-progressbar (1.9.0)
43
+ savon (2.11.2)
44
+ akami (~> 1.2)
45
+ builder (>= 2.1.2)
46
+ gyoku (~> 1.2)
47
+ httpi (~> 2.3)
48
+ nokogiri (>= 1.4.0)
49
+ nori (~> 2.4)
50
+ wasabi (~> 3.4)
51
+ socksify (1.7.1)
52
+ unicode-display_width (1.3.0)
53
+ wasabi (3.5.0)
54
+ httpi (~> 2.0)
55
+ nokogiri (>= 1.4.2)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ rake
62
+ rspec (~> 2)
63
+ rubocop
64
+ savon (~> 2.11.1)
65
+
66
+ BUNDLED WITH
67
+ 1.16.0
data/Rakefile ADDED
File without changes
data/Readme.md ADDED
@@ -0,0 +1,54 @@
1
+ # Shipgate-Soap Wrapper for ruby
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'postat'
9
+ ```
10
+
11
+ And then execute:
12
+ ```shell
13
+ $ bundle
14
+ ```
15
+ Or install it yourself as:
16
+ ```shell
17
+ $ gem install postat
18
+ ```
19
+
20
+ ##### After bundle
21
+ ```shell
22
+ $ rails g postat
23
+ ```
24
+ This adds the following:
25
+ * `config/initializers/postat.rb`
26
+
27
+ * `config/postat.yml`
28
+ `config/postat-example.yml`
29
+ ```yml
30
+ development:
31
+ guid: 'guid'
32
+ username: 'username'
33
+ password: 'password'
34
+ namespace: 'http://example.com/'
35
+ wsdl: 'http://example.com/soap?WSDL'
36
+ ```
37
+
38
+ * `.gitignore`
39
+ ```
40
+ config/postat.yml
41
+ ```
42
+
43
+ ## Usage
44
+ This Gem provides you with a Wrapper for the Shipgate-Soap-Api
45
+
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/datyv/postat. 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.
50
+
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/base'
4
+
5
+ class PostatGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ desc 'Copy the initializer for Postat'
9
+ def copy_initializer_file
10
+ copy_file 'initializer.rb', 'config/initializers/postat.rb'
11
+ end
12
+
13
+ desc 'Copy the yml for Postat'
14
+ def copy_yml_files
15
+ copy_file 'initializer.yml', 'config/postat.yml'
16
+ copy_file 'initializer.yml', 'config/postat-example.yml'
17
+ end
18
+
19
+ desc 'Add yml to .gitignore'
20
+ def add_to_gitignore
21
+ append_to_file '.gitignore', 'config/postat.yml'
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ POSTAT_CONFIG = {
4
+ guid: ENV['POSTAT_GUID'] || 'guid',
5
+ username: ENV['POSTAT_USERNAME'] || 'username',
6
+ password: ENV['POSTAT_PASSWORD'] || 'password',
7
+ namespace: ENV['POSTAT_NAMESPACE'] || 'http://example.com/',
8
+ wsdl: ENV['POSTAT_WSDL'] || 'http://example.com/soap?WSDL'
9
+ }
10
+
11
+ config_file = File.expand_path("#{Rails.root}/config/postat.yml", __FILE__)
12
+ if File.exist?(config_file)
13
+ configs_from_file = YAML.safe_load(File.read(config_file))
14
+ POSTAT_CONFIG.merge!(configs_from_file[Rails.env])
15
+ POSTAT_CONFIG.symbolize_keys!
16
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ development:
4
+ guid: 'guid'
5
+ username: 'username'
6
+ password: 'password'
7
+ namespace: 'http://example.com/'
8
+ wsdl: 'http://example.com/soap?WSDL'
9
+
10
+ test:
11
+ guid: 'guid'
12
+ username: 'username'
13
+ password: 'password'
14
+ namespace: 'http://example.com/'
15
+ wsdl: 'http://example.com/soap?WSDL'
16
+
17
+ beta:
18
+ guid: 'guid'
19
+ username: 'username'
20
+ password: 'password'
21
+ namespace: 'http://example.com/'
22
+ wsdl: 'http://example.com/soap?WSDL'
23
+
24
+ production:
25
+ guid: 'guid'
26
+ username: 'username'
27
+ password: 'password'
28
+ namespace: 'http://example.com/'
29
+ wsdl: 'http://example.com/soap?WSDL'
data/lib/postat.rb ADDED
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'savon'
4
+
5
+ class Postat
6
+ attr_reader :client
7
+
8
+ def initialize
9
+ @user = POSTAT_CONFIG[:username] || raise('missing :user')
10
+ @password = POSTAT_CONFIG[:password] || raise('missing :password')
11
+ @guid = POSTAT_CONFIG[:guid] || raise('missing :guid')
12
+ @client = Savon.client wsdl: POSTAT_CONFIG[:wsdl], namespace_identifier: :ryl, convert_request_keys_to: :none
13
+ end
14
+
15
+ def delete_label(options = {})
16
+ message = add_common_params
17
+ options[:shipments]&.each do |shipment|
18
+ message[:Shipments] << { 'CancelRequest.Shipment' => shipment }
19
+ end
20
+ response = client.call(:delete_label, message: { ShippingRequest: message })
21
+ handle_response response
22
+ end
23
+
24
+ def generate_label(options = {})
25
+ message = add_common_params
26
+ message[:DeliveryProductCode] = options[:delivery_code]
27
+ message[:ReturnProductCode] = options[:return_code]
28
+ message[:Shipments]['Request.Shipment'] = build_shipment(options)
29
+ response = client.call(:create_label, message: { ShippingRequest: message },
30
+ attributes: { 'xmlns' => 'http://rylos.lu/' })
31
+ handle_response response
32
+ end
33
+
34
+ private
35
+
36
+ def handle_response(response)
37
+ response = response.to_hash
38
+ success = response&.dig(:create_label_response, :create_label_result, :was_successful) || false
39
+ return response if success
40
+ message = response&.dig(:create_label_response, :create_label_result, :messages, :message) || []
41
+ raise StandardError, message.values&.join(': ')
42
+ end
43
+
44
+ def build_shipment(options = {})
45
+ shipment = {}
46
+ shipment[:Shipper] = add_address(options[:from])
47
+ shipment[:Receiver] = add_address(options[:to])
48
+ shipment[:Date] = (Time.zone.now + 180).iso8601
49
+ shipment[:PaymentType] = 'RECEIVER'
50
+ shipment[:CustomerReference] = options[:reference_number] if options[:delivery_code]
51
+ shipment[:ReturnReference] = options[:reference_number] if options[:return_code]
52
+ shipment[:CurrencyCode] = 'EUR'
53
+ shipment[:AdditionalInsurance] = 0
54
+ commodities = add_commodities(options[:commodities])
55
+ shipment[:Commodities] = commodities unless commodities.empty?
56
+ packages = add_packages(options[:package])
57
+ shipment[:Packages] = packages unless packages.empty?
58
+ shipment[:Label] = { ImageType: 'PDF', PaperFormat: 'A5' }
59
+ shipment
60
+ end
61
+
62
+ def add_common_params
63
+ { Credentials: {
64
+ Guid: @guid,
65
+ Username: @user,
66
+ Password: @password
67
+ },
68
+ Carrier: 'POSTAT',
69
+ Shipments: {} }
70
+ end
71
+
72
+ def add_address(address)
73
+ { CompanyName: address[:company].to_s,
74
+ PersonName: "#{address[:first_name]} #{address[:last_name]}".squish,
75
+ CareOf: address[:care_of].to_s,
76
+ PhoneNumber: address[:phone].to_s,
77
+ EMailAddress: address[:email].to_s,
78
+ CountryCode: address[:country].to_s,
79
+ StateCode: address[:state_code].to_s,
80
+ PostalCode: address[:zip_code].to_s,
81
+ CityName: address[:city].to_s,
82
+ StreetName: address[:street].to_s,
83
+ StreetNo: address[:street_no].to_s }
84
+ end
85
+
86
+ def add_commodities(commodities = [])
87
+ commodity_array = []
88
+ commodities = [commodities] if commodities.is_a?(Hash)
89
+ [*commodities].each_with_index do |commodity, _i|
90
+ commodity_array << {
91
+ 'Request.Commodity' => {
92
+ CountryOfManufacture: commodity[:country_iso].to_s,
93
+ CustomsValue: { Amount: commodity[:price], Currency: 'EUR' },
94
+ Weight: { Amount: commodity[:weight].to_i, WeightType: 'KG' },
95
+ Description: commodity[:category].to_s,
96
+ Name: commodity[:name].to_s,
97
+ NumberOfPieces: 1,
98
+ UnitPrice: { Amount: commodity[:price], Currency: 'EUR' },
99
+ Quantity: 1
100
+ }
101
+ }
102
+ end
103
+ commodity_array
104
+ end
105
+
106
+ def add_packages(packages = [])
107
+ package_array = []
108
+ packages = [packages] if packages.is_a?(Hash)
109
+ [*packages].each_with_index do |package, i|
110
+ package_array << {
111
+ 'Request.Package' => {
112
+ SequenceNumber: i += 1,
113
+ GroupPackageCount: packages.size,
114
+ Weight: { Amount: package[:weight].to_i, WeightType: 'KG' },
115
+ Length: package[:length].to_i,
116
+ Width: package[:width].to_i,
117
+ Height: package[:height].to_i,
118
+ DimensionType: 'CM',
119
+ PackageType: 'CARTON'
120
+ }
121
+ }
122
+ end
123
+ package_array
124
+ end
125
+ end
data/postat.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'postat'
6
+ s.version = '0.0.1'
7
+ s.authors = ['Datyv']
8
+ s.email = ['yvesgoizet@gmail.com']
9
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
10
+
11
+ s.homepage = 'https://github.com/Datyv/postat'
12
+ s.license = 'MIT'
13
+ s.require_paths = ['lib']
14
+ s.summary = 'Wrapper for Rylos SOAP Api for PostAt'
15
+ s.test_files = ['spec/postat_spec.rb', 'spec/spec_helper.rb']
16
+
17
+ if s.respond_to? :specification_version
18
+ s.specification_version = 3
19
+
20
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0')
21
+ s.add_runtime_dependency('savon', ['~> 2.10.0'])
22
+ else
23
+ s.add_dependency('savon', ['~> 2.10.0'])
24
+ end
25
+ else
26
+ s.add_dependency('savon', ['~> 2.10.0'])
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path('spec/spec_helper')
2
+
3
+ describe Postat do
4
+ let(:config) { YAML.load_file('spec/config.yml') }
5
+ let(:client) { Postat.new(config) }
6
+
7
+ it 'has a VERSION' do
8
+ Postat::VERSION.should =~ /^\d+\.\d+\.\d+$/
9
+ end
10
+
11
+ describe :flush do
12
+ it 'can do it' do
13
+ client.flush(config[:cname], '/foo')
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift 'lib'
2
+ require 'post_at'
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: postat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Datyv
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-05 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.0
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.0
27
+ description:
28
+ email:
29
+ - yvesgoizet@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - Rakefile
38
+ - Readme.md
39
+ - lib/generators/postat/postat_generator.rb
40
+ - lib/generators/postat/templates/initializer.rb
41
+ - lib/generators/postat/templates/initializer.yml
42
+ - lib/postat.rb
43
+ - postat.gemspec
44
+ - spec/postat_spec.rb
45
+ - spec/spec_helper.rb
46
+ homepage: https://github.com/Datyv/postat
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.6.13
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Wrapper for Rylos SOAP Api for PostAt
70
+ test_files:
71
+ - spec/postat_spec.rb
72
+ - spec/spec_helper.rb