2015-04-13 03:14:25 +03:00
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
2015-07-16 18:00:51 +03:00
|
|
|
|
# noinspection RubyResolve
|
2015-04-13 03:14:25 +03:00
|
|
|
|
require 'net/http'
|
2015-07-16 18:00:51 +03:00
|
|
|
|
# noinspection RubyResolve
|
2015-04-13 03:14:25 +03:00
|
|
|
|
require 'net/https'
|
2015-07-16 18:00:51 +03:00
|
|
|
|
# noinspection RubyResolve
|
2015-04-13 03:14:25 +03:00
|
|
|
|
require 'uri'
|
2015-07-16 18:00:51 +03:00
|
|
|
|
# noinspection RubyResolve
|
2015-04-13 03:14:25 +03:00
|
|
|
|
require 'json'
|
|
|
|
|
|
|
|
|
|
# RetailCRM API Client
|
2015-07-16 18:00:51 +03:00
|
|
|
|
# noinspection ALL
|
2015-04-13 03:14:25 +03:00
|
|
|
|
class Retailcrm
|
|
|
|
|
|
|
|
|
|
def initialize(url, key)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
@version = 3
|
|
|
|
|
@url = "#{url}/api/v#{@version}/"
|
|
|
|
|
@key = key
|
|
|
|
|
@params = { :apiKey => @key }
|
2015-04-14 17:31:43 +03:00
|
|
|
|
@filter = nil
|
|
|
|
|
@ids = nil
|
2015-04-13 18:07:40 +03:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
##
|
|
|
|
|
# === Get orders by filter
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
2015-04-14 17:31:43 +03:00
|
|
|
|
# >> Retailcrm.orders({:email => 'test@example.com', :status => 'new'}, 50, 2)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
2015-04-14 17:31:43 +03:00
|
|
|
|
# filter (Hash)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
# limit (Integer) (20|50|100)
|
|
|
|
|
# page (Integer)
|
2015-04-13 18:07:40 +03:00
|
|
|
|
def orders(filter = nil, limit = 20, page = 1)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}orders"
|
|
|
|
|
@params[:limit] = limit
|
|
|
|
|
@params[:page] = page
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@filter = filter.to_a.map { |x| "filter[#{x[0]}]=#{x[1]}" }.join('&')
|
2015-04-14 17:31:43 +03:00
|
|
|
|
make_request(url)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Get orders statuses
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.orders_statuses([26120, 19282])
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# ids (Array)
|
|
|
|
|
def orders_statuses(ids = [])
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@ids = ids.map { |x| "ids[]=#{x}" }.join('&')
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}orders/statuses"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Get orders by id (or externalId)
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.orders_get(345, 'id')
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# id (Integer)
|
|
|
|
|
# by (String)
|
2015-04-15 15:06:05 +03:00
|
|
|
|
# site (String)
|
|
|
|
|
def orders_get(id, by = 'externalId', site = nil)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}orders/#{id}"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
if by != 'externalId'
|
2015-04-14 18:05:47 +03:00
|
|
|
|
@params[:by] = by
|
2015-04-15 15:06:05 +03:00
|
|
|
|
@params[:site] = site
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Create order
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.orders_create(order)
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# order (Array)
|
2015-04-15 15:06:05 +03:00
|
|
|
|
# site (String)
|
|
|
|
|
def orders_create(order, site = nil)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}orders/create"
|
|
|
|
|
@params[:order] = order.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
@params[:site] = site
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url, 'post')
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Edit order
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.orders_edit(order)
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# order (Array)
|
2015-04-15 15:06:05 +03:00
|
|
|
|
# site (String)
|
|
|
|
|
def orders_edit(order, site = nil)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
id = order[:externalId]
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}orders/#{id}/edit"
|
|
|
|
|
@params[:order] = order.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
@params[:site] = site
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url, 'post')
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Upload orders
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.orders_upload(orders)
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# orders (Array)
|
2015-04-15 15:06:05 +03:00
|
|
|
|
# site (String)
|
|
|
|
|
def orders_upload(orders, site = nil)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}orders/upload"
|
|
|
|
|
@params[:orders] = orders.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
@params[:site] = site
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url, 'post')
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Set external ids for orders created into CRM
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.orders_fix_external_ids([{:id => 200, :externalId => 334}, {:id => 201, :externalId => 364}])
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# orders (Array)
|
|
|
|
|
def orders_fix_external_ids(orders)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}orders/fix-external-ids"
|
|
|
|
|
@params[:orders] = orders.to_json
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url, 'post')
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Get orders history
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.orders_history('2015-04-10 22:23:12', '2015-04-10 23:33:12')
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
2015-04-13 18:07:40 +03:00
|
|
|
|
# start_date (Time) (Time.strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
|
|
# end_date (Time) (Time.strftime('%Y-%m-%d %H:%M:%S'))
|
2015-04-13 03:14:25 +03:00
|
|
|
|
# limit (Integer) (20|50|100)
|
|
|
|
|
# offset (Integer)
|
2015-04-13 18:07:40 +03:00
|
|
|
|
# skip_my_changes (Boolean)
|
|
|
|
|
def orders_history(start_date = nil, end_date = nil, limit = 100, offset = 0, skip_my_changes = true)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}orders/history"
|
|
|
|
|
@params[:startDate] = start_date
|
|
|
|
|
@params[:endDate] = end_date
|
|
|
|
|
@params[:limit] = limit
|
|
|
|
|
@params[:offset] = offset
|
|
|
|
|
@params[:skipMyChanges] = skip_my_changes
|
|
|
|
|
make_request(url)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Get orders assembly history
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.orders_packs_history({:orderId => 26120, :startDate => '2015-04-10 23:33:12'}, 50, 2)
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# filter (Hash)
|
|
|
|
|
# limit (Integer) (20|50|100)
|
|
|
|
|
# page (Integer)
|
|
|
|
|
def orders_packs_history(filter = nil, limit = 20, page = 1)
|
|
|
|
|
url = "#{@url}orders/packs/history"
|
|
|
|
|
@params[:limit] = limit
|
|
|
|
|
@params[:page] = page
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@filter = filter.to_a.map { |x| "filter[#{x[0]}]=#{x[1]}" }.join('&')
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
2015-04-14 17:31:43 +03:00
|
|
|
|
# === Get customers by filter
|
2015-04-13 03:14:25 +03:00
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
2015-04-14 17:31:43 +03:00
|
|
|
|
# >> Retailcrm.customers({:email => 'test@example.com'}, 50, 2)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
2015-04-14 17:31:43 +03:00
|
|
|
|
# filter (Hash)
|
|
|
|
|
# limit (Integer) (20|50|100)
|
|
|
|
|
# page (Integer)
|
|
|
|
|
def customers(filter = nil, limit = 20, page = 1)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}customers"
|
|
|
|
|
@params[:limit] = limit
|
|
|
|
|
@params[:page] = page
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@filter = filter.to_a.map { |x| "filter[#{x[0]}]=#{x[1]}" }.join('&')
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Get customers by id (or externalId)
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.customers_get(345, 'id')
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# id (Integer)
|
|
|
|
|
# by (String)
|
2015-04-15 15:06:05 +03:00
|
|
|
|
# site (String)
|
|
|
|
|
def customers_get(id, by = 'externalId', site = nil)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}customers/#{id}"
|
2015-04-15 15:06:05 +03:00
|
|
|
|
@params[:site] = site
|
2015-04-13 18:07:40 +03:00
|
|
|
|
if by != 'externalId'
|
2015-04-14 18:05:47 +03:00
|
|
|
|
@params[:by] = by
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Create customer
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.customer_create(customer)
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# customer (Array)
|
2015-04-15 15:06:05 +03:00
|
|
|
|
# site (String)
|
|
|
|
|
def customers_create(customer, site = nil)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}customers/create"
|
|
|
|
|
@params[:customer] = customer.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
@params[:site] = site
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url, 'post')
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Edit customer
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.customers_edit(customer)
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# customer (Array)
|
2015-04-15 15:06:05 +03:00
|
|
|
|
# site (String)
|
|
|
|
|
def customers_edit(customer, site = nil)
|
2015-04-13 18:07:40 +03:00
|
|
|
|
id = customer[:externalId]
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}customers/#{id}/edit"
|
|
|
|
|
@params[:customer] = customer.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
@params[:site] = site
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url, 'post')
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Upload customers
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.customers_upload(customers)
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# customers (Array)
|
2015-04-15 15:06:05 +03:00
|
|
|
|
# site (String)
|
|
|
|
|
def customers_upload(customers, site = nil)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}customers/upload"
|
|
|
|
|
@params[:customers] = customers.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
@params[:site] = site
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url, 'post')
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Set external ids for customers created into CRM
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.customers_fix_external_ids([{:id => 200, :externalId => 334}, {:id => 201, :externalId => 364}])
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# customers (Array)
|
|
|
|
|
def customers_fix_external_ids(customers)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}customers/fix-external-ids"
|
|
|
|
|
@params[:customers] = customers.to_json
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url, 'post')
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-14 18:05:47 +03:00
|
|
|
|
##
|
|
|
|
|
# === Get purchace prices & stock balance
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.store_inventories({:productExternalId => 26120, :details => 1}, 50, 2)
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# filter (Hash)
|
|
|
|
|
# limit (Integer) (20|50|100)
|
|
|
|
|
# page (Integer)
|
|
|
|
|
def store_inventories(filter = nil, limit = 20, page = 1)
|
|
|
|
|
url = "#{@url}store/inventories"
|
|
|
|
|
@params[:limit] = limit
|
|
|
|
|
@params[:page] = page
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@filter = filter.to_a.map { |x| "filter[#{x[0]}]=#{x[1]}" }.join('&')
|
2015-04-14 18:05:47 +03:00
|
|
|
|
make_request(url)
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-15 15:06:05 +03:00
|
|
|
|
##
|
|
|
|
|
# === Set purchace prices & stock balance
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
# Example:
|
|
|
|
|
# >> Retailcrm.store_inventories_upload({:offers => [{:externalId => 123, :stores => [{:code => 'store_1', :available => 15, :purchasePrice => 1000}]}]}, :site => 'main_site')
|
|
|
|
|
# => {...}
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
|
|
|
|
# offers (Array)
|
|
|
|
|
# site (String)
|
|
|
|
|
def store_inventories_upload(offers = [], site = nil)
|
|
|
|
|
url = "#{@url}store/inventories/upload"
|
|
|
|
|
@params[:offers] = offers
|
|
|
|
|
@params[:site] = site
|
|
|
|
|
make_request(url, 'post')
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
##
|
|
|
|
|
# === Get delivery services
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def delivery_services
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}reference/delivery-services"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-15 15:06:05 +03:00
|
|
|
|
##
|
|
|
|
|
# === Edit delivery service
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def delivery_services_edit(delivery_service)
|
|
|
|
|
code = delivery_service[:code]
|
|
|
|
|
url = "#{@url}reference/delivery-services/#{code}/edit"
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@params[:deliveryService] = delivery_service.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
make_request(url, 'post')
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
# Get delivery types
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def delivery_types
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}reference/delivery-types"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-15 15:06:05 +03:00
|
|
|
|
##
|
|
|
|
|
# === Edit delivery type
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def delivery_types_edit(delivery_type)
|
|
|
|
|
code = delivery_type[:code]
|
|
|
|
|
url = "#{@url}reference/delivery-types/#{code}/edit"
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@params[:deliveryType] = delivery_type.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
make_request(url, 'post')
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
##
|
|
|
|
|
# === Get order methods
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def order_methods
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}reference/order-methods"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-15 15:06:05 +03:00
|
|
|
|
##
|
|
|
|
|
# === Edit order method
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def order_methods_edit(order_method)
|
|
|
|
|
code = order_method[:code]
|
|
|
|
|
url = "#{@url}reference/order-methods/#{code}/edit"
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@params[:orderMethod] = order_method.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
make_request(url, 'post')
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
##
|
|
|
|
|
# === Get order types
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def order_types
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}reference/order-types"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-15 15:06:05 +03:00
|
|
|
|
##
|
|
|
|
|
# === Edit order type
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def order_types_edit(order_type)
|
|
|
|
|
code = order_type[:code]
|
|
|
|
|
url = "#{@url}reference/order-types/#{code}/edit"
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@params[:orderType] = order_type.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
make_request(url, 'post')
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
# Get payment statuses
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def payment_statuses
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}reference/payment-statuses"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-15 15:06:05 +03:00
|
|
|
|
##
|
|
|
|
|
# === Edit payment status
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def payment_statuses_edit(payment_status)
|
|
|
|
|
code = payment_status[:code]
|
|
|
|
|
url = "#{@url}reference/payment-statuses/#{code}/edit"
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@params[:paymentStatus] = payment_status.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
make_request(url, 'post')
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
##
|
|
|
|
|
# === Get payment types
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def payment_types
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}reference/payment-types"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-15 15:06:05 +03:00
|
|
|
|
##
|
|
|
|
|
# === Edit payment type
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def payment_types_edit(payment_type)
|
|
|
|
|
code = payment_type[:code]
|
2015-07-16 18:00:51 +03:00
|
|
|
|
url = "#{@url}reference/payment-types/#{code}/edit"
|
|
|
|
|
@params[:paymentType] = payment_type.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
make_request(url, 'post')
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
##
|
|
|
|
|
# === Get product statuses
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def product_statuses
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}reference/product-statuses"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-15 15:06:05 +03:00
|
|
|
|
##
|
|
|
|
|
# === Edit product status
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def product_statuses_edit(product_status)
|
|
|
|
|
code = product_status[:code]
|
|
|
|
|
url = "#{@url}reference/product-statuses/#{code}/edit"
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@params[:productStatus] = product_status.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
make_request(url, 'post')
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
# Get sites list
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def sites
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}reference/sites"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-15 15:06:05 +03:00
|
|
|
|
##
|
|
|
|
|
# === Edit site
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def sites_edit(site)
|
|
|
|
|
code = site[:code]
|
|
|
|
|
url = "#{@url}reference/sites/#{code}/edit"
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@params[:site] = site.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
make_request(url, 'post')
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
##
|
|
|
|
|
# === Get status groups
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def status_groups
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}reference/status-groups"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Get statuses
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def statuses
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}reference/statuses"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-15 15:06:05 +03:00
|
|
|
|
##
|
|
|
|
|
# === Edit status
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def statuses_edit(status)
|
|
|
|
|
code = status[:code]
|
|
|
|
|
url = "#{@url}reference/statuses/#{code}/edit"
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@params[:status] = status.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
make_request(url, 'post')
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
##
|
|
|
|
|
# === Get stores
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def stores
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}reference/stores"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
2015-04-15 15:06:05 +03:00
|
|
|
|
##
|
|
|
|
|
# === Edit store
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def stores_edit(store)
|
|
|
|
|
code = store[:code]
|
|
|
|
|
url = "#{@url}reference/stores/#{code}/edit"
|
2015-07-16 18:00:51 +03:00
|
|
|
|
@params[:store] = store.to_json
|
2015-04-15 15:06:05 +03:00
|
|
|
|
make_request(url, 'post')
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# === Statistic update
|
|
|
|
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
|
|
|
|
#
|
|
|
|
|
def statistic_update
|
2015-04-14 18:05:47 +03:00
|
|
|
|
url = "#{@url}statistic/update"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
make_request(url)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
|
|
def make_request(url, method='get')
|
|
|
|
|
raise ArgumentError, 'url must be not empty' unless !url.empty?
|
|
|
|
|
uri = URI.parse(url)
|
|
|
|
|
https = Net::HTTP.new(uri.host, uri.port)
|
|
|
|
|
https.use_ssl = true
|
2015-04-14 17:31:43 +03:00
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
if method == 'post'
|
|
|
|
|
request = Net::HTTP::Post.new(uri)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
request.set_form_data(@params)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
elsif method == 'get'
|
|
|
|
|
request = Net::HTTP::Get.new(uri.path)
|
2015-04-14 18:05:47 +03:00
|
|
|
|
request.set_form_data(@params)
|
2015-07-16 18:00:51 +03:00
|
|
|
|
data = "#{request.body}"
|
2015-04-13 18:07:40 +03:00
|
|
|
|
|
2015-07-16 18:00:51 +03:00
|
|
|
|
unless @filter.nil?
|
|
|
|
|
data = data + "&#{@filter}"
|
2015-04-14 17:31:43 +03:00
|
|
|
|
end
|
|
|
|
|
|
2015-07-16 18:00:51 +03:00
|
|
|
|
unless @ids.nil?
|
|
|
|
|
data = data + "&#{@ids}"
|
2015-04-14 17:31:43 +03:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
request = Net::HTTP::Get.new("#{uri.path}?#{data}")
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
response = https.request(request)
|
2015-04-13 18:07:40 +03:00
|
|
|
|
Retailcrm::Response.new(response.code, response.body)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
class Retailcrm::Response
|
2015-04-13 18:07:40 +03:00
|
|
|
|
attr_reader :status, :response
|
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
def initialize(status, body)
|
|
|
|
|
@status = status
|
2015-04-13 18:07:40 +03:00
|
|
|
|
@response = body.empty? ? [] : JSON.parse(body)
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
2015-04-13 18:07:40 +03:00
|
|
|
|
|
2015-04-13 03:14:25 +03:00
|
|
|
|
def is_successfull?
|
2015-04-13 18:07:40 +03:00
|
|
|
|
@status.to_i < 400
|
2015-04-13 03:14:25 +03:00
|
|
|
|
end
|
|
|
|
|
end
|