yandex-delivery 0.0.1 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a2fc2639ef507d2e4f38a0f344aadcf214f861ffd8a62cc628dd26f547b6c92
|
4
|
+
data.tar.gz: 1efaafc00e1454ea7df4cd58eac5eb5b35aca08fce8d3ac4ec0c94e3f3aa0c36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66bd2349a7c9dcd081f5bc25ea0baab44121701386e2d281da43e8481ff632faaac800563ffe38682b23ad809110a31d1bb3b39ce3736eab8e37216bbebe0e9e
|
7
|
+
data.tar.gz: 63b9aa136866b19245b485a6843a7bf2f5b075986eb87cdca991ff05ffdf6c2f509ff102f216849a033d2737c2ba1134a4667fb6839c27f35d6f6717fa82cd1e
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Pavel Osetrov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,254 @@
|
|
1
|
+
# Yandex-delivery
|
2
|
+
|
3
|
+
API wrapper для Яндекс.доставки [API](https://yandex.ru/dev/delivery-3/doc/dg/).
|
4
|
+
|
5
|
+
## Установка Ruby
|
6
|
+
|
7
|
+
$ gem install yandex-delivery
|
8
|
+
|
9
|
+
## Установка Rails
|
10
|
+
|
11
|
+
добавьте в Gemfile:
|
12
|
+
|
13
|
+
gem 'yandex-delivery'
|
14
|
+
|
15
|
+
и запустите `bundle install`.
|
16
|
+
|
17
|
+
Затем:
|
18
|
+
|
19
|
+
rails g yandex_delivery:install
|
20
|
+
|
21
|
+
## Требования
|
22
|
+
|
23
|
+
Необходимо получить [токен авторизации](https://yandex.ru/dev/delivery-3/doc/dg/concepts/access.html).
|
24
|
+
|
25
|
+
## Использование Rails
|
26
|
+
|
27
|
+
В файл `config/yandex_delivery2.yml` вставьте ваши данные из настоек яндекс доставки и токен авторизации
|
28
|
+
|
29
|
+
## Использование Ruby
|
30
|
+
|
31
|
+
Сначала создайте экземпляр объекта `YandexDelivery::Request`:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
delivery = YandexDelivery::Request.new(api_key: "your_access_token")
|
35
|
+
```
|
36
|
+
|
37
|
+
Вы можете изменять `api_key`, `timeout`, `open_timeout`, `faraday_adapter`, `proxy`, `symbolize_keys`, `logger`, и `debug`:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
YandexDelivery::Request.api_key = "your_access_token"
|
41
|
+
YandexDelivery::Request.timeout = 15
|
42
|
+
YandexDelivery::Request.open_timeout = 15
|
43
|
+
YandexDelivery::Request.symbolize_keys = true
|
44
|
+
YandexDelivery::Request.debug = false
|
45
|
+
```
|
46
|
+
|
47
|
+
Либо в файле `config/initializers/yandex_delivery2.rb` для Rails.
|
48
|
+
|
49
|
+
## Debug Logging
|
50
|
+
|
51
|
+
Pass `debug: true` to enable debug logging to STDOUT.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
delivery = YandexDelivery::Request.new(api_key: "your_access_token", debug: true)
|
55
|
+
```
|
56
|
+
|
57
|
+
### Custom logger
|
58
|
+
|
59
|
+
Ruby `Logger.new` is used by default, but it can be overrided using:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
delivery = YandexDelivery::Request.new(api_key: "your_access_token", debug: true, logger: MyLogger.new)
|
63
|
+
```
|
64
|
+
|
65
|
+
Logger can be also set by globally:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
YandexDelivery::Request.logger = MyLogger.new
|
69
|
+
```
|
70
|
+
|
71
|
+
## Примеры
|
72
|
+
|
73
|
+
### Варианты доставки
|
74
|
+
|
75
|
+
#### Поиск вариантов доставки
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
# для Rails senderId указывать не обязательно, в запрос подставится значение из config/yandex_delivery2.yml
|
79
|
+
body = {
|
80
|
+
:to=>{:location=>"Санкт-Петербург"},
|
81
|
+
:dimensions=>{:length=>1, :height=>1, :width=>1, :weight=>1}
|
82
|
+
}
|
83
|
+
|
84
|
+
YandexDelivery::Request.delivery_options.upsert(body: body)
|
85
|
+
```
|
86
|
+
|
87
|
+
#### Поиск пунктов выдачи заказов
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
YandexDelivery::Request.pickup_points.upsert(body: {locationId: 2})
|
91
|
+
```
|
92
|
+
|
93
|
+
### Операции с заказами
|
94
|
+
|
95
|
+
#### Создать черновик заказа
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
response = YandexDelivery::Request.orders.create(body: {deliveryType: 'COURIER'})
|
99
|
+
order_id = response.body
|
100
|
+
```
|
101
|
+
|
102
|
+
#### Обновить черновик заказа
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
YandexDelivery::Request.orders(order_id).upsert(body: {deliveryType: 'PICKUP'})
|
106
|
+
```
|
107
|
+
|
108
|
+
#### Оформить заказ
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
YandexDelivery::Request.orders.submit.create(body: {orderIds: [order_id]})
|
112
|
+
```
|
113
|
+
|
114
|
+
#### Получить данные о заказе
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
response = YandexDelivery::Request.orders(order_id).retrieve
|
118
|
+
order = response.body
|
119
|
+
```
|
120
|
+
|
121
|
+
#### Удалить заказ
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
YandexDelivery::Request.orders(order_id).delete
|
125
|
+
```
|
126
|
+
|
127
|
+
#### Получить ярлык заказа
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
YandexDelivery::Request.orders(order_id).label.retrieve
|
131
|
+
```
|
132
|
+
|
133
|
+
#### Поиск заказов
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
sender_ids = YandexDelivery.senders.map{|sender| sender['id']}
|
137
|
+
YandexDelivery::Request.orders.search.upsert(body: {senderIds: sender_ids, orderIds: [order_id]})
|
138
|
+
```
|
139
|
+
|
140
|
+
#### Получить историю статусов заказа
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
YandexDelivery::Request.orders(order_id).statuses.retrieve
|
144
|
+
```
|
145
|
+
|
146
|
+
#### Получить статус заказов
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
YandexDelivery::Request.orders.status.upsert
|
150
|
+
```
|
151
|
+
|
152
|
+
### Операции с отгрузками
|
153
|
+
|
154
|
+
#### Создать заявку на отгрузку
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
body = {
|
158
|
+
cabinetId: YandexDelivery.client['id'],
|
159
|
+
shipment: {
|
160
|
+
type: "WITHDRAW",
|
161
|
+
date: "2020-10-05",
|
162
|
+
warehouseFrom: YandexDelivery.warehouses.first['id'],
|
163
|
+
warehouseTo: 123,
|
164
|
+
partnerTo: 678
|
165
|
+
},
|
166
|
+
intervalId: 765478,
|
167
|
+
dimensions: {
|
168
|
+
length: 10,
|
169
|
+
width: 15,
|
170
|
+
height: 40,
|
171
|
+
weight: 5.5
|
172
|
+
},
|
173
|
+
courier: {
|
174
|
+
type: "CAR",
|
175
|
+
firstName: "Василий",
|
176
|
+
middleName: "Иванович",
|
177
|
+
lastName: "Пупкин",
|
178
|
+
phone: "+79998887766",
|
179
|
+
carNumber: "о000оо",
|
180
|
+
carBrand: "Maybach"
|
181
|
+
},
|
182
|
+
comment: "comment"
|
183
|
+
}
|
184
|
+
response = YandexDelivery::Request.shipments.application.create(body: body)
|
185
|
+
shipment_id = response.body['id']
|
186
|
+
```
|
187
|
+
|
188
|
+
#### Подтвердить отгрузку
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
body = {
|
192
|
+
cabinetId: YandexDelivery.client['id'],
|
193
|
+
shipmentApplicationIds: [shipment_id]
|
194
|
+
}
|
195
|
+
YandexDelivery::Request.shipments.application.submit.create(body: body)
|
196
|
+
```
|
197
|
+
|
198
|
+
#### Получить список отгрузок
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
body = {
|
202
|
+
cabinetId: YandexDelivery.client['id'],
|
203
|
+
shipmentType: "IMPORT",
|
204
|
+
dateFrom: "2020-10-05",
|
205
|
+
"dateTo": "2020-11-05",
|
206
|
+
"partnerIds":
|
207
|
+
[
|
208
|
+
239847,
|
209
|
+
98234,
|
210
|
+
54968
|
211
|
+
]
|
212
|
+
}
|
213
|
+
YandexDelivery::Request.shipments.search.upsert(body: body)
|
214
|
+
```
|
215
|
+
|
216
|
+
#### Получить интервалы самопривозов
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
warehouse_id = YandexDelivery.warehouses.first['id']
|
220
|
+
YandexDelivery::Request.shipments.intervals.import.retrieve(params: {warehouseId: warehouse_id, date: '2020-10-06'})
|
221
|
+
```
|
222
|
+
|
223
|
+
#### Получить интервалы заборов
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
YandexDelivery::Request.shipments.intervals.withdraw.retrieve(params: {partnerId: 106, date: '2020-10-06'})
|
227
|
+
```
|
228
|
+
|
229
|
+
#### Получить акт передачи заказов
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
YandexDelivery::Request.shipments.applications(shipment_id).act.retrieve(params: {cabinetId: YandexDelivery.client['id']})
|
233
|
+
```
|
234
|
+
|
235
|
+
### Справочные данные
|
236
|
+
|
237
|
+
#### Получить полный адрес
|
238
|
+
|
239
|
+
```ruby
|
240
|
+
YandexDelivery::Request.location.retrieve(params: {term: 'Санкт-Петербург'})
|
241
|
+
```
|
242
|
+
|
243
|
+
#### Получить индекс по адресу
|
244
|
+
|
245
|
+
```ruby
|
246
|
+
response = YandexDelivery::Request.location.postal_code.retrieve(params: {address: 'Санкт-Петербург, ул. Профессора Попова, д. 37Щ, БЦ "Сенатор"'})
|
247
|
+
postal_code = response.body.first[:postalCode]
|
248
|
+
```
|
249
|
+
|
250
|
+
#### Получить список служб доставки
|
251
|
+
|
252
|
+
```ruby
|
253
|
+
YandexDelivery::Request.delivery_services.retrieve(params: {cabinetId: YandexDelivery.client['id']})
|
254
|
+
```
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'yandex_delivery'
|
2
2
|
|
3
3
|
YandexDelivery.setup do |config|
|
4
|
-
if File.exist?('config/
|
4
|
+
if File.exist?('config/yandex_delivery2.yml')
|
5
5
|
template = ERB.new(File.new('config/yandex_delivery2.yml').read)
|
6
6
|
processed = YAML.safe_load(template.result(binding))
|
7
7
|
|
@@ -11,11 +11,6 @@ YandexDelivery.setup do |config|
|
|
11
11
|
config::Request.symbolize_keys = true
|
12
12
|
config::Request.debug = false
|
13
13
|
|
14
|
-
# processed['YANDEX_DELIVERY_API_KEY'].each do |k, v|
|
15
|
-
# config::create_method k.underscore.to_sym
|
16
|
-
# config::register "#{k.underscore}_key".to_sym, v
|
17
|
-
# end
|
18
|
-
|
19
14
|
processed['YANDEX_DELIVERY'].each do |k, v|
|
20
15
|
config::register k.underscore.to_sym, v
|
21
16
|
end
|
@@ -140,12 +140,11 @@ module YandexDelivery
|
|
140
140
|
if request
|
141
141
|
request.params.merge!(params) if params
|
142
142
|
request.headers['Content-Type'] = 'application/json'
|
143
|
-
request.headers['Authorization
|
143
|
+
request.headers['Authorization'] = "OAuth #{self.api_key}"
|
144
144
|
request.headers.merge!(headers) if headers
|
145
145
|
request.body = body if body
|
146
146
|
request.options.timeout = self.timeout
|
147
147
|
request.options.open_timeout = self.open_timeout
|
148
|
-
p request
|
149
148
|
end
|
150
149
|
end
|
151
150
|
|
@@ -179,8 +178,7 @@ module YandexDelivery
|
|
179
178
|
end
|
180
179
|
|
181
180
|
def validate_api_key
|
182
|
-
|
183
|
-
unless api_key && (api_key["-"] || self.api_endpoint)
|
181
|
+
unless self.api_key
|
184
182
|
raise YandexDelivery::YandexDeliveryError, "You must set an api_key prior to making a call"
|
185
183
|
end
|
186
184
|
end
|
@@ -7,7 +7,7 @@ module YandexDelivery
|
|
7
7
|
|
8
8
|
def initialize(api_key: nil, api_endpoint: nil, timeout: nil, open_timeout: nil, proxy: nil, faraday_adapter: nil, symbolize_keys: false, debug: false, logger: nil)
|
9
9
|
@path_parts = []
|
10
|
-
@api_key = api_key || self.class.api_key || ENV['
|
10
|
+
@api_key = api_key || self.class.api_key || ENV['YANDEX_DELIVERY_ACCESS_TOKEN']
|
11
11
|
@api_key = @api_key.strip if @api_key
|
12
12
|
@api_endpoint = api_endpoint || self.class.api_endpoint
|
13
13
|
@timeout = timeout || self.class.timeout || DEFAULT_TIMEOUT
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yandex-delivery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Osetrov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2020-08-11 00:00:00.000000000 Z
|
@@ -44,6 +44,8 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
+
- LICENSE
|
48
|
+
- README.markdown
|
47
49
|
- lib/generators/yandex_delivery/install/USAGE
|
48
50
|
- lib/generators/yandex_delivery/install/install_generator.rb
|
49
51
|
- lib/generators/yandex_delivery/install/templates/yandex_delivery.rb
|
@@ -59,7 +61,7 @@ homepage: https://github.com/osetrov/yandex-delivery
|
|
59
61
|
licenses:
|
60
62
|
- MIT
|
61
63
|
metadata: {}
|
62
|
-
post_install_message:
|
64
|
+
post_install_message:
|
63
65
|
rdoc_options: []
|
64
66
|
require_paths:
|
65
67
|
- lib
|
@@ -75,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
77
|
version: '0'
|
76
78
|
requirements: []
|
77
79
|
rubygems_version: 3.1.4
|
78
|
-
signing_key:
|
80
|
+
signing_key:
|
79
81
|
specification_version: 4
|
80
82
|
summary: Yandex delivery
|
81
83
|
test_files: []
|