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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e2dd2e94cf5d52c7eebdf4a18042255649e249d
4
- data.tar.gz: 057cba8b7c63214dc2e7eee4bf97508d33820bdd
3
+ metadata.gz: dcd5d4af3dbd874f0f5de6ba024e4e6ca3ba3770
4
+ data.tar.gz: 7cba79eae714f11570a8c60716635e4a0d8da2c5
5
5
  SHA512:
6
- metadata.gz: 21f2b551b674a7a7dfb18e4e879963524642f44418a637e9346b5e7f58d6e1b595adba1402f5ee42a291c3faa058b07f04c9bb733d30f8ab6cd9c1783bba7ac0
7
- data.tar.gz: e3935ecc003e5168d792572c3cb76351f315d0ead833dbbfaedc0bc95b86f470f993996879c3d5d8bba068f56af9940b20b0f85c7e504e9aa44167bf2e9fc250
6
+ metadata.gz: 116974f970164cc7e9bd429822b28f89d8263375d3d4f5f09d0e600ca9de3a1d3276148700dd58e4020e37206ad57fb663550b31655fe750090dae0a77bc15c7
7
+ data.tar.gz: 7c99040a265acf725f20901de705c9e979995ed2b4010e4c0db971e874dad15b49a80802dc98f4bfbe4ec50ecd105f85a2a7a49a25ca6419c34a07230f0eaf6d
data/.travis.yml CHANGED
@@ -1,8 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.1.3
5
4
  - 2.2.3
6
5
  - 2.3.0
7
- - jruby-19mode
8
6
  before_install: gem install bundler -v 1.11.2
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.
@@ -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 request(method, *args)
23
- response = RestClient.send(method, *args)
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
@@ -20,4 +20,6 @@ module PacklinkLite
20
20
  inspect
21
21
  end
22
22
  end
23
+
24
+ class ResponseError < Error; end
23
25
  end
@@ -1,3 +1,3 @@
1
1
  module PacklinkLite
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
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.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-23 00:00:00.000000000 Z
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client