Merge pull request #3 from gwinn/master

Update client methods & docs
This commit is contained in:
Alex Lushpai 2016-03-08 01:28:47 +03:00
commit 4358a6e815
4 changed files with 245 additions and 72 deletions

View File

@ -1,18 +1,18 @@
[![Gem Version](https://badge.fury.io/rb/retailcrm.svg)](http://badge.fury.io/rb/retailcrm)
Ruby-клиент для retailCRM API
=============================
retailCRM API ruby client
=========================
### Установка
### Install
```
gem install retailcrm
```
### Примеры использования
### Examples
#### Получение информации о заказе
#### Get order
```ruby
require 'retailcrm'
@ -24,7 +24,7 @@ order = response[:order]
```
#### Создание заказа
#### Create order
```ruby
require 'retailcrm'
@ -69,10 +69,7 @@ order_id = response[:id]
```
#### Документация REST API
#### Documentation
http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#### Документация API библиотеки
http://www.rubydoc.info/gems/retailcrm
* http://www.retailcrm.ru/docs/Developers/ApiVersion3
* http://www.rubydoc.info/gems/retailcrm

78
README.ru.md Normal file
View File

@ -0,0 +1,78 @@
[![Gem Version](https://badge.fury.io/rb/retailcrm.svg)](http://badge.fury.io/rb/retailcrm)
Ruby-клиент для retailCRM API
=============================
### Установка
```
gem install retailcrm
```
### Примеры использования
#### Получение информации о заказе
```ruby
require 'retailcrm'
api = Retailcrm.new('https://yourcrmname.retailcrm.ru', 'yourApiKeyHere')
response = api.orders_get(345, 'id').response
order = response[:order]
```
#### Создание заказа
```ruby
require 'retailcrm'
api = Retailcrm.new('https://yourcrmname.retailcrm.ru', 'yourApiKeyHere')
order = {
:externalId => 171,
:number => '171',
:email => 'test@example.com',
:createdAt => '2014-10-28 19:31:10',
:discountPercent => 10,
:firstName => 'Jack',
:lastName => 'Daniels',
:customer => {
:externalId => 8768,
:firstName => 'Jack',
:lastName => 'Daniels',
:phones => [{ :number => '+79000000000' }],
},
:delivery => {
:code => 'courier',
:cost => 500,
:address => {:text => '300000, Russia, Moscow, Tverskaya st., 56'}
},
:items => [
{
:productId => 170,
:initialPrice => 500,
:quantity => 2
},
{
:productId => 175,
:initialPrice => 1300,
:quantity => 1
}
]
}
response = api.orders_create(order).response
order_id = response[:id]
```
#### Документация REST API
http://www.retailcrm.ru/docs/Developers/ApiVersion3
#### Документация API библиотеки
http://www.rubydoc.info/gems/retailcrm

View File

@ -24,7 +24,7 @@ class Retailcrm
##
# === Get orders by filter
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.orders({:email => 'test@example.com', :status => 'new'}, 50, 2)
@ -44,7 +44,7 @@ class Retailcrm
##
# === Get orders statuses
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.orders_statuses([26120, 19282])
@ -60,7 +60,7 @@ class Retailcrm
##
# === Get orders by id (or externalId)
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.orders_get(345, 'id')
@ -81,7 +81,7 @@ class Retailcrm
##
# === Create order
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.orders_create(order)
@ -99,7 +99,7 @@ class Retailcrm
##
# === Edit order
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.orders_edit(order)
@ -118,7 +118,7 @@ class Retailcrm
##
# === Upload orders
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.orders_upload(orders)
@ -136,7 +136,7 @@ class Retailcrm
##
# === Set external ids for orders created into CRM
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.orders_fix_external_ids([{:id => 200, :externalId => 334}, {:id => 201, :externalId => 364}])
@ -152,7 +152,7 @@ class Retailcrm
##
# === Get orders history
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.orders_history('2015-04-10 22:23:12', '2015-04-10 23:33:12')
@ -174,29 +174,9 @@ 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
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.customers({:email => 'test@example.com'}, 50, 2)
@ -216,7 +196,7 @@ class Retailcrm
##
# === Get customers by id (or externalId)
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.customers_get(345, 'id')
@ -237,7 +217,7 @@ class Retailcrm
##
# === Create customer
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.customer_create(customer)
@ -255,7 +235,7 @@ class Retailcrm
##
# === Edit customer
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.customers_edit(customer)
@ -274,7 +254,7 @@ class Retailcrm
##
# === Upload customers
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.customers_upload(customers)
@ -292,7 +272,7 @@ class Retailcrm
##
# === Set external ids for customers created into CRM
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.customers_fix_external_ids([{:id => 200, :externalId => 334}, {:id => 201, :externalId => 364}])
@ -308,7 +288,7 @@ class Retailcrm
##
# === Get purchace prices & stock balance
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.store_inventories({:productExternalId => 26120, :details => 1}, 50, 2)
@ -328,7 +308,7 @@ class Retailcrm
##
# === Set purchace prices & stock balance
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# Example:
# >> Retailcrm.store_inventories_upload({:offers => [{:externalId => 123, :stores => [{:code => 'store_1', :available => 15, :purchasePrice => 1000}]}]}, :site => 'main_site')
@ -344,9 +324,120 @@ class Retailcrm
make_request(url, 'post')
end
##
# === Get packs by filter
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# 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
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# 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
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# 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
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# 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
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# 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
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
# 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
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def delivery_services
url = "#{@url}reference/delivery-services"
@ -355,7 +446,7 @@ class Retailcrm
##
# === Edit delivery service
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def delivery_services_edit(delivery_service)
code = delivery_service[:code]
@ -365,7 +456,7 @@ class Retailcrm
end
# Get delivery types
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def delivery_types
url = "#{@url}reference/delivery-types"
@ -374,7 +465,7 @@ class Retailcrm
##
# === Edit delivery type
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def delivery_types_edit(delivery_type)
code = delivery_type[:code]
@ -385,7 +476,7 @@ class Retailcrm
##
# === Get order methods
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def order_methods
url = "#{@url}reference/order-methods"
@ -394,7 +485,7 @@ class Retailcrm
##
# === Edit order method
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def order_methods_edit(order_method)
code = order_method[:code]
@ -405,7 +496,7 @@ class Retailcrm
##
# === Get order types
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def order_types
url = "#{@url}reference/order-types"
@ -414,7 +505,7 @@ class Retailcrm
##
# === Edit order type
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def order_types_edit(order_type)
code = order_type[:code]
@ -424,7 +515,7 @@ class Retailcrm
end
# Get payment statuses
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def payment_statuses
url = "#{@url}reference/payment-statuses"
@ -433,7 +524,7 @@ class Retailcrm
##
# === Edit payment status
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def payment_statuses_edit(payment_status)
code = payment_status[:code]
@ -444,7 +535,7 @@ class Retailcrm
##
# === Get payment types
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def payment_types
url = "#{@url}reference/payment-types"
@ -453,7 +544,7 @@ class Retailcrm
##
# === Edit payment type
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def payment_types_edit(payment_type)
code = payment_type[:code]
@ -464,7 +555,7 @@ class Retailcrm
##
# === Get product statuses
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def product_statuses
url = "#{@url}reference/product-statuses"
@ -473,7 +564,7 @@ class Retailcrm
##
# === Edit product status
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def product_statuses_edit(product_status)
code = product_status[:code]
@ -483,7 +574,7 @@ class Retailcrm
end
# Get sites list
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def sites
url = "#{@url}reference/sites"
@ -492,7 +583,7 @@ class Retailcrm
##
# === Edit site
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def sites_edit(site)
code = site[:code]
@ -503,7 +594,7 @@ class Retailcrm
##
# === Get status groups
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def status_groups
url = "#{@url}reference/status-groups"
@ -511,7 +602,7 @@ class Retailcrm
end
# Get statuses
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def statuses
url = "#{@url}reference/statuses"
@ -520,7 +611,7 @@ class Retailcrm
##
# === Edit status
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def statuses_edit(status)
code = status[:code]
@ -531,7 +622,7 @@ class Retailcrm
##
# === Get stores
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def stores
url = "#{@url}reference/stores"
@ -540,7 +631,7 @@ class Retailcrm
##
# === Edit store
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def stores_edit(store)
code = store[:code]
@ -549,10 +640,17 @@ class Retailcrm
make_request(url, 'post')
end
# Get countries list
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
def countries
url = "#{@url}reference/countries"
make_request(url)
end
##
# === Statistic update
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
# http://www.retailcrm.ru/docs/Developers/ApiVersion3
#
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.1'
s.date = '2015-04-15'
s.version = '1.1.2'
s.date = '2016-03-07'
s.summary = 'RetailCRM Rest API client'
s.description = 'Library for interact with RetailCRM API'
s.authors = ['Alex Lushpai']