wing.rb 0.1.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
+ SHA256:
3
+ metadata.gz: 751c45ed1de71b19c8d603fdd747e433d16740cd6343fd07ba3be53a10ed4a50
4
+ data.tar.gz: 25610c4279bd7556a1eb707cd614c684d66c2d77116e27bbebb883ce3e94eb48
5
+ SHA512:
6
+ metadata.gz: 96db770ece76403c5e1d20119eade878d36490434cbe246e37fda80a413a36a03f9189266259f6835e9a8251dc80e4232d91eba8f1a4a1cf4dbc3b0f15eac1fe
7
+ data.tar.gz: 719e6d38a10746ede63e9a1cff73fea68ba7b2ca9cb2cfed12425d63705610629c1b14781070f2d4ae62bb3af658f864d1be5dc4ae13f49edcaf3aec3373fb37
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in wing.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wing-ruby (0.1.0)
5
+ httparty (~> 0.16.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ crack (0.4.3)
13
+ safe_yaml (~> 1.0.0)
14
+ diff-lcs (1.3)
15
+ hashdiff (1.0.0)
16
+ httparty (0.16.2)
17
+ multi_xml (>= 0.5.2)
18
+ multi_xml (0.6.0)
19
+ public_suffix (4.0.3)
20
+ rake (12.3.3)
21
+ rspec (3.9.0)
22
+ rspec-core (~> 3.9.0)
23
+ rspec-expectations (~> 3.9.0)
24
+ rspec-mocks (~> 3.9.0)
25
+ rspec-core (3.9.1)
26
+ rspec-support (~> 3.9.1)
27
+ rspec-expectations (3.9.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-mocks (3.9.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.9.0)
33
+ rspec-support (3.9.2)
34
+ safe_yaml (1.0.5)
35
+ webmock (3.8.2)
36
+ addressable (>= 2.3.6)
37
+ crack (>= 0.3.2)
38
+ hashdiff (>= 0.4.0, < 2.0.0)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ rake (~> 12.0)
45
+ rspec (~> 3.0)
46
+ webmock (~> 3)
47
+ wing-ruby!
48
+
49
+ BUNDLED WITH
50
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Kevin Chavanne
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,40 @@
1
+ # Wing
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/wing`. 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 'wing'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install wing
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wing.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wing"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/wing.rb ADDED
@@ -0,0 +1,23 @@
1
+ require "wing/configuration"
2
+ require "wing/version"
3
+ require "wing/client"
4
+
5
+ module Wing
6
+ class Error < StandardError; end
7
+
8
+ class << self
9
+ attr_accessor :configuration
10
+ end
11
+
12
+ def self.configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def self.reset_configuration
17
+ @configuration = Configuration.new
18
+ end
19
+
20
+ def self.configure
21
+ yield(configuration)
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ module Wing
2
+ module Actions
3
+ end
4
+ end
5
+
6
+ require_relative "actions/orders"
7
+ require_relative "actions/stores"
@@ -0,0 +1,33 @@
1
+ module Wing
2
+ module Actions
3
+ module Orders
4
+ def list_orders(options = { page: 1, limit: 20, createdBefore: nil, createdAfter: nil, sort: nil })
5
+ get("/order", query: prepare_query(options)).parsed_response
6
+ end
7
+
8
+ def get_order(order_id)
9
+ get("/order/#{order_id}").parsed_response
10
+ end
11
+
12
+ def create_order(data, options = {})
13
+ post("/order", data, options).parsed_response
14
+ end
15
+
16
+ def generate_return_sticker(order_id:)
17
+ post("/a/awb/#{order_id}?returnLabel=true").parsed_response
18
+ end
19
+
20
+ private
21
+
22
+ def prepare_query(options = { page: 1, limit: 20, createdBefore: nil, createdAfter: nil, sort: nil })
23
+ {
24
+ page: options[:page],
25
+ limit: options[:limit],
26
+ createdBefore: options[:createdBefore],
27
+ createdAfter: options[:createdAfter],
28
+ sort: options[:sort]
29
+ }.delete_if { |key, value| value.nil? }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ module Wing
2
+ module Actions
3
+ module Stores
4
+ def list_stores(options = { page: 1, limit: 20, createdBefore: nil, createdAfter: nil })
5
+ get("/store", query: prepare_query(options)).parsed_response
6
+ end
7
+
8
+ def create_store(data, options = {})
9
+ post("/store", data, options).parsed_response
10
+ end
11
+
12
+ private
13
+
14
+ def prepare_query(options = { page: 1, limit: 20, createdBefore: nil, createdAfter: nil })
15
+ {
16
+ page: options[:page],
17
+ limit: options[:limit],
18
+ createdBefore: options[:createdBefore],
19
+ createdAfter: options[:createdAfter],
20
+ }.delete_if { |key, value| value.nil? }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,78 @@
1
+ require 'httparty'
2
+ require 'wing/actions'
3
+ require 'wing/error'
4
+
5
+ module Wing
6
+ class Client
7
+ include Wing::Actions::Stores
8
+ include Wing::Actions::Orders
9
+
10
+ API_VERSION = "v1".freeze
11
+ BASE_URL = "https://api.wing.eu/".freeze
12
+ USER_AGENT = "wing-ruby/#{VERSION}".freeze
13
+
14
+ def initialize(api_key: nil, api_secret: nil)
15
+ @api_key = api_key || Wing::configuration.api_key
16
+ @api_secret = api_secret || Wing::configuration.api_secret
17
+ end
18
+
19
+ def base_url
20
+ "#{BASE_URL}#{API_VERSION}"
21
+ end
22
+
23
+ def get(path, options = {})
24
+ execute(:get, path, options)
25
+ end
26
+
27
+ def post(path, data = {}, options = {})
28
+ execute(:post, path, options.merge(body: data))
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :api_key, :api_secret
34
+
35
+ def execute(method, path, options)
36
+ begin
37
+ response = request(method, path, options)
38
+ rescue *Error::NET_HTTP_ERRORS => err
39
+ raise ConnectionError.new, err.message
40
+ end
41
+
42
+ case response.code
43
+ when 200..299
44
+ response
45
+ when 400
46
+ raise BadRequestError.new(response['errorDescription'])
47
+ when 401
48
+ raise AuthenticationError.new(response['errorDescription'])
49
+ when 404
50
+ raise NotFoundError.new(response['errorDescription'])
51
+ when 400..499
52
+ raise ResponseError.new(response['errorDescription'])
53
+ when 500
54
+ raise InternalServerError.new(response['errorDescription'])
55
+ when 500..599
56
+ raise ServerError.new(response['errorDescription'])
57
+ end
58
+ end
59
+
60
+ def request(method, path, options)
61
+ HTTParty.send(method, base_url + path, base_options.merge(options))
62
+ end
63
+
64
+ def base_options
65
+ {
66
+ format: :json,
67
+ headers: {
68
+ "Accept" => "application/json",
69
+ "User-Agent" => USER_AGENT
70
+ },
71
+ basic_auth: {
72
+ username: api_key,
73
+ password: api_secret
74
+ }
75
+ }
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,11 @@
1
+ module Wing
2
+ class Configuration
3
+ attr_accessor :api_key
4
+ attr_accessor :api_secret
5
+
6
+ def initialize
7
+ @api_key = nil
8
+ @api_secret = nil
9
+ end
10
+ end
11
+ end
data/lib/wing/error.rb ADDED
@@ -0,0 +1,42 @@
1
+ module Wing
2
+ class Error < StandardError
3
+ NET_HTTP_ERRORS = [
4
+ EOFError,
5
+ Errno::ECONNABORTED,
6
+ Errno::ECONNREFUSED,
7
+ Errno::ECONNRESET,
8
+ Errno::EHOSTUNREACH,
9
+ Errno::EINVAL,
10
+ Errno::ENETUNREACH,
11
+ Net::HTTPBadResponse,
12
+ Net::HTTPHeaderSyntaxError,
13
+ Net::ProtocolError,
14
+ Net::OpenTimeout,
15
+ Net::ReadTimeout,
16
+ SocketError,
17
+ Zlib::GzipFile::Error,
18
+ OpenSSL::SSL::SSLError
19
+ ]
20
+ end
21
+
22
+ # Raised on errors in the 400-499 range
23
+ class ResponseError < Error; end
24
+
25
+ # Raised when the API returns a 400 HTTP status code
26
+ class BadRequestError < ResponseError; end
27
+
28
+ # Raised when the API returns a 401 HTTP status code
29
+ class AuthenticationError < ResponseError; end
30
+
31
+ # Raised when the API returns a 404 HTTP status code
32
+ class NotFoundError < ResponseError; end
33
+
34
+ # Raised on errors in the 500-599 range
35
+ class ServerError < Error; end
36
+
37
+ # Raised when the API returns a 500 HTTP status code
38
+ class InternalServerError < ServerError; end
39
+
40
+ # Raised when we can't establish a connection to the API or if reading the reponse times out
41
+ class ConnectionError < Error; end
42
+ end
@@ -0,0 +1,3 @@
1
+ module Wing
2
+ VERSION = "0.1.1"
3
+ end
Binary file
data/wing.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ require_relative 'lib/wing/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "wing.rb"
5
+ spec.version = Wing::VERSION
6
+ spec.authors = ["Kevin Chavanne"]
7
+ spec.email = ["kevin.chavanne@gmail.com"]
8
+
9
+ spec.summary = %q{Ruby wrapper for wing API}
10
+ spec.description = %q{This gem is a wrapper on Wing API v2, that offers shipping services (https://www.wing.eu). }
11
+ spec.homepage = "https://www.github.com/wedressfair/wing-ruby"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://www.github.com/wedressfair/wing-ruby"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "rspec", "~> 3.2"
28
+ spec.add_development_dependency "rake", "~> 12"
29
+ spec.add_development_dependency "webmock", "~> 3"
30
+ spec.add_runtime_dependency "httparty", "~> 0.16.2"
31
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wing.rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Chavanne
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.16.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.16.2
69
+ description: 'This gem is a wrapper on Wing API v2, that offers shipping services
70
+ (https://www.wing.eu). '
71
+ email:
72
+ - kevin.chavanne@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/wing.rb
85
+ - lib/wing/actions.rb
86
+ - lib/wing/actions/orders.rb
87
+ - lib/wing/actions/stores.rb
88
+ - lib/wing/client.rb
89
+ - lib/wing/configuration.rb
90
+ - lib/wing/error.rb
91
+ - lib/wing/version.rb
92
+ - wing-ruby-0.1.0.gem
93
+ - wing.gemspec
94
+ homepage: https://www.github.com/wedressfair/wing-ruby
95
+ licenses:
96
+ - MIT
97
+ metadata:
98
+ homepage_uri: https://www.github.com/wedressfair/wing-ruby
99
+ source_code_uri: https://www.github.com/wedressfair/wing-ruby
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 2.3.0
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubygems_version: 3.0.3
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Ruby wrapper for wing API
119
+ test_files: []