yandex-delivery 0.0.3 → 0.0.8

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: 20948af6947ba0c5eacd0d0a8e0f46bf818f1a15eae22180309cc6781550a91a
4
- data.tar.gz: 68fabec7fa939e083146b7f6ce8f8ebe701d5a1722aab54c09f4663ac09b8b67
3
+ metadata.gz: 6ba338d37a068e4369364fc6f381913f1e6a968c532ee5db77f5b1df1302fc97
4
+ data.tar.gz: 73d448721cdfbe808bcf696e93ecded3e94e66e59533689a9772efe269442ee1
5
5
  SHA512:
6
- metadata.gz: 052ef2f8e89462737a5db6fa555bec56945fba5907c93a302382aae0589c833f734bc4009f4a05b33fc5b4be37a7e80867dd7cb929a092d084d1a2003089c8d1
7
- data.tar.gz: 258765b235e43f80a363a75eb724e824a7b414fe9b8b3e011d0a1c7c366f054d0a58bb909545d3787acf3b09fa4d3bcabbf82a3a4fadda7ebdbadc271a96cbe0
6
+ metadata.gz: dbda8e042c4d4f9f956d9f49cae7c492d1d3207b6580b744a60b59596e9611294dedac81d348c1347eb3f306ac0fd669428ab63b5422468ce4745880d2d98d9e
7
+ data.tar.gz: c6a070acd02dea393683083073ef4b267e382051ff99c973f86433f722b802cc915dbc28c2870f08f17cd6c3b58c56f158b0d79d17028014464e9c51171172dc
data/README.markdown CHANGED
@@ -70,7 +70,9 @@ YandexDelivery::Request.logger = MyLogger.new
70
70
 
71
71
  ## Примеры
72
72
 
73
- ### Поиск вариантов доставки
73
+ ### Варианты доставки
74
+
75
+ #### Поиск вариантов доставки
74
76
 
75
77
  ```ruby
76
78
  # для Rails senderId указывать не обязательно, в запрос подставится значение из config/yandex_delivery2.yml
@@ -80,4 +82,173 @@ body = {
80
82
  }
81
83
 
82
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']})
83
254
  ```
@@ -1,10 +1,11 @@
1
1
  require 'yandex_delivery'
2
2
 
3
3
  YandexDelivery.setup do |config|
4
- if File.exist?('config/yandex_delivery.yml')
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
 
8
+ config::Request.app_id = processed['YANDEX_DELIVERY_APP_ID']
8
9
  config::Request.api_key = processed['YANDEX_DELIVERY_ACCESS_TOKEN']
9
10
  config::Request.timeout = 15
10
11
  config::Request.open_timeout = 15
@@ -1,3 +1,4 @@
1
+ YANDEX_DELIVERY_APP_ID: ''
1
2
  YANDEX_DELIVERY_ACCESS_TOKEN: ''
2
3
 
3
4
  YANDEX_DELIVERY: {
@@ -81,6 +81,10 @@ module YandexDelivery
81
81
  @request_builder.api_key
82
82
  end
83
83
 
84
+ def app_id
85
+ @request_builder.app_id
86
+ end
87
+
84
88
  def api_endpoint
85
89
  @request_builder.api_endpoint
86
90
  end
@@ -145,7 +149,6 @@ module YandexDelivery
145
149
  request.body = body if body
146
150
  request.options.timeout = self.timeout
147
151
  request.options.open_timeout = self.open_timeout
148
- p request
149
152
  end
150
153
  end
151
154
 
@@ -179,8 +182,7 @@ module YandexDelivery
179
182
  end
180
183
 
181
184
  def validate_api_key
182
- api_key = self.api_key
183
- unless api_key && (api_key["-"] || self.api_endpoint)
185
+ unless self.api_key
184
186
  raise YandexDelivery::YandexDeliveryError, "You must set an api_key prior to making a call"
185
187
  end
186
188
  end
@@ -1,14 +1,16 @@
1
1
  module YandexDelivery
2
2
  class Request
3
- attr_accessor :api_key, :api_endpoint, :timeout, :open_timeout, :proxy, :faraday_adapter, :symbolize_keys, :debug, :logger
3
+ attr_accessor :api_key, :app_id, :api_endpoint, :timeout, :open_timeout, :proxy, :faraday_adapter, :symbolize_keys, :debug, :logger
4
4
 
5
5
  DEFAULT_TIMEOUT = 60
6
6
  DEFAULT_OPEN_TIMEOUT = 60
7
7
 
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)
8
+ def initialize(api_key: nil, app_id: 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
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
+ @app_id = app_id || self.class.app_id || ENV['YANDEX_DELIVERY_APP_ID']
13
+ @app_id = @app_id.strip if @app_id
12
14
  @api_endpoint = api_endpoint || self.class.api_endpoint
13
15
  @timeout = timeout || self.class.timeout || DEFAULT_TIMEOUT
14
16
  @open_timeout = open_timeout || self.class.open_timeout || DEFAULT_OPEN_TIMEOUT
@@ -80,10 +82,12 @@ module YandexDelivery
80
82
  end
81
83
 
82
84
  class << self
83
- attr_accessor :api_key, :timeout, :open_timeout, :api_endpoint, :proxy, :faraday_adapter, :symbolize_keys, :debug, :logger
85
+ attr_accessor :api_key, :app_id, :timeout, :open_timeout, :api_endpoint, :proxy, :faraday_adapter, :symbolize_keys, :debug, :logger
84
86
 
85
87
  def method_missing(sym, *args, &block)
86
- new(api_key: self.api_key, api_endpoint: self.api_endpoint, timeout: self.timeout, open_timeout: self.open_timeout, faraday_adapter: self.faraday_adapter, symbolize_keys: self.symbolize_keys, debug: self.debug, proxy: self.proxy, logger: self.logger).send(sym, *args, &block)
88
+ new(api_key: self.api_key, app_id: self.app_id, api_endpoint: self.api_endpoint, timeout: self.timeout,
89
+ open_timeout: self.open_timeout, faraday_adapter: self.faraday_adapter, symbolize_keys: self.symbolize_keys,
90
+ debug: self.debug, proxy: self.proxy, logger: self.logger).send(sym, *args, &block)
87
91
  end
88
92
 
89
93
  def respond_to_missing?(method_name, include_private = false)
@@ -1,3 +1,3 @@
1
1
  module YandexDelivery
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
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.3
4
+ version: 0.0.8
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
@@ -61,7 +61,7 @@ homepage: https://github.com/osetrov/yandex-delivery
61
61
  licenses:
62
62
  - MIT
63
63
  metadata: {}
64
- post_install_message:
64
+ post_install_message:
65
65
  rdoc_options: []
66
66
  require_paths:
67
67
  - lib
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  requirements: []
79
79
  rubygems_version: 3.1.4
80
- signing_key:
80
+ signing_key:
81
81
  specification_version: 4
82
82
  summary: Yandex delivery
83
83
  test_files: []