moysklad 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/rspec.yml +29 -0
  3. data/lib/moysklad/client.rb +9 -4
  4. data/lib/moysklad/entities/assortment.rb +0 -2
  5. data/lib/moysklad/entities/attribute.rb +0 -3
  6. data/lib/moysklad/entities/attribute_metadata.rb +0 -2
  7. data/lib/moysklad/entities/attribute_value.rb +3 -4
  8. data/lib/moysklad/entities/characteristic.rb +0 -2
  9. data/lib/moysklad/entities/characteristic_metadata.rb +0 -2
  10. data/lib/moysklad/entities/collection.rb +0 -3
  11. data/lib/moysklad/entities/company_settings_metadata.rb +0 -2
  12. data/lib/moysklad/entities/consignment.rb +0 -3
  13. data/lib/moysklad/entities/context.rb +0 -2
  14. data/lib/moysklad/entities/counterparty.rb +4 -2
  15. data/lib/moysklad/entities/country.rb +2 -8
  16. data/lib/moysklad/entities/currency.rb +0 -2
  17. data/lib/moysklad/entities/custom_entity.rb +0 -3
  18. data/lib/moysklad/entities/customer_order.rb +0 -7
  19. data/lib/moysklad/entities/customer_order_position.rb +0 -4
  20. data/lib/moysklad/entities/employee.rb +0 -2
  21. data/lib/moysklad/entities/entity.rb +0 -3
  22. data/lib/moysklad/entities/group.rb +5 -2
  23. data/lib/moysklad/entities/image.rb +0 -1
  24. data/lib/moysklad/entities/meta.rb +0 -2
  25. data/lib/moysklad/entities/organization.rb +0 -2
  26. data/lib/moysklad/entities/price.rb +0 -1
  27. data/lib/moysklad/entities/price_type.rb +0 -2
  28. data/lib/moysklad/entities/product.rb +0 -7
  29. data/lib/moysklad/entities/productfolder.rb +0 -2
  30. data/lib/moysklad/entities/rate.rb +0 -3
  31. data/lib/moysklad/entities/resource_metadata.rb +0 -5
  32. data/lib/moysklad/entities/service.rb +5 -10
  33. data/lib/moysklad/entities/shortcut.rb +0 -2
  34. data/lib/moysklad/entities/store.rb +0 -1
  35. data/lib/moysklad/entities/uom.rb +0 -2
  36. data/lib/moysklad/entities/variant.rb +0 -4
  37. data/lib/moysklad/entities.rb +42 -35
  38. data/lib/moysklad/resources/assortments.rb +0 -1
  39. data/lib/moysklad/resources/base.rb +4 -3
  40. data/lib/moysklad/resources/custom_entities.rb +3 -1
  41. data/lib/moysklad/resources/custom_entity_metadata.rb +1 -1
  42. data/lib/moysklad/resources/embedded_entity_metadata.rb +2 -2
  43. data/lib/moysklad/resources/indexed.rb +1 -5
  44. data/lib/moysklad/resources/positions.rb +15 -0
  45. data/lib/moysklad/resources/stock.rb +1 -1
  46. data/lib/moysklad/resources/subresource.rb +0 -1
  47. data/lib/moysklad/resources.rb +22 -9
  48. data/lib/moysklad/universe.rb +1 -1
  49. data/lib/moysklad/version.rb +1 -1
  50. data/lib/moysklad.rb +11 -7
  51. data/moysklad.gemspec +2 -2
  52. data/spec/lib/moysklad/entities/customer_order_position_spec.rb +4 -17
  53. data/spec/lib/moysklad/entities/customer_order_spec.rb +7 -37
  54. data/spec/lib/moysklad/resources/base_spec.rb +0 -54
  55. data/spec/lib/moysklad/resources_spec.rb +0 -2
  56. data/spec/lib/moysklad/universe_spec.rb +0 -23
  57. data/spec/lib/moysklad_spec.rb +0 -1
  58. data/spec/support/resource.rb +1 -66
  59. metadata +10 -146
  60. data/.travis.yml +0 -5
  61. data/lib/moysklad/entities/attachment_document.rb +0 -16
  62. data/lib/moysklad/entities/barcode.rb +0 -19
  63. data/lib/moysklad/entities/common_object.rb +0 -27
  64. data/lib/moysklad/entities/company.rb +0 -20
  65. data/lib/moysklad/entities/company_concern.rb +0 -20
  66. data/lib/moysklad/entities/contact.rb +0 -15
  67. data/lib/moysklad/entities/custom_entity_metadata.rb +0 -11
  68. data/lib/moysklad/entities/embedded_entity_metadata.rb +0 -18
  69. data/lib/moysklad/entities/error.rb +0 -13
  70. data/lib/moysklad/entities/good_folder.rb +0 -10
  71. data/lib/moysklad/entities/good_ref.rb +0 -12
  72. data/lib/moysklad/entities/images.rb +0 -10
  73. data/lib/moysklad/entities/my_company.rb +0 -12
  74. data/lib/moysklad/entities/sale_price.rb +0 -18
  75. data/lib/moysklad/entities/sale_prices.rb +0 -10
  76. data/lib/moysklad/entities/slot.rb +0 -10
  77. data/lib/moysklad/entities/workflow.rb +0 -11
  78. data/lib/moysklad/entities/workflow_state.rb +0 -8
  79. data/spec/fixtures/302.raw +0 -15
  80. data/spec/fixtures/400.raw +0 -8
  81. data/spec/fixtures/401.html +0 -1
  82. data/spec/fixtures/401_2.html +0 -1
  83. data/spec/fixtures/405.raw +0 -9
  84. data/spec/fixtures/500.raw +0 -8
  85. data/spec/fixtures/502.raw +0 -8
  86. data/spec/fixtures/Consignment_list_0.raw +0 -14
  87. data/spec/fixtures/Consignment_list_1000.raw +0 -14
  88. data/spec/fixtures/Country_list.raw +0 -14
  89. data/spec/fixtures/CustomEntityMetadata_list.raw +0 -14
  90. data/spec/fixtures/CustomEntity_list.raw +0 -14
  91. data/spec/fixtures/CustomEntity_list_bad_chars.raw +0 -17
  92. data/spec/fixtures/EmbeddedEntityMetadata_list.raw +0 -15
  93. data/spec/fixtures/Feature_list.raw +0 -14
  94. data/spec/fixtures/Feature_list_1000.raw +0 -14
  95. data/spec/fixtures/Good_WithManyAttributes.raw +0 -13
  96. data/spec/fixtures/Good_e932ebe1-2e22-11e4-9406-002590a28eca.raw +0 -12
  97. data/spec/fixtures/Good_eb77ad57-2e22-11e4-4030-002590a28eca.raw +0 -12
  98. data/spec/fixtures/Goods_list.raw +0 -14
  99. data/spec/fixtures/Metadata_list.raw +0 -14
  100. data/spec/fixtures/PriceType_list.raw +0 -14
  101. data/spec/fixtures/Stock.raw +0 -11
  102. data/spec/fixtures/Stock_showConsignments.raw +0 -11
  103. data/spec/fixtures/Uom_list.raw +0 -14
  104. data/spec/fixtures/Warehouse_list.raw +0 -14
  105. data/spec/fixtures/Workflow_list.raw +0 -15
  106. data/spec/fixtures/attribute_boolean.xml +0 -6
  107. data/spec/fixtures/attribute_dictionary.xml +0 -5
  108. data/spec/fixtures/attribute_double.xml +0 -6
  109. data/spec/fixtures/attribute_file.xml +0 -12
  110. data/spec/fixtures/attribute_long.xml +0 -6
  111. data/spec/fixtures/attribute_text.xml +0 -5
  112. data/spec/fixtures/attribute_time.xml +0 -6
  113. data/spec/fixtures/attribute_url.xml +0 -6
  114. data/spec/fixtures/bad_chars.xml +0 -6
  115. data/spec/fixtures/customer_order.xml +0 -28
  116. data/spec/fixtures/good_with_attributes.raw +0 -12
  117. data/spec/fixtures/good_with_image.xml +0 -39
  118. data/spec/fixtures/resource_forbidden.raw +0 -9
  119. data/spec/fixtures/wrong_password.raw +0 -9
  120. data/spec/fixtures/wrong_type.raw +0 -70
  121. data/spec/fixtures/wrong_user.raw +0 -9
  122. data/spec/lib/moysklad/client/errors_spec.rb +0 -102
  123. data/spec/lib/moysklad/entities/attribute_metadata_spec.rb +0 -30
  124. data/spec/lib/moysklad/entities/attribute_spec.rb +0 -36
  125. data/spec/lib/moysklad/entities/country_spec.rb +0 -25
  126. data/spec/lib/moysklad/entities/custom_entity_metadata_spec.rb +0 -34
  127. data/spec/lib/moysklad/entities/custom_entity_spec.rb +0 -34
  128. data/spec/lib/moysklad/entities/good_spec.rb +0 -55
  129. data/spec/lib/moysklad/resources/countries_spec.rb +0 -22
  130. data/spec/lib/moysklad/resources/custom_entity_metadata_spec.rb +0 -13
  131. data/spec/lib/moysklad/resources/embedded_entity_metadata_indexed_spec.rb +0 -20
  132. data/spec/lib/moysklad/resources/embedded_entity_metadata_spec.rb +0 -11
  133. data/spec/lib/moysklad/resources/good_folders_spec.rb +0 -17
  134. data/spec/lib/moysklad/resources/indexed_spec.rb +0 -61
  135. data/spec/lib/moysklad/resources/stock_spec.rb +0 -63
  136. data/spec/lib/moysklad/resources/warehouses_spec.rb +0 -20
  137. data/spec/lib/moysklad/resources/workflows_spec.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0434de2e989bb1cb0ca34205101ee8c0e978540b
4
- data.tar.gz: ccd6cc1de782b6baf31c331b7e20fe9d7a5c5698
2
+ SHA256:
3
+ metadata.gz: abdc083d3dbc4b8020ce96a71f348d4da052c9a9a85ff66acb1b5c16e3ba1a89
4
+ data.tar.gz: e925e1cd59dda2dffa9cb16b855989ed35901239ca1e56d08ae9c6d9d4db8bb8
5
5
  SHA512:
6
- metadata.gz: 9beac30a1c510af7d1aff68e5a24ede6d24ec6cf86fdee7486e0e6826c5410a9b0212523ea649076f6575935af3c7ad751c01c58f78e086a54f77cdc9bd9970b
7
- data.tar.gz: cf62d29570bae5e6f4dfae85ee1ca4f283a55a95e28a7b898c1f2bb768d530a011aaae5f72b5ec9a9880b66d310f197788861e62e08ce835e2f9276c3276090c
6
+ metadata.gz: 10c0597144a06f4c3b243c3f8309a2ae1d241dfbe575280a9dd1d9144c4040a29441229ba392c6ddf51bbb52916f414dbdb14822c5ac22270fed77061f05a966
7
+ data.tar.gz: 6d374cfec6e3985bad837f7d82a26d50cc9436c3a5f6f5b54c3fe940fa75337f9743e176d70d0e5db1281cffa9a7a0d3e6a3fefbe1e373853a2c5b776b80fbc0
@@ -0,0 +1,29 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Rspec
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - name: Checkout repository and submodules
21
+ uses: actions/checkout@v2
22
+ with:
23
+ submodules: recursive
24
+ - name: Set up Ruby
25
+ uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: 3.1.4
28
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
29
+ - run: bundle exec rspec
@@ -8,8 +8,13 @@ class Moysklad::Client
8
8
  URL ='https://online.moysklad.ru/api/remap/1.1/'
9
9
 
10
10
  def initialize login: nil, password: nil
11
- @client = Faraday.new URL
12
- @client.basic_auth login, password
11
+ @client = Faraday.new URL do |conn|
12
+ if Faraday::VERSION.split('.').first.to_i < 2
13
+ conn.request(:basic_auth, login, password)
14
+ else
15
+ conn.request(:authorization, :basic, login, password)
16
+ end
17
+ end
13
18
  end
14
19
 
15
20
  def download(path, filename)
@@ -28,7 +33,6 @@ class Moysklad::Client
28
33
  req.url path
29
34
  req.headers['Content-Type'] = 'application/json'
30
35
  req.headers['Accept'] = '*/*'
31
- puts data
32
36
  req.body = data
33
37
  end
34
38
  parse_response result
@@ -64,8 +68,9 @@ class Moysklad::Client
64
68
  end
65
69
 
66
70
  def parse_response res
71
+ Moysklad.logger.debug "Response [#{res.status}]: #{res.body}"
72
+
67
73
  if res.status == 200
68
- Moysklad.logger.info "Response: #{res.body}"
69
74
  return if res.body.blank?
70
75
  JSON.parse res.body
71
76
  else
@@ -1,5 +1,3 @@
1
- require_relative 'entity'
2
-
3
1
  module Moysklad::Entities
4
2
  class Assortment < Entity
5
3
  end
@@ -1,6 +1,3 @@
1
- require_relative 'attribute_value'
2
- require_relative 'meta'
3
-
4
1
  # Атрибут товара (ссылка на его тип и его значение)
5
2
  module Moysklad::Entities
6
3
  class Attribute < Base
@@ -1,5 +1,3 @@
1
- require_relative 'attribute_value'
2
-
3
1
  module Moysklad::Entities
4
2
  class AttributeMetadata < Base
5
3
  attribute :meta, Meta
@@ -1,11 +1,10 @@
1
- require_relative 'custom_entity'
2
-
3
1
  module Moysklad::Entities
4
2
  class AttributeValue < Virtus::Attribute
5
3
  def coerce(value)
6
- if value.is_a? String
4
+ case value
5
+ when String, Float
7
6
  value
8
- elsif value.is_a? ::Hash
7
+ when ::Hash
9
8
  if value['meta']['type'] == 'customentity'
10
9
  CustomEntity.new value
11
10
  else
@@ -1,5 +1,3 @@
1
- require_relative 'attribute'
2
-
3
1
  module Moysklad::Entities
4
2
  class Characteristic < Attribute
5
3
  end
@@ -1,5 +1,3 @@
1
- require_relative 'attribute_metadata'
2
-
3
1
  module Moysklad::Entities
4
2
  class CharacteristicMetadata < AttributeMetadata
5
3
  end
@@ -1,6 +1,3 @@
1
- require_relative 'context'
2
- require_relative 'collection_meta'
3
-
4
1
  module Moysklad::Entities
5
2
  class RowItems < Virtus::Attribute
6
3
  include ActiveSupport::Inflector
@@ -1,5 +1,3 @@
1
- require_relative 'meta'
2
-
3
1
  module Moysklad::Entities
4
2
  class EntityMeta < Base
5
3
  attribute :href, String
@@ -1,6 +1,3 @@
1
- require_relative 'entity'
2
- require_relative 'assortment'
3
-
4
1
  module Moysklad::Entities
5
2
  class Consignment < Entity
6
3
  attribute :meta, Meta
@@ -1,5 +1,3 @@
1
- require_relative 'employee'
2
-
3
1
  module Moysklad::Entities
4
2
  class Context
5
3
  include Virtus.model
@@ -1,5 +1,3 @@
1
- require_relative 'entity'
2
-
3
1
  module Moysklad::Entities
4
2
  class Counterparty < Entity
5
3
  attribute :email, String
@@ -14,5 +12,9 @@ module Moysklad::Entities
14
12
  attribute :kpp, String
15
13
  attribute :ogrn, String
16
14
  attribute :okpo, String
15
+
16
+ attribute :description, String
17
+
18
+ attribute :syncid, String
17
19
  end
18
20
  end
@@ -1,10 +1,4 @@
1
1
  module Moysklad::Entities
2
- class Country < Base
3
- include CommonObject
4
- include Moysklad::Entities::XmlFix
5
-
6
- tag 'country'
7
-
8
- element :code, String
2
+ class Country < Entity
9
3
  end
10
- end
4
+ end
@@ -1,5 +1,3 @@
1
- require_relative 'meta'
2
-
3
1
  module Moysklad::Entities
4
2
  class Currency < Base
5
3
  class Unit < Base
@@ -1,6 +1,3 @@
1
- require_relative 'meta'
2
- require_relative 'context'
3
-
4
1
  # Элемент в справочнике (DictionaryEntity)
5
2
  module Moysklad::Entities
6
3
  class CustomEntity < Base
@@ -1,10 +1,3 @@
1
- require_relative 'entity'
2
- require_relative 'owner'
3
- require_relative 'group'
4
- require_relative 'rate'
5
- require_relative 'customer_order_position'
6
- require_relative 'time'
7
-
8
1
  module Moysklad::Entities
9
2
  # Пример:
10
3
  # https://online.moysklad.ru/api/remap/1.1/doc/index.html#документ-заказ-покупателя
@@ -1,7 +1,3 @@
1
- require_relative 'base'
2
- require_relative 'meta'
3
- require_relative 'assortment'
4
-
5
1
  module Moysklad::Entities
6
2
  class CustomerOrderPosition < Base
7
3
  attribute :quantity, Integer
@@ -1,5 +1,3 @@
1
- require_relative 'meta'
2
-
3
1
  module Moysklad::Entities
4
2
  class Employee < Base
5
3
  attribute :meta, Meta
@@ -1,6 +1,3 @@
1
- require_relative 'base'
2
- require_relative 'meta'
3
-
4
1
  module Moysklad::Entities
5
2
  class Entity < Base
6
3
 
@@ -1,7 +1,10 @@
1
- require_relative 'meta'
2
-
3
1
  module Moysklad::Entities
4
2
  class Group < Base
5
3
  attribute :meta, Meta
4
+ attribute :name, String
5
+
6
+ def id
7
+ URI.parse(meta['href']).path.split('/').last
8
+ end
6
9
  end
7
10
  end
@@ -1,4 +1,3 @@
1
- require_relative 'base'
2
1
  module Moysklad::Entities
3
2
  class Image < Base
4
3
  attribute :meta, Meta
@@ -1,5 +1,3 @@
1
- require_relative 'base'
2
-
3
1
  module Moysklad::Entities
4
2
  class Meta < Base
5
3
  attribute :href, String
@@ -1,5 +1,3 @@
1
- require_relative 'entity'
2
-
3
1
  module Moysklad::Entities
4
2
  class Organization < Entity
5
3
  attribute :externalCode, String
@@ -1,4 +1,3 @@
1
- require_relative 'currency'
2
1
  module Moysklad::Entities
3
2
  class Price < Base
4
3
  attribute :value, Float
@@ -1,5 +1,3 @@
1
- require_relative 'base'
2
-
3
1
  module Moysklad::Entities
4
2
  class PriceType < Base
5
3
  attribute :name, String
@@ -1,10 +1,3 @@
1
- require_relative 'currency'
2
- require_relative 'productfolder'
3
- require_relative 'uom'
4
- require_relative 'entity'
5
- require_relative 'attribute_metadata'
6
- require_relative 'image'
7
-
8
1
  module Moysklad::Entities
9
2
  class Product < Entity
10
3
  attribute :accountId, String
@@ -1,5 +1,3 @@
1
- require_relative 'entity'
2
-
3
1
  module Moysklad::Entities
4
2
  class Productfolder < Entity
5
3
  attribute :accountId, String
@@ -1,6 +1,3 @@
1
- require_relative 'base'
2
- require_relative 'currency'
3
-
4
1
  module Moysklad::Entities
5
2
  class Rate < Base
6
3
  attribute :currency, Currency
@@ -1,8 +1,3 @@
1
- require_relative 'base'
2
- require_relative 'attribute_metadata'
3
- require_relative 'characteristic_metadata'
4
- require_relative 'price_type'
5
-
6
1
  module Moysklad::Entities
7
2
  class ResourceMetadata < Base
8
3
  attribute :meta, Meta
@@ -1,9 +1,3 @@
1
- require_relative 'entity'
2
- require_relative 'uom'
3
- require_relative 'owner'
4
- require_relative 'group'
5
- require_relative 'price'
6
-
7
1
  module Moysklad::Entities
8
2
  class Service < Entity
9
3
  attribute :accountId, String
@@ -13,6 +7,7 @@ module Moysklad::Entities
13
7
  attribute :effectiveVat, Float
14
8
  attribute :pathName, String
15
9
  attribute :productFolder, Productfolder
10
+ attribute :description, String
16
11
 
17
12
  attribute :uom, Uom
18
13
 
@@ -20,9 +15,9 @@ module Moysklad::Entities
20
15
  attribute :salePrices, Array[Price]
21
16
 
22
17
  # Когда загружаем через ассортименты эти поля устанавливаются
23
- attribute :stock, Float
24
- attribute :reserve, Float
25
- attribute :inTransit, Float
26
- attribute :quantity, Float
18
+ # attribute :stock, Float
19
+ # attribute :reserve, Float
20
+ # attribute :inTransit, Float
21
+ # attribute :quantity, Float
27
22
  end
28
23
  end
@@ -1,5 +1,3 @@
1
- require_relative 'meta'
2
-
3
1
  module Moysklad::Entities
4
2
  class Shortcut < Base
5
3
  attribute :meta, Meta
@@ -1,4 +1,3 @@
1
- require_relative 'entity'
2
1
  module Moysklad::Entities
3
2
  class Store < Entity
4
3
  attribute :address, String
@@ -1,5 +1,3 @@
1
- require_relative 'meta'
2
-
3
1
  module Moysklad::Entities
4
2
  class Uom < Base
5
3
  attribute :meta, Meta
@@ -1,7 +1,3 @@
1
- require_relative 'characteristic'
2
- require_relative 'shortcut'
3
- require_relative 'entity'
4
-
5
1
  module Moysklad::Entities
6
2
  class Variant < Entity
7
3
 
@@ -1,42 +1,49 @@
1
1
  module Moysklad
2
2
  module Entities
3
- extend ActiveSupport::Autoload
4
3
  %w{
5
- AttachmentDocument
6
- Uom
7
- Productfolder
8
- Product
9
- Bundle
10
- Barcode
11
- Error
12
- Consignment
13
- MyCompany
14
- Attribute
15
- GoodRef
16
- Base
17
- Counterparty
18
- Organization
19
- CustomerOrder
20
- CustomerOrderPosition
21
- CustomEntity
22
- Variant
23
- AttributeMetadata
24
- EmbeddedEntityMetadata
25
- CompanySettingsMetadata
26
- Price
27
- Currency
28
- Company
29
- Store
30
- Service
31
- Owner
32
- Group
33
- Collection
34
- Page
35
- ResourceMetadata
36
- Attribute
37
- Characteristic
4
+ base
5
+ meta
6
+ entity
7
+ country
8
+ assortment
9
+ attribute_value
10
+ attribute
11
+ attribute_metadata
12
+ owner
13
+ group
14
+ productfolder
15
+ uom
16
+ currency
17
+ price
18
+ image
19
+ employee
20
+ context
21
+ product
22
+ bundle
23
+ characteristic
24
+ characteristic_metadata
25
+ collection_meta
26
+ collection
27
+ company_settings_metadata
28
+ consignment
29
+ contract
30
+ counterparty
31
+ custom_entity
32
+ rate
33
+ customer_order
34
+ customer_order_position
35
+ organization
36
+ page
37
+ price_type
38
+ rate
39
+ resource_metadata
40
+ service
41
+ shortcut
42
+ store
43
+ time
44
+ variant
38
45
  }.each do |m|
39
- autoload m
46
+ require_relative "entities/#{m}"
40
47
  end
41
48
  end
42
49
  end
@@ -1,4 +1,3 @@
1
- require_relative 'load_all'
2
1
  module Moysklad::Resources
3
2
  class Assortments < Base
4
3
  include LoadAll
@@ -1,5 +1,6 @@
1
- require 'json'
2
1
  class Moysklad::Resources::Base
2
+ include Moysklad::Resources::Positions
3
+
3
4
  PREFIX_PATH = 'entity/'
4
5
 
5
6
  def self.inherited superclass
@@ -10,8 +11,8 @@ class Moysklad::Resources::Base
10
11
  # Возвращает этот-же ресурс только индексированный
11
12
  #
12
13
  # @return [Moysklad::Resources::Indexed]
13
- def self.indexed *args
14
- Moysklad::Resources::Indexed.new new(*args)
14
+ def self.indexed client: nil, list_path: nil
15
+ Moysklad::Resources::Indexed.new new(client: client, list_path: list_path)
15
16
  end
16
17
 
17
18
  # https://support.moysklad.ru/hc/ru/articles/203404253-REST-сервис-синхронизации-данных
@@ -2,7 +2,9 @@ module Moysklad::Resources
2
2
  # Элементы словаря
3
3
  class CustomEntities < Base
4
4
  # custom_entity_meta_id - id словаря, элементы которого хотим получить
5
- def initialize custom_entity_meta_id: nil, client:, list_path: nil
5
+ def initialize(custom_entity_meta_id: nil, client: nil, list_path: nil)
6
+ raise 'Client empty' if client.nil? # support ruby 2.0.0
7
+
6
8
  @custom_entity_meta_id = custom_entity_meta_id
7
9
  super client: client, list_path: list_path
8
10
  end
@@ -5,7 +5,7 @@ module Moysklad::Resources
5
5
  # https://online.moysklad.ru/api/remap/1.1/entity/product/metadata/
6
6
  class CustomEntityMetadata < Base
7
7
 
8
- def list
8
+ def list(_params)
9
9
  raise
10
10
  end
11
11
 
@@ -12,8 +12,8 @@ module Moysklad::Resources
12
12
  :embedded_entity_metadata
13
13
  end
14
14
 
15
- def self.indexed *args
16
- Moysklad::Resources::EmbeddedEntityMetadataIndexed.new new(*args)
15
+ def self.indexed client: nil, list_path: nil
16
+ Moysklad::Resources::EmbeddedEntityMetadataIndexed.new new(client: client, list_path: list_path)
17
17
  end
18
18
  end
19
19
  end
@@ -1,7 +1,3 @@
1
- require_relative 'where_filter'
2
- require_relative 'load_all'
3
- require_relative 'indexed_cache'
4
-
5
1
  module Moysklad::Resources
6
2
  class Indexed < SimpleDelegator
7
3
  WrongEntriesCountError = Class.new StandardError
@@ -58,7 +54,7 @@ module Moysklad::Resources
58
54
  cached_index
59
55
  end
60
56
 
61
- def pull_list(params)
57
+ def pull_list(params={})
62
58
  load_all(params)
63
59
  end
64
60
 
@@ -0,0 +1,15 @@
1
+ # API сервиса МойСклад позволяет оперировать с такими документами как Отгрузка, Заказ покупателя, Счёт покупателю, Розничная продажа.
2
+ # Перечисленные документы содержат позиции, работать с которыми можно как в составе отдельного документа, так и с помощью специальных ресурсов для управления позициями документа.
3
+
4
+ module Moysklad::Resources::Positions
5
+ # Создаем позицию документа по uuid
6
+ #
7
+ # @return [Moysklad::Entities::Base]
8
+ def create_position model_uuid, position
9
+ position.class.build client.post(create_position_path(model_uuid), position.to_json)
10
+ end
11
+
12
+ def create_position_path(model_uuid)
13
+ [prefix_path, model_uuid, 'positions'].join('/')
14
+ end
15
+ end
@@ -6,7 +6,7 @@ module Moysklad::Resources
6
6
  end
7
7
 
8
8
  def all
9
- page.items
9
+ list
10
10
  end
11
11
 
12
12
  def find
@@ -1,4 +1,3 @@
1
- require_relative 'where_filter'
2
1
  module Moysklad::Resources
3
2
  class Subresource < Struct.new(:items)
4
3
  include WhereFilter
@@ -1,26 +1,39 @@
1
1
  module Moysklad::Resources
2
2
  mattr_accessor :resources
3
3
 
4
- extend ActiveSupport::Autoload
5
-
6
4
  def self.register_resource resource_class
7
5
  self.resources ||= []
8
6
  self.resources << resource_class
9
7
  end
10
8
 
11
- require_relative 'resources/base'
12
- require_relative 'resources/indexed'
13
- require_relative 'resources/custom_entities'
14
- require_relative 'resources/assortments'
9
+ %w{
10
+ positions
11
+ base
12
+ load_all
13
+ assortments
14
+ custom_entities
15
+ custom_entity_metadata
16
+ embedded_entity_metadata
17
+ where_filter
18
+ indexed_cache
19
+ indexed
20
+ embedded_entity_metadata_indexed
21
+ products
22
+ stock
23
+ subresource
24
+ }.each do |m|
25
+ require_relative "resources/#{m}"
26
+ end
15
27
 
16
28
  # Простые ресурсы, которые создаются автоматически
17
- %w{Products Productfolders Uoms PriceType Countries Variants
29
+ %w{Productfolders Uoms PriceType Countries Variants
18
30
  Counterparty
19
31
  Organization
32
+ Service
33
+ Bundle
20
34
  CustomerOrders Store
21
35
  Currency
22
- Workflows
23
- Companies Consignments MyCompanies}.each do |klass_name|
36
+ Consignments Group}.each do |klass_name|
24
37
  const_set klass_name, Class.new( Base )
25
38
  end
26
39
  end
@@ -40,7 +40,7 @@ module Moysklad
40
40
  Moysklad::Resources.resources.each do |resource_klass|
41
41
  @@resources_list << resource_klass.pluralized_type.to_sym
42
42
  define_method resource_klass.pluralized_type do |opts={}|
43
- @resources[resource_klass.type] ||= resource_klass.indexed( opts.merge client: client )
43
+ @resources[resource_klass.type] ||= resource_klass.indexed( **opts.merge(client: client) )
44
44
  end
45
45
  end
46
46
 
@@ -1,3 +1,3 @@
1
1
  module Moysklad
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.2"
3
3
  end