moysklad 0.3.4 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a56ce8eb66a010543868f61ec27181f39c1aea72452e8c02597c850f8980f39e
4
- data.tar.gz: 58c9aeff4402bb50fc03c3790c8a96ad3e72b51a75e967c46dafe91a4ffee853
3
+ metadata.gz: ac800af878e9eda7d3452b7b4b416dfd9e88b834bec446e18f77a12a8a1d7f08
4
+ data.tar.gz: e70f8fed1d9a27dc108380900037517c818e73e8d3456f33b76b82ee59a6a3ee
5
5
  SHA512:
6
- metadata.gz: 87330dee8f7938f0afd81f19f8e3bed3935caeafa39d45f8e2d83548ef1b8d37067fc1a42534a6a8ffd7424313a6e33d9ac33851c2f357b980d891ee0cd1e156
7
- data.tar.gz: 6e9a856cf5679a24070e66c3d5832e4e68f7fe6c8cd4a091ce12dd89d2a41ff28ef5efe41578b7e48ee9a6ecb550dc1f1ffa33390ed33b3005ff6b587a9fd148
6
+ metadata.gz: af8dfe3809f719f2aa9ee89214adf498d16a0d2b735c413e5dc373a1b2fcf507bfa726d43f5404799369e63e3173ce68d4e238b3c96b9dd9e8a412876e1b6bbe
7
+ data.tar.gz: 4ac7ad746a4ddd88170c7a0813903ebf68762528a83c98793c71e0b11d119c42896e4a2e490051c332fd6b738831fbe07693629e5c3997a4936e3aeec4c93863
@@ -0,0 +1,16 @@
1
+ # Concern
2
+ module AttributesConverter
3
+ def initialize(data = {})
4
+ if data['attributes']
5
+ if data['attributes'].is_a? Array
6
+ data['attrs'] = data.delete 'attributes'
7
+ binding.pry
8
+ elsif data['attributes'].is_a? Hash
9
+ puts data['attributes']
10
+ else
11
+ binding.pry
12
+ end
13
+ end
14
+ super data
15
+ end
16
+ end
@@ -1,14 +1,20 @@
1
1
  require 'faraday'
2
+ require 'faraday/detailed_logger'
3
+ require 'faraday_curl'
2
4
 
3
5
  require_relative 'client/errors'
4
6
 
5
7
  class Moysklad::Client
8
+ URL ='https://api.moysklad.ru/api/remap/1.2/'
6
9
 
7
- # URL = 'https://online.moysklad.ru'
8
- URL ='https://online.moysklad.ru/api/remap/1.1/'
9
-
10
- def initialize login: nil, password: nil
10
+ def initialize login: nil, password: nil, logger: nil
11
11
  @client = Faraday.new URL do |conn|
12
+ unless logger.nil?
13
+ binding.pry
14
+ conn.response :detailed_logger, logger
15
+ conn.request :curl, logger, :info
16
+ end
17
+
12
18
  conn.options.timeout = ENV.fetch('MOYSKLAD_HTTP_TIMEOUT', 120)
13
19
  if Faraday::VERSION.split('.').first.to_i < 2
14
20
  conn.request(:basic_auth, login, password)
@@ -34,6 +40,7 @@ class Moysklad::Client
34
40
  req.url path
35
41
  req.headers['Content-Type'] = 'application/json'
36
42
  req.headers['Accept'] = '*/*'
43
+ req.headers['Accept-Encoding'] = 'gzip'
37
44
  req.body = data
38
45
  end
39
46
  parse_response result
@@ -45,6 +52,7 @@ class Moysklad::Client
45
52
  req.url path
46
53
  req.headers['Content-Type'] = 'application/json'
47
54
  req.headers['Accept'] = '*/*'
55
+ req.headers['Accept-Encoding'] = 'gzip'
48
56
  req.body = data
49
57
  end
50
58
  parse_response result
@@ -56,6 +64,7 @@ class Moysklad::Client
56
64
  req.url path
57
65
  req.headers['Content-Type'] = 'application/json'
58
66
  req.headers['Accept'] = '*/*'
67
+ req.headers['Accept-Encoding'] = 'gzip'
59
68
  end
60
69
  parse_response result
61
70
  end
@@ -10,11 +10,6 @@ module Moysklad::Entities
10
10
  entity
11
11
  end
12
12
 
13
- def initialize(data = {})
14
- data['attrs'] = data.delete 'attributes' if data['attributes']
15
- super (data || {}).merge(dump: data)
16
- end
17
-
18
13
  def to_json(*args)
19
14
  presented = {}
20
15
  to_h.each_pair do |k, v|
@@ -1,17 +1,12 @@
1
1
  # Элемент в справочнике (DictionaryEntity)
2
2
  module Moysklad::Entities
3
3
  class CustomEntity < Base
4
- attribute :meta, Meta
5
- attribute :accountId, String
6
- attribute :id, String
7
- attribute :name, String
8
- attribute :externalCode, String
9
- attribute :description, String
10
-
11
- # TODO remove
12
- def entityMetadataUuid
13
- dictionaryId
14
- end
4
+ attribute :meta, Meta
5
+ attribute :accountId, String
6
+ attribute :id, String
7
+ attribute :name, String
8
+ attribute :externalCode, String
9
+ attribute :description, String
15
10
 
16
11
  # ID Словаря
17
12
  def dictionaryId
@@ -1,9 +1,9 @@
1
1
  module Moysklad::Entities
2
2
  class Meta < Base
3
- attribute :href, String
3
+ attribute :href, String
4
4
  attribute :metadataHref, String
5
- attribute :type, String
6
- attribute :mediaType, String # application/json
5
+ attribute :type, String
6
+ attribute :mediaType, String # application/json
7
7
 
8
8
  def id
9
9
  @id ||= href.split('/').last
@@ -1,5 +1,6 @@
1
1
  module Moysklad::Entities
2
2
  class Organization < Entity
3
+ include AttributesConverter
3
4
  attribute :externalCode, String
4
5
  attribute :archived, Boolean
5
6
  attribute :companyType, String
@@ -2,7 +2,7 @@ module Moysklad::Entities
2
2
  class Price < Base
3
3
  attribute :value, Float
4
4
  attribute :currency, Currency
5
- attribute :priceType, String # Цена продажи/ Распродажа
5
+ attribute :priceType, PriceType # Цена продажи/ Распродажа
6
6
 
7
7
  def self.from_money money
8
8
  raise 'not implemented'
@@ -1,5 +1,6 @@
1
1
  module Moysklad::Entities
2
2
  class Product < Entity
3
+ include AttributesConverter
3
4
  attribute :accountId, String
4
5
  attribute :owner, Owner
5
6
  attribute :group, Group
@@ -1,5 +1,6 @@
1
1
  module Moysklad::Entities
2
2
  class ResourceMetadata < Base
3
+ include AttributesConverter
3
4
  attribute :meta, Meta
4
5
  attribute :attrs, Array[AttributeMetadata]
5
6
  attribute :characteristics, Array[CharacteristicMetadata]
@@ -1,5 +1,6 @@
1
1
  module Moysklad::Entities
2
2
  class Store < Entity
3
+ include AttributesConverter
3
4
  attribute :address, String
4
5
  attribute :description, String
5
6
  attribute :parent, Hash
@@ -13,7 +13,8 @@ module Moysklad
13
13
  group
14
14
  productfolder
15
15
  uom
16
- currency
16
+ currency
17
+ price_type
17
18
  price
18
19
  image
19
20
  employee
@@ -34,7 +35,6 @@ module Moysklad
34
35
  customer_order_position
35
36
  organization
36
37
  page
37
- price_type
38
38
  rate
39
39
  resource_metadata
40
40
  service
@@ -15,25 +15,20 @@ module Moysklad
15
15
  end
16
16
 
17
17
  def company_settings_metadata
18
- Moysklad::Entities::CompanySettingsMetadata.build client.get('entity/companysettings/metadata'), self
18
+ @company_settings_metadata ||= Moysklad::Entities::CompanySettingsMetadata.build client.get('context/companysettings/metadata'), self
19
19
  end
20
20
 
21
21
  # Все элементы всех словарей
22
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
23
+ @all_custom_entities ||= company_settings_metadata.customEntities.map { |d| d.entities(self) }.flatten
29
24
  end
30
25
 
31
26
  # Ленивое создание universe
32
27
  #
33
28
  # @param login
34
29
  # @param password
35
- def self.build login: nil, password: nil
36
- new client: client_class.new(login: login, password: password)
30
+ def self.build login: nil, password: nil, logger: nil
31
+ new client: client_class.new(login: login, password: password, logger: nil)
37
32
  end
38
33
 
39
34
  @@resources_list = []
@@ -47,7 +42,5 @@ module Moysklad
47
42
  def class_by_resource resource
48
43
  "Moysklad::Resources::#{resource.to_s.singularize.capitalize}".constantize
49
44
  end
50
-
51
45
  end
52
-
53
46
  end
@@ -1,3 +1,3 @@
1
1
  module Moysklad
2
- VERSION = '0.3.4'
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/moysklad.rb CHANGED
@@ -2,6 +2,7 @@ require 'virtus'
2
2
  require 'json'
3
3
  require 'active_support'
4
4
  require 'moysklad/version'
5
+ require 'moysklad/attributes_converter'
5
6
 
6
7
  require 'logger'
7
8
 
data/moysklad.gemspec CHANGED
@@ -37,4 +37,6 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency 'guard-ctags-bundler'
38
38
  spec.add_development_dependency 'yard'
39
39
  spec.add_development_dependency 'minitest', '~> 5.1'
40
+ spec.add_development_dependency 'faraday-detailed_logger'
41
+ spec.add_development_dependency 'faraday_curl', '~> 0.0.2'
40
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moysklad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danil Pismenny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-24 00:00:00.000000000 Z
11
+ date: 2023-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -220,6 +220,34 @@ dependencies:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
222
  version: '5.1'
223
+ - !ruby/object:Gem::Dependency
224
+ name: faraday-detailed_logger
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: faraday_curl
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: 0.0.2
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: 0.0.2
223
251
  description: Правильный клиент для работы c REST XML API moyslad.ru, созданный по
224
252
  принципам SOLID
225
253
  email:
@@ -238,6 +266,7 @@ files:
238
266
  - README.md
239
267
  - Rakefile
240
268
  - lib/moysklad.rb
269
+ - lib/moysklad/attributes_converter.rb
241
270
  - lib/moysklad/client.rb
242
271
  - lib/moysklad/client/errors.rb
243
272
  - lib/moysklad/entities.rb