packlink_lite 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/packlink_lite.rb +1 -0
- data/lib/packlink_lite/client.rb +18 -7
- data/lib/packlink_lite/errors.rb +23 -0
- data/lib/packlink_lite/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e2dd2e94cf5d52c7eebdf4a18042255649e249d
|
4
|
+
data.tar.gz: 057cba8b7c63214dc2e7eee4bf97508d33820bdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21f2b551b674a7a7dfb18e4e879963524642f44418a637e9346b5e7f58d6e1b595adba1402f5ee42a291c3faa058b07f04c9bb733d30f8ab6cd9c1783bba7ac0
|
7
|
+
data.tar.gz: e3935ecc003e5168d792572c3cb76351f315d0ead833dbbfaedc0bc95b86f470f993996879c3d5d8bba068f56af9940b20b0f85c7e504e9aa44167bf2e9fc250
|
data/lib/packlink_lite.rb
CHANGED
data/lib/packlink_lite/client.rb
CHANGED
@@ -5,28 +5,39 @@ module PacklinkLite
|
|
5
5
|
def get(path, params = nil)
|
6
6
|
url = url(path)
|
7
7
|
url+= '?' + build_nested_query(params) if params
|
8
|
-
|
9
|
-
handle_response(response)
|
8
|
+
request(:get, url, headers)
|
10
9
|
end
|
11
10
|
|
12
11
|
def post(path, payload)
|
13
12
|
payload = payload.to_json unless payload.is_a?(String)
|
14
|
-
|
15
|
-
handle_response(response)
|
13
|
+
request(:post, url(path), payload, headers)
|
16
14
|
end
|
17
15
|
|
18
16
|
def delete(path)
|
19
|
-
|
20
|
-
handle_response(response)
|
17
|
+
request(:delete, url(path))
|
21
18
|
end
|
22
19
|
|
23
20
|
private
|
24
21
|
|
22
|
+
def request(method, *args)
|
23
|
+
response = RestClient.send(method, *args)
|
24
|
+
parse_response(response)
|
25
|
+
rescue RestClient::Exception => e
|
26
|
+
message = extract_error_message(e.http_body) || e.message
|
27
|
+
raise Error.new(message, e.http_body, e.http_code)
|
28
|
+
end
|
29
|
+
|
30
|
+
def extract_error_message(body)
|
31
|
+
result = parse_response(body)
|
32
|
+
result['message'] || result['messages']
|
33
|
+
rescue JSON::ParserError
|
34
|
+
end
|
35
|
+
|
25
36
|
def url(path)
|
26
37
|
PacklinkLite.url + path
|
27
38
|
end
|
28
39
|
|
29
|
-
def
|
40
|
+
def parse_response(response)
|
30
41
|
JSON.parse(response)
|
31
42
|
end
|
32
43
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PacklinkLite
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :http_body, :http_code
|
4
|
+
|
5
|
+
def initialize(message, http_body = nil, http_code = nil)
|
6
|
+
@message = message
|
7
|
+
@http_body = http_body
|
8
|
+
@http_code = http_code
|
9
|
+
end
|
10
|
+
|
11
|
+
def inspect
|
12
|
+
"#{message}: #{http_body}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def message
|
16
|
+
@message || self.class.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
inspect
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laurynas Butkus
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/packlink_lite.rb
|
114
114
|
- lib/packlink_lite/client.rb
|
115
115
|
- lib/packlink_lite/configuration.rb
|
116
|
+
- lib/packlink_lite/errors.rb
|
116
117
|
- lib/packlink_lite/label.rb
|
117
118
|
- lib/packlink_lite/order.rb
|
118
119
|
- lib/packlink_lite/service.rb
|