ozon-logistics 0.0.2 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +20 -1
- data/lib/generators/ozon_logistics/install/templates/ozon_logistics.rb +4 -4
- data/lib/ozon-logistics.rb +0 -1
- data/lib/ozon-logistics/api_request.rb +35 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 435947ecbb9b47558a5610a41123d5b075a2120d6b68bf869ab3b53117685def
|
4
|
+
data.tar.gz: fc432a84ae37d456622f62e9e7095834ad07a1fb7719a9ea16b62365cf99d076
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64f7a27b9ab6e5ecccbb9c3047b01d95ddaf2896a75898f19dc08b602cf46b92f22b54c2c33519eca364ea2b8ac298dc6aad1f6735a39dd82ed295ebb68f2ed7
|
7
|
+
data.tar.gz: 6935d1def31c667bc04d999e55c6811ed7fd3b00a5ca2c4cefddd4908455bd9cbf5c63d4bb7d6abf237d89952abc271a64a12b2e5af92a9e69b17bdffa0a0894
|
data/README.markdown
CHANGED
@@ -16,7 +16,7 @@ API wrapper для Ozon.Logistics [API](https://api-stg.ozonru.me/principal-inte
|
|
16
16
|
|
17
17
|
Затем:
|
18
18
|
|
19
|
-
rails g
|
19
|
+
rails g ozon_logistics:install
|
20
20
|
|
21
21
|
## Требования
|
22
22
|
|
@@ -304,4 +304,23 @@ params = {
|
|
304
304
|
}
|
305
305
|
response = OzonLogistics::Request.tracking.article.retrieve(params: params)
|
306
306
|
article = response.body
|
307
|
+
```
|
308
|
+
|
309
|
+
### DropOff
|
310
|
+
|
311
|
+
#### Метод создания завки на отгрузк
|
312
|
+
```ruby
|
313
|
+
body = {
|
314
|
+
"orderIds": [
|
315
|
+
0
|
316
|
+
]
|
317
|
+
}
|
318
|
+
response = OzonLogistics::Request.dropoff.create(body: body).body
|
319
|
+
drop_off_id = response[:id]
|
320
|
+
```
|
321
|
+
|
322
|
+
#### Метод для для получения акта по ID заявки на отгрузку
|
323
|
+
```ruby
|
324
|
+
response = OzonLogistics::Request.dropoff(drop_off_id).act
|
325
|
+
p response.body
|
307
326
|
```
|
@@ -4,14 +4,14 @@ OzonLogistics.setup do |config|
|
|
4
4
|
if File.exist?('config/ozon_logistics.yml')
|
5
5
|
processed = YAML.load_file('config/ozon_logistics.yml')[Rails.env]
|
6
6
|
|
7
|
+
processed.each do |k, v|
|
8
|
+
config::register k.underscore.to_sym, v
|
9
|
+
end
|
10
|
+
|
7
11
|
config::Request.access_token = ENV['OZON_LOGISTICS_ACCESS_TOKEN'] || OzonLogistics.generate_access_token.try(:dig, "access_token")
|
8
12
|
config::Request.timeout = 15
|
9
13
|
config::Request.open_timeout = 15
|
10
14
|
config::Request.symbolize_keys = true
|
11
15
|
config::Request.debug = false
|
12
|
-
|
13
|
-
processed.each do |k, v|
|
14
|
-
config::register k.underscore.to_sym, v
|
15
|
-
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/ozon-logistics.rb
CHANGED
@@ -6,7 +6,6 @@ require 'ozon-logistics/response'
|
|
6
6
|
|
7
7
|
module OzonLogistics
|
8
8
|
class << self
|
9
|
-
|
10
9
|
def generate_access_token(client_id=OzonLogistics.client_id, client_secret=OzonLogistics.client_secret, grant_type=OzonLogistics.grant_type)
|
11
10
|
response = Faraday.post(OzonLogistics.url_token, "grant_type=#{grant_type}&client_id=#{client_id}&client_secret=#{client_secret}")
|
12
11
|
JSON.parse(response.body)
|
@@ -5,7 +5,7 @@ module OzonLogistics
|
|
5
5
|
@request_builder = builder
|
6
6
|
end
|
7
7
|
|
8
|
-
def post(params: nil, headers: nil, body: {})
|
8
|
+
def post(params: nil, headers: nil, body: {}, first_time: true)
|
9
9
|
validate_access_token
|
10
10
|
|
11
11
|
begin
|
@@ -14,11 +14,16 @@ module OzonLogistics
|
|
14
14
|
end
|
15
15
|
parse_response(response)
|
16
16
|
rescue => e
|
17
|
-
|
17
|
+
if e.response.try(:code) == 401 && first_time
|
18
|
+
OzonLogistics::Request.access_token = OzonLogistics.generate_access_token.try(:dig, "access_token")
|
19
|
+
self.post(params: params, headers: headers, body: body, first_time: false)
|
20
|
+
else
|
21
|
+
handle_error(e)
|
22
|
+
end
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
21
|
-
def patch(params: nil, headers: nil, body: {})
|
26
|
+
def patch(params: nil, headers: nil, body: {}, first_time: true)
|
22
27
|
validate_access_token
|
23
28
|
|
24
29
|
begin
|
@@ -28,11 +33,16 @@ module OzonLogistics
|
|
28
33
|
end
|
29
34
|
parse_response(response)
|
30
35
|
rescue => e
|
31
|
-
|
36
|
+
if e.response.try(:code) == 401 && first_time
|
37
|
+
OzonLogistics::Request.access_token = OzonLogistics.generate_access_token.try(:dig, "access_token")
|
38
|
+
self.patch(params: params, headers: headers, body: body, first_time: false)
|
39
|
+
else
|
40
|
+
handle_error(e)
|
41
|
+
end
|
32
42
|
end
|
33
43
|
end
|
34
44
|
|
35
|
-
def put(params: nil, headers: nil, body: {})
|
45
|
+
def put(params: nil, headers: nil, body: {}, first_time: true)
|
36
46
|
validate_access_token
|
37
47
|
|
38
48
|
begin
|
@@ -41,11 +51,16 @@ module OzonLogistics
|
|
41
51
|
end
|
42
52
|
parse_response(response)
|
43
53
|
rescue => e
|
44
|
-
|
54
|
+
if e.response.try(:code) == 401 && first_time
|
55
|
+
OzonLogistics::Request.access_token = OzonLogistics.generate_access_token.try(:dig, "access_token")
|
56
|
+
self.put(params: params, headers: headers, body: body, first_time: false)
|
57
|
+
else
|
58
|
+
handle_error(e)
|
59
|
+
end
|
45
60
|
end
|
46
61
|
end
|
47
62
|
|
48
|
-
def get(params: nil, headers: nil)
|
63
|
+
def get(params: nil, headers: nil, first_time: true)
|
49
64
|
validate_access_token
|
50
65
|
|
51
66
|
begin
|
@@ -54,11 +69,16 @@ module OzonLogistics
|
|
54
69
|
end
|
55
70
|
parse_response(response)
|
56
71
|
rescue => e
|
57
|
-
|
72
|
+
if e.response.try(:code) == 401 && first_time
|
73
|
+
OzonLogistics::Request.access_token = OzonLogistics.generate_access_token.try(:dig, "access_token")
|
74
|
+
self.get(params: params, headers: headers, first_time: false)
|
75
|
+
else
|
76
|
+
handle_error(e)
|
77
|
+
end
|
58
78
|
end
|
59
79
|
end
|
60
80
|
|
61
|
-
def delete(params: nil, headers: nil)
|
81
|
+
def delete(params: nil, headers: nil, first_time: true)
|
62
82
|
validate_access_token
|
63
83
|
|
64
84
|
begin
|
@@ -67,7 +87,12 @@ module OzonLogistics
|
|
67
87
|
end
|
68
88
|
parse_response(response)
|
69
89
|
rescue => e
|
70
|
-
|
90
|
+
if e.response.try(:code) == 401 && first_time
|
91
|
+
OzonLogistics::Request.access_token = OzonLogistics.generate_access_token.try(:dig, "access_token")
|
92
|
+
self.delete(params: params, headers: headers, first_time: false)
|
93
|
+
else
|
94
|
+
handle_error(e)
|
95
|
+
end
|
71
96
|
end
|
72
97
|
end
|
73
98
|
|