Class: Cdek::Resources::Deliverypoints

Inherits:
Base
  • Object
show all
Defined in:
lib/cdek/resources/deliverypoints.rb

Overview

Список пунктов выдачи заказов (ПВЗ/Постамат) CDEK API v2. Эндпоинт: GET /deliverypoints

Параметры (наиболее часто используемые):

  • city_code — код города CDEK (получается через Locations#cities)

  • postal_code — почтовый индекс

  • type — “PVZ” | “POSTAMAT” | “ALL”

  • country_code — двухбуквенный код страны (RU и т.п.)

  • region_code — код региона

  • code — код конкретного пункта (например MSK2181)

  • have_cashless / have_cash / allowed_cod / is_dressing_room —

    булевы фильтры
    
  • weight_min / weight_max — допустимый вес посылки

  • is_handout — выдаёт ли посылки

  • is_reception — принимает ли посылки

  • size / page — пагинация

Возвращает массив пунктов в формате CDEK API (массив Hash).

Примеры:

Cdek.deliverypoints.list(city_code: 44, type: "PVZ", size: 100)
Cdek.deliverypoints.pvz_for_city(44)
Cdek.deliverypoints.find("MSK2181")

Constant Summary collapse

LIST_PATH =
"/deliverypoints"
DEFAULT_TYPE =
"PVZ"

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Cdek::Resources::Base

Instance Method Details

#find(code) ⇒ Object

Найти конкретный пункт по его коду (CDEK ID, например MSK2181). Возвращает Hash пункта или nil.



44
45
46
47
# File 'lib/cdek/resources/deliverypoints.rb', line 44

def find(code)
  result = list(code: code, size: 1)
  result.is_a?(Array) ? result.first : nil
end

#list(params = {}) ⇒ Object



32
33
34
# File 'lib/cdek/resources/deliverypoints.rb', line 32

def list(params = {})
  client.get(LIST_PATH, params: params.compact)
end

#pvz_for_city(city_code, extra = {}) ⇒ Object

Шорткат: ПВЗ по коду города. extra — дополнительные фильтры (например, have_cashless: true), которые мерджатся к city_code и type.



38
39
40
# File 'lib/cdek/resources/deliverypoints.rb', line 38

def pvz_for_city(city_code, extra = {})
  list({ city_code: city_code, type: DEFAULT_TYPE }.merge(extra))
end