packlink_lite 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/README.md +7 -0
- data/lib/packlink_lite/client.rb +17 -8
- data/lib/packlink_lite/errors.rb +2 -0
- data/lib/packlink_lite/version.rb +1 -1
- data/lib/packlink_lite.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcd5d4af3dbd874f0f5de6ba024e4e6ca3ba3770
|
4
|
+
data.tar.gz: 7cba79eae714f11570a8c60716635e4a0d8da2c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 116974f970164cc7e9bd429822b28f89d8263375d3d4f5f09d0e600ca9de3a1d3276148700dd58e4020e37206ad57fb663550b31655fe750090dae0a77bc15c7
|
7
|
+
data.tar.gz: 7c99040a265acf725f20901de705c9e979995ed2b4010e4c0db971e874dad15b49a80802dc98f4bfbe4ec50ecd105f85a2a7a49a25ca6419c34a07230f0eaf6d
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -45,6 +45,13 @@ order = PacklinkLite::Order.create(order_hash)
|
|
45
45
|
tracking_history = PacklinkLite::TrackingHistory.find(shipment_reference)
|
46
46
|
```
|
47
47
|
|
48
|
+
### Set callback urls
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
PacklinkLite.change_shipment_callback_url(url)
|
52
|
+
PacklinkLite.change_tracking_callback_url(url)
|
53
|
+
```
|
54
|
+
|
48
55
|
## Contributing
|
49
56
|
|
50
57
|
Bug reports and pull requests are welcome on GitHub at https://github.com/laurynas/packlink_lite.
|
data/lib/packlink_lite/client.rb
CHANGED
@@ -2,26 +2,33 @@ require 'rest-client'
|
|
2
2
|
|
3
3
|
module PacklinkLite
|
4
4
|
class Client
|
5
|
-
def get(path, params = nil)
|
5
|
+
def get(path, params = nil, options = {})
|
6
6
|
url = url(path)
|
7
7
|
url+= '?' + build_nested_query(params) if params
|
8
|
-
request(:get, url, headers)
|
8
|
+
response = request(:get, url, headers)
|
9
|
+
process_response(response, options)
|
9
10
|
end
|
10
11
|
|
11
|
-
def post(path, payload)
|
12
|
+
def post(path, payload, options = {})
|
12
13
|
payload = payload.to_json unless payload.is_a?(String)
|
13
|
-
request(:post, url(path), payload, headers)
|
14
|
+
response = request(:post, url(path), payload, headers)
|
15
|
+
process_response(response, options)
|
14
16
|
end
|
15
17
|
|
16
|
-
def delete(path)
|
17
|
-
request(:delete, url(path))
|
18
|
+
def delete(path, options = {})
|
19
|
+
response = request(:delete, url(path))
|
20
|
+
process_response(response, options)
|
18
21
|
end
|
19
22
|
|
20
23
|
private
|
21
24
|
|
22
|
-
def
|
23
|
-
response
|
25
|
+
def process_response(response, parse_response: true)
|
26
|
+
return response unless parse_response
|
24
27
|
parse_response(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
def request(method, *args)
|
31
|
+
RestClient.send(method, *args)
|
25
32
|
rescue RestClient::Exception => e
|
26
33
|
message = extract_error_message(e.http_body) || e.message
|
27
34
|
raise Error.new(message, e.http_body, e.http_code)
|
@@ -39,6 +46,8 @@ module PacklinkLite
|
|
39
46
|
|
40
47
|
def parse_response(response)
|
41
48
|
JSON.parse(response)
|
49
|
+
rescue JSON::ParserError => e
|
50
|
+
raise ResponseError.new(e.message, response)
|
42
51
|
end
|
43
52
|
|
44
53
|
def headers
|
data/lib/packlink_lite/errors.rb
CHANGED
data/lib/packlink_lite.rb
CHANGED
@@ -29,4 +29,12 @@ module PacklinkLite
|
|
29
29
|
def url
|
30
30
|
config.testing? ? SANDBOX_URL : PRODUCTION_URL
|
31
31
|
end
|
32
|
+
|
33
|
+
def change_shipment_callback_url(url)
|
34
|
+
client.post('shipments/callback', { url: url }, parse_response: false)
|
35
|
+
end
|
36
|
+
|
37
|
+
def change_tracking_callback_url(url)
|
38
|
+
client.post('shipments/tracking_callback', { url: url }, parse_response: false)
|
39
|
+
end
|
32
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: packlink_lite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laurynas Butkus
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|