mirror of
https://github.com/retailcrm/api-client-ruby.git
synced 2024-11-22 21:16:08 +03:00
store_inventories method, orders_packs_history method, refactoring, update bootstrap file
This commit is contained in:
parent
bb39e0481a
commit
eeb450f6e3
142
lib/retailcrm.rb
142
lib/retailcrm.rb
@ -9,10 +9,10 @@ require 'json'
|
|||||||
class Retailcrm
|
class Retailcrm
|
||||||
|
|
||||||
def initialize(url, key)
|
def initialize(url, key)
|
||||||
@rr_version = 3
|
@version = 3
|
||||||
@rr_url = "#{url}/api/v#{@rr_version}/"
|
@url = "#{url}/api/v#{@version}/"
|
||||||
@rr_key = key
|
@key = key
|
||||||
@rr_params = { :apiKey => @rr_key }
|
@params = { :apiKey => @key }
|
||||||
@filter = nil
|
@filter = nil
|
||||||
@ids = nil
|
@ids = nil
|
||||||
end
|
end
|
||||||
@ -30,9 +30,9 @@ class Retailcrm
|
|||||||
# limit (Integer) (20|50|100)
|
# limit (Integer) (20|50|100)
|
||||||
# page (Integer)
|
# page (Integer)
|
||||||
def orders(filter = nil, limit = 20, page = 1)
|
def orders(filter = nil, limit = 20, page = 1)
|
||||||
url = "#{@rr_url}orders"
|
url = "#{@url}orders"
|
||||||
@rr_params[:limit] = limit
|
@params[:limit] = limit
|
||||||
@rr_params[:page] = page
|
@params[:page] = page
|
||||||
@filter = filter.to_a.map { |x| "filter[#{x[0]}]=#{x[1]}" }.join("&")
|
@filter = filter.to_a.map { |x| "filter[#{x[0]}]=#{x[1]}" }.join("&")
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
@ -49,7 +49,7 @@ class Retailcrm
|
|||||||
# ids (Array)
|
# ids (Array)
|
||||||
def orders_statuses(ids = [])
|
def orders_statuses(ids = [])
|
||||||
@ids = ids.map { |x| "ids[]=#{x}" }.join("&")
|
@ids = ids.map { |x| "ids[]=#{x}" }.join("&")
|
||||||
url = "#{@rr_url}orders/statuses"
|
url = "#{@url}orders/statuses"
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -65,9 +65,9 @@ class Retailcrm
|
|||||||
# id (Integer)
|
# id (Integer)
|
||||||
# by (String)
|
# by (String)
|
||||||
def orders_get(id, by = 'externalId')
|
def orders_get(id, by = 'externalId')
|
||||||
url = "#{@rr_url}orders/#{id}"
|
url = "#{@url}orders/#{id}"
|
||||||
if by != 'externalId'
|
if by != 'externalId'
|
||||||
@rr_params[:by] = by
|
@params[:by] = by
|
||||||
end
|
end
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
@ -83,8 +83,8 @@ class Retailcrm
|
|||||||
# Arguments:
|
# Arguments:
|
||||||
# order (Array)
|
# order (Array)
|
||||||
def orders_create(order)
|
def orders_create(order)
|
||||||
url = "#{@rr_url}orders/create"
|
url = "#{@url}orders/create"
|
||||||
@rr_params[:order] = order.to_json
|
@params[:order] = order.to_json
|
||||||
make_request(url, 'post')
|
make_request(url, 'post')
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -100,8 +100,8 @@ class Retailcrm
|
|||||||
# order (Array)
|
# order (Array)
|
||||||
def orders_edit(order)
|
def orders_edit(order)
|
||||||
id = order[:externalId]
|
id = order[:externalId]
|
||||||
url = "#{@rr_url}orders/#{id}/edit"
|
url = "#{@url}orders/#{id}/edit"
|
||||||
@rr_params[:order] = order.to_json
|
@params[:order] = order.to_json
|
||||||
make_request(url, 'post')
|
make_request(url, 'post')
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -116,8 +116,8 @@ class Retailcrm
|
|||||||
# Arguments:
|
# Arguments:
|
||||||
# orders (Array)
|
# orders (Array)
|
||||||
def orders_upload(orders)
|
def orders_upload(orders)
|
||||||
url = "#{@rr_url}orders/upload"
|
url = "#{@url}orders/upload"
|
||||||
@rr_params[:orders] = orders.to_json
|
@params[:orders] = orders.to_json
|
||||||
make_request(url, 'post')
|
make_request(url, 'post')
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -132,8 +132,8 @@ class Retailcrm
|
|||||||
# Arguments:
|
# Arguments:
|
||||||
# orders (Array)
|
# orders (Array)
|
||||||
def orders_fix_external_ids(orders)
|
def orders_fix_external_ids(orders)
|
||||||
url = "#{@rr_url}orders/fix-external-ids"
|
url = "#{@url}orders/fix-external-ids"
|
||||||
@rr_params[:orders] = orders.to_json
|
@params[:orders] = orders.to_json
|
||||||
make_request(url, 'post')
|
make_request(url, 'post')
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -152,12 +152,32 @@ class Retailcrm
|
|||||||
# offset (Integer)
|
# offset (Integer)
|
||||||
# skip_my_changes (Boolean)
|
# skip_my_changes (Boolean)
|
||||||
def orders_history(start_date = nil, end_date = nil, limit = 100, offset = 0, skip_my_changes = true)
|
def orders_history(start_date = nil, end_date = nil, limit = 100, offset = 0, skip_my_changes = true)
|
||||||
url = "#{@rr_url}orders/history"
|
url = "#{@url}orders/history"
|
||||||
@rr_params[:startDate] = start_date
|
@params[:startDate] = start_date
|
||||||
@rr_params[:endDate] = end_date
|
@params[:endDate] = end_date
|
||||||
@rr_params[:limit] = limit
|
@params[:limit] = limit
|
||||||
@rr_params[:offset] = offset
|
@params[:offset] = offset
|
||||||
@rr_params[:skipMyChanges] = skip_my_changes
|
@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
|
||||||
|
@filter = filter.to_a.map { |x| "filter[#{x[0]}]=#{x[1]}" }.join("&")
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -174,9 +194,9 @@ class Retailcrm
|
|||||||
# limit (Integer) (20|50|100)
|
# limit (Integer) (20|50|100)
|
||||||
# page (Integer)
|
# page (Integer)
|
||||||
def customers(filter = nil, limit = 20, page = 1)
|
def customers(filter = nil, limit = 20, page = 1)
|
||||||
url = "#{@rr_url}customers"
|
url = "#{@url}customers"
|
||||||
@rr_params[:limit] = limit
|
@params[:limit] = limit
|
||||||
@rr_params[:page] = page
|
@params[:page] = page
|
||||||
@filter = filter.to_a.map { |x| "filter[#{x[0]}]=#{x[1]}" }.join("&")
|
@filter = filter.to_a.map { |x| "filter[#{x[0]}]=#{x[1]}" }.join("&")
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
@ -193,9 +213,9 @@ class Retailcrm
|
|||||||
# id (Integer)
|
# id (Integer)
|
||||||
# by (String)
|
# by (String)
|
||||||
def customers_get(id, by = 'externalId')
|
def customers_get(id, by = 'externalId')
|
||||||
url = "#{@rr_url}customers/#{id}"
|
url = "#{@url}customers/#{id}"
|
||||||
if by != 'externalId'
|
if by != 'externalId'
|
||||||
@rr_params[:by] = by
|
@params[:by] = by
|
||||||
end
|
end
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
@ -211,8 +231,8 @@ class Retailcrm
|
|||||||
# Arguments:
|
# Arguments:
|
||||||
# customer (Array)
|
# customer (Array)
|
||||||
def customers_create(customer)
|
def customers_create(customer)
|
||||||
url = "#{@rr_url}customers/create"
|
url = "#{@url}customers/create"
|
||||||
@rr_params[:customer] = customer.to_json
|
@params[:customer] = customer.to_json
|
||||||
make_request(url, 'post')
|
make_request(url, 'post')
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -228,8 +248,8 @@ class Retailcrm
|
|||||||
# customer (Array)
|
# customer (Array)
|
||||||
def customers_edit(customer)
|
def customers_edit(customer)
|
||||||
id = customer[:externalId]
|
id = customer[:externalId]
|
||||||
url = "#{@rr_url}customers/#{id}/edit"
|
url = "#{@url}customers/#{id}/edit"
|
||||||
@rr_params[:customer] = customer.to_json
|
@params[:customer] = customer.to_json
|
||||||
make_request(url, 'post')
|
make_request(url, 'post')
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -244,8 +264,8 @@ class Retailcrm
|
|||||||
# Arguments:
|
# Arguments:
|
||||||
# customers (Array)
|
# customers (Array)
|
||||||
def customers_upload(customers)
|
def customers_upload(customers)
|
||||||
url = "#{@rr_url}customers/upload"
|
url = "#{@url}customers/upload"
|
||||||
@rr_params[:customers] = customers.to_json
|
@params[:customers] = customers.to_json
|
||||||
make_request(url, 'post')
|
make_request(url, 'post')
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -260,17 +280,37 @@ class Retailcrm
|
|||||||
# Arguments:
|
# Arguments:
|
||||||
# customers (Array)
|
# customers (Array)
|
||||||
def customers_fix_external_ids(customers)
|
def customers_fix_external_ids(customers)
|
||||||
url = "#{@rr_url}customers/fix-external-ids"
|
url = "#{@url}customers/fix-external-ids"
|
||||||
@rr_params[:customers] = customers.to_json
|
@params[:customers] = customers.to_json
|
||||||
make_request(url, 'post')
|
make_request(url, 'post')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# === 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
|
||||||
|
@filter = filter.to_a.map { |x| "filter[#{x[0]}]=#{x[1]}" }.join("&")
|
||||||
|
make_request(url)
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# === Get delivery services
|
# === Get delivery services
|
||||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||||
#
|
#
|
||||||
def delivery_services
|
def delivery_services
|
||||||
url = "#{@rr_url}reference/delivery-services"
|
url = "#{@url}reference/delivery-services"
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -278,7 +318,7 @@ class Retailcrm
|
|||||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||||
#
|
#
|
||||||
def delivery_types
|
def delivery_types
|
||||||
url = "#{@rr_url}reference/delivery-types"
|
url = "#{@url}reference/delivery-types"
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -287,7 +327,7 @@ class Retailcrm
|
|||||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||||
#
|
#
|
||||||
def order_methods
|
def order_methods
|
||||||
url = "#{@rr_url}reference/order-methods"
|
url = "#{@url}reference/order-methods"
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -296,7 +336,7 @@ class Retailcrm
|
|||||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||||
#
|
#
|
||||||
def order_types
|
def order_types
|
||||||
url = "#{@rr_url}reference/order-types"
|
url = "#{@url}reference/order-types"
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -304,7 +344,7 @@ class Retailcrm
|
|||||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||||
#
|
#
|
||||||
def payment_statuses
|
def payment_statuses
|
||||||
url = "#{@rr_url}reference/payment-statuses"
|
url = "#{@url}reference/payment-statuses"
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -313,7 +353,7 @@ class Retailcrm
|
|||||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||||
#
|
#
|
||||||
def payment_types
|
def payment_types
|
||||||
url = "#{@rr_url}reference/payment-types"
|
url = "#{@url}reference/payment-types"
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -322,7 +362,7 @@ class Retailcrm
|
|||||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||||
#
|
#
|
||||||
def product_statuses
|
def product_statuses
|
||||||
url = "#{@rr_url}reference/product-statuses"
|
url = "#{@url}reference/product-statuses"
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -330,7 +370,7 @@ class Retailcrm
|
|||||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||||
#
|
#
|
||||||
def sites
|
def sites
|
||||||
url = "#{@rr_url}reference/sites"
|
url = "#{@url}reference/sites"
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -339,7 +379,7 @@ class Retailcrm
|
|||||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||||
#
|
#
|
||||||
def status_groups
|
def status_groups
|
||||||
url = "#{@rr_url}reference/status-groups"
|
url = "#{@url}reference/status-groups"
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -347,7 +387,7 @@ class Retailcrm
|
|||||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||||
#
|
#
|
||||||
def statuses
|
def statuses
|
||||||
url = "#{@rr_url}reference/statuses"
|
url = "#{@url}reference/statuses"
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -356,7 +396,7 @@ class Retailcrm
|
|||||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||||
#
|
#
|
||||||
def stores
|
def stores
|
||||||
url = "#{@rr_url}reference/stores"
|
url = "#{@url}reference/stores"
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -366,7 +406,7 @@ class Retailcrm
|
|||||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||||
#
|
#
|
||||||
def statistic_update
|
def statistic_update
|
||||||
url = "#{@rr_url}statistic/update"
|
url = "#{@url}statistic/update"
|
||||||
make_request(url)
|
make_request(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -380,10 +420,10 @@ class Retailcrm
|
|||||||
|
|
||||||
if method == 'post'
|
if method == 'post'
|
||||||
request = Net::HTTP::Post.new(uri)
|
request = Net::HTTP::Post.new(uri)
|
||||||
request.set_form_data(@rr_params)
|
request.set_form_data(@params)
|
||||||
elsif method == 'get'
|
elsif method == 'get'
|
||||||
request = Net::HTTP::Get.new(uri.path)
|
request = Net::HTTP::Get.new(uri.path)
|
||||||
request.set_form_data(@rr_params)
|
request.set_form_data(@params)
|
||||||
|
|
||||||
if @filter.nil?
|
if @filter.nil?
|
||||||
data = "#{request.body}"
|
data = "#{request.body}"
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
class Bootstrap
|
class Bootstrap
|
||||||
|
|
||||||
attr_reader :api_key, :api_url, :order, :customer, :order_edit
|
attr_reader :api_key, :api_url, :order, :order_edit, :orders, :customer
|
||||||
|
|
||||||
def initialize()
|
def initialize
|
||||||
@api_url = 'https://demo.retailcrm.ru'
|
@api_url = 'https://demo.retailcrm.ru'
|
||||||
@api_key = ''
|
@api_key = ''
|
||||||
|
|
||||||
id = Time.now.to_i
|
id = Time.now.to_i
|
||||||
time = Time.now.strftime("%F %T")
|
time = Time.now.strftime('%F %T')
|
||||||
|
|
||||||
@customer = {
|
@customer = {
|
||||||
:externalId => id,
|
:externalId => id,
|
||||||
@ -60,6 +60,74 @@ class Bootstrap
|
|||||||
:phone => '+79999999999',
|
:phone => '+79999999999',
|
||||||
:status => 'cancel-other',
|
:status => 'cancel-other',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@orders = [
|
||||||
|
{
|
||||||
|
:externalId => id,
|
||||||
|
:number => "#{id}",
|
||||||
|
:orderType => 'eshop-individual',
|
||||||
|
:orderMethod => 'phone',
|
||||||
|
:createdAt => time,
|
||||||
|
:discountPercent => 10,
|
||||||
|
:firstName => 'API',
|
||||||
|
:lastName => 'Test',
|
||||||
|
:customer => {
|
||||||
|
:firstName => 'Тестовый',
|
||||||
|
:lastName => 'Клиент',
|
||||||
|
:phones => [{:number => '+79099099090'}],
|
||||||
|
},
|
||||||
|
:delivery => {
|
||||||
|
:code => 'courier',
|
||||||
|
:cost => 500,
|
||||||
|
:address => {:text => '344000, Ростов-на-Дону, пр. Буденовский, 13'}
|
||||||
|
},
|
||||||
|
:status => 'new',
|
||||||
|
:items => [
|
||||||
|
{
|
||||||
|
:productName => 'Товар 1',
|
||||||
|
:initialPrice => 500,
|
||||||
|
:quantity => 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:productName => 'Товар 2',
|
||||||
|
:initialPrice => 1300,
|
||||||
|
:quantity => 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:externalId => id+1,
|
||||||
|
:number => "#{id+1}",
|
||||||
|
:orderType => 'eshop-individual',
|
||||||
|
:createdAt => time,
|
||||||
|
:discount => 200,
|
||||||
|
:firstName => 'API2',
|
||||||
|
:lastName => 'Test2',
|
||||||
|
:customer => {
|
||||||
|
:firstName => 'Тестовый2',
|
||||||
|
:lastName => 'Клиент2',
|
||||||
|
:phones => [{:number => '+79099099000'}],
|
||||||
|
},
|
||||||
|
:delivery => {
|
||||||
|
:code => 'ems',
|
||||||
|
:cost => 500,
|
||||||
|
:address => {:text => '344000, Ростов-на-Дону, пр. Буденовский, 15'}
|
||||||
|
},
|
||||||
|
:status => 'availability-confirmed',
|
||||||
|
:items => [
|
||||||
|
{
|
||||||
|
:productName => 'Товар 3',
|
||||||
|
:initialPrice => 500,
|
||||||
|
:quantity => 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:productName => 'Товар 4',
|
||||||
|
:initialPrice => 1300,
|
||||||
|
:quantity => 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user