Compare commits

..

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

13 changed files with 277 additions and 573 deletions

3
.gitignore vendored
View file

@ -1,3 +1,2 @@
*.gem
spec/bootstrap.rb
/test/bootstrap.rb

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.intarocrm.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

@ -3,10 +3,10 @@
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs.push 'lib'
t.test_files = FileList['spec/spec_*.rb']
t.libs.push "lib"
t.test_files = FileList['test/test_*.rb', 'test/spec_*.rb']
t.verbose = true
end
desc 'Run tests'
desc "Run tests"
task :default => :test

View file

@ -1,16 +1,11 @@
# 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)
@ -24,6 +19,7 @@ class Retailcrm
##
# === Get orders by filter
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.orders({:email => 'test@example.com', :status => 'new'}, 50, 2)
@ -37,12 +33,13 @@ 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])
@ -51,13 +48,14 @@ 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')
@ -66,18 +64,17 @@ class Retailcrm
# Arguments:
# id (Integer)
# by (String)
# site (String)
def orders_get(id, by = 'externalId', site = nil)
def orders_get(id, by = 'externalId')
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)
@ -85,16 +82,15 @@ class Retailcrm
#
# Arguments:
# order (Array)
# site (String)
def orders_create(order, site = nil)
def orders_create(order)
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)
@ -102,17 +98,16 @@ class Retailcrm
#
# Arguments:
# order (Array)
# site (String)
def orders_edit(order, site = nil)
def orders_edit(order)
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)
@ -120,16 +115,15 @@ class Retailcrm
#
# Arguments:
# orders (Array)
# site (String)
def orders_upload(orders, site = nil)
def orders_upload(orders)
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}])
@ -145,6 +139,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 +161,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)
@ -181,12 +197,13 @@ 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')
@ -195,10 +212,8 @@ class Retailcrm
# Arguments:
# id (Integer)
# by (String)
# site (String)
def customers_get(id, by = 'externalId', site = nil)
def customers_get(id, by = 'externalId')
url = "#{@url}customers/#{id}"
@params[:site] = site
if by != 'externalId'
@params[:by] = by
end
@ -207,6 +222,7 @@ class Retailcrm
##
# === Create customer
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.customer_create(customer)
@ -214,16 +230,15 @@ class Retailcrm
#
# Arguments:
# customer (Array)
# site (String)
def customers_create(customer, site = nil)
def customers_create(customer)
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)
@ -231,17 +246,16 @@ class Retailcrm
#
# Arguments:
# customer (Array)
# site (String)
def customers_edit(customer, site = nil)
def customers_edit(customer)
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)
@ -249,16 +263,15 @@ class Retailcrm
#
# Arguments:
# customers (Array)
# site (String)
def customers_upload(customers, site = nil)
def customers_upload(customers)
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}])
@ -274,6 +287,7 @@ class Retailcrm
##
# === Get purchace prices & stock balance
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.store_inventories({:productExternalId => 26120, :details => 1}, 50, 2)
@ -287,275 +301,82 @@ 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"
@ -563,49 +384,26 @@ 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"
@ -626,14 +424,17 @@ class Retailcrm
elsif method == 'get'
request = Net::HTTP::Get.new(uri.path)
request.set_form_data(@params)
data = "#{request.body}"
unless @filter.nil?
data = data + "&#{@filter}"
if @filter.nil?
data = "#{request.body}"
else
data = "#{request.body}&#{@filter}"
end
unless @ids.nil?
data = data + "&#{@ids}"
if @ids.nil?
data = "#{request.body}"
else
data = "#{request.body}&#{@ids}"
end
request = Net::HTTP::Get.new("#{uri.path}?#{data}")

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.0.1'
s.date = '2015-04-14'
s.summary = 'RetailCRM Rest API client'
s.description = 'Library for interact with RetailCRM API'
s.authors = ['Alex Lushpai']

View file

@ -1,204 +0,0 @@
# 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

View file

@ -1,30 +0,0 @@
# 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

View file

@ -1,39 +0,0 @@
# 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

View file

@ -1,16 +0,0 @@
# 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

133
test/bootstrap.rb.dist Normal file
View file

@ -0,0 +1,133 @@
# 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

26
test/spec_retailcrm.rb Normal file
View file

@ -0,0 +1,26 @@
# 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

27
test/test_retailcrm.rb Normal file
View file

@ -0,0 +1,27 @@
# 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