moysklad 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/rspec.yml +29 -0
- data/.gitignore +1 -0
- data/README.md +14 -3
- data/lib/moysklad/client/errors.rb +60 -30
- data/lib/moysklad/client.rb +39 -11
- data/lib/moysklad/entities/assortment.rb +4 -0
- data/lib/moysklad/entities/attribute.rb +111 -37
- data/lib/moysklad/entities/attribute_metadata.rb +7 -31
- data/lib/moysklad/entities/attribute_value.rb +18 -0
- data/lib/moysklad/entities/base.rb +23 -8
- data/lib/moysklad/entities/bundle.rb +39 -0
- data/lib/moysklad/entities/characteristic.rb +4 -0
- data/lib/moysklad/entities/characteristic_metadata.rb +4 -0
- data/lib/moysklad/entities/collection.rb +27 -7
- data/lib/moysklad/entities/collection_meta.rb +11 -0
- data/lib/moysklad/entities/company_settings_metadata.rb +26 -0
- data/lib/moysklad/entities/consignment.rb +16 -17
- data/lib/moysklad/entities/context.rb +7 -0
- data/lib/moysklad/entities/counterparty.rb +20 -0
- data/lib/moysklad/entities/country.rb +2 -8
- data/lib/moysklad/entities/currency.rb +27 -0
- data/lib/moysklad/entities/custom_entity.rb +17 -10
- data/lib/moysklad/entities/customer_order.rb +109 -23
- data/lib/moysklad/entities/customer_order_position.rb +6 -18
- data/lib/moysklad/entities/employee.rb +5 -0
- data/lib/moysklad/entities/entity.rb +39 -0
- data/lib/moysklad/entities/group.rb +10 -0
- data/lib/moysklad/entities/image.rb +16 -0
- data/lib/moysklad/entities/meta.rb +12 -0
- data/lib/moysklad/entities/organization.rb +17 -0
- data/lib/moysklad/entities/owner.rb +4 -0
- data/lib/moysklad/entities/price.rb +4 -8
- data/lib/moysklad/entities/price_type.rb +0 -8
- data/lib/moysklad/entities/product.rb +47 -0
- data/lib/moysklad/entities/productfolder.rb +11 -0
- data/lib/moysklad/entities/rate.rb +6 -0
- data/lib/moysklad/entities/resource_metadata.rb +8 -0
- data/lib/moysklad/entities/service.rb +23 -0
- data/lib/moysklad/entities/shortcut.rb +9 -0
- data/lib/moysklad/entities/store.rb +9 -0
- data/lib/moysklad/entities/time.rb +13 -0
- data/lib/moysklad/entities/uom.rb +5 -0
- data/lib/moysklad/entities/variant.rb +47 -0
- data/lib/moysklad/entities.rb +42 -39
- data/lib/moysklad/error.rb +1 -0
- data/lib/moysklad/resources/assortments.rb +13 -0
- data/lib/moysklad/resources/base.rb +35 -46
- data/lib/moysklad/resources/custom_entities.rb +29 -0
- data/lib/moysklad/resources/custom_entity_metadata.rb +12 -8
- data/lib/moysklad/resources/embedded_entity_metadata.rb +2 -3
- data/lib/moysklad/resources/indexed.rb +21 -37
- data/lib/moysklad/resources/indexed_cache.rb +36 -0
- data/lib/moysklad/resources/load_all.rb +21 -0
- data/lib/moysklad/resources/positions.rb +15 -0
- data/lib/moysklad/resources/products.rb +10 -0
- data/lib/moysklad/resources/stock.rb +1 -1
- data/lib/moysklad/resources/subresource.rb +0 -1
- data/lib/moysklad/resources/where_filter.rb +0 -1
- data/lib/moysklad/resources.rb +26 -11
- data/lib/moysklad/universe.rb +16 -2
- data/lib/moysklad/version.rb +1 -1
- data/lib/moysklad.rb +12 -7
- data/moysklad.gemspec +5 -3
- data/scripts/rest.sh +5 -2
- data/spec/lib/moysklad/entities/customer_order_position_spec.rb +4 -17
- data/spec/lib/moysklad/entities/customer_order_spec.rb +8 -33
- data/spec/lib/moysklad/resources/base_spec.rb +0 -54
- data/spec/lib/moysklad/resources_spec.rb +0 -2
- data/spec/lib/moysklad/universe_spec.rb +0 -23
- data/spec/lib/moysklad_spec.rb +0 -1
- data/spec/spec_helper.rb +2 -1
- data/spec/support/resource.rb +1 -66
- data/test.rb +177 -0
- metadata +89 -172
- data/.travis.yml +0 -4
- data/lib/moysklad/entities/barcode.rb +0 -13
- data/lib/moysklad/entities/common.rb +0 -15
- data/lib/moysklad/entities/common_object.rb +0 -29
- data/lib/moysklad/entities/company.rb +0 -20
- data/lib/moysklad/entities/company_concern.rb +0 -20
- data/lib/moysklad/entities/contact.rb +0 -15
- data/lib/moysklad/entities/custom_entity_metadata.rb +0 -36
- data/lib/moysklad/entities/embedded_entity_metadata.rb +0 -18
- data/lib/moysklad/entities/error.rb +0 -13
- data/lib/moysklad/entities/feature.rb +0 -20
- data/lib/moysklad/entities/good.rb +0 -34
- data/lib/moysklad/entities/good_folder.rb +0 -9
- data/lib/moysklad/entities/good_ref.rb +0 -12
- data/lib/moysklad/entities/my_company.rb +0 -12
- data/lib/moysklad/entities/sale_price.rb +0 -18
- data/lib/moysklad/entities/sale_prices.rb +0 -10
- data/lib/moysklad/entities/slot.rb +0 -10
- data/lib/moysklad/entities/stock_to.rb +0 -33
- data/lib/moysklad/entities/warehouse.rb +0 -15
- data/lib/moysklad/entities/xml_fix.rb +0 -15
- data/spec/fixtures/302.raw +0 -15
- data/spec/fixtures/400.raw +0 -8
- data/spec/fixtures/401.html +0 -1
- data/spec/fixtures/401_2.html +0 -1
- data/spec/fixtures/405.raw +0 -9
- data/spec/fixtures/500.raw +0 -8
- data/spec/fixtures/502.raw +0 -8
- data/spec/fixtures/Consignment_list_0.raw +0 -14
- data/spec/fixtures/Consignment_list_1000.raw +0 -14
- data/spec/fixtures/Country_list.raw +0 -14
- data/spec/fixtures/CustomEntityMetadata_list.raw +0 -14
- data/spec/fixtures/CustomEntity_list.raw +0 -14
- data/spec/fixtures/CustomEntity_list_bad_chars.raw +0 -17
- data/spec/fixtures/EmbeddedEntityMetadata_list.raw +0 -15
- data/spec/fixtures/Feature_list.raw +0 -14
- data/spec/fixtures/Feature_list_1000.raw +0 -14
- data/spec/fixtures/Good_e932ebe1-2e22-11e4-9406-002590a28eca.raw +0 -12
- data/spec/fixtures/Good_eb77ad57-2e22-11e4-4030-002590a28eca.raw +0 -12
- data/spec/fixtures/Goods_list.raw +0 -14
- data/spec/fixtures/Metadata_list.raw +0 -14
- data/spec/fixtures/PriceType_list.raw +0 -14
- data/spec/fixtures/Stock.raw +0 -11
- data/spec/fixtures/Stock_showConsignments.raw +0 -11
- data/spec/fixtures/Uom_list.raw +0 -14
- data/spec/fixtures/Warehouse_list.raw +0 -14
- data/spec/fixtures/attribute_boolean.xml +0 -6
- data/spec/fixtures/attribute_dictionary.xml +0 -5
- data/spec/fixtures/attribute_double.xml +0 -6
- data/spec/fixtures/attribute_file.xml +0 -12
- data/spec/fixtures/attribute_long.xml +0 -6
- data/spec/fixtures/attribute_text.xml +0 -5
- data/spec/fixtures/attribute_time.xml +0 -6
- data/spec/fixtures/attribute_url.xml +0 -6
- data/spec/fixtures/bad_chars.xml +0 -6
- data/spec/fixtures/customer_order.xml +0 -28
- data/spec/fixtures/good_with_attributes.raw +0 -12
- data/spec/fixtures/resource_forbidden.raw +0 -9
- data/spec/fixtures/wrong_password.raw +0 -9
- data/spec/fixtures/wrong_type.raw +0 -70
- data/spec/fixtures/wrong_user.raw +0 -9
- data/spec/lib/moysklad/client/errors_spec.rb +0 -102
- data/spec/lib/moysklad/entities/attribute_metadata_spec.rb +0 -30
- data/spec/lib/moysklad/entities/attribute_spec.rb +0 -36
- data/spec/lib/moysklad/entities/country_spec.rb +0 -25
- data/spec/lib/moysklad/entities/custom_entity_metadata_spec.rb +0 -34
- data/spec/lib/moysklad/entities/custom_entity_spec.rb +0 -34
- data/spec/lib/moysklad/entities/good_spec.rb +0 -46
- data/spec/lib/moysklad/resources/countries_spec.rb +0 -22
- data/spec/lib/moysklad/resources/custom_entity_metadata_spec.rb +0 -13
- data/spec/lib/moysklad/resources/embedded_entity_metadata_indexed_spec.rb +0 -20
- data/spec/lib/moysklad/resources/embedded_entity_metadata_spec.rb +0 -11
- data/spec/lib/moysklad/resources/good_folders_spec.rb +0 -17
- data/spec/lib/moysklad/resources/indexed_spec.rb +0 -61
- data/spec/lib/moysklad/resources/stock_spec.rb +0 -63
- data/spec/lib/moysklad/resources/warehouses_spec.rb +0 -20
data/lib/moysklad/universe.rb
CHANGED
@@ -14,6 +14,20 @@ module Moysklad
|
|
14
14
|
Client
|
15
15
|
end
|
16
16
|
|
17
|
+
def company_settings_metadata
|
18
|
+
Moysklad::Entities::CompanySettingsMetadata.build client.get('entity/companysettings/metadata'), self
|
19
|
+
end
|
20
|
+
|
21
|
+
# Все элементы всех словарей
|
22
|
+
def all_custom_entities
|
23
|
+
list = []
|
24
|
+
dictionaries = company_settings_metadata.customEntities
|
25
|
+
dictionaries.each do |d|
|
26
|
+
list += d.entities(self)
|
27
|
+
end
|
28
|
+
list
|
29
|
+
end
|
30
|
+
|
17
31
|
# Ленивое создание universe
|
18
32
|
#
|
19
33
|
# @param login
|
@@ -25,8 +39,8 @@ module Moysklad
|
|
25
39
|
@@resources_list = []
|
26
40
|
Moysklad::Resources.resources.each do |resource_klass|
|
27
41
|
@@resources_list << resource_klass.pluralized_type.to_sym
|
28
|
-
define_method resource_klass.pluralized_type do
|
29
|
-
@resources[resource_klass.type] ||= resource_klass.indexed( client: client )
|
42
|
+
define_method resource_klass.pluralized_type do |opts={}|
|
43
|
+
@resources[resource_klass.type] ||= resource_klass.indexed( **opts.merge(client: client) )
|
30
44
|
end
|
31
45
|
end
|
32
46
|
|
data/lib/moysklad/version.rb
CHANGED
data/lib/moysklad.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
|
-
require '
|
1
|
+
require 'virtus'
|
2
|
+
require 'json'
|
2
3
|
require 'active_support'
|
3
|
-
require
|
4
|
+
require 'moysklad/version'
|
4
5
|
|
5
6
|
require 'logger'
|
6
7
|
|
7
8
|
module Moysklad
|
8
9
|
mattr_accessor :custom_logger
|
9
|
-
extend ActiveSupport::Autoload
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
%w{
|
12
|
+
entities
|
13
|
+
error
|
14
|
+
resources
|
15
|
+
client
|
16
|
+
universe
|
17
|
+
}.each do |m|
|
18
|
+
require_relative "moysklad/#{m}"
|
19
|
+
end
|
15
20
|
|
16
21
|
def self.logger= value
|
17
22
|
self.custom_logger = value
|
data/moysklad.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["danil@brandymint.ru"]
|
11
11
|
spec.summary = %q{Клиент для работы с API moysklad.ru}
|
12
12
|
spec.description = %q{Правильный клиент для работы c REST XML API moyslad.ru, созданный по принципам SOLID}
|
13
|
-
spec.homepage = "https://github.com/
|
13
|
+
spec.homepage = "https://github.com/dapi/moysklad"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -21,10 +21,11 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.required_ruby_version = '>= 2.0.0'
|
22
22
|
|
23
23
|
spec.add_runtime_dependency 'faraday'
|
24
|
-
spec.add_runtime_dependency '
|
24
|
+
spec.add_runtime_dependency 'virtus'
|
25
|
+
# spec.add_runtime_dependency 'nokogiri-happymapper'
|
25
26
|
spec.add_runtime_dependency 'activesupport', '>=3.0.0'
|
26
27
|
|
27
|
-
spec.add_development_dependency "bundler"
|
28
|
+
spec.add_development_dependency "bundler"
|
28
29
|
spec.add_development_dependency "rake"
|
29
30
|
spec.add_development_dependency "rspec"
|
30
31
|
spec.add_development_dependency "rspec-collection_matchers"
|
@@ -35,4 +36,5 @@ Gem::Specification.new do |spec|
|
|
35
36
|
spec.add_development_dependency "guard-rspec"
|
36
37
|
spec.add_development_dependency 'guard-ctags-bundler'
|
37
38
|
spec.add_development_dependency 'yard'
|
39
|
+
spec.add_development_dependency 'minitest', '~> 5.1'
|
38
40
|
end
|
data/scripts/rest.sh
CHANGED
@@ -11,16 +11,19 @@ fi
|
|
11
11
|
|
12
12
|
if [ -z "$resource" ]; then
|
13
13
|
echo "Запуск: rest.sh Resoruce [action]"
|
14
|
-
echo "Например: rest.sh
|
14
|
+
echo "Например: rest.sh entity product"
|
15
15
|
exit 2
|
16
16
|
fi
|
17
17
|
|
18
|
-
|
18
|
+
# url_v1.0="https://online.moysklad.ru/exchange/rest/ms/xml/$1/$2"
|
19
|
+
# url="https://online.moysklad.ru/api/remap/1.1/"
|
20
|
+
url="https://online.moysklad.ru/api/remap/1.1/$resource/$action"
|
19
21
|
|
20
22
|
if [ "$action"=="list" ] && [ -n "$start" ]; then
|
21
23
|
url="$url?start=$start"
|
22
24
|
fi
|
23
25
|
|
26
|
+
# url="https://online.moysklad.ru/api/remap/1.1/entity/variant/metadata/characteristics/3e277152-78ac-11e4-7a07-673c000ca568"
|
24
27
|
echo $url >&2
|
25
28
|
curl --max-redirs 3 -is -u $MS_LOGIN:$MS_PASSWORD $url
|
26
29
|
|
@@ -5,31 +5,18 @@ describe Moysklad::Entities::CustomerOrderPosition do
|
|
5
5
|
subject {
|
6
6
|
p= Moysklad::Entities::CustomerOrderPosition.new
|
7
7
|
p.vat = 18
|
8
|
-
p.
|
9
|
-
p.
|
8
|
+
p.price = Moysklad::Entities::Price.new
|
9
|
+
p.price.value = 123
|
10
10
|
p.reserve = true
|
11
11
|
p
|
12
12
|
}
|
13
13
|
|
14
|
-
it '
|
15
|
-
expect(subject.
|
14
|
+
it 'to_json' do
|
15
|
+
expect(subject.to_json).to be_a String
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'to_s' do
|
19
19
|
expect(subject.to_s).to be_a String
|
20
20
|
end
|
21
|
-
|
22
|
-
it 'include xml' do
|
23
|
-
expect(subject.to_xml).to include '<?xml version="1.0" encoding="utf-8"?>'
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'include customerOrderPosition' do
|
27
|
-
expect(subject.to_xml).to include "<customerOrderPosition"
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'include basePrice' do
|
31
|
-
expect(subject.to_xml).to include "<basePrice"
|
32
|
-
end
|
33
21
|
end
|
34
|
-
|
35
22
|
end
|
@@ -3,51 +3,26 @@ require 'spec_helper'
|
|
3
3
|
describe Moysklad::Entities::CustomerOrder do
|
4
4
|
context 'generate' do
|
5
5
|
subject {
|
6
|
-
p= Moysklad::Entities::CustomerOrderPosition.new
|
6
|
+
p= Moysklad::Entities::CustomerOrderPosition.new
|
7
7
|
p.vat = 18
|
8
|
-
p.
|
9
|
-
p.
|
10
|
-
p.reserve =
|
8
|
+
p.price = Moysklad::Entities::Price.new
|
9
|
+
p.price.value = 123
|
10
|
+
p.reserve = 123
|
11
11
|
|
12
12
|
co = Moysklad::Entities::CustomerOrder.new
|
13
13
|
co.sum = Moysklad::Entities::Price.new
|
14
|
-
co.sum.
|
14
|
+
co.sum.value = 456
|
15
15
|
co.description = 'Описание'
|
16
|
-
co.
|
16
|
+
co.positions = [p]
|
17
17
|
co
|
18
18
|
}
|
19
19
|
|
20
|
-
it '
|
21
|
-
expect(subject.
|
20
|
+
it 'to_json' do
|
21
|
+
expect(subject.to_json).to be_a String
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'to_s' do
|
25
25
|
expect(subject.to_s).to be_a String
|
26
26
|
end
|
27
|
-
|
28
|
-
it 'include xml' do
|
29
|
-
expect(subject.to_xml).to include '<?xml version="1.0" encoding="utf-8"?>'
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'include customerOrder' do
|
33
|
-
expect(subject.to_xml).to include "<customerOrder"
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'include customerOrderPosition' do
|
37
|
-
expect(subject.to_xml).to include "<customerOrderPosition"
|
38
|
-
end
|
39
27
|
end
|
40
|
-
|
41
|
-
context 'parse' do
|
42
|
-
subject { Moysklad::Entities::CustomerOrder.parse File.read './spec/fixtures/customer_order.xml' }
|
43
|
-
|
44
|
-
it 'include customerOrder' do
|
45
|
-
expect(subject.to_xml).to include "<customerOrder"
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'include customerOrderPosition' do
|
49
|
-
expect(subject.to_xml).to include "<customerOrderPosition"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
28
|
end
|
@@ -4,58 +4,4 @@ describe Moysklad::Resources::Base do
|
|
4
4
|
it 'should be loaded' do
|
5
5
|
expect(described_class).to be_a Class
|
6
6
|
end
|
7
|
-
|
8
|
-
describe 'правильно определяет название модели' do
|
9
|
-
let!(:entity_class) { Moysklad::Entities::Computer = Class.new }
|
10
|
-
subject { Moysklad::Resources::Computers = Class.new described_class }
|
11
|
-
|
12
|
-
it do
|
13
|
-
expect(subject.entity_class).to eq entity_class
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'испрвляет на лету xml с плохими символами' do
|
18
|
-
let(:xml) { File.read './spec/fixtures/bad_chars.xml' }
|
19
|
-
let(:client) { Moysklad::Client.new }
|
20
|
-
let(:res) { described_class.new client: client }
|
21
|
-
|
22
|
-
before do
|
23
|
-
allow(described_class).to receive(:entity_class).and_return Moysklad::Entities::CustomEntity
|
24
|
-
end
|
25
|
-
|
26
|
-
subject { res.send :parse_page, xml }
|
27
|
-
|
28
|
-
it do
|
29
|
-
expect{subject}.to_not raise_error
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'ошибка есть если парсинг напрямую' do
|
33
|
-
before do
|
34
|
-
expect_any_instance_of(described_class).to receive(:parse_content).and_return xml
|
35
|
-
end
|
36
|
-
it do
|
37
|
-
expect{subject}.to raise_error Nokogiri::XML::SyntaxError
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
describe 'page' do
|
44
|
-
let(:resource) { Moysklad::Resources::Features.new client: client }
|
45
|
-
|
46
|
-
before do
|
47
|
-
stub_rest :Feature
|
48
|
-
end
|
49
|
-
|
50
|
-
subject { resource.page }
|
51
|
-
|
52
|
-
it do
|
53
|
-
expect(subject).to be_a Moysklad::Entities::Page
|
54
|
-
expect(subject.total).to eq feature_list_items_count
|
55
|
-
expect(subject.count).to eq Moysklad::Entities::Collection::DEFAULT_COUNT
|
56
|
-
expect(subject.start).to eq 0
|
57
|
-
expect(subject.items.count).to eq feature_list_items_count
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
7
|
end
|
@@ -3,8 +3,6 @@ require 'spec_helper'
|
|
3
3
|
describe Moysklad::Resources do
|
4
4
|
it 'should be loaded' do
|
5
5
|
expect(Moysklad::Resources).to be_a Module
|
6
|
-
|
7
|
-
expect(Moysklad::Resources.resources).to include(Moysklad::Resources::Features)
|
8
6
|
expect(Moysklad::Resources.resources).to include(Moysklad::Resources::EmbeddedEntityMetadata)
|
9
7
|
end
|
10
8
|
end
|
@@ -5,14 +5,6 @@ describe Moysklad::Universe do
|
|
5
5
|
|
6
6
|
subject { described_class.new client: client }
|
7
7
|
|
8
|
-
it 'should have a features resoruce' do
|
9
|
-
expect(subject.features).to be_a Moysklad::Resources::Indexed
|
10
|
-
end
|
11
|
-
|
12
|
-
it do
|
13
|
-
expect(subject.features.resource).to be_a Moysklad::Resources::Features
|
14
|
-
end
|
15
|
-
|
16
8
|
it do
|
17
9
|
expect(subject.embedded_entity_metadata.resource).to be_a Moysklad::Resources::EmbeddedEntityMetadata
|
18
10
|
end
|
@@ -21,10 +13,6 @@ describe Moysklad::Universe do
|
|
21
13
|
expect(subject.resources_list).to have_at_least(10).items
|
22
14
|
end
|
23
15
|
|
24
|
-
it do
|
25
|
-
expect(subject.resources_list).to include(:features)
|
26
|
-
end
|
27
|
-
|
28
16
|
describe '.build' do
|
29
17
|
let(:login) { 'alala' }
|
30
18
|
let(:password) { 'ulala' }
|
@@ -38,16 +26,5 @@ describe Moysklad::Universe do
|
|
38
26
|
it do
|
39
27
|
expect(subject.client).to be_a Moysklad::Client
|
40
28
|
end
|
41
|
-
|
42
29
|
end
|
43
|
-
|
44
|
-
describe do
|
45
|
-
before do
|
46
|
-
stub_rest :CustomEntityMetadata, :list, 0, './spec/fixtures/resource_forbidden.raw'
|
47
|
-
end
|
48
|
-
it do
|
49
|
-
expect{subject.custom_entity_metadata.all}.to raise_error Moysklad::Client::ResourceForbidden
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
30
|
end
|
data/spec/lib/moysklad_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -9,6 +9,7 @@ require 'faraday'
|
|
9
9
|
# https://github.com/vcr/vcr
|
10
10
|
require 'webmock/rspec'
|
11
11
|
require 'rspec/collection_matchers'
|
12
|
+
require 'pry'
|
12
13
|
|
13
14
|
Moysklad.logger = Logger.new '/dev/null'
|
14
15
|
Dir["./spec/support/**/*.rb"].sort.each { |f| require f}
|
@@ -42,7 +43,7 @@ RSpec.configure do |config|
|
|
42
43
|
# # => "be bigger than 2 and smaller than 4"
|
43
44
|
# ...rather than:
|
44
45
|
# # => "be bigger than 2"
|
45
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
46
|
+
# expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
46
47
|
end
|
47
48
|
|
48
49
|
# rspec-mocks config goes here. You can use an alternate test double
|
data/spec/support/resource.rb
CHANGED
@@ -1,70 +1,5 @@
|
|
1
1
|
module RspecResourceSupport
|
2
|
-
|
3
|
-
def raw_consignment_0_list
|
4
|
-
File.new './spec/fixtures/Consignment_list_0.raw'
|
5
|
-
end
|
6
|
-
|
7
|
-
def raw_consignment_1000_list
|
8
|
-
File.new './spec/fixtures/Consignment_list_1000.raw'
|
9
|
-
end
|
10
|
-
|
11
|
-
def total_consignment_count
|
12
|
-
1280
|
13
|
-
end
|
14
|
-
|
15
|
-
def feature_list_items_count
|
16
|
-
863
|
17
|
-
end
|
18
|
-
|
19
|
-
def raw_feature_list
|
20
|
-
File.new './spec/fixtures/Feature_list.raw'
|
21
|
-
end
|
22
|
-
|
23
|
-
def feature_list_items_count
|
24
|
-
863
|
25
|
-
end
|
26
|
-
|
27
|
-
def stub_rest type, action=:list, start=nil, file=nil
|
28
|
-
url = "https://online.moysklad.ru/exchange/rest/ms/xml/#{type}/#{action}"
|
29
|
-
url << "?start=#{start}" if start
|
30
|
-
stub_request(:get, url).to_return File.new( file || "./spec/fixtures/#{type}_#{action}.raw" )
|
31
|
-
end
|
32
|
-
|
33
|
-
def stub_stock_rest_with_consignments
|
34
|
-
url = 'https://online.moysklad.ru/exchange/rest/stock/xml?showConsignments=true'
|
35
|
-
stub_request(:get, url).to_return File.new "./spec/fixtures/Stock_showConsignments.raw"
|
36
|
-
end
|
37
|
-
|
38
|
-
def stub_stock_rest
|
39
|
-
url = 'https://online.moysklad.ru/exchange/rest/stock/xml'
|
40
|
-
stub_request(:get, url).to_return File.new "./spec/fixtures/Stock.raw"
|
41
|
-
end
|
42
|
-
|
43
|
-
def client
|
44
|
-
@client ||= Moysklad::Client.new
|
45
|
-
end
|
46
|
-
|
47
|
-
def universe
|
48
|
-
@universe ||= Moysklad::Universe.new client: client
|
49
|
-
end
|
50
|
-
|
51
|
-
def resource_list_url res=nil, start=nil
|
52
|
-
res ||= resource
|
53
|
-
url = Moysklad::Client::URL + '/' + res.send(:list_path)
|
54
|
-
url+="?start=#{start}" if start
|
55
|
-
|
56
|
-
return url
|
57
|
-
end
|
58
|
-
|
59
|
-
def consignments_resource
|
60
|
-
@consignments_resource ||= Moysklad::Resources::Consignments.new client: client
|
61
|
-
end
|
62
|
-
|
63
|
-
def stub_consignments_requests
|
64
|
-
stub_request(:get, resource_list_url(consignments_resource, 0)).to_return(raw_consignment_0_list)
|
65
|
-
stub_request(:get, resource_list_url(consignments_resource, 1000)).to_return(raw_consignment_1000_list)
|
66
|
-
end
|
67
|
-
|
2
|
+
# TODO json stub
|
68
3
|
end
|
69
4
|
|
70
5
|
RSpec.configure do |config|
|
data/test.rb
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
#!/bin/bash ruby
|
2
|
+
$LOAD_PATH.unshift './lib'
|
3
|
+
require 'moysklad'
|
4
|
+
require 'byebug'
|
5
|
+
require 'pry'
|
6
|
+
universe = Moysklad::Universe.build login: ENV['MS_LOGIN'], password: ENV['MS_PASSWORD']
|
7
|
+
|
8
|
+
|
9
|
+
# goods -> products
|
10
|
+
# good_folders -> productfolders
|
11
|
+
# features -> variants
|
12
|
+
# consignments -> assortments
|
13
|
+
# stock.listWithConsignments
|
14
|
+
# uom -> done
|
15
|
+
# warehouses
|
16
|
+
#
|
17
|
+
# custom_entities -> значения словарей (придется брать по-одному)
|
18
|
+
#
|
19
|
+
# custom_entity_metadata -> словари
|
20
|
+
# https://online.moysklad.ru/api/remap/1.1/entity/companysettings/metadata/
|
21
|
+
#
|
22
|
+
# https://online.moysklad.ru/api/remap/1.1/entity/product/metadata/
|
23
|
+
# https://online.moysklad.ru/api/remap/1.1/entity/variant/metadata/
|
24
|
+
#
|
25
|
+
# attributes + characteristics
|
26
|
+
#
|
27
|
+
# embeded_entity_metada -> свойства
|
28
|
+
#
|
29
|
+
# https://online.moysklad.ru/api/remap/1.1/entity/companysettings/metadata/
|
30
|
+
# https://online.moysklad.ru/api/remap/1.1/entity/variant/metadata/
|
31
|
+
# https://online.moysklad.ru/api/remap/1.1/entity/product/metadata/
|
32
|
+
#
|
33
|
+
# stores = universe.stores.all
|
34
|
+
|
35
|
+
# binding.pry
|
36
|
+
# puts universe.uoms.list
|
37
|
+
#
|
38
|
+
# Список словарей
|
39
|
+
# m = universe.company_settings_metadata
|
40
|
+
##
|
41
|
+
## Список аттрибутов
|
42
|
+
#dictionaries = m.customEntities
|
43
|
+
|
44
|
+
#dictionaries.each do |a|
|
45
|
+
#puts '---'
|
46
|
+
#puts a.meta.href
|
47
|
+
#puts a.entityMeta.href
|
48
|
+
#binding.pry
|
49
|
+
#puts a.entities(universe).map { |e| [e.id, e.name].join(':') }.join(', ')
|
50
|
+
#end
|
51
|
+
|
52
|
+
a = universe.counterparties.all(filter: { phone: '79033891228' })
|
53
|
+
|
54
|
+
|
55
|
+
binding.pry
|
56
|
+
|
57
|
+
# products = universe.products.all
|
58
|
+
|
59
|
+
o = universe.organizations.all
|
60
|
+
|
61
|
+
organization = o.first
|
62
|
+
|
63
|
+
cp = Moysklad::Entities::Counterparty.new(
|
64
|
+
name: 'Письменный Данил Викторович (test)',
|
65
|
+
externalCode: 'test-couterpaty',
|
66
|
+
actualAddress: 'Чебоксары, ул. Водопроводная, дом 7',
|
67
|
+
email: 'danil@brandymint.ru',
|
68
|
+
tags: ['kiiiosk'],
|
69
|
+
phone: '+79033891228'
|
70
|
+
)
|
71
|
+
agent = universe.counterparties.create cp
|
72
|
+
assortment = {
|
73
|
+
meta: {
|
74
|
+
"href"=>"https://online.moysklad.ru/api/remap/1.1/entity/product/022528e1-fcfe-11e6-7a69-97110054d4e7",
|
75
|
+
"metadataHref"=>"https://online.moysklad.ru/api/remap/1.1/entity/product/metadata",
|
76
|
+
"type"=>"product",
|
77
|
+
"mediaType"=>"application/json"
|
78
|
+
}
|
79
|
+
}
|
80
|
+
positions = [
|
81
|
+
Moysklad::Entities::CustomerOrderPosition.new(
|
82
|
+
quantity: 1,
|
83
|
+
price: 123,
|
84
|
+
discount: 0,
|
85
|
+
vat: 0,
|
86
|
+
reserve: 1,
|
87
|
+
assortment: assortment
|
88
|
+
)
|
89
|
+
]
|
90
|
+
customer_order = Moysklad::Entities::CustomerOrder.new(
|
91
|
+
name: "TEST-#{Time.now.to_i}",
|
92
|
+
code: '123456',
|
93
|
+
moment: Moysklad::Entities::Time.now,
|
94
|
+
vatEnabled: false,
|
95
|
+
applicable: false,
|
96
|
+
organization: organization,
|
97
|
+
agent: agent,
|
98
|
+
# state: state,
|
99
|
+
positions: positions,
|
100
|
+
description: 'Тестовый заказ'
|
101
|
+
)
|
102
|
+
|
103
|
+
order = universe.customer_orders.create customer_order
|
104
|
+
|
105
|
+
binding.pry
|
106
|
+
puts order
|
107
|
+
|
108
|
+
# puts universe.currencies.findWhere isoCode: '643'
|
109
|
+
# Получаем рекурсивно действительно все значения
|
110
|
+
#custom_entities = universe.all_custom_entities
|
111
|
+
#binding.pry
|
112
|
+
#puts custom_entities.count
|
113
|
+
#
|
114
|
+
# Все элементы словаря
|
115
|
+
# list = universe.custom_entities(custom_entity_meta_id: 'e63c1592-807b-11e4-90a2-8ecb00113f68').all
|
116
|
+
# puts list
|
117
|
+
# attrs = universe.variants.metadata.attrs
|
118
|
+
# attr = attrs.first
|
119
|
+
# e63c1592-807b-11e4-90a2-8ecb00113f68
|
120
|
+
# entities = attr.entities universe
|
121
|
+
#id = "022528e1-fcfe-11e6-7a69-97110054d4e7"
|
122
|
+
#byebug
|
123
|
+
#products = universe.products.all(expand: :productFolder)
|
124
|
+
#byebug
|
125
|
+
#products.each do |p|
|
126
|
+
#puts p.dump.to_json
|
127
|
+
## binding.pry if p.externalCode == 'fhiI8yDIjwC-1-kiIbSO62'
|
128
|
+
## puts "#{p.externalCode}\t#{p.id}\t#{p.name}"
|
129
|
+
#end
|
130
|
+
# product.image.download(client)
|
131
|
+
|
132
|
+
#products.rows.each do |p|
|
133
|
+
#binding.pry if p.attrs.count > 0
|
134
|
+
#end
|
135
|
+
|
136
|
+
|
137
|
+
#puts products.count
|
138
|
+
|
139
|
+
#products.rows.each do |p|
|
140
|
+
#next unless p.characteristics
|
141
|
+
#puts p.characteristics.map { |c| c.meta.href }
|
142
|
+
## #puts p.characteristics.join('; ')
|
143
|
+
#end
|
144
|
+
# puts products.metadata
|
145
|
+
#roduct = products.rows.first
|
146
|
+
|
147
|
+
# Товар с attributes
|
148
|
+
# product = universe.products.get "02bbdea5-dbde-11e6-7a69-8f55000f3f4e"
|
149
|
+
|
150
|
+
#product_folders = universe.productfolders.list
|
151
|
+
#puts product_folders.rows.map { |pf| pf['dump'] }
|
152
|
+
#puts product_folders.meta.size
|
153
|
+
#puts universe.productfolders.get product_folders.rows.first.id
|
154
|
+
|
155
|
+
# variants = universe.variants.list
|
156
|
+
# byebug
|
157
|
+
## puts variants.meta.size
|
158
|
+
#variants.rows.each do |v|
|
159
|
+
#next unless v.characteristics
|
160
|
+
#puts v.characteristics.map { |c| c.meta.href }
|
161
|
+
## puts v.characteristics.join('; ')
|
162
|
+
#end
|
163
|
+
#puts products.meta.size
|
164
|
+
## puts universe.variants.get variants.rows.first.id
|
165
|
+
##
|
166
|
+
# stores = universe.stores.list
|
167
|
+
#puts stores.meta.size
|
168
|
+
## puts universe.stores.get stores.rows.first.id
|
169
|
+
#
|
170
|
+
|
171
|
+
# consignments = universe.consignments.all
|
172
|
+
#
|
173
|
+
#stockstore_uri = universe.stores.all.last.meta.href
|
174
|
+
#puts stockstore_uri
|
175
|
+
#list = universe.assortments.all stockstore: stockstore_uri
|
176
|
+
#binding.pry
|
177
|
+
#puts list.count
|