moysklad 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +1 -0
  4. data/README.md +14 -3
  5. data/lib/moysklad.rb +3 -2
  6. data/lib/moysklad/client.rb +37 -10
  7. data/lib/moysklad/client/errors.rb +60 -30
  8. data/lib/moysklad/entities.rb +17 -21
  9. data/lib/moysklad/entities/assortment.rb +6 -0
  10. data/lib/moysklad/entities/attachment_document.rb +16 -0
  11. data/lib/moysklad/entities/attribute.rb +114 -37
  12. data/lib/moysklad/entities/attribute_metadata.rb +9 -31
  13. data/lib/moysklad/entities/attribute_value.rb +19 -0
  14. data/lib/moysklad/entities/barcode.rb +10 -4
  15. data/lib/moysklad/entities/base.rb +23 -8
  16. data/lib/moysklad/entities/bundle.rb +39 -0
  17. data/lib/moysklad/entities/characteristic.rb +6 -0
  18. data/lib/moysklad/entities/characteristic_metadata.rb +6 -0
  19. data/lib/moysklad/entities/collection.rb +30 -7
  20. data/lib/moysklad/entities/collection_meta.rb +11 -0
  21. data/lib/moysklad/entities/common_object.rb +0 -2
  22. data/lib/moysklad/entities/company_settings_metadata.rb +28 -0
  23. data/lib/moysklad/entities/consignment.rb +19 -17
  24. data/lib/moysklad/entities/context.rb +9 -0
  25. data/lib/moysklad/entities/counterparty.rb +18 -0
  26. data/lib/moysklad/entities/currency.rb +29 -0
  27. data/lib/moysklad/entities/custom_entity.rb +20 -10
  28. data/lib/moysklad/entities/custom_entity_metadata.rb +7 -32
  29. data/lib/moysklad/entities/customer_order.rb +116 -23
  30. data/lib/moysklad/entities/customer_order_position.rb +10 -18
  31. data/lib/moysklad/entities/employee.rb +7 -0
  32. data/lib/moysklad/entities/entity.rb +42 -0
  33. data/lib/moysklad/entities/good_folder.rb +1 -0
  34. data/lib/moysklad/entities/group.rb +7 -0
  35. data/lib/moysklad/entities/image.rb +17 -0
  36. data/lib/moysklad/entities/images.rb +10 -0
  37. data/lib/moysklad/entities/meta.rb +14 -0
  38. data/lib/moysklad/entities/organization.rb +19 -0
  39. data/lib/moysklad/entities/owner.rb +4 -0
  40. data/lib/moysklad/entities/price.rb +5 -8
  41. data/lib/moysklad/entities/price_type.rb +2 -8
  42. data/lib/moysklad/entities/product.rb +54 -0
  43. data/lib/moysklad/entities/productfolder.rb +13 -0
  44. data/lib/moysklad/entities/rate.rb +9 -0
  45. data/lib/moysklad/entities/resource_metadata.rb +13 -0
  46. data/lib/moysklad/entities/service.rb +28 -0
  47. data/lib/moysklad/entities/shortcut.rb +11 -0
  48. data/lib/moysklad/entities/store.rb +10 -0
  49. data/lib/moysklad/entities/time.rb +13 -0
  50. data/lib/moysklad/entities/uom.rb +7 -0
  51. data/lib/moysklad/entities/variant.rb +51 -0
  52. data/lib/moysklad/entities/workflow.rb +11 -0
  53. data/lib/moysklad/entities/workflow_state.rb +8 -0
  54. data/lib/moysklad/error.rb +1 -0
  55. data/lib/moysklad/resources.rb +9 -7
  56. data/lib/moysklad/resources/assortments.rb +14 -0
  57. data/lib/moysklad/resources/base.rb +32 -44
  58. data/lib/moysklad/resources/custom_entities.rb +27 -0
  59. data/lib/moysklad/resources/custom_entity_metadata.rb +12 -8
  60. data/lib/moysklad/resources/embedded_entity_metadata.rb +0 -1
  61. data/lib/moysklad/resources/indexed.rb +23 -35
  62. data/lib/moysklad/resources/indexed_cache.rb +36 -0
  63. data/lib/moysklad/resources/load_all.rb +21 -0
  64. data/lib/moysklad/resources/products.rb +10 -0
  65. data/lib/moysklad/resources/where_filter.rb +0 -1
  66. data/lib/moysklad/universe.rb +16 -2
  67. data/lib/moysklad/version.rb +1 -1
  68. data/moysklad.gemspec +3 -1
  69. data/scripts/rest.sh +5 -2
  70. data/spec/fixtures/Good_WithManyAttributes.raw +13 -0
  71. data/spec/fixtures/Workflow_list.raw +15 -0
  72. data/spec/fixtures/good_with_image.xml +39 -0
  73. data/spec/lib/moysklad/entities/customer_order_spec.rb +7 -2
  74. data/spec/lib/moysklad/entities/good_spec.rb +9 -0
  75. data/spec/lib/moysklad/resources/workflows_spec.rb +21 -0
  76. data/spec/spec_helper.rb +2 -1
  77. data/test.rb +177 -0
  78. metadata +97 -44
  79. data/lib/moysklad/entities/common.rb +0 -15
  80. data/lib/moysklad/entities/feature.rb +0 -20
  81. data/lib/moysklad/entities/good.rb +0 -34
  82. data/lib/moysklad/entities/stock_to.rb +0 -33
  83. data/lib/moysklad/entities/warehouse.rb +0 -15
  84. data/lib/moysklad/entities/xml_fix.rb +0 -15
@@ -0,0 +1,36 @@
1
+ module IndexedCache
2
+ def cache!
3
+ all.count
4
+ end
5
+
6
+ private
7
+
8
+ def cache_fetch
9
+ return cache[:list] if cache[:list]
10
+ cache[:list] = yield
11
+ cache[:index] = prepare_index cache[:list]
12
+
13
+ cache[:list]
14
+ end
15
+
16
+ def cache
17
+ @cache ||= {}
18
+ @cache[cache_key] ||= { index: nil, list: nil}
19
+ end
20
+
21
+ def cached_index
22
+ cache[:index]
23
+ end
24
+
25
+ def cache_index(index)
26
+ cache[:index] = index
27
+ end
28
+
29
+ def cache_key
30
+ if __getobj__.respond_to? :cache_key
31
+ __getobj__.send :cache_key
32
+ else
33
+ :default
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ module Moysklad::Resources
2
+ module LoadAll
3
+ def load_all(params = {})
4
+ limit = 100
5
+ offset = 0
6
+ rows = []
7
+ collection = nil
8
+
9
+ begin
10
+ collection = list params.merge(limit: limit, offset: offset)
11
+ rows += collection.rows
12
+ break if collection.rows.empty?
13
+ offset = rows.count
14
+ end while offset<collection.meta.size
15
+
16
+ raise WrongEntriesCountError, "При загрузке коллекции в результате колиество не совпадает с total: #{rows.count}<>#{collection.meta.size}" unless rows.count==collection.meta.size
17
+
18
+ rows
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ module Moysklad::Resources
2
+ class Products < Base
3
+
4
+ private
5
+
6
+ def entity_class
7
+ Moysklad::Entities::Product
8
+ end
9
+ end
10
+ end
@@ -23,5 +23,4 @@ module Moysklad::Resources::WhereFilter
23
23
  def filtered? o, filter={}
24
24
  filter.select { |k,v| o.send(k)==v }.count == filter.keys.count
25
25
  end
26
-
27
26
  end
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module Moysklad
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -21,7 +21,8 @@ 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 'nokogiri-happymapper'
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
28
  spec.add_development_dependency "bundler", "~> 1.6"
@@ -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
@@ -11,16 +11,19 @@ fi
11
11
 
12
12
  if [ -z "$resource" ]; then
13
13
  echo "Запуск: rest.sh Resoruce [action]"
14
- echo "Например: rest.sh Feature list"
14
+ echo "Например: rest.sh entity product"
15
15
  exit 2
16
16
  fi
17
17
 
18
- url="https://online.moysklad.ru/exchange/rest/ms/xml/$1/$2"
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
 
@@ -0,0 +1,13 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/1.6.2
3
+ Date: Wed, 11 Feb 2015 17:05:51 GMT
4
+ Content-Type: application/xml
5
+ Content-Length: 6444
6
+ Connection: close
7
+ Vary: Accept-Encoding
8
+ Cache-Control: max-age=0
9
+ Expires: Wed, 11 Feb 2015 17:05:51 GMT
10
+ Strict-Transport-Security: max-age=15552000
11
+
12
+ <?xml version="1.0" encoding="UTF-8"?>
13
+ <good isSerialTrackable="false" buyPrice="0.0" weight="0.0" volume="0.0" minPrice="0.0" uomUuid="4d39c858-717b-4bba-aa48-cb9a9b1d80ea" countryUuid="7143be8a-b2f8-4a8a-acfd-8fda2fbf5875" salePrice="1000.0" archived="false" parentUuid="7398f10b-d204-4ef1-b6af-e7e051b300fb" productCode="" name="Тестовый товар – не удалять" updated="2015-02-11T19:51:28.642+03:00" updatedBy="ekaterina@citycycle" readMode="ALL" changeMode="SELF"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cf1ed-b1ed-11e4-7a40-e89700085026</uuid><code></code><externalcode>-i3alIWbi2Q0HfWNTgS5p0</externalcode><description></description><attribute goodUuid="bb0cf1ed-b1ed-11e4-7a40-e89700085026" metadataUuid="6b08959c-b1ed-11e4-7a40-e89700084a06" doubleValue="88.544" updated="2015-02-11T15:58:53.152+03:00" updatedBy="admin@citycycle" readMode="ALL" changeMode="SELF"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cf8ff-b1ed-11e4-7a40-e8970008502c</uuid></attribute><attribute goodUuid="bb0cf1ed-b1ed-11e4-7a40-e89700085026" metadataUuid="30ef6a10-985d-11e4-90a2-8ecb00a7e836" booleanValue="false" updated="2015-02-11T15:58:53.152+03:00" updatedBy="admin@citycycle" readMode="ALL" changeMode="SELF"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cfa5c-b1ed-11e4-7a40-e8970008502e</uuid></attribute><attribute goodUuid="bb0cf1ed-b1ed-11e4-7a40-e89700085026" metadataUuid="20346ffb-985d-11e4-90a2-8ecb00a7e821" booleanValue="false" updated="2015-02-11T15:58:53.152+03:00" updatedBy="admin@citycycle" readMode="ALL" changeMode="SELF"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cf87a-b1ed-11e4-7a40-e8970008502b</uuid></attribute><attribute goodUuid="bb0cf1ed-b1ed-11e4-7a40-e89700085026" metadataUuid="6b0890b1-b1ed-11e4-7a40-e89700084a03" longValue="10000" updated="2015-02-11T15:58:53.152+03:00" updatedBy="admin@citycycle" readMode="ALL" changeMode="SELF"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cf68d-b1ed-11e4-7a40-e89700085028</uuid></attribute><attribute goodUuid="bb0cf1ed-b1ed-11e4-7a40-e89700085026" metadataUuid="6b089454-b1ed-11e4-7a40-e89700084a05" updated="2015-02-11T19:51:28.642+03:00" updatedBy="ekaterina@citycycle" readMode="ALL" changeMode="SELF"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>392bcd27-b20e-11e4-90a2-8ecb000ad930</uuid><file created="2015-02-11T19:51:23.363+03:00" filename="logo.png" miniatureUuid="3621a8f7-b20e-11e4-90a2-8ecb000ad8f7" name="logo.png" updated="2015-02-11T19:51:23.543+03:00" updatedBy="ekaterina@citycycle" readMode="ALL" changeMode="NONE"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>3606423a-b20e-11e4-90a2-8ecb000ad8f6</uuid><externalcode>YvJUiPsFg2so7SyR5tnIV1</externalcode></file></attribute><attribute goodUuid="bb0cf1ed-b1ed-11e4-7a40-e89700085026" metadataUuid="6b089715-b1ed-11e4-7a40-e89700084a07" valueString="да" updated="2015-02-11T15:58:53.152+03:00" updatedBy="admin@citycycle" readMode="ALL" changeMode="SELF"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cf7f7-b1ed-11e4-7a40-e8970008502a</uuid></attribute><attribute goodUuid="bb0cf1ed-b1ed-11e4-7a40-e89700085026" metadataUuid="fc04dc6a-985c-11e4-90a2-8ecb00a7e80e" booleanValue="false" updated="2015-02-11T15:58:53.152+03:00" updatedBy="admin@citycycle" readMode="ALL" changeMode="SELF"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cf561-b1ed-11e4-7a40-e89700085027</uuid></attribute><attribute goodUuid="bb0cf1ed-b1ed-11e4-7a40-e89700085026" metadataUuid="6b0892fa-b1ed-11e4-7a40-e89700084a04" timeValue="2015-02-19T16:01:00+03:00" updated="2015-02-11T15:58:53.152+03:00" updatedBy="admin@citycycle" readMode="ALL" changeMode="SELF"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cf75d-b1ed-11e4-7a40-e89700085029</uuid></attribute><attribute goodUuid="bb0cf1ed-b1ed-11e4-7a40-e89700085026" metadataUuid="6b089863-b1ed-11e4-7a40-e89700084a08" valueText="http://citycycle.ru" updated="2015-02-11T15:58:53.152+03:00" updatedBy="admin@citycycle" readMode="ALL" changeMode="SELF"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cf99a-b1ed-11e4-7a40-e8970008502d</uuid></attribute><salePrices><price priceTypeUuid="79e988f6-9ec8-4c43-99e8-964dfbfc5fd3" value="0.0" readMode="ALL" changeMode="ALL"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cfe76-b1ed-11e4-7a40-e89700085034</uuid></price><price priceTypeUuid="3aad66f6-f4f9-4531-a692-1a496c478e13" value="1000.0" readMode="ALL" changeMode="ALL"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cfdcf-b1ed-11e4-7a40-e89700085032</uuid></price><price priceTypeUuid="2a2661c5-8c8a-449c-ab86-f9230455b668" value="0.0" readMode="ALL" changeMode="ALL"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cfd76-b1ed-11e4-7a40-e89700085031</uuid></price><price priceTypeUuid="c277a779-4753-11e3-f9a9-7054d21a8d1e" value="0.0" readMode="ALL" changeMode="ALL"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cfe23-b1ed-11e4-7a40-e89700085033</uuid></price><price priceTypeUuid="5f60590b-713d-4c75-a0fc-88ffc666b212" value="0.0" readMode="ALL" changeMode="ALL"><accountUuid>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountUuid><accountId>49933001-0e7b-11e2-ef0e-3c4a92f3a0a7</accountId><uuid>bb0cfce9-b1ed-11e4-7a40-e89700085030</uuid></price></salePrices><preferences/><images/></good>
@@ -0,0 +1,15 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/1.6.2
3
+ Date: Wed, 12 Aug 2015 07:20:48 GMT
4
+ Content-Type: application/xml
5
+ Content-Length: 4799
6
+ Connection: close
7
+ Vary: Accept-Encoding
8
+ Cache-Control: max-age=0
9
+ Expires: Wed, 12 Aug 2015 07:20:48 GMT
10
+ Strict-Transport-Security: max-age=15552000
11
+
12
+ <?xml version="1.0" encoding="UTF-8"?>
13
+ <collection total="2" start="0" count="1000">
14
+ <workflow name="Company" updated="2015-05-21T08:26:33.431+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f16989a0-ff79-11e4-90a2-8ecb0000fdf2</uuid><code>Company</code><externalcode>tN7veej4jMS9KcyyK-vHX3</externalcode><state name="Новый" updated="2015-05-21T08:26:33.431+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f1698cf1-ff79-11e4-90a2-8ecb0000fdf3</uuid><externalcode>cQXl6qZWgwrSwAdI1uKVO1</externalcode></state><state name="Выслано предложение" updated="2015-05-21T08:26:33.431+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f1698f6d-ff79-11e4-90a2-8ecb0000fdf4</uuid><externalcode>Rfoga-j9hOdp1Vwcxggdj1</externalcode></state><state name="Переговоры" updated="2015-05-21T08:26:33.431+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f1699170-ff79-11e4-90a2-8ecb0000fdf5</uuid><externalcode>IALPXyAfiblZtZBvuGKh00</externalcode></state><state name="Сделка заключена" updated="2015-05-21T08:26:33.431+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f169936c-ff79-11e4-90a2-8ecb0000fdf6</uuid><externalcode>2QbEgpjIiYTHPtHKZm4g02</externalcode></state><state name="Сделка не заключена" updated="2015-05-21T08:26:33.431+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f169959e-ff79-11e4-90a2-8ecb0000fdf7</uuid><externalcode>B9gtJ6eFjxcgerTWLWMoB2</externalcode></state></workflow><workflow name="CustomerOrder" updated="2015-05-21T08:26:33.440+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f16b098e-ff79-11e4-90a2-8ecb0000fdf8</uuid><code>CustomerOrder</code><externalcode>i1qBfRLng9DjiavLTYbQY3</externalcode><state name="Новый" updated="2015-05-21T08:26:33.440+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f16b0ca9-ff79-11e4-90a2-8ecb0000fdf9</uuid><externalcode>5KVb7kdAhZQWTzDjJua8Y2</externalcode></state><state name="Подтвержден" updated="2015-05-21T08:26:33.441+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f16b0eac-ff79-11e4-90a2-8ecb0000fdfa</uuid><externalcode>Z1HGneBcgihh5oUNwoVZJ3</externalcode></state><state name="Собран" updated="2015-05-21T08:26:33.441+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f16b10db-ff79-11e4-90a2-8ecb0000fdfb</uuid><externalcode>a5XhhUNdhQWi33lXkUVap1</externalcode></state><state name="Отгружен" updated="2015-05-21T08:26:33.441+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f16b1305-ff79-11e4-90a2-8ecb0000fdfc</uuid><externalcode>zO4xNkffjTeQbbkURlq8N2</externalcode></state><state name="Доставлен" updated="2015-05-21T08:26:33.441+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f16b153f-ff79-11e4-90a2-8ecb0000fdfd</uuid><externalcode>OVF255slisrP0zULxCJL73</externalcode></state><state name="Возврат" updated="2015-05-21T08:26:33.441+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f16b183a-ff79-11e4-90a2-8ecb0000fdfe</uuid><externalcode>6yBHyHuEjYXFiumpAvz071</externalcode></state><state name="Отменен" updated="2015-05-21T08:26:33.441+03:00" updatedBy="admin@12storeez"><accountUuid>f147c89f-ff79-11e4-90a2-8ecb00000414</accountUuid><accountId>f147c89f-ff79-11e4-90a2-8ecb00000414</accountId><uuid>f16b1a44-ff79-11e4-90a2-8ecb0000fdff</uuid><externalcode>Q4o9Pn16gy9ALQmJqMsA80</externalcode></state></workflow>
15
+ </collection>
@@ -0,0 +1,39 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <good isSerialTrackable="false" weight="0.0" volume="0.0" supplierUuid="c64b1466-a5a2-11e5-7a69-97110001b177" minPrice="0.0" salePrice="499000.0" buyPrice="0.0" archived="false" parentUuid="951a2697-a5a0-11e5-7a69-971100010422" productCode="AJ-001-M-B/Bl/O" name="Nike air jordan 4 NEW 5" updated="2015-12-20T14:02:15.338+03:00" updatedBy="admin@bronx">
3
+ <accountUuid>1539f44c-a412-11e5-7a69-9711000014a3</accountUuid>
4
+ <accountId>1539f44c-a412-11e5-7a69-9711000014a3</accountId>
5
+ <uuid>0779df4f-a5a1-11e5-7a69-93a700078b39</uuid>
6
+ <groupUuid>153a5ed2-a412-11e5-7a69-9711000014a4</groupUuid>
7
+ <ownerUid>admin@bronx</ownerUid>
8
+ <shared>true</shared>
9
+ <code>5728</code>
10
+ <externalcode>5728</externalcode>
11
+ <description/>
12
+ <salePrices>
13
+ <price priceTypeUuid="155b00d1-a412-11e5-7a69-8f5500135f57" value="499000.0">
14
+ <accountUuid>1539f44c-a412-11e5-7a69-9711000014a3</accountUuid>
15
+ <accountId>1539f44c-a412-11e5-7a69-9711000014a3</accountId>
16
+ <uuid>0779e72a-a5a1-11e5-7a69-93a700078b3d</uuid>
17
+ <groupUuid>153a5ed2-a412-11e5-7a69-9711000014a4</groupUuid>
18
+ <ownerUid>admin@bronx</ownerUid>
19
+ <shared>true</shared>
20
+ </price>
21
+ </salePrices>
22
+ <barcode barcode="2000000059280" barcodeType="EAN13">
23
+ <accountUuid>1539f44c-a412-11e5-7a69-9711000014a3</accountUuid>
24
+ <accountId>1539f44c-a412-11e5-7a69-9711000014a3</accountId>
25
+ <uuid>0779e5fc-a5a1-11e5-7a69-93a700078b3c</uuid>
26
+ <groupUuid>153a5ed2-a412-11e5-7a69-9711000014a4</groupUuid>
27
+ <ownerUid>admin@bronx</ownerUid>
28
+ <shared>true</shared>
29
+ </barcode>
30
+ <preferences/>
31
+ <images>
32
+ <image tinyUuid="fe686a63-a708-11e5-7a69-971100051bcf" created="2015-12-20T14:01:17.290+03:00" filename="715ef5cffd4c1a183cba3aadfe549fd2.png" miniatureUuid="fec2f1a9-a708-11e5-7a69-971100051bd6" name="715ef5cffd4c1a183cba3aadfe549fd2" updated="2015-12-20T14:01:17.290+03:00" updatedBy="admin@bronx">
33
+ <accountUuid>1539f44c-a412-11e5-7a69-9711000014a3</accountUuid>
34
+ <accountId>1539f44c-a412-11e5-7a69-9711000014a3</accountId>
35
+ <uuid>fe700e25-a708-11e5-7a69-971100051bd0</uuid>
36
+ <externalcode>VXgiz18ZgWNgMtS-BsdYU1</externalcode>
37
+ </image>
38
+ </images>
39
+ </good>
@@ -3,7 +3,7 @@ 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
8
  p.basePrice = Moysklad::Entities::Price.new
9
9
  p.basePrice.sum = 123
@@ -17,6 +17,12 @@ describe Moysklad::Entities::CustomerOrder do
17
17
  co
18
18
  }
19
19
 
20
+ it 'state' do
21
+ stub_rest 'Workflow', :list, 0
22
+ allow(subject).to receive(:stateUuid).and_return 'f16b0ca9-ff79-11e4-90a2-8ecb0000fdf9'
23
+ expect(subject.state universe).to be_a Moysklad::Entities::WorkflowState
24
+ end
25
+
20
26
  it 'to_xml' do
21
27
  expect(subject.to_xml).to be_a String
22
28
  end
@@ -49,5 +55,4 @@ describe Moysklad::Entities::CustomerOrder do
49
55
  expect(subject.to_xml).to include "<customerOrderPosition"
50
56
  end
51
57
  end
52
-
53
58
  end
@@ -43,4 +43,13 @@ describe Moysklad::Entities::Good do
43
43
  end
44
44
  end
45
45
 
46
+ describe 'image' do
47
+ let(:xml) { File.read './spec/fixtures/good_with_image.xml' }
48
+ subject { described_class.parse xml }
49
+
50
+ it do
51
+ expect(subject.images.image.count).to eq 1
52
+ end
53
+ end
54
+
46
55
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Moysklad::Resources::Workflows do
4
+ before do
5
+ stub_rest 'Workflow'
6
+ end
7
+
8
+ subject { described_class.new client: client }
9
+
10
+ it do
11
+ expect(subject.list.count).to eq 2
12
+ end
13
+
14
+ it do
15
+ expect(subject.send(:list_path)).to eq "exchange/rest/ms/xml/Workflow/list"
16
+ end
17
+
18
+ it do
19
+ expect(subject.list.first).to be_a Moysklad::Entities::Workflow
20
+ end
21
+ end
@@ -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/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