mirror of
https://github.com/retailcrm/api-client-ruby.git
synced 2025-04-05 06:03:35 +03:00
Compare commits
13 commits
Author | SHA1 | Date | |
---|---|---|---|
|
979d06550a | ||
|
30999696f9 | ||
|
978f2f0509 | ||
|
4358a6e815 | ||
|
2ffec96adb | ||
|
06c5ce871d | ||
|
0763201af2 | ||
|
c9cc8a76de | ||
|
1f2cd4128e | ||
|
d21553e681 | ||
|
9b43a56c97 | ||
|
a0ebbe5b38 | ||
|
c358e13330 |
13 changed files with 573 additions and 277 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
*.gem
|
||||
/test/bootstrap.rb
|
||||
spec/bootstrap.rb
|
||||
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Alex Lushpai
|
||||
Copyright (c) 2013-2020 RetailDriver LLC
|
||||
|
||||
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
|
||||
|
|
27
README.md
27
README.md
|
@ -1,35 +1,36 @@
|
|||
[](http://badge.fury.io/rb/retailcrm)
|
||||
[](https://rubygems.org/gems/retailcrm)
|
||||
[](http://www.rubydoc.info/gems/retailcrm)
|
||||
|
||||
Ruby-клиент для retailCRM API
|
||||
=============================
|
||||
RetailCRM API ruby client
|
||||
=========================
|
||||
|
||||
|
||||
### Установка
|
||||
### Install
|
||||
|
||||
```
|
||||
gem install retailcrm
|
||||
```
|
||||
|
||||
### Примеры использования
|
||||
### Examples
|
||||
|
||||
#### Получение информации о заказе
|
||||
#### Get order
|
||||
|
||||
```ruby
|
||||
require 'retailcrm'
|
||||
|
||||
api = Retailcrm.new('https://yourcrmname.retailcrm.ru', 'yourApiKeyHere')
|
||||
api = Retailcrm.new('https://demo.retailcrm.pro', 'yourApiKeyHere')
|
||||
|
||||
response = api.orders_get(345, 'id').response
|
||||
order = response[:order]
|
||||
|
||||
```
|
||||
|
||||
#### Создание заказа
|
||||
#### Create order
|
||||
|
||||
```ruby
|
||||
require 'retailcrm'
|
||||
|
||||
api = Retailcrm.new('https://yourcrmname.intarocrm.ru', 'yourApiKeyHere')
|
||||
api = Retailcrm.new('https://demo.retailcrm.pro', 'yourApiKeyHere')
|
||||
|
||||
order = {
|
||||
:externalId => 171,
|
||||
|
@ -68,11 +69,3 @@ 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
|
6
Rakefile
6
Rakefile
|
@ -3,10 +3,10 @@
|
|||
require 'rake/testtask'
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
t.libs.push "lib"
|
||||
t.test_files = FileList['test/test_*.rb', 'test/spec_*.rb']
|
||||
t.libs.push 'lib'
|
||||
t.test_files = FileList['spec/spec_*.rb']
|
||||
t.verbose = true
|
||||
end
|
||||
|
||||
desc "Run tests"
|
||||
desc 'Run tests'
|
||||
task :default => :test
|
||||
|
|
333
lib/retailcrm.rb
333
lib/retailcrm.rb
|
@ -1,11 +1,16 @@
|
|||
# encoding: utf-8
|
||||
|
||||
# noinspection RubyResolve
|
||||
require 'net/http'
|
||||
# noinspection RubyResolve
|
||||
require 'net/https'
|
||||
# noinspection RubyResolve
|
||||
require 'uri'
|
||||
# noinspection RubyResolve
|
||||
require 'json'
|
||||
|
||||
# RetailCRM API Client
|
||||
# noinspection ALL
|
||||
class Retailcrm
|
||||
|
||||
def initialize(url, key)
|
||||
|
@ -19,7 +24,6 @@ class Retailcrm
|
|||
|
||||
##
|
||||
# === Get orders by filter
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
# Example:
|
||||
# >> Retailcrm.orders({:email => 'test@example.com', :status => 'new'}, 50, 2)
|
||||
|
@ -33,13 +37,12 @@ class Retailcrm
|
|||
url = "#{@url}orders"
|
||||
@params[:limit] = limit
|
||||
@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)
|
||||
end
|
||||
|
||||
##
|
||||
# === Get orders statuses
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
# Example:
|
||||
# >> Retailcrm.orders_statuses([26120, 19282])
|
||||
|
@ -48,14 +51,13 @@ class Retailcrm
|
|||
# Arguments:
|
||||
# ids (Array)
|
||||
def orders_statuses(ids = [])
|
||||
@ids = ids.map { |x| "ids[]=#{x}" }.join("&")
|
||||
@ids = ids.map { |x| "ids[]=#{x}" }.join('&')
|
||||
url = "#{@url}orders/statuses"
|
||||
make_request(url)
|
||||
end
|
||||
|
||||
##
|
||||
# === Get orders by id (or externalId)
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
# Example:
|
||||
# >> Retailcrm.orders_get(345, 'id')
|
||||
|
@ -64,17 +66,18 @@ class Retailcrm
|
|||
# Arguments:
|
||||
# id (Integer)
|
||||
# by (String)
|
||||
def orders_get(id, by = 'externalId')
|
||||
# site (String)
|
||||
def orders_get(id, by = 'externalId', site = nil)
|
||||
url = "#{@url}orders/#{id}"
|
||||
if by != 'externalId'
|
||||
@params[:by] = by
|
||||
@params[:site] = site
|
||||
end
|
||||
make_request(url)
|
||||
end
|
||||
|
||||
##
|
||||
# === Create order
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
# Example:
|
||||
# >> Retailcrm.orders_create(order)
|
||||
|
@ -82,15 +85,16 @@ class Retailcrm
|
|||
#
|
||||
# Arguments:
|
||||
# order (Array)
|
||||
def orders_create(order)
|
||||
# site (String)
|
||||
def orders_create(order, site = nil)
|
||||
url = "#{@url}orders/create"
|
||||
@params[:order] = order.to_json
|
||||
@params[:site] = site
|
||||
make_request(url, 'post')
|
||||
end
|
||||
|
||||
##
|
||||
# === Edit order
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
# Example:
|
||||
# >> Retailcrm.orders_edit(order)
|
||||
|
@ -98,16 +102,17 @@ class Retailcrm
|
|||
#
|
||||
# Arguments:
|
||||
# order (Array)
|
||||
def orders_edit(order)
|
||||
# site (String)
|
||||
def orders_edit(order, site = nil)
|
||||
id = order[:externalId]
|
||||
url = "#{@url}orders/#{id}/edit"
|
||||
@params[:order] = order.to_json
|
||||
@params[:site] = site
|
||||
make_request(url, 'post')
|
||||
end
|
||||
|
||||
##
|
||||
# === Upload orders
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
# Example:
|
||||
# >> Retailcrm.orders_upload(orders)
|
||||
|
@ -115,15 +120,16 @@ class Retailcrm
|
|||
#
|
||||
# Arguments:
|
||||
# orders (Array)
|
||||
def orders_upload(orders)
|
||||
# site (String)
|
||||
def orders_upload(orders, site = nil)
|
||||
url = "#{@url}orders/upload"
|
||||
@params[:orders] = orders.to_json
|
||||
@params[:site] = site
|
||||
make_request(url, 'post')
|
||||
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}])
|
||||
|
@ -139,7 +145,6 @@ 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')
|
||||
|
@ -161,29 +166,8 @@ 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)
|
||||
|
@ -197,13 +181,12 @@ class Retailcrm
|
|||
url = "#{@url}customers"
|
||||
@params[:limit] = limit
|
||||
@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)
|
||||
end
|
||||
|
||||
##
|
||||
# === Get customers by id (or externalId)
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
# Example:
|
||||
# >> Retailcrm.customers_get(345, 'id')
|
||||
|
@ -212,8 +195,10 @@ class Retailcrm
|
|||
# Arguments:
|
||||
# id (Integer)
|
||||
# by (String)
|
||||
def customers_get(id, by = 'externalId')
|
||||
# site (String)
|
||||
def customers_get(id, by = 'externalId', site = nil)
|
||||
url = "#{@url}customers/#{id}"
|
||||
@params[:site] = site
|
||||
if by != 'externalId'
|
||||
@params[:by] = by
|
||||
end
|
||||
|
@ -222,7 +207,6 @@ class Retailcrm
|
|||
|
||||
##
|
||||
# === Create customer
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
# Example:
|
||||
# >> Retailcrm.customer_create(customer)
|
||||
|
@ -230,15 +214,16 @@ class Retailcrm
|
|||
#
|
||||
# Arguments:
|
||||
# customer (Array)
|
||||
def customers_create(customer)
|
||||
# site (String)
|
||||
def customers_create(customer, site = nil)
|
||||
url = "#{@url}customers/create"
|
||||
@params[:customer] = customer.to_json
|
||||
@params[:site] = site
|
||||
make_request(url, 'post')
|
||||
end
|
||||
|
||||
##
|
||||
# === Edit customer
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
# Example:
|
||||
# >> Retailcrm.customers_edit(customer)
|
||||
|
@ -246,16 +231,17 @@ class Retailcrm
|
|||
#
|
||||
# Arguments:
|
||||
# customer (Array)
|
||||
def customers_edit(customer)
|
||||
# site (String)
|
||||
def customers_edit(customer, site = nil)
|
||||
id = customer[:externalId]
|
||||
url = "#{@url}customers/#{id}/edit"
|
||||
@params[:customer] = customer.to_json
|
||||
@params[:site] = site
|
||||
make_request(url, 'post')
|
||||
end
|
||||
|
||||
##
|
||||
# === Upload customers
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
# Example:
|
||||
# >> Retailcrm.customers_upload(customers)
|
||||
|
@ -263,15 +249,16 @@ class Retailcrm
|
|||
#
|
||||
# Arguments:
|
||||
# customers (Array)
|
||||
def customers_upload(customers)
|
||||
# site (String)
|
||||
def customers_upload(customers, site = nil)
|
||||
url = "#{@url}customers/upload"
|
||||
@params[:customers] = customers.to_json
|
||||
@params[:site] = site
|
||||
make_request(url, 'post')
|
||||
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}])
|
||||
|
@ -287,7 +274,6 @@ class Retailcrm
|
|||
|
||||
##
|
||||
# === Get purchace prices & stock balance
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
# Example:
|
||||
# >> Retailcrm.store_inventories({:productExternalId => 26120, :details => 1}, 50, 2)
|
||||
|
@ -301,82 +287,275 @@ class Retailcrm
|
|||
url = "#{@url}store/inventories"
|
||||
@params[:limit] = limit
|
||||
@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)
|
||||
end
|
||||
|
||||
##
|
||||
# === Set purchace prices & stock balance
|
||||
#
|
||||
# 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
|
||||
|
||||
##
|
||||
# === 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"
|
||||
make_request(url)
|
||||
end
|
||||
|
||||
##
|
||||
# === Edit delivery service
|
||||
#
|
||||
def delivery_services_edit(delivery_service)
|
||||
code = delivery_service[:code]
|
||||
url = "#{@url}reference/delivery-services/#{code}/edit"
|
||||
@params[:deliveryService] = delivery_service.to_json
|
||||
make_request(url, 'post')
|
||||
end
|
||||
|
||||
# Get delivery types
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
def delivery_types
|
||||
url = "#{@url}reference/delivery-types"
|
||||
make_request(url)
|
||||
end
|
||||
|
||||
##
|
||||
# === Edit delivery type
|
||||
#
|
||||
def delivery_types_edit(delivery_type)
|
||||
code = delivery_type[:code]
|
||||
url = "#{@url}reference/delivery-types/#{code}/edit"
|
||||
@params[:deliveryType] = delivery_type.to_json
|
||||
make_request(url, 'post')
|
||||
end
|
||||
|
||||
##
|
||||
# === Get order methods
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
def order_methods
|
||||
url = "#{@url}reference/order-methods"
|
||||
make_request(url)
|
||||
end
|
||||
|
||||
##
|
||||
# === Edit order method
|
||||
#
|
||||
def order_methods_edit(order_method)
|
||||
code = order_method[:code]
|
||||
url = "#{@url}reference/order-methods/#{code}/edit"
|
||||
@params[:orderMethod] = order_method.to_json
|
||||
make_request(url, 'post')
|
||||
end
|
||||
|
||||
##
|
||||
# === Get order types
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
def order_types
|
||||
url = "#{@url}reference/order-types"
|
||||
make_request(url)
|
||||
end
|
||||
|
||||
##
|
||||
# === Edit order type
|
||||
#
|
||||
def order_types_edit(order_type)
|
||||
code = order_type[:code]
|
||||
url = "#{@url}reference/order-types/#{code}/edit"
|
||||
@params[:orderType] = order_type.to_json
|
||||
make_request(url, 'post')
|
||||
end
|
||||
|
||||
# Get payment statuses
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
def payment_statuses
|
||||
url = "#{@url}reference/payment-statuses"
|
||||
make_request(url)
|
||||
end
|
||||
|
||||
##
|
||||
# === Edit payment status
|
||||
#
|
||||
def payment_statuses_edit(payment_status)
|
||||
code = payment_status[:code]
|
||||
url = "#{@url}reference/payment-statuses/#{code}/edit"
|
||||
@params[:paymentStatus] = payment_status.to_json
|
||||
make_request(url, 'post')
|
||||
end
|
||||
|
||||
##
|
||||
# === Get payment types
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
def payment_types
|
||||
url = "#{@url}reference/payment-types"
|
||||
make_request(url)
|
||||
end
|
||||
|
||||
##
|
||||
# === Edit payment type
|
||||
#
|
||||
def payment_types_edit(payment_type)
|
||||
code = payment_type[:code]
|
||||
url = "#{@url}reference/payment-types/#{code}/edit"
|
||||
@params[:paymentType] = payment_type.to_json
|
||||
make_request(url, 'post')
|
||||
end
|
||||
|
||||
##
|
||||
# === Get product statuses
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
def product_statuses
|
||||
url = "#{@url}reference/product-statuses"
|
||||
make_request(url)
|
||||
end
|
||||
|
||||
##
|
||||
# === Edit product status
|
||||
#
|
||||
def product_statuses_edit(product_status)
|
||||
code = product_status[:code]
|
||||
url = "#{@url}reference/product-statuses/#{code}/edit"
|
||||
@params[:productStatus] = product_status.to_json
|
||||
make_request(url, 'post')
|
||||
end
|
||||
|
||||
# Get sites list
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
def sites
|
||||
url = "#{@url}reference/sites"
|
||||
make_request(url)
|
||||
end
|
||||
|
||||
##
|
||||
# === Edit site
|
||||
#
|
||||
def sites_edit(site)
|
||||
code = site[:code]
|
||||
url = "#{@url}reference/sites/#{code}/edit"
|
||||
@params[:site] = site.to_json
|
||||
make_request(url, 'post')
|
||||
end
|
||||
|
||||
##
|
||||
# === Get status groups
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
def status_groups
|
||||
url = "#{@url}reference/status-groups"
|
||||
|
@ -384,26 +563,49 @@ class Retailcrm
|
|||
end
|
||||
|
||||
# Get statuses
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
def statuses
|
||||
url = "#{@url}reference/statuses"
|
||||
make_request(url)
|
||||
end
|
||||
|
||||
##
|
||||
# === Edit status
|
||||
#
|
||||
def statuses_edit(status)
|
||||
code = status[:code]
|
||||
url = "#{@url}reference/statuses/#{code}/edit"
|
||||
@params[:status] = status.to_json
|
||||
make_request(url, 'post')
|
||||
end
|
||||
|
||||
##
|
||||
# === Get stores
|
||||
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
|
||||
#
|
||||
def stores
|
||||
url = "#{@url}reference/stores"
|
||||
make_request(url)
|
||||
end
|
||||
|
||||
##
|
||||
# === Edit store
|
||||
#
|
||||
def stores_edit(store)
|
||||
code = store[:code]
|
||||
url = "#{@url}reference/stores/#{code}/edit"
|
||||
@params[:store] = store.to_json
|
||||
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"
|
||||
|
@ -424,17 +626,14 @@ class Retailcrm
|
|||
elsif method == 'get'
|
||||
request = Net::HTTP::Get.new(uri.path)
|
||||
request.set_form_data(@params)
|
||||
data = "#{request.body}"
|
||||
|
||||
if @filter.nil?
|
||||
data = "#{request.body}"
|
||||
else
|
||||
data = "#{request.body}&#{@filter}"
|
||||
unless @filter.nil?
|
||||
data = data + "&#{@filter}"
|
||||
end
|
||||
|
||||
if @ids.nil?
|
||||
data = "#{request.body}"
|
||||
else
|
||||
data = "#{request.body}&#{@ids}"
|
||||
unless @ids.nil?
|
||||
data = data + "&#{@ids}"
|
||||
end
|
||||
|
||||
request = Net::HTTP::Get.new("#{uri.path}?#{data}")
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Gem::Specification.new do |s|
|
||||
s.name = 'retailcrm'
|
||||
s.version = '1.0.1'
|
||||
s.date = '2015-04-14'
|
||||
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']
|
||||
|
|
204
spec/bootstrap-dist.rb
Normal file
204
spec/bootstrap-dist.rb
Normal file
|
@ -0,0 +1,204 @@
|
|||
# encoding: utf-8
|
||||
|
||||
class Bootstrap
|
||||
|
||||
attr_reader :api_key, :api_url, :order, :customer, :refs_get, :refs_edit
|
||||
|
||||
def initialize
|
||||
@api_url = 'https://demo.retailcrm.pro'
|
||||
@api_key = 'YourAPIKeyRightHere'
|
||||
|
||||
id = Time.now.to_i
|
||||
time = Time.now.strftime('%F %T')
|
||||
|
||||
@customer = {
|
||||
:externalId => id,
|
||||
:createdAt => time,
|
||||
:firstName => 'John',
|
||||
:lastName => 'Doe',
|
||||
:email => 'john@example.org',
|
||||
:phones => [{:number => '+79099099090'}]
|
||||
}
|
||||
|
||||
@order = {
|
||||
:create => {
|
||||
:externalId => id,
|
||||
:number => "#{id}",
|
||||
:orderType => 'eshop-individual',
|
||||
:orderMethod => 'phone',
|
||||
:createdAt => time,
|
||||
:discountPercent => 10,
|
||||
:firstName => 'API',
|
||||
:lastName => 'Test',
|
||||
:customer => {
|
||||
:firstName => 'John',
|
||||
:lastName => 'Doe',
|
||||
:phones => [{:number => '+79099099090'}],
|
||||
},
|
||||
:delivery => {
|
||||
:code => 'courier',
|
||||
:cost => 500
|
||||
},
|
||||
:status => 'new',
|
||||
:items => [
|
||||
{
|
||||
:productName => 'First',
|
||||
:initialPrice => 500,
|
||||
:quantity => 2
|
||||
},
|
||||
{
|
||||
:productName => 'Second',
|
||||
:initialPrice => 1300,
|
||||
:quantity => 1
|
||||
}
|
||||
]
|
||||
},
|
||||
:edit => {
|
||||
:externalId => 1428877985,
|
||||
:email => 'spec@example.org',
|
||||
:phone => '+79999999999',
|
||||
:status => 'cancel-other',
|
||||
:delivery => {
|
||||
:code => 'ems',
|
||||
:cost => 300,
|
||||
}
|
||||
},
|
||||
:mass => [
|
||||
{
|
||||
:externalId => id,
|
||||
:number => "#{id}",
|
||||
:orderType => 'eshop-individual',
|
||||
:orderMethod => 'phone',
|
||||
:createdAt => time,
|
||||
:discountPercent => 10,
|
||||
:firstName => 'API',
|
||||
:lastName => 'Test',
|
||||
:customer => {
|
||||
:firstName => 'John',
|
||||
:lastName => 'Doe',
|
||||
:phones => [{:number => '+79099099090'}],
|
||||
},
|
||||
:delivery => {
|
||||
:code => 'courier',
|
||||
:cost => 500
|
||||
},
|
||||
:status => 'new',
|
||||
:items => [
|
||||
{
|
||||
:productName => 'First',
|
||||
:initialPrice => 500,
|
||||
:quantity => 2
|
||||
},
|
||||
{
|
||||
:productName => 'Second',
|
||||
:initialPrice => 1300,
|
||||
:quantity => 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
:externalId => id+1,
|
||||
:number => "#{id+1}",
|
||||
:orderType => 'eshop-individual',
|
||||
:createdAt => time,
|
||||
:discount => 200,
|
||||
:firstName => 'API2',
|
||||
:lastName => 'Test2',
|
||||
:customer => {
|
||||
:firstName => 'Joe',
|
||||
:lastName => 'Doe',
|
||||
:phones => [{:number => '+79099099000'}],
|
||||
},
|
||||
:delivery => {
|
||||
:code => 'ems',
|
||||
:cost => 500
|
||||
},
|
||||
:status => 'availability-confirmed',
|
||||
:items => [
|
||||
{
|
||||
:productName => 'Third',
|
||||
:initialPrice => 500,
|
||||
:quantity => 2
|
||||
},
|
||||
{
|
||||
:productName => 'Extra',
|
||||
:initialPrice => 1300,
|
||||
:quantity => 1
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@refs_get = %w(
|
||||
delivery_services
|
||||
delivery_types
|
||||
order_methods
|
||||
order_types
|
||||
payment_statuses
|
||||
payment_types
|
||||
product_statuses
|
||||
status_groups
|
||||
statuses
|
||||
sites
|
||||
stores
|
||||
)
|
||||
|
||||
@refs_edit = {
|
||||
delivery_types_edit: {
|
||||
name: 'Rake delivery type',
|
||||
code: 'rake-delivery-type',
|
||||
defaultCost: 300,
|
||||
defaultNetCost: 0,
|
||||
description: 'Test delivery type through Rake test task'
|
||||
},
|
||||
delivery_services_edit: {
|
||||
name: 'Rake delivery service',
|
||||
code: 'rake-delivery-service',
|
||||
deliveryType: 'rake-delivery-type'
|
||||
},
|
||||
order_methods_edit: {
|
||||
name: 'Rake order method',
|
||||
code: 'rake-order-method',
|
||||
},
|
||||
order_types_edit: {
|
||||
name: 'Rake order type',
|
||||
code: 'rake-order-type',
|
||||
},
|
||||
payment_statuses_edit: {
|
||||
name: 'Rake payment status',
|
||||
code: 'rake-payment-status',
|
||||
description: 'Test payment status through Rake test task'
|
||||
},
|
||||
payment_types_edit: {
|
||||
name: 'Rake payment type',
|
||||
code: 'rake-payment-type',
|
||||
description: 'Test payment type through Rake test task'
|
||||
},
|
||||
product_statuses_edit: {
|
||||
ordering: 65,
|
||||
name: 'Rake product status',
|
||||
code: 'rake-payment-type',
|
||||
cancelStatus: true,
|
||||
orderStatusByProductStatus: 'cancel-other',
|
||||
},
|
||||
statuses_edit: {
|
||||
name: 'Rake status',
|
||||
code: 'rake-status',
|
||||
group: 'new',
|
||||
},
|
||||
sites_edit: {
|
||||
name: 'Rake Shop',
|
||||
url: 'http://example.org',
|
||||
code: 'api-client-all',
|
||||
loadFromYml: false,
|
||||
},
|
||||
stores_edit: {
|
||||
type: 'store-type-online',
|
||||
code: 'rake-store',
|
||||
name: 'Rake Store'
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
30
spec/spec_customers.rb
Normal file
30
spec/spec_customers.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
# encoding: utf-8
|
||||
|
||||
require 'minitest/autorun'
|
||||
require 'minitest/spec'
|
||||
require 'minitest-spec-context'
|
||||
require 'pp'
|
||||
|
||||
require_relative '../lib/retailcrm'
|
||||
require_relative './bootstrap'
|
||||
|
||||
describe Retailcrm do
|
||||
|
||||
before do
|
||||
@bootstrap = Bootstrap.new
|
||||
@api = Retailcrm.new(@bootstrap.api_url, @bootstrap.api_key)
|
||||
@customer = @bootstrap.customer
|
||||
end
|
||||
|
||||
describe '#customers' do
|
||||
it 'responds with 200' do
|
||||
res = @api.customers({:email => 'test@example.com'}, 50, 1)
|
||||
res.status.to_i.must_equal 200
|
||||
res.response['customers'].must_be_instance_of Array
|
||||
res.response['customers'].each do |x|
|
||||
x['email'].must_equal 'test@example.com'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
39
spec/spec_references.rb
Normal file
39
spec/spec_references.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
# encoding: utf-8
|
||||
|
||||
require 'minitest/autorun'
|
||||
require 'minitest/spec'
|
||||
require 'minitest-spec-context'
|
||||
require 'pp'
|
||||
|
||||
require_relative '../lib/retailcrm'
|
||||
require_relative './bootstrap'
|
||||
|
||||
describe Retailcrm do
|
||||
|
||||
before do
|
||||
@bootstrap = Bootstrap.new
|
||||
@api = Retailcrm.new(@bootstrap.api_url, @bootstrap.api_key)
|
||||
@ref = @bootstrap.refs_edit
|
||||
end
|
||||
|
||||
describe '#reference get' do
|
||||
it 'responds with 200' do
|
||||
@bootstrap.refs_get.each { |method|
|
||||
res = @api.public_send(method)
|
||||
res.status.to_i.must_equal 200
|
||||
sleep 0.3
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe '#reference edit' do
|
||||
it 'responds with 200 or 201' do
|
||||
@bootstrap.refs_edit.each do |method, data|
|
||||
res = @api.public_send(method, data)
|
||||
res.status.to_i.must_be :<, 202
|
||||
sleep 0.3
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
16
spec/spec_retailcrm.rb
Normal file
16
spec/spec_retailcrm.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# encoding: utf-8
|
||||
|
||||
require 'minitest/autorun'
|
||||
require 'minitest/spec'
|
||||
|
||||
require_relative '../lib/retailcrm'
|
||||
require_relative './bootstrap'
|
||||
|
||||
describe Retailcrm do
|
||||
|
||||
before do
|
||||
@bootstrap = Bootstrap.new
|
||||
@api = Retailcrm.new(@bootstrap.api_url, @bootstrap.api_key)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,133 +0,0 @@
|
|||
# encoding: utf-8
|
||||
|
||||
class Bootstrap
|
||||
|
||||
attr_reader :api_key, :api_url, :order, :order_edit, :orders, :customer
|
||||
|
||||
def initialize
|
||||
@api_url = 'https://demo.retailcrm.ru'
|
||||
@api_key = ''
|
||||
|
||||
id = Time.now.to_i
|
||||
time = Time.now.strftime('%F %T')
|
||||
|
||||
@customer = {
|
||||
:externalId => id,
|
||||
:createdAt => time,
|
||||
:firstName => 'API',
|
||||
:lastName => 'Test',
|
||||
:email => 'pupkin@example.org',
|
||||
:phones => [{:number => '+79099099090'}]
|
||||
}
|
||||
|
||||
@order = {
|
||||
: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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@order_edit = {
|
||||
:externalId => 1428877985,
|
||||
:email => 'test@example.org',
|
||||
:phone => '+79999999999',
|
||||
: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
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
# encoding: utf-8
|
||||
|
||||
require 'minitest/autorun'
|
||||
require 'minitest/spec'
|
||||
|
||||
require_relative '../lib/retailcrm'
|
||||
require_relative './bootstrap'
|
||||
|
||||
describe Retailcrm do
|
||||
before do
|
||||
@boot = Bootstrap.new
|
||||
@api = Retailcrm.new(@boot.api_url, @boot.api_key)
|
||||
end
|
||||
|
||||
describe '#delivery services status code' do
|
||||
it 'checks successful status code of delivery services' do
|
||||
@api.delivery_services.status.to_i.must_be :<, 400
|
||||
end
|
||||
end
|
||||
|
||||
describe '#delivery types status code' do
|
||||
it 'checks successful status code of delivery types' do
|
||||
@api.delivery_types.status.to_i.must_be :<, 400
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,27 +0,0 @@
|
|||
# encoding: utf-8
|
||||
|
||||
require 'minitest/autorun'
|
||||
require_relative '../lib/retailcrm'
|
||||
require_relative './bootstrap'
|
||||
|
||||
class RetailcrmTest < Minitest::Test
|
||||
def setup
|
||||
@boot = Bootstrap.new
|
||||
@api = Retailcrm.new(@boot.api_url, @boot.api_key)
|
||||
end
|
||||
|
||||
def test_delivery_services
|
||||
assert_equal true,
|
||||
@api.delivery_services.is_successfull?
|
||||
end
|
||||
|
||||
def test_delivery_types
|
||||
assert_equal true,
|
||||
@api.delivery_types.is_successfull?
|
||||
end
|
||||
|
||||
def test_order_methods
|
||||
assert_equal true,
|
||||
@api.order_methods.is_successfull?
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue