moysklad 0.0.2 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +2 -0
  4. data/Guardfile +5 -0
  5. data/Rakefile +6 -0
  6. data/lib/moysklad/client.rb +1 -1
  7. data/lib/moysklad/client/errors.rb +6 -4
  8. data/lib/moysklad/entities.rb +5 -0
  9. data/lib/moysklad/entities/attribute.rb +27 -2
  10. data/lib/moysklad/entities/attribute_metadata.rb +27 -0
  11. data/lib/moysklad/entities/base.rb +10 -0
  12. data/lib/moysklad/entities/common.rb +0 -1
  13. data/lib/moysklad/entities/custom_entity.rb +18 -0
  14. data/lib/moysklad/entities/custom_entity_metadata.rb +35 -0
  15. data/lib/moysklad/entities/customer_order.rb +4 -0
  16. data/lib/moysklad/entities/customer_order_position.rb +1 -0
  17. data/lib/moysklad/entities/embedded_entity_metadata.rb +2 -0
  18. data/lib/moysklad/entities/feature.rb +2 -3
  19. data/lib/moysklad/entities/good.rb +12 -9
  20. data/lib/moysklad/entities/good_folder.rb +9 -0
  21. data/lib/moysklad/entities/price.rb +1 -1
  22. data/lib/moysklad/entities/xml_fix.rb +9 -5
  23. data/lib/moysklad/resources.rb +7 -11
  24. data/lib/moysklad/resources/base.rb +11 -2
  25. data/lib/moysklad/resources/custom_entity_metadata.rb +18 -0
  26. data/lib/moysklad/resources/indexed.rb +56 -46
  27. data/lib/moysklad/resources/metadata.rb +20 -0
  28. data/lib/moysklad/resources/metadata_indexed.rb +7 -0
  29. data/lib/moysklad/resources/subresource.rb +21 -0
  30. data/lib/moysklad/resources/where_filter.rb +16 -0
  31. data/lib/moysklad/universe.rb +1 -5
  32. data/lib/moysklad/version.rb +1 -1
  33. data/moysklad.gemspec +2 -0
  34. data/scripts/rest.sh +7 -1
  35. data/spec/fixtures/302.raw +15 -0
  36. data/spec/fixtures/400.raw +8 -0
  37. data/spec/fixtures/CustomEntityMetadata_list.raw +14 -0
  38. data/spec/fixtures/CustomEntity_list.raw +14 -0
  39. data/spec/fixtures/Good_e932ebe1-2e22-11e4-9406-002590a28eca.raw +12 -0
  40. data/spec/fixtures/Good_eb77ad57-2e22-11e4-4030-002590a28eca.raw +12 -0
  41. data/spec/fixtures/Goods_list.raw +14 -0
  42. data/spec/fixtures/Metadata_list.raw +14 -0
  43. data/spec/fixtures/attribute_boolean.xml +6 -0
  44. data/spec/fixtures/attribute_dictionary.xml +5 -0
  45. data/spec/fixtures/attribute_double.xml +6 -0
  46. data/spec/fixtures/attribute_file.xml +12 -0
  47. data/spec/fixtures/attribute_long.xml +6 -0
  48. data/spec/fixtures/attribute_text.xml +5 -0
  49. data/spec/fixtures/attribute_time.xml +6 -0
  50. data/spec/fixtures/attribute_url.xml +6 -0
  51. data/spec/fixtures/customer_order.xml +28 -0
  52. data/spec/fixtures/good_with_attributes.raw +12 -0
  53. data/spec/lib/moysklad/entities/attribute_metadata_spec.rb +30 -0
  54. data/spec/lib/moysklad/entities/attribute_spec.rb +36 -0
  55. data/spec/lib/moysklad/entities/custom_entity_metadata_spec.rb +34 -0
  56. data/spec/lib/moysklad/entities/custom_entity_spec.rb +35 -0
  57. data/spec/lib/moysklad/entities/customer_order_position_spec.rb +35 -0
  58. data/spec/lib/moysklad/entities/customer_order_spec.rb +53 -0
  59. data/spec/lib/moysklad/entities/good_spec.rb +46 -0
  60. data/spec/lib/moysklad/resources/base_spec.rb +1 -3
  61. data/spec/lib/moysklad/resources/custom_entity_metadata_spec.rb +13 -0
  62. data/spec/lib/moysklad/resources/good_folders_spec.rb +17 -0
  63. data/spec/lib/moysklad/resources/indexed_spec.rb +31 -3
  64. data/spec/lib/moysklad/resources/metadata_indexed_spec.rb +20 -0
  65. data/spec/lib/moysklad/resources/metadata_spec.rb +15 -0
  66. data/spec/lib/moysklad/resources/subresource_spec.rb +13 -0
  67. data/spec/lib/moysklad/resources_spec.rb +1 -0
  68. data/spec/lib/moysklad/universe_spec.rb +1 -0
  69. data/spec/support/resource.rb +10 -0
  70. metadata +99 -2
@@ -0,0 +1,12 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/1.6.2
3
+ Date: Tue, 25 Nov 2014 12:01:30 GMT
4
+ Content-Type: application/xml
5
+ Content-Length: 2605
6
+ Connection: close
7
+ Cache-Control: max-age=0
8
+ Expires: Tue, 25 Nov 2014 12:01:30 GMT
9
+ Strict-Transport-Security: max-age=15552000
10
+
11
+ <?xml version="1.0" encoding="UTF-8"?>
12
+ <good isSerialTrackable="false" buyPrice="41650.0" weight="3.2" volume="0.0" minPrice="0.0" uomUuid="19f1edc0-fc42-4001-94cb-c9ec9c62ec10" salePrice="300000.0" saleCurrencyUuid="2f7eb413-1666-11e4-9bee-002590a28eca" buyCurrencyUuid="2f7eb413-1666-11e4-9bee-002590a28eca" archived="false" parentUuid="eb576125-2e22-11e4-dd7b-002590a28eca" productCode="R006-P11-17" name="Кольцо Нимфа-2 малое с цирконами и жемчугом серебряное" updated="2014-11-25T14:52:08.066+03:00" updatedBy="admin@wannabejewelry" readMode="ALL" changeMode="NONE"><accountUuid>2f678846-1666-11e4-1e95-002590a28eca</accountUuid><accountId>2f678846-1666-11e4-1e95-002590a28eca</accountId><uuid>eb77ad57-2e22-11e4-4030-002590a28eca</uuid><code></code><externalcode>--7Hmbooi3KoVlMu7aOGV2</externalcode><description></description><attribute goodUuid="eb77ad57-2e22-11e4-4030-002590a28eca" metadataUuid="5abf49e6-7498-11e4-90a2-8ecb0038d40f" entityValueUuid="751b464c-7498-11e4-90a2-8ecb0038d853" updated="2014-11-25T14:52:07.429+03:00" updatedBy="admin@wannabejewelry" readMode="ALL" changeMode="NONE"><accountUuid>2f678846-1666-11e4-1e95-002590a28eca</accountUuid><accountId>2f678846-1666-11e4-1e95-002590a28eca</accountId><uuid>7f0831cf-7499-11e4-90a2-8ecb00390d2b</uuid></attribute><attribute goodUuid="eb77ad57-2e22-11e4-4030-002590a28eca" metadataUuid="54a59b46-7499-11e4-90a2-8ecb0039058c" valueText="test test" updated="2014-11-25T14:52:08.067+03:00" updatedBy="admin@wannabejewelry" readMode="ALL" changeMode="NONE"><accountUuid>2f678846-1666-11e4-1e95-002590a28eca</accountUuid><accountId>2f678846-1666-11e4-1e95-002590a28eca</accountId><uuid>6e9bda3c-7499-11e4-90a2-8ecb00390a08</uuid></attribute><attribute goodUuid="eb77ad57-2e22-11e4-4030-002590a28eca" metadataUuid="ffdf0643-7493-11e4-90a2-8ecb0037b75b" entityValueUuid="d3f18c9e-7493-11e4-90a2-8ecb0037ae75" updated="2014-11-25T14:38:48.876+03:00" updatedBy="admin@wannabejewelry" readMode="ALL" changeMode="NONE"><accountUuid>2f678846-1666-11e4-1e95-002590a28eca</accountUuid><accountId>2f678846-1666-11e4-1e95-002590a28eca</accountId><uuid>a30eb457-7497-11e4-90a2-8ecb0038ae7b</uuid></attribute><salePrices><price currencyUuid="2f7eb413-1666-11e4-9bee-002590a28eca" priceTypeUuid="2f7ee9c7-1666-11e4-5b14-002590a28eca" value="300000.0" readMode="ALL" changeMode="ALL"><accountUuid>2f678846-1666-11e4-1e95-002590a28eca</accountUuid><accountId>2f678846-1666-11e4-1e95-002590a28eca</accountId><uuid>eb77b286-2e22-11e4-545e-002590a28eca</uuid></price></salePrices><preferences/><images/></good>
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Moysklad::Entities::AttributeMetadata do
4
+ let(:metadata_resource) { Moysklad::Resources::Metadata.indexed client: client }
5
+ let(:subresource) { metadata_resource.subresource_by_name :GoodFolder }
6
+ let(:attribute_metadata) { subresource.items.first }
7
+
8
+ before do
9
+ stub_rest :Metadata, :list, 0
10
+ stub_rest :CustomEntityMetadata, :list, 0
11
+ end
12
+
13
+ context do
14
+ subject { attribute_metadata.dictionatyMetadata universe }
15
+ it do
16
+ expect(subject).to be_a Moysklad::Entities::CustomEntityMetadata
17
+ expect(subject.uuid).to eq attribute_metadata.dictionaryMetadataUuid
18
+ end
19
+ end
20
+
21
+ context do
22
+ subject { attribute_metadata.entityMetadata universe }
23
+
24
+ it do
25
+ expect(subject).to be_a Moysklad::Entities::EmbeddedEntityMetadata
26
+ expect(subject.uuid).to eq attribute_metadata.entityMetadataUuid
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Moysklad::Entities::Attribute do
4
+ let(:good_uuid) { 'eb77ad57-2e22-11e4-4030-002590a28eca' }
5
+
6
+ before do
7
+ stub_rest :Good, good_uuid
8
+ stub_rest :Metadata, :list, 0
9
+ stub_rest :CustomEntity, :list, 0
10
+ end
11
+
12
+ let(:goods_resource) { Moysklad::Resources::Goods.indexed client: client }
13
+ let(:good) { goods_resource.get good_uuid }
14
+
15
+ let(:attribute_with_id_custom) { good.attributes.first }
16
+ let(:attribute_with_text) { good.attributes.second }
17
+
18
+ it 'should get ' do
19
+ expect(good).to be_a Moysklad::Entities::Good
20
+ end
21
+
22
+ describe 'аттрибут типа ID_CUSTOM' do
23
+ subject { attribute_with_id_custom }
24
+
25
+ it do
26
+ expect(subject.metadata(universe)).to be_a Moysklad::Entities::AttributeMetadata
27
+ expect(subject.metadata(universe).name).to eq 'Вставки'
28
+ expect(subject.attributeName(universe)).to eq 'Вставки'
29
+ end
30
+
31
+ it do
32
+ expect(subject.get_value(universe)).to eq "Культ. жемчуг, куб. циркон"
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Moysklad::Entities::CustomEntityMetadata do
4
+ before do
5
+ stub_rest :CustomEntityMetadata, :list, 0
6
+ stub_rest :CustomEntity, :list, 0
7
+ end
8
+
9
+ let(:resource) { Moysklad::Resources::CustomEntityMetadata.indexed client: client }
10
+
11
+ describe do
12
+ let(:custom_entity_metadata) { resource.all.first }
13
+
14
+ subject { custom_entity_metadata }
15
+
16
+ it do
17
+ expect(subject).to be_a Moysklad::Entities::CustomEntityMetadata
18
+ end
19
+
20
+ it 'unicoded xml' do
21
+ expect(subject.to_xml).to start_with '<?xml version="1.0" encoding="utf-8"?>'
22
+ end
23
+
24
+ context 'entities' do
25
+
26
+ it do
27
+ expect(subject.entities(universe)).to be_a Array
28
+ expect(subject.entities(universe).first).to be_a Moysklad::Entities::CustomEntity
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Moysklad::Entities::CustomEntity do
4
+
5
+ before do
6
+ stub_rest :CustomEntityMetadata, :list, 0
7
+ stub_rest :CustomEntity, :list, 0
8
+ end
9
+
10
+ let(:resource) { Moysklad::Resources::CustomEntities.indexed client: client }
11
+
12
+ describe do
13
+ let(:custom_entity) { resource.all.first }
14
+
15
+ subject { custom_entity }
16
+
17
+ it do
18
+ expect(subject).to be_a Moysklad::Entities::CustomEntity
19
+ end
20
+
21
+ it 'unicoded xml' do
22
+ expect(subject.to_xml).to start_with '<?xml version="1.0" encoding="utf-8"?>'
23
+ end
24
+
25
+ context 'entityMetadata' do
26
+
27
+ it do
28
+ expect(subject.entityMetadata(universe)).to be_a Moysklad::Entities::CustomEntityMetadata
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Moysklad::Entities::CustomerOrderPosition do
4
+ context 'generate' do
5
+ subject {
6
+ p= Moysklad::Entities::CustomerOrderPosition.new
7
+ p.vat = 18
8
+ p.basePrice = Moysklad::Entities::Price.new
9
+ p.basePrice.sum = 123
10
+ p.reserve = true
11
+ p
12
+ }
13
+
14
+ it 'to_xml' do
15
+ expect(subject.to_xml).to be_a String
16
+ end
17
+
18
+ it 'to_s' do
19
+ expect(subject.to_s).to be_a String
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
+ end
34
+
35
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Moysklad::Entities::CustomerOrder do
4
+ context 'generate' do
5
+ subject {
6
+ p= Moysklad::Entities::CustomerOrderPosition.new
7
+ p.vat = 18
8
+ p.basePrice = Moysklad::Entities::Price.new
9
+ p.basePrice.sum = 123
10
+ p.reserve = true
11
+
12
+ co = Moysklad::Entities::CustomerOrder.new
13
+ co.sum = Moysklad::Entities::Price.new
14
+ co.sum.sum = 456
15
+ co.description = 'Описание'
16
+ co.customerOrderPosition = p
17
+ co
18
+ }
19
+
20
+ it 'to_xml' do
21
+ expect(subject.to_xml).to be_a String
22
+ end
23
+
24
+ it 'to_s' do
25
+ expect(subject.to_s).to be_a String
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
+ 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
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Moysklad::Entities::Good do
4
+ let(:good_uuid) { 'eb77ad57-2e22-11e4-4030-002590a28eca' }
5
+
6
+ let(:raw_response) { File.new "./spec/fixtures/Good_#{good_uuid}.raw" }
7
+ let(:raw_features_list_response) { File.new "./spec/fixtures/Feature_list.raw" }
8
+
9
+ before do
10
+ stub_request(:get, "https://online.moysklad.ru/exchange/rest/ms/xml/Good/#{good_uuid}").to_return(raw_response)
11
+ stub_request(:get, "https://online.moysklad.ru/exchange/rest/ms/xml/Feature/list?start=0").to_return(raw_features_list_response)
12
+ end
13
+
14
+ let(:goods_resource) { Moysklad::Resources::Goods.indexed client: client }
15
+ let(:good) { goods_resource.get good_uuid }
16
+
17
+ describe 'features' do
18
+ let(:features) { good.features universe }
19
+
20
+ it do
21
+ expect(features).to be_a Array
22
+ expect(features.count).to eq 3
23
+ end
24
+
25
+ context do
26
+ subject { features.first }
27
+ it do
28
+ expect(subject).to be_a Moysklad::Entities::Feature
29
+ end
30
+ end
31
+ end
32
+
33
+ it 'to_xml' do
34
+ expect(subject.to_xml).to be_a String
35
+ expect(subject.to_xml).to include "<?xml"
36
+ expect(subject.to_xml).to include "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
37
+ end
38
+
39
+ describe 'attribute' do
40
+ it do
41
+ expect(good.attributes).to be_a Array
42
+ expect(good.attributes.first).to be_a Moysklad::Entities::Attribute
43
+ end
44
+ end
45
+
46
+ end
@@ -15,12 +15,10 @@ describe Moysklad::Resources::Base do
15
15
  end
16
16
 
17
17
  describe 'collection' do
18
- let(:raw_response) { raw_feature_list }
19
18
  let(:resource) { Moysklad::Resources::Features.new client: client }
20
- let(:url) { resource_list_url }
21
19
 
22
20
  before do
23
- stub_request(:get, url).to_return(raw_response)
21
+ stub_rest :Feature
24
22
  end
25
23
 
26
24
  subject { resource.collection }
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Moysklad::Resources::CustomEntityMetadata do
4
+
5
+ describe do
6
+ subject { described_class.new client: client }
7
+ it 'should get list' do
8
+ expect(subject.send(:list_path)).to eq "exchange/rest/ms/xml/CustomEntityMetadata/list"
9
+ end
10
+ end
11
+
12
+ end
13
+
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Moysklad::Resources::GoodFolders do
4
+
5
+ it 'should be GoodFolder' do
6
+ expect(described_class.entity_class).to eq Moysklad::Entities::GoodFolder
7
+ end
8
+
9
+ describe 'resource' do
10
+ subject { Moysklad::Resources::GoodFolders.new client: client }
11
+
12
+ it 'should get item' do
13
+ expect(subject.send(:list_path)).to eq "exchange/rest/ms/xml/GoodFolder/list"
14
+ end
15
+ end
16
+
17
+ end
@@ -7,7 +7,9 @@ describe Moysklad::Resources::Indexed do
7
7
  stub_consignments_requests
8
8
  end
9
9
 
10
- subject { Moysklad::Resources::Indexed.new consignments_resource }
10
+ let(:resource) { Moysklad::Resources::Indexed.new consignments_resource }
11
+
12
+ subject { resource }
11
13
 
12
14
  it 'загружено верное количество данных' do
13
15
  expect(subject.all.count).to eq items_count
@@ -23,11 +25,37 @@ describe Moysklad::Resources::Indexed do
23
25
  end
24
26
 
25
27
  it 'элемет получаем из кеша' do
26
- expect(subject.get uuid).to be_a consignments_resource.class.entity_class
28
+ expect(subject.find uuid).to be_a consignments_resource.class.entity_class
27
29
  expect(WebMock).to have_requested(:get, resource_list_url(consignments_resource, 0)).once
28
30
  expect(WebMock).to have_requested(:get, resource_list_url(consignments_resource, 1000)).once
29
31
  end
30
32
  end
31
33
 
32
- end
34
+ describe 'filtered?' do
35
+ subject { resource.send :filtered?, item, filter }
33
36
 
37
+ context 'под фильтр попадает все если фильтр пуст' do
38
+ let(:item) { double }
39
+ let(:filter) { {} }
40
+ it do
41
+ expect(subject).to be true
42
+ end
43
+ end
44
+
45
+ context 'отсеивает что не надо' do
46
+ let(:item) { double some_key: 123 }
47
+ let(:filter) { { some_key: 124} }
48
+ it do
49
+ expect(subject).to be false
50
+ end
51
+ end
52
+ context 'фильтрует что надо' do
53
+ let(:item) { double some_key: 123 }
54
+ let(:filter) { { some_key: 123} }
55
+ it do
56
+ expect(subject).to be true
57
+ end
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Moysklad::Resources::MetadataIndexed do
4
+
5
+ let(:article_uuid) { 'dc410ce3-505a-11e4-90a2-8eca00496371' }
6
+
7
+ before do
8
+ stub_rest :Metadata, :list, 0
9
+ end
10
+
11
+ describe 'subresource' do
12
+ let(:metadata_resource) { Moysklad::Resources::Metadata.indexed client: client }
13
+ subject { metadata_resource.subresource_by_name :GoodFolder }
14
+
15
+ it { expect(subject).to be_a Moysklad::Resources::Subresource }
16
+ it { expect(subject.items.first).to be_a Moysklad::Entities::AttributeMetadata }
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Moysklad::Resources::Metadata do
4
+ it 'should be loaded' do
5
+ expect(Moysklad::Resources::Metadata).to be_a Class
6
+ end
7
+
8
+ describe do
9
+ subject { Moysklad::Resources::Metadata.new client: client }
10
+ it 'should get list' do
11
+ expect(subject.send(:list_path)).to eq "exchange/rest/ms/xml/Metadata/list"
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Moysklad::Resources::Subresource do
4
+ let(:item) { double key1: 1, key2: 2 }
5
+
6
+ let(:items) { [item] }
7
+
8
+ subject { described_class.new items }
9
+
10
+ it { expect(subject.items).to eq items }
11
+
12
+ end
13
+
@@ -5,5 +5,6 @@ describe Moysklad::Resources do
5
5
  expect(Moysklad::Resources).to be_a Module
6
6
 
7
7
  expect(Moysklad::Resources.resources).to include(Moysklad::Resources::Features)
8
+ expect(Moysklad::Resources.resources).to include(Moysklad::Resources::Metadata)
8
9
  end
9
10
  end