Skip to content

Commit

Permalink
create_shipment, make_return
Browse files Browse the repository at this point in the history
  • Loading branch information
Nu-hin committed Mar 8, 2014
1 parent 04def07 commit 30abae0
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 96 deletions.
1 change: 1 addition & 0 deletions lib/pickpoint_api.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require('logger')

module PickpointApi
VERSION = "0.1"

@logger = Logger.new($stdout)
@logger.level = Logger::INFO
Expand Down
227 changes: 134 additions & 93 deletions lib/pickpoint_api/api_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,70 +39,50 @@ def logout

end

# Регистрация одноместного отправления
# Регистрация одноместных отправлений
def create_sending(data)
ensure_session_state
data = attach_session_id(data, 'Sendings')
response = execute_action(:create_sending, data)
response = JSON.parse(response)
sendings_request(:create_sending, data)
end

# Мониторинг отправления
def track_sending(invoice_id = nil, sender_invoice_number = nil)
request_by_invoice_id(:track_sending, invoice_id, sender_invoice_number)
# Регистрация многоместных отправлений
def create_shipment(data)
sendings_request(:create_shipment, data)
end

# Получение информации по отправлению
def sending_info(invoice_id = nil, sender_invoice_number = nil)
request_by_invoice_id(:sending_info, invoice_id, sender_invoice_number)
end

# Формирование этикеток в PDF
def make_label(invoice_id)
request_by_invoice_ids(invoice_id, :make_label)
end
# Создание отправления клиентского возврата
def make_return(options)
ensure_session_state

# Формирование этикеток в PDF для принтера Zebra
def make_zlabel(invoice_id)
request_by_invoice_ids(invoice_id, :make_zlabel)
end
if !options[:invoice_id].nil? && !options[:sender_invoice_number].nil?
raise ApiError 'Only :invoice_id or :sender_invoice_number parameter should be specified'
end

# Формирование реестра по списку отправлений в PDF
def make_reestr(invoice_id)
request_by_invoice_ids(invoice_id, :make_reestr)
end
data = {
'SessionId' => @session_id
}

# Получение истории по списку отправлений
def track_sendings(invoice_id)
request_by_invoice_ids(invoice_id, :track_sendings)
end
if !options[:invoice_id].nil?
data['InvoiceNumber'] = options[:invoice_id]
elsif !options[:sender_invoice_number].nil?
data['GCInvoiceNumber'] = options[:sender_invoice_number]
else
raise ApiError 'Either :invoice_id or :sender_invoice_number parameter should be specified'
end

# Получение справочника статусов отправления
def get_states
parameterless_request(:get_states)
end
response = execute_action(:get_delivery_cost, data)
res = JSON.parse(response)

# Получение списка городов
def city_list
parameterless_request(:city_list)
end
errors = res.select do |x|
!x['Error'].nil? && !x['Error'].empty?
end.map do |x|
x['Error']
end

# Получение списка терминалов
def postamat_list
parameterless_request(:postamat_list)
end
if !errors.empty
raise ApiError errors.join(';')
end

# Получение списка отправлений, прошедших этап (статус)
def get_invoices_change_state(state, date_from, date_to = DateTime.now)
ensure_session_state
data = {
'SessionId' => @session_id,
'DateFrom' => date_from.strftime('%d.%m.%y'),
'DateTo' => date_to.strftime('%d.%m.%y'),
'State' => state
}
response = execute_action(:get_invoices_change_state, data)
JSON.parse(response)
res
end

# Получение списка возвратных отправлений
Expand All @@ -123,19 +103,38 @@ def get_return_invoices_list(date_from, date_to = DateTime.now)
res
end

# Получение информации по зонам
def get_zone(city, pt = nil)
# Мониторинг отправления
def track_sending(invoice_id = nil, sender_invoice_number = nil)
request_by_invoice_id(:track_sending, invoice_id, sender_invoice_number)
end

# Получение информации по отправлению
def sending_info(invoice_id = nil, sender_invoice_number = nil)
request_by_invoice_id(:sending_info, invoice_id, sender_invoice_number)
end

# Получение стоимости доставки
def get_delivery_cost(options)
ensure_session_state
data = {
'SessionId' => @session_id,
'FromCity' => city
}

if !pt.nil?
data['ToPT'] = pt
if !options[:invoice_ids].nil? && !options[:sender_invoice_numbers].nil?
raise ApiError 'Only :invoice_ids or :sender_invoice_numbers parameter should be specified'
end

response = execute_action(:get_zone, data)
data = if !options[:invoice_ids].nil?
options[:invoice_ids].map do |invoice_id|
{'InvoiceNumber' => invoice_id}
end
elsif !options[:sender_invoice_numbers].nil?
options[:invoice_ids].map do |invoice_id|
{'SenderInvoiceNumber' => invoice_id}
end
else
raise ApiError 'Either :invoice_ids or :sender_invoice_numbers parameter should be specified'
end

data = attach_session_id('Sendings', data)
response = execute_action(:get_delivery_cost, data)
JSON.parse(response)
end

Expand Down Expand Up @@ -163,22 +162,14 @@ def courier_cancel(courier_order_number)
res['Canceled']
end

# Получение информации по вложимому
def enclose_info(barcode)
ensure_session_state
data = attach_session_id('Barcode', barcode)
response = execute_action(:enclose_info, data)
res = JSON.parse(response)

if !res['Error'].nil? && !res['Error'].empty?
raise ApiError res['Error']
end

res
# Формирование реестра по списку отправлений в PDF
def make_reestr(invoice_id)
request_by_invoice_ids(invoice_id, :make_reestr)
end

# Формирование реестра (по списку отправлений)
def make_reestr_number(invoice_ids)
ensure_session_state
response = request_by_invoice_ids(invoice_id, :make_reestr_number)
res = JSON.parse(response)

Expand All @@ -191,6 +182,7 @@ def make_reestr_number(invoice_ids)

# Получение созданного реестра в PDF
def get_reestr(invoice_id = nil, reestr_number = nil)
ensure_session_state
data = {
'SessionId' => @session_id
}
Expand All @@ -207,37 +199,86 @@ def get_reestr(invoice_id = nil, reestr_number = nil)
end
end

# Получение акта возврата товара
def get_product_return_order(ikn, document_number, date_from, date_to = DateTime.now)
return_request(:get_product_return_order, ikn, document_number, date_from, date_to)
# Формирование этикеток в PDF
def make_label(invoice_id)
request_by_invoice_ids(invoice_id, :make_label)
end

# Формирование этикеток в PDF для принтера Zebra
def make_zlabel(invoice_id)
request_by_invoice_ids(invoice_id, :make_zlabel)
end

# Получение списка городов
def city_list
parameterless_request(:city_list)
end

# Получение списка терминалов
def postamat_list
parameterless_request(:postamat_list)
end

# Получение информации по зонам
def get_zone(city, pt = nil)
ensure_session_state
data = {
'SessionId' => @session_id,
'FromCity' => city
}

if !pt.nil?
data['ToPT'] = pt
end

response = execute_action(:get_zone, data)
JSON.parse(response)
end

# Получение акта возврата денег
def get_money_return_order(ikn, document_number, date_from, date_to = DateTime.now)
return_request(:get_money_return_order, ikn, document_number, date_from, date_to)
end

# Получение стоимости доставки
def get_delivery_cost(options)
# Получение акта возврата товара
def get_product_return_order(ikn, document_number, date_from, date_to = DateTime.now)
return_request(:get_product_return_order, ikn, document_number, date_from, date_to)
end

if !options[:invoice_ids].nil? && !options[:sender_invoice_numbers].nil?
raise ApiError
end
# Получение информации по вложимому
def enclose_info(barcode)
ensure_session_state
data = attach_session_id('Barcode', barcode)
response = execute_action(:enclose_info, data)
res = JSON.parse(response)

data = if !options[:invoice_ids].nil?
options[:invoice_ids].map do |invoice_id|
{'InvoiceNumber' => invoice_id}
end
elsif !options[:sender_invoice_numbers].nil?
options[:invoice_ids].map do |invoice_id|
{'SenderInvoiceNumber' => invoice_id}
end
else
raise ApiError
if !res['Error'].nil? && !res['Error'].empty?
raise ApiError res['Error']
end

data = attach_session_id('Sendings', data)
response = execute_action(:get_delivery_cost, data)
res
end

# Получение истории по списку отправлений
def track_sendings(invoice_id)
request_by_invoice_ids(invoice_id, :track_sendings)
end

# Получение справочника статусов отправления
def get_states
parameterless_request(:get_states)
end

# Получение списка отправлений, прошедших этап (статус)
def get_invoices_change_state(state, date_from, date_to = DateTime.now)
ensure_session_state
data = {
'SessionId' => @session_id,
'DateFrom' => date_from.strftime('%d.%m.%y'),
'DateTo' => date_to.strftime('%d.%m.%y'),
'State' => state
}
response = execute_action(:get_invoices_change_state, data)
JSON.parse(response)
end

Expand Down
8 changes: 8 additions & 0 deletions lib/pickpoint_api/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ def initialize(hash = {})

private

def sendings_request(action, data)
ensure_session_state
data = attach_session_id(data, 'Sendings')
response = execute_action(action, data)
response = JSON.parse(response)
end

def parameterless_request(action)
ensure_session_state
response = execute_action(action)
Expand Down Expand Up @@ -46,6 +53,7 @@ def request_by_invoice_ids(invoice_ids, action)
end

def return_request(action, ikn, document_number, date_from, date_to = DateTime.now)
ensure_session_state
data = {
'SessionId' => @session_id,
'IKN' => ikn,
Expand Down
4 changes: 3 additions & 1 deletion pickpoint_api.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative('./lib/pickpoint_api.rb')

Gem::Specification.new do |s|
s.name = "pickpoint_api"
s.version = "0.1"
s.version = ::PickpointApi.VERSION
s.authors = ["Kinderly LTD"]
s.email = ["[email protected]"]
s.homepage = "http://github.com/kinderly/pickpoint_api"
Expand Down
4 changes: 2 additions & 2 deletions spec/support/dummy_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module DummyData
].to_json


SAMPLE_SENDING_REQUEST = {
SAMPLE_SENDING_REQUEST = [{
'EDTN' => 14,
'IKN' => '9990000000',
'Invoice' => {
Expand All @@ -86,6 +86,6 @@ module DummyData
'Price' => 4290.0
}]
}
}
}]

end

0 comments on commit 30abae0

Please sign in to comment.