tiramizoo 0.2.4 → 0.2.5

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
- SHA1:
3
- metadata.gz: fd944b347fbcfcf34040980535cd31d52a786ddb
4
- data.tar.gz: 26800bc4c6f63a2701837bec7282fa803af40ced
2
+ SHA256:
3
+ metadata.gz: cc299be5b062c2079511f452ed60b82a9338884da106881c5a91ec8a28abf940
4
+ data.tar.gz: b85b449c979668c129b2b533382bbd79189df10d6977aaddbdd0f5090ff8be3f
5
5
  SHA512:
6
- metadata.gz: 29af4e8d8fd2fef2848c694b2e85da42504659861aa6ea0fba78454326165394a1bd94bec8babf4214f379130e718ad48809b3639c8041f352ed9ad6cace07cb
7
- data.tar.gz: ce877e83e99ffa4636173143b9a2456be67862c3234040881e5758400344da89c3b4922cf8656270819bbdd8507960d1d99a2dbd5243488ffe21f2a94c87a828
6
+ metadata.gz: 74685f78c1b68fccbe98bb9981eeb816ebf283d3d6459272e41ec22536a90c2eda1bd5b10118dc5e8b109d54ad9683c81ceed9a3b5716b116a41df26e155cc1d
7
+ data.tar.gz: 06cb1ae01f0c1d7072df13a36b06dd2f46a32fd28f0b71ce9a6bb8681db0ac97fbebc75a23c621d8dc485fb9559e7bf3c0d42db54e81b6a5b14063af92c222ae
data/lib/tiramizoo.rb CHANGED
@@ -28,19 +28,7 @@ module Tiramizoo
28
28
  :headers => {"Api-Token" => api_token, "Content-Type" => "application/json"}
29
29
  })
30
30
 
31
- case response.status
32
- when 200
33
- JSON.parse(response.body)
34
- when 401
35
- raise InvalidApiToken
36
- when 500
37
- raise ServerError
38
- when 503
39
- raise ServerIsUndergoingMaintenance
40
- else
41
- logger.warn("[tiramizoo-api] status: #{response.status}, body: #{response.body}")
42
- raise UnknownError.new(response.status_line)
43
- end
31
+ handle_response(response)
44
32
  end
45
33
 
46
34
  def service_areas
@@ -49,19 +37,7 @@ module Tiramizoo
49
37
  :headers => {"Api-Token" => api_token, "Content-Type" => "application/json"}
50
38
  })
51
39
 
52
- case response.status
53
- when 200
54
- JSON.parse(response.body)
55
- when 401
56
- raise InvalidApiToken
57
- when 500
58
- raise ServerError
59
- when 503
60
- raise ServerIsUndergoingMaintenance
61
- else
62
- logger.warn("[tiramizoo-api] status: #{response.status}, body: #{response.body}")
63
- raise UnknownError.new(response.status_line)
64
- end
40
+ handle_response(response)
65
41
  end
66
42
 
67
43
  def create_order(sender = {}, recipient = {}, packages = [], time_window = {}, options = {})
@@ -105,21 +81,16 @@ module Tiramizoo
105
81
  :body => request_body
106
82
  })
107
83
 
108
- case response.status
109
- when 201
110
- JSON.parse(response.body)
111
- when 401
112
- raise InvalidApiToken
113
- when 422
114
- raise UnprocessableEntity.new(response.body.force_encoding("utf-8"))
115
- when 500
116
- raise ServerError
117
- when 503
118
- raise ServerIsUndergoingMaintenance
119
- else
120
- logger.warn("[tiramizoo-api] status: #{response.status}, body: #{response.body}")
121
- raise UnknownError.new(response.status_line)
122
- end
84
+ handle_response(response)
85
+ end
86
+
87
+ def get_order(identifier)
88
+ response = connection.get({
89
+ :path => "/api/v1/orders/#{identifier}",
90
+ :headers => {"Api-Token" => api_token, "Content-Type" => "application/json"}
91
+ })
92
+
93
+ handle_response(response)
123
94
  end
124
95
 
125
96
  def cancel_order(order_identifier)
@@ -134,23 +105,7 @@ module Tiramizoo
134
105
  :body => body.to_json
135
106
  })
136
107
 
137
- case response.status
138
- when 200
139
- JSON.parse(response.body)
140
- when 401
141
- raise InvalidApiToken
142
- when 404
143
- raise NotFound
144
- when 422
145
- raise UnprocessableEntity.new(response.body.force_encoding("utf-8"))
146
- when 500
147
- raise ServerError
148
- when 503
149
- raise ServerIsUndergoingMaintenance
150
- else
151
- logger.warn("[tiramizoo-api] status: #{response.status}, body: #{response.body}")
152
- raise UnknownError.new(response.status_line)
153
- end
108
+ handle_response(response)
154
109
  end
155
110
 
156
111
  def calculate_distance(origin, destination)
@@ -166,15 +121,7 @@ module Tiramizoo
166
121
  :write_timeout => 1
167
122
  })
168
123
 
169
- case response.status
170
- when 200
171
- JSON.parse(response.body)["distance"]
172
- when 401
173
- raise InvalidApiToken
174
- else
175
- logger.warn("[tiramizoo-api] status: #{response.status}, body: #{response.body}")
176
- raise UnknownError.new(response.status_line)
177
- end
124
+ handle_response(response)
178
125
  end
179
126
 
180
127
  def geocode(address_line, postal_code, city, country_code)
@@ -192,11 +139,21 @@ module Tiramizoo
192
139
  :write_timeout => 1
193
140
  })
194
141
 
142
+ handle_response(response)
143
+ end
144
+
145
+ def handle_response(response)
195
146
  case response.status
196
- when 200
147
+ when 200, 201
197
148
  JSON.parse(response.body)
198
149
  when 401
199
150
  raise InvalidApiToken
151
+ when 422
152
+ raise UnprocessableEntity.new(response.body.force_encoding("utf-8"))
153
+ when 500
154
+ raise ServerError
155
+ when 503
156
+ raise ServerIsUndergoingMaintenance
200
157
  else
201
158
  logger.warn("[tiramizoo-api] status: #{response.status}, body: #{response.body}")
202
159
  raise UnknownError.new(response.status_line)
@@ -1,3 +1,3 @@
1
1
  module Tiramizoo
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiramizoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiramizoo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-08 00:00:00.000000000 Z
11
+ date: 2019-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  version: '0'
88
88
  requirements: []
89
89
  rubyforge_project:
90
- rubygems_version: 2.5.1
90
+ rubygems_version: 2.7.6
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: Tiramizoo API