Compare commits

..

No commits in common. "master" and "v1.1.1" have entirely different histories.

5 changed files with 101 additions and 144 deletions

View file

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2013-2020 RetailDriver LLC
Copyright (c) 2013 Alex Lushpai
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in

View file

@ -1,36 +1,35 @@
[![Gem](https://img.shields.io/gem/v/retailcrm?color=red)](https://rubygems.org/gems/retailcrm)
[![RDoc](https://img.shields.io/badge/RDoc-reference-red.svg)](http://www.rubydoc.info/gems/retailcrm)
[![Gem Version](https://badge.fury.io/rb/retailcrm.svg)](http://badge.fury.io/rb/retailcrm)
RetailCRM API ruby client
=========================
Ruby-клиент для retailCRM API
=============================
### Install
### Установка
```
gem install retailcrm
```
### Examples
### Примеры использования
#### Get order
#### Получение информации о заказе
```ruby
require 'retailcrm'
api = Retailcrm.new('https://demo.retailcrm.pro', 'yourApiKeyHere')
api = Retailcrm.new('https://yourcrmname.retailcrm.ru', 'yourApiKeyHere')
response = api.orders_get(345, 'id').response
order = response[:order]
```
#### Create order
#### Создание заказа
```ruby
require 'retailcrm'
api = Retailcrm.new('https://demo.retailcrm.pro', 'yourApiKeyHere')
api = Retailcrm.new('https://yourcrmname.retailcrm.ru', 'yourApiKeyHere')
order = {
:externalId => 171,
@ -69,3 +68,11 @@ response = api.orders_create(order).response
order_id = response[:id]
```
#### Документация REST API
http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#### Документация API библиотеки
http://www.rubydoc.info/gems/retailcrm

View file

@ -24,6 +24,7 @@ class Retailcrm
##
# === Get orders by filter
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.orders({:email => 'test@example.com', :status => 'new'}, 50, 2)
@ -43,6 +44,7 @@ class Retailcrm
##
# === Get orders statuses
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.orders_statuses([26120, 19282])
@ -58,6 +60,7 @@ class Retailcrm
##
# === Get orders by id (or externalId)
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.orders_get(345, 'id')
@ -78,6 +81,7 @@ class Retailcrm
##
# === Create order
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.orders_create(order)
@ -95,6 +99,7 @@ class Retailcrm
##
# === Edit order
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.orders_edit(order)
@ -113,6 +118,7 @@ class Retailcrm
##
# === Upload orders
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.orders_upload(orders)
@ -130,6 +136,7 @@ class Retailcrm
##
# === 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}])
@ -145,6 +152,7 @@ class Retailcrm
##
# === 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')
@ -166,8 +174,29 @@ class Retailcrm
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)
end
##
# === Get customers by filter
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.customers({:email => 'test@example.com'}, 50, 2)
@ -187,6 +216,7 @@ class Retailcrm
##
# === Get customers by id (or externalId)
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.customers_get(345, 'id')
@ -207,6 +237,7 @@ class Retailcrm
##
# === Create customer
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.customer_create(customer)
@ -224,6 +255,7 @@ class Retailcrm
##
# === Edit customer
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.customers_edit(customer)
@ -242,6 +274,7 @@ class Retailcrm
##
# === Upload customers
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.customers_upload(customers)
@ -259,6 +292,7 @@ class Retailcrm
##
# === 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}])
@ -274,6 +308,7 @@ class Retailcrm
##
# === Get purchace prices & stock balance
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.store_inventories({:productExternalId => 26120, :details => 1}, 50, 2)
@ -293,6 +328,7 @@ class Retailcrm
##
# === 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')
@ -308,113 +344,9 @@ class Retailcrm
make_request(url, 'post')
end
##
# === Get packs by filter
#
# Example:
# >> Retailcrm.packs({:store => 'main'}, 50, 2)
# => {...}
#
# Arguments:
# filter (Hash)
# limit (Integer) (20|50|100)
# page (Integer)
def packs(filter = nil, limit = 20, page = 1)
url = "#{@url}orders/packs"
@params[:limit] = limit
@params[:page] = page
@filter = filter.to_a.map { |x| "filter[#{x[0]}]=#{x[1]}" }.join('&')
make_request(url)
end
##
# === Create pack
#
# Example:
# >> Retailcrm.packs_create(pack)
# => {...}
#
# Arguments:
# pack (Array)
# site (String)
def packs_create(pack, site = nil)
url = "#{@url}orders/packs/create"
@params[:pack] = pack.to_json
@params[:site] = site
make_request(url, 'post')
end
##
# === Get orders assembly history
#
# Example:
# >> Retailcrm.packs_history({:orderId => 26120, :startDate => '2015-04-10 23:33:12'}, 50, 2)
# => {...}
#
# Arguments:
# filter (Hash)
# limit (Integer) (20|50|100)
# page (Integer)
def 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)
end
##
# === Get pack by id
#
# Example:
# >> Retailcrm.packs_get(345)
# => {...}
#
# Arguments:
# id (Integer)
# site (String)
def packs_get(id, site = nil)
url = "#{@url}orders/packs/#{id}"
@params[:site] = site
make_request(url)
end
##
# === Edit pack
#
# Example:
# >> Retailcrm.packs_edit(pack)
# => {...}
#
# Arguments:
# pack (Array)
# site (String)
def packs_edit(pack, site = nil)
id = pack[:id]
url = "#{@url}orders/packs/#{id}/edit"
@params[:pack] = pack.to_json
@params[:site] = site
make_request(url, 'post')
end
##
# === Delete pack
#
# Example:
# >> Retailcrm.packs_delete(14)
# => {...}
#
# Arguments:
# id (Integer)
# site (String)
def packs_delete(id, site = nil)
url = "#{@url}orders/packs/#{id}/delete"
@params[:site] = site
make_request(url, 'post')
end
##
# === Get delivery services
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def delivery_services
url = "#{@url}reference/delivery-services"
@ -423,6 +355,7 @@ class Retailcrm
##
# === Edit delivery service
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def delivery_services_edit(delivery_service)
code = delivery_service[:code]
@ -432,6 +365,7 @@ class Retailcrm
end
# Get delivery types
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def delivery_types
url = "#{@url}reference/delivery-types"
@ -440,6 +374,7 @@ class Retailcrm
##
# === Edit delivery type
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def delivery_types_edit(delivery_type)
code = delivery_type[:code]
@ -450,6 +385,7 @@ class Retailcrm
##
# === Get order methods
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def order_methods
url = "#{@url}reference/order-methods"
@ -458,6 +394,7 @@ class Retailcrm
##
# === Edit order method
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def order_methods_edit(order_method)
code = order_method[:code]
@ -468,6 +405,7 @@ class Retailcrm
##
# === Get order types
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def order_types
url = "#{@url}reference/order-types"
@ -476,6 +414,7 @@ class Retailcrm
##
# === Edit order type
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def order_types_edit(order_type)
code = order_type[:code]
@ -485,6 +424,7 @@ class Retailcrm
end
# Get payment statuses
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def payment_statuses
url = "#{@url}reference/payment-statuses"
@ -493,6 +433,7 @@ class Retailcrm
##
# === Edit payment status
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def payment_statuses_edit(payment_status)
code = payment_status[:code]
@ -503,6 +444,7 @@ class Retailcrm
##
# === Get payment types
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def payment_types
url = "#{@url}reference/payment-types"
@ -511,6 +453,7 @@ class Retailcrm
##
# === Edit payment type
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def payment_types_edit(payment_type)
code = payment_type[:code]
@ -521,6 +464,7 @@ class Retailcrm
##
# === Get product statuses
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def product_statuses
url = "#{@url}reference/product-statuses"
@ -529,6 +473,7 @@ class Retailcrm
##
# === Edit product status
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def product_statuses_edit(product_status)
code = product_status[:code]
@ -538,6 +483,7 @@ class Retailcrm
end
# Get sites list
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def sites
url = "#{@url}reference/sites"
@ -546,6 +492,7 @@ class Retailcrm
##
# === Edit site
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def sites_edit(site)
code = site[:code]
@ -556,6 +503,7 @@ class Retailcrm
##
# === Get status groups
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def status_groups
url = "#{@url}reference/status-groups"
@ -563,6 +511,7 @@ class Retailcrm
end
# Get statuses
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def statuses
url = "#{@url}reference/statuses"
@ -571,6 +520,7 @@ class Retailcrm
##
# === Edit status
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def statuses_edit(status)
code = status[:code]
@ -581,6 +531,7 @@ class Retailcrm
##
# === Get stores
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def stores
url = "#{@url}reference/stores"
@ -589,6 +540,7 @@ class Retailcrm
##
# === Edit store
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def stores_edit(store)
code = store[:code]
@ -597,15 +549,10 @@ class Retailcrm
make_request(url, 'post')
end
# Get countries list
#
def countries
url = "#{@url}reference/countries"
make_request(url)
end
##
# === Statistic update
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def statistic_update
url = "#{@url}statistic/update"

View file

@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'retailcrm'
s.version = '1.1.2'
s.date = '2016-03-07'
s.version = '1.1.1'
s.date = '2015-04-15'
s.summary = 'RetailCRM Rest API client'
s.description = 'Library for interact with RetailCRM API'
s.authors = ['Alex Lushpai']

View file

@ -5,7 +5,7 @@ class Bootstrap
attr_reader :api_key, :api_url, :order, :customer, :refs_get, :refs_edit
def initialize
@api_url = 'https://demo.retailcrm.pro'
@api_url = 'https://demo.retailcrm.ru'
@api_key = 'YourAPIKeyRightHere'
id = Time.now.to_i
@ -14,9 +14,9 @@ class Bootstrap
@customer = {
:externalId => id,
:createdAt => time,
:firstName => 'John',
:lastName => 'Doe',
:email => 'john@example.org',
:firstName => 'API',
:lastName => 'Test',
:email => 'pupkin@example.org',
:phones => [{:number => '+79099099090'}]
}
@ -31,23 +31,24 @@ class Bootstrap
:firstName => 'API',
:lastName => 'Test',
:customer => {
:firstName => 'John',
:lastName => 'Doe',
:firstName => 'Тестовый',
:lastName => 'Клиент',
:phones => [{:number => '+79099099090'}],
},
:delivery => {
:code => 'courier',
:cost => 500
:cost => 500,
:address => {:text => '344000, Ростов-на-Дону, пр. Буденовский, 13'}
},
:status => 'new',
:items => [
{
:productName => 'First',
:productName => 'Товар 1',
:initialPrice => 500,
:quantity => 2
},
{
:productName => 'Second',
:productName => 'Товар 2',
:initialPrice => 1300,
:quantity => 1
}
@ -74,23 +75,24 @@ class Bootstrap
:firstName => 'API',
:lastName => 'Test',
:customer => {
:firstName => 'John',
:lastName => 'Doe',
:firstName => 'Тестовый',
:lastName => 'Клиент',
:phones => [{:number => '+79099099090'}],
},
:delivery => {
:code => 'courier',
:cost => 500
:cost => 500,
:address => {:text => '344000, Ростов-на-Дону, пр. Буденовский, 13'}
},
:status => 'new',
:items => [
{
:productName => 'First',
:productName => 'Товар 1',
:initialPrice => 500,
:quantity => 2
},
{
:productName => 'Second',
:productName => 'Товар 2',
:initialPrice => 1300,
:quantity => 1
}
@ -105,23 +107,24 @@ class Bootstrap
:firstName => 'API2',
:lastName => 'Test2',
:customer => {
:firstName => 'Joe',
:lastName => 'Doe',
:firstName => 'Тестовый2',
:lastName => 'Клиент2',
:phones => [{:number => '+79099099000'}],
},
:delivery => {
:code => 'ems',
:cost => 500
:cost => 500,
:address => {:text => '344000, Ростов-на-Дону, пр. Буденовский, 15'}
},
:status => 'availability-confirmed',
:items => [
{
:productName => 'Third',
:productName => 'Товар 3',
:initialPrice => 500,
:quantity => 2
},
{
:productName => 'Extra',
:productName => 'Товар 4',
:initialPrice => 1300,
:quantity => 1
}
@ -189,7 +192,7 @@ class Bootstrap
},
sites_edit: {
name: 'Rake Shop',
url: 'http://example.org',
url: 'http://yandex.ru',
code: 'api-client-all',
loadFromYml: false,
},