Compare commits

...

11 commits

Author SHA1 Message Date
Alex Lushpai
979d06550a
Update product name, cleanup annotations 2020-12-15 13:30:40 +03:00
Alex Lushpai
30999696f9
Update README.md 2020-02-19 13:50:59 +03:00
Alex Lushpai
978f2f0509 Update README.md 2016-03-14 23:07:43 +03:00
Alex Lushpai
4358a6e815 Merge pull request #3 from gwinn/master
Update client methods & docs
2016-03-08 01:28:47 +03:00
Alex Lushpai
2ffec96adb fix typos 2016-03-08 01:26:58 +03:00
Alex Lushpai
06c5ce871d gemspec 2016-03-08 01:25:01 +03:00
Alex Lushpai
0763201af2 update client methods & docs 2016-03-08 01:23:25 +03:00
Alex Lushpai
c9cc8a76de Merge pull request #2 from gwinn/master
Исправления для filters и методов редактирования справочников
2015-07-16 18:05:55 +03:00
Alex Lushpai
1f2cd4128e enable specs for refs 2015-07-16 18:03:57 +03:00
Alex Lushpai
d21553e681 fix references edit methods, fix make request to proper collect of ids & filters, referenses tests added 2015-07-16 18:01:35 +03:00
Alex Lushpai
9b43a56c97 Update README.md 2015-04-27 14:24:24 +03:00
13 changed files with 443 additions and 281 deletions

3
.gitignore vendored
View file

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

View file

@ -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

View file

@ -1,35 +1,36 @@
[![Gem Version](https://badge.fury.io/rb/retailcrm.svg)](http://badge.fury.io/rb/retailcrm)
[![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)
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

View file

@ -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

View file

@ -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')
@ -76,7 +78,6 @@ class Retailcrm
##
# === Create order
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.orders_create(order)
@ -94,7 +95,6 @@ class Retailcrm
##
# === Edit order
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.orders_edit(order)
@ -113,7 +113,6 @@ class Retailcrm
##
# === Upload orders
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.orders_upload(orders)
@ -131,7 +130,6 @@ 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}])
@ -147,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')
@ -169,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)
@ -205,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')
@ -232,7 +207,6 @@ class Retailcrm
##
# === Create customer
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.customer_create(customer)
@ -250,7 +224,6 @@ class Retailcrm
##
# === Edit customer
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.customers_edit(customer)
@ -269,7 +242,6 @@ class Retailcrm
##
# === Upload customers
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
# Example:
# >> Retailcrm.customers_upload(customers)
@ -287,7 +259,6 @@ 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}])
@ -303,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)
@ -317,13 +287,12 @@ 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
# 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')
@ -339,9 +308,113 @@ 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"
@ -350,16 +423,15 @@ class Retailcrm
##
# === Edit delivery service
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
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"
@ -368,17 +440,16 @@ class Retailcrm
##
# === Edit delivery type
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
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"
@ -387,17 +458,16 @@ class Retailcrm
##
# === Edit order method
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
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"
@ -406,16 +476,15 @@ class Retailcrm
##
# === Edit order type
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
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"
@ -424,17 +493,16 @@ class Retailcrm
##
# === Edit payment status
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
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"
@ -443,17 +511,16 @@ class Retailcrm
##
# === Edit payment type
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def payment_types_edit(payment_type)
code = payment_type[:code]
url = "#{@url}reference/payment-type/#{code}/edit"
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"
@ -462,16 +529,15 @@ class Retailcrm
##
# === Edit product status
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
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"
@ -480,17 +546,16 @@ class Retailcrm
##
# === Edit site
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
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"
@ -498,7 +563,6 @@ class Retailcrm
end
# Get statuses
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
def statuses
url = "#{@url}reference/statuses"
@ -507,17 +571,16 @@ class Retailcrm
##
# === Edit status
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
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"
@ -526,18 +589,23 @@ class Retailcrm
##
# === Edit store
# http://www.retailcrm.ru/docs/Разработчики/СправочникМетодовAPIV3
#
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"
@ -558,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}")

View file

@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'retailcrm'
s.version = '1.1.0'
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']

204
spec/bootstrap-dist.rb Normal file
View 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
View 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
View 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
View 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

View file

@ -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

View file

@ -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

View file

@ -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