packlink_lite 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 +11 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +56 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/packlink_lite.rb +31 -0
- data/lib/packlink_lite/client.rb +60 -0
- data/lib/packlink_lite/configuration.rb +6 -0
- data/lib/packlink_lite/label.rb +7 -0
- data/lib/packlink_lite/order.rb +9 -0
- data/lib/packlink_lite/service.rb +9 -0
- data/lib/packlink_lite/shipment.rb +13 -0
- data/lib/packlink_lite/tracking_history.rb +7 -0
- data/lib/packlink_lite/version.rb +3 -0
- data/packlink_lite.gemspec +29 -0
- metadata +148 -0
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
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) 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
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,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,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:
|