Module: CdekClient
- Extended by:
- CdekClient
- Included in:
- CdekClient
- Defined in:
- lib/cdek_client.rb,
lib/cdek_client/util.rb,
lib/cdek_client/client.rb,
lib/cdek_client/errors.rb,
lib/cdek_client/result.rb,
lib/cdek_client/version.rb,
lib/cdek_client/abstract_client.rb,
lib/cdek_client/calculator_client.rb,
lib/cdek_client/calculator_errors.rb
Defined Under Namespace
Modules: Calculator, Util
Classes: APIError, AbstractClient, AttributeEmptyError, AuthError, BarcodeDublError, CalculatorClient, CallDublError, CallcourierCityError, CallcourierCountError, CallcourierDateDublError, CallcourierDateExistsError, CallcourierDatetimeError, CallcourierTimeError, CallcourierTimeIntervalError, CallcourierTimelunchError, CashLimitError, CashNoError, Client, DatabaseError, DatabaseTestError, DateformatError, DateinvoiceError, DboAuthError, DboAuthHashError, DboCityIncorrectForServiceError, DboClientCurrencyError, DboDateCreateInvalidError, DboForbiddenSumForCashError, DboIncorrectUrlError, DboInvalidAdditionalserviceError, DboNeedAuthError, DboNotFoundError, DboPackageNumberEmptyError, DboParamEmptyError, DboParamMistakeError, DboParamMistakePvzError, DboParamServiceInterfaceError, DboPayerEmptyError, DboReceiverAddressTitleEmptyError, DboReceiverCityAmbiguousError, DboReceiverCityEmptyError, DboReceiverCityIncorrectError, DboReceiverCityNotIntegerError, DboResultEmptyError, DboResultServiceEmptyError, DboSenderAddressTitleEmptyError, DboSenderCityAmbiguousError, DboSenderCityEmptyError, DboSenderCityIncorrectError, DboSenderCityNotIntegerError, DboServiceEmptyError, DboTypeEmptyError, DboWeightEmptyError, DeleterequestOrderActnumberError, DeleterequestOrderDeletedError, DeleterequestOrderError, DeleterequestOrderMoveError, Error, FileNotexistsError, FileSaveError, FirstDublExistsError, InforequestDatebegError, InforequestError, InvalidAddressDeliveryError, InvalidAmountError, InvalidCostError, InvalidCostexError, InvalidDeliveryrecipientcostError, InvalidDispachnumberError, InvalidIntakeserviceError, InvalidIntakeserviceTocityError, InvalidNumberDeleteError, InvalidNumberError, InvalidPaymentError, InvalidPaymentexError, InvalidServicecodeError, InvalidSizeError, InvalidTarifftypecodeError, InvalidWeightError, InvalidXmlError, ItemNotfindError, NeedAttributeError, NotEqualCallcountError, NotEqualOrdercountError, NotFoundCostexError, NotFoundPassportnumberError, NotFoundPaymentexError, NotFoundReccityError, NotFoundRegistrationaddressError, NotFoundSendcityError, NotFoundTarifftypecodeError, NotValidPassportnumberError, NotfoundcurrencyError, NotfoundtagError, OrderCountError, OrderDeleteError, OrderDublError, OrderDublExistsError, OrderNotfindError, OrdersNotFoundError, PackageNotfindError, PackageNumDublError, PrintOrderError, PvzClosedError, PvzNotfoundByPostcodeError, PvzNotfoundError, PvzWeightError, PvzWeightLimitError, PvzcodeError, PvzcodeNotfoundError, ReccitycodeError, ReccitypostcodeDublError, ReccitypostcodeError, ResponseError, Result, ScheduleChangeError, ScheduleDateError, ScheduleDublError, SendcitycodeError, SendcitypostcodeDublError, SendcitypostcodeError, UnknownDocTypeError, UnknownVersionError, UnkownAPIError, WarekeyDublError, WeightLimitError, XmlEmptyError
Constant Summary
collapse
- HOSTS =
{
primary: {
host: 'gw.edostavka.ru',
port: 11443
}.freeze,
secondary: {
host: 'lk.cdek.ru',
port: 11443
}.freeze,
calculator_primary: {
host: 'api.edostavka.ru',
port: 80
}.freeze,
calculator_secondary: {
host: 'lk.cdek.ru',
port: 8080
}.freeze
}.freeze
- PATHS =
{
pickup_points: 'pvzlist.php',
order_statuses: 'status_report_h.php',
order_infos: 'info_report.php',
new_orders: 'new_orders.php',
new_schedule: 'new_schedule.php',
call_courier: 'call_courier.php',
delete_orders: 'delete_orders.php',
orders_print: 'orders_print.php',
calculate: 'calculator/calculate_price_by_json.php'
}.freeze
- RESPONSE_NORMALIZATION_RULES =
{
pickup_points: {
CityCode: :to_i,
coordX: :to_f,
coordY: :to_f,
WeightLimit: {
WeightMin: :to_f,
WeightMax: :to_f
}.freeze
}.freeze,
order_statuses: {
DeliveryDate: :to_time,
ReturnDispatchNumber: :to_i,
Status: {
Date: :to_time,
Code: :to_i,
CityCode: :to_i,
State: {
Date: :to_time,
Code: :to_i,
CityCode: :to_i
}.freeze
}.freeze,
Reason: {
Date: :to_time,
Code: :to_i
}.freeze,
DelayReason: {
Date: :to_time,
Code: :to_i,
State: {
Date: :to_time,
Code: :to_i,
CityCode: :to_i
}.freeze
}.freeze,
Package: {
Item: {
DelivAmount: :to_i
}.freeze
}.freeze,
Attempt: {
ScheduleCode: :to_i
}.freeze,
Call: {
CallGood: {
Good: {
Date: :to_date,
DateDeliv: :to_date
}.freeze
}.freeze,
CallFail: {
Fail: {
Date: :to_date,
ReasonCode: :to_i
}.freeze
}.freeze,
CallDelay: {
Delay: {
Date: :to_date,
DateNext: :to_date
}.freeze
}.freeze
}.freeze
}.freeze,
order_infos: {
Date: :to_date,
TariffTypeCode: :to_i,
Weight: :to_f,
DeliverySum: :to_f,
DateLastChange: :to_time,
CashOnDeliv: :to_f,
CachOnDelivFac: :to_f,
SendCity: {
Code: :to_i
}.freeze,
RecCity: {
Code: :to_i
}.freeze,
AddedService: {
ServiceCode: :to_i,
Sum: :to_f
}.freeze
}.freeze,
calculate: {
price: :to_f,
deliveryPeriodMin: :to_i,
deliveryPeriodMax: :to_i,
deliveryDateMin: :to_date,
deliveryDateMax: :to_date,
tariffId: :to_i,
cashOnDelivery: :to_f,
priceByCurrency: :to_f
}.freeze
}.freeze
- CALCULATOR_API_VERSION =
'1.0'
- TIME_FORMAT =
'%Y-%m-%dT%H:%M:%S'
- DATE_FORMAT =
'%Y-%m-%d'
- API_ERROR_MAPPINGS =
{
ERR_API: APIError,
ERR_ATTRIBUTE_EMPTY: AttributeEmptyError,
ERR_AUTH: AuthError,
ERR_BARCODE_DUBL: BarcodeDublError,
ERR_CALLCOURIER_CITY: CallcourierCityError,
ERR_CALLCOURIER_COUNT: CallcourierCountError,
ERR_CALLCOURIER_DATETIME: CallcourierDatetimeError,
ERR_CALLCOURIER_DATE_DUBL: CallcourierDateDublError,
ERR_CALLCOURIER_DATE_EXISTS: CallcourierDateExistsError,
ERR_CALLCOURIER_TIME: CallcourierTimeError,
ERR_CALLCOURIER_TIMELUNCH: CallcourierTimelunchError,
ERR_CALLCOURIER_TIME_INTERVAL: CallcourierTimeIntervalError,
ERR_CALL_DUBL: CallDublError,
ERR_CASH_LIMIT: CashLimitError,
ERR_CASH_NO: CashNoError,
ERR_DATABASE: DatabaseError,
ERR_DATABASE_test: DatabaseTestError,
ERR_DATEFORMAT: DateformatError,
ERR_DATEINVOICE: DateinvoiceError,
ERR_DBO_AUTH: DboAuthError,
ERR_DBO_AUTH_HASH: DboAuthHashError,
ERR_DBO_CITY_INCORRECT_FOR_SERVICE: DboCityIncorrectForServiceError,
ERR_DBO_CLIENT_CURRENCY: DboClientCurrencyError,
ERR_DBO_DATE_CREATE_INVALID: DboDateCreateInvalidError,
ERR_DBO_FORBIDDEN_SUM_FOR_CASH: DboForbiddenSumForCashError,
ERR_DBO_INCORRECT_URL: DboIncorrectUrlError,
ERR_DBO_INVALID_ADDITIONALSERVICE: DboInvalidAdditionalserviceError,
ERR_DBO_NEED_AUTH: DboNeedAuthError,
ERR_DBO_NOT_FOUND: DboNotFoundError,
ERR_DBO_PACKAGE_NUMBER_EMPTY: DboPackageNumberEmptyError,
ERR_DBO_PARAM_EMPTY: DboParamEmptyError,
ERR_DBO_PARAM_MISTAKE: DboParamMistakeError,
ERR_DBO_PARAM_MISTAKE_PVZ: DboParamMistakePvzError,
ERR_DBO_PARAM_SERVICE_INTERFACE: DboParamServiceInterfaceError,
ERR_DBO_PAYER_EMPTY: DboPayerEmptyError,
ERR_DBO_RECEIVER_ADDRESS_TITLE_EMPTY: DboReceiverAddressTitleEmptyError,
ERR_DBO_RECEIVER_CITY_AMBIGUOUS: DboReceiverCityAmbiguousError,
ERR_DBO_RECEIVER_CITY_EMPTY: DboReceiverCityEmptyError,
ERR_DBO_RECEIVER_CITY_INCORRECT: DboReceiverCityIncorrectError,
ERR_DBO_RECEIVER_CITY_NOT_INTEGER: DboReceiverCityNotIntegerError,
ERR_DBO_RESULT_EMPTY: DboResultEmptyError,
ERR_DBO_RESULT_SERVICE_EMPTY: DboResultServiceEmptyError,
ERR_DBO_SENDER_ADDRESS_TITLE_EMPTY: DboSenderAddressTitleEmptyError,
ERR_DBO_SENDER_CITY_AMBIGUOUS: DboSenderCityAmbiguousError,
ERR_DBO_SENDER_CITY_EMPTY: DboSenderCityEmptyError,
ERR_DBO_SENDER_CITY_INCORRECT: DboSenderCityIncorrectError,
ERR_DBO_SENDER_CITY_NOT_INTEGER: DboSenderCityNotIntegerError,
ERR_DBO_SERVICE_EMPTY: DboServiceEmptyError,
ERR_DBO_TYPE_EMPTY: DboTypeEmptyError,
ERR_DBO_WEIGHT_EMPTY: DboWeightEmptyError,
ERR_DELETEREQUEST_ORDER: DeleterequestOrderError,
ERR_DELETEREQUEST_ORDER_ACTNUMBER: DeleterequestOrderActnumberError,
ERR_DELETEREQUEST_ORDER_DELETED: DeleterequestOrderDeletedError,
ERR_DELETEREQUEST_ORDER_MOVE: DeleterequestOrderMoveError,
ERR_FILE_NOTEXISTS: FileNotexistsError,
ERR_FILE_SAVE: FileSaveError,
ERR_FIRST_DUBL_EXISTS: FirstDublExistsError,
ERR_INFOREQUEST: InforequestError,
ERR_INFOREQUEST_DATEBEG: InforequestDatebegError,
ERR_INVALID_ADDRESS_DELIVERY: InvalidAddressDeliveryError,
ERR_INVALID_AMOUNT: InvalidAmountError,
ERR_INVALID_COST: InvalidCostError,
ERR_INVALID_COSTEX: InvalidCostexError,
ERR_INVALID_DELIVERYRECIPIENTCOST: InvalidDeliveryrecipientcostError,
ERR_INVALID_DISPACHNUMBER: InvalidDispachnumberError,
ERR_INVALID_INTAKESERVICE: InvalidIntakeserviceError,
ERR_INVALID_INTAKESERVICE_TOCITY: InvalidIntakeserviceTocityError,
ERR_INVALID_NUMBER: InvalidNumberError,
ERR_INVALID_NUMBER_DELETE: InvalidNumberDeleteError,
ERR_INVALID_PAYMENT: InvalidPaymentError,
ERR_INVALID_PAYMENTEX: InvalidPaymentexError,
ERR_INVALID_SERVICECODE: InvalidServicecodeError,
ERR_INVALID_SIZE: InvalidSizeError,
ERR_INVALID_TARIFFTYPECODE: InvalidTarifftypecodeError,
ERR_INVALID_WEIGHT: InvalidWeightError,
ERR_INVALID_XML: InvalidXmlError,
ERR_ITEM_NOTFIND: ItemNotfindError,
ERR_NEED_ATTRIBUTE: NeedAttributeError,
ERR_NOTFOUNDCURRENCY: NotfoundcurrencyError,
ERR_NOTFOUNDTAG: NotfoundtagError,
ERR_NOT_EQUAL_CALLCOUNT: NotEqualCallcountError,
ERR_NOT_EQUAL_ORDERCOUNT: NotEqualOrdercountError,
ERR_NOT_FOUND_COSTEX: NotFoundCostexError,
ERR_NOT_FOUND_PASSPORTNUMBER: NotFoundPassportnumberError,
ERR_NOT_FOUND_PAYMENTEX: NotFoundPaymentexError,
ERR_NOT_FOUND_RECCITY: NotFoundReccityError,
ERR_NOT_FOUND_REGISTRATIONADDRESS: NotFoundRegistrationaddressError,
ERR_NOT_FOUND_SENDCITY: NotFoundSendcityError,
ERR_NOT_FOUND_TARIFFTYPECODE: NotFoundTarifftypecodeError,
ERR_NOT_VALID_PASSPORTNUMBER: NotValidPassportnumberError,
ERR_ORDER_COUNT: OrderCountError,
ERR_ORDER_DELETE: OrderDeleteError,
ERR_ORDER_DUBL: OrderDublError,
ERR_ORDER_DUBL_EXISTS: OrderDublExistsError,
ERR_ORDER_NOTFIND: OrderNotfindError,
ERR_ORDERS_NOT_FOUND: OrdersNotFoundError,
ERR_PACKAGE_NOTFIND: PackageNotfindError,
ERR_PACKAGE_NUM_DUBL: PackageNumDublError,
ERR_PRINT_ORDER: PrintOrderError,
ERR_PVZCODE: PvzcodeError,
ERR_PVZCODE_NOTFOUND: PvzcodeNotfoundError,
ERR_PVZ_CLOSED: PvzClosedError,
ERR_PVZ_NOTFOUND: PvzNotfoundError,
ERR_PVZ_NOTFOUND_BY_POSTCODE: PvzNotfoundByPostcodeError,
ERR_PVZ_WEIGHT: PvzWeightError,
ERR_PVZ_WEIGHT_LIMIT: PvzWeightLimitError,
ERR_RECCITYCODE: ReccitycodeError,
ERR_RECCITYPOSTCODE: ReccitypostcodeError,
ERR_RECCITYPOSTCODE_DUBL: ReccitypostcodeDublError,
ERR_SCHEDULE_CHANGE: ScheduleChangeError,
ERR_SCHEDULE_DATE: ScheduleDateError,
ERR_SCHEDULE_DUBL: ScheduleDublError,
ERR_SENDCITYCODE: SendcitycodeError,
ERR_SENDCITYPOSTCODE: SendcitypostcodeError,
ERR_SENDCITYPOSTCODE_DUBL: SendcitypostcodeDublError,
ERR_UNKNOWN_DOC_TYPE: UnknownDocTypeError,
ERR_UNKNOWN_VERSION: UnknownVersionError,
ERR_WAREKEY_DUBL: WarekeyDublError,
ERR_WEIGHT_LIMIT: WeightLimitError,
ERR_XML_EMPTY: XmlEmptyError
}
- VERSION =
'0.0.2'
Instance Method Summary
collapse
Instance Method Details
148
149
150
151
|
# File 'lib/cdek_client.rb', line 148
def format_date(date_or_time)
format = date_or_time.is_a?(Time) || date_or_time.is_a?(DateTime) ? TIME_FORMAT : DATE_FORMAT
date_or_time.strftime(format)
end
|
#generate_secure(formatted_date, password) ⇒ Object
144
145
146
|
# File 'lib/cdek_client.rb', line 144
def generate_secure(formatted_date, password)
Digest::MD5.hexdigest("#{formatted_date}&#{password}")
end
|
#get_api_error(code, message) ⇒ Object
258
259
260
261
|
# File 'lib/cdek_client/errors.rb', line 258
def get_api_error(code, message)
klass = API_ERROR_MAPPINGS[code.to_sym] || UnkownAPIError
klass.new code, message
end
|