packlink_lite 0.1.0

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: 0ff464661f493b1f01020f2db2bf298cdeae58e8
4
+ data.tar.gz: 0091ddb428e56da4c4c1c603c56bd5c399e6981e
5
+ SHA512:
6
+ metadata.gz: c667effad5cb1441e491b7fb4f857f8f6e4af04d4937e5d19ea612cc0090731a2419591d66e11fdbba2d9802b185bce4bb2cc12bb06e4d107fb748475f0fb2f3
7
+ data.tar.gz: 090f5b0896429dbf3c2fd60e09ec3c3fa468e995e4a891235c86f484d8a05f74bb27747c9b173047a2f3f335905acc9e01649148bf31ac7244601fcd0d9ed34f
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /.ruby-version
4
+ /.env
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.3
5
+ - 2.2.3
6
+ - 2.3.0
7
+ - jruby-19mode
8
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in packlink_lite.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Laurynas Butkus
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,56 @@
1
+ # PacklinkLite
2
+
3
+ [![Build Status](https://travis-ci.org/laurynas/packlink_lite.svg?branch=master)](https://travis-ci.org/laurynas/packlink_lite)
4
+
5
+ Packlink.com API client
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'packlink_lite'
13
+ ```
14
+
15
+ ## Configuration
16
+
17
+ ```ruby
18
+ PacklinkLite.configure do |config|
19
+ config.api_key = ENV['PACKLINK_API_KEY']
20
+ config.testing = true
21
+ end
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Fetch services list
27
+
28
+ ```ruby
29
+ services = PacklinkLite::Service.all(
30
+ from: { country: 'DE', zip: 56457 },
31
+ to: { country: 'DE', zip: 56457 },
32
+ packages: { 0 => { width: 10, height: 10, length: 10, weight: 1 } }
33
+ )
34
+ ```
35
+
36
+ ### Create order
37
+
38
+ ```ruby
39
+ order = PacklinkLite::Order.create(order_hash)
40
+ ```
41
+
42
+ ### Fetch shipment tracking
43
+
44
+ ```ruby
45
+ tracking_history = PacklinkLite::TrackingHistory.find(shipment_reference)
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/laurynas/packlink_lite.
51
+
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
56
+
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 "packlink_lite"
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,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
@@ -0,0 +1,31 @@
1
+ require 'packlink_lite/version'
2
+ require 'packlink_lite/configuration'
3
+ require 'packlink_lite/client'
4
+ require 'packlink_lite/service'
5
+ require 'packlink_lite/order'
6
+ require 'packlink_lite/shipment'
7
+ require 'packlink_lite/label'
8
+ require 'packlink_lite/tracking_history'
9
+
10
+ module PacklinkLite
11
+ PRODUCTION_URL = 'https://api.packlink.com/v1/'
12
+ SANDBOX_URL = 'https://apisandbox.packlink.com/v1/'
13
+
14
+ module_function
15
+
16
+ def configure
17
+ yield(config)
18
+ end
19
+
20
+ def config
21
+ @configuration ||= Configuration.new
22
+ end
23
+
24
+ def client
25
+ @client ||= Client.new
26
+ end
27
+
28
+ def url
29
+ config.testing? ? SANDBOX_URL : PRODUCTION_URL
30
+ end
31
+ end
@@ -0,0 +1,60 @@
1
+ require 'rest-client'
2
+
3
+ module PacklinkLite
4
+ class Client
5
+ def get(path, params = nil)
6
+ url = url(path)
7
+ url+= '?' + build_nested_query(params) if params
8
+ response = RestClient.get(url, headers)
9
+ handle_response(response)
10
+ end
11
+
12
+ def post(path, payload)
13
+ payload = payload.to_json unless payload.is_a?(String)
14
+ response = RestClient.post(url(path), payload, headers)
15
+ handle_response(response)
16
+ end
17
+
18
+ def delete(path)
19
+ response = RestClient.delete(url(path))
20
+ handle_response(response)
21
+ end
22
+
23
+ private
24
+
25
+ def url(path)
26
+ PacklinkLite.url + path
27
+ end
28
+
29
+ def handle_response(response)
30
+ JSON.parse(response)
31
+ end
32
+
33
+ def headers
34
+ { 'Authorization' => PacklinkLite.config.api_key,
35
+ 'Content-Type' => 'application/json' }
36
+ end
37
+
38
+ def build_nested_query(value, prefix = nil)
39
+ case value
40
+ when Array
41
+ value.map { |v|
42
+ build_nested_query(v, "#{prefix}[]")
43
+ }.join("&")
44
+ when Hash
45
+ value.map { |k, v|
46
+ build_nested_query(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k))
47
+ }.reject(&:empty?).join('&')
48
+ when nil
49
+ prefix
50
+ else
51
+ raise ArgumentError, "value must be a Hash" if prefix.nil?
52
+ "#{prefix}=#{escape(value)}"
53
+ end
54
+ end
55
+
56
+ def escape(s)
57
+ URI.encode_www_form_component(s)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,6 @@
1
+ module PacklinkLite
2
+ class Configuration
3
+ attr_accessor :api_key, :testing
4
+ alias_method :testing?, :testing
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module PacklinkLite
2
+ class Label
3
+ def self.all(shipment_reference)
4
+ PacklinkLite.client.get("shipments/#{shipment_reference}/labels")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module PacklinkLite
2
+ class Order
3
+ PATH = 'orders'
4
+
5
+ def self.create(payload)
6
+ PacklinkLite.client.post(PATH, payload)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module PacklinkLite
2
+ class Service
3
+ PATH = 'services'
4
+
5
+ def self.all(query)
6
+ PacklinkLite.client.get(PATH, query)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module PacklinkLite
2
+ class Shipment
3
+ PATH = 'shipments'
4
+
5
+ def self.all(params = {})
6
+ PacklinkLite.client.get(PATH, params)
7
+ end
8
+
9
+ def self.find(reference)
10
+ PacklinkLite.client.get(PATH + '/' + reference)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module PacklinkLite
2
+ class TrackingHistory
3
+ def self.find(shipment_reference)
4
+ PacklinkLite.client.get("shipments/#{shipment_reference}/track")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module PacklinkLite
2
+ VERSION = "0.1.0"
3
+ end
@@ -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 'packlink_lite/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'packlink_lite'
8
+ spec.version = PacklinkLite::VERSION
9
+ spec.authors = ['Laurynas Butkus']
10
+ spec.email = ['laurynas.butkus@gmail.com']
11
+
12
+ spec.summary = %q{Packlink.com API client}
13
+ spec.description = %q{Client to access packlink.com shipping API}
14
+ spec.homepage = 'https://github.com/laurynas/packlink_lite'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'rest-client', '~> 1.8'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.11'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'dotenv', '~> 2.1'
28
+ spec.add_development_dependency 'webmock', '~> 1.24'
29
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: packlink_lite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Laurynas Butkus
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
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.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.1'
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.24'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.24'
97
+ description: Client to access packlink.com shipping API
98
+ email:
99
+ - laurynas.butkus@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/packlink_lite.rb
114
+ - lib/packlink_lite/client.rb
115
+ - lib/packlink_lite/configuration.rb
116
+ - lib/packlink_lite/label.rb
117
+ - lib/packlink_lite/order.rb
118
+ - lib/packlink_lite/service.rb
119
+ - lib/packlink_lite/shipment.rb
120
+ - lib/packlink_lite/tracking_history.rb
121
+ - lib/packlink_lite/version.rb
122
+ - packlink_lite.gemspec
123
+ homepage: https://github.com/laurynas/packlink_lite
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.2.2
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Packlink.com API client
147
+ test_files: []
148
+ has_rdoc: