moysklad 0.3.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a56ce8eb66a010543868f61ec27181f39c1aea72452e8c02597c850f8980f39e
4
- data.tar.gz: 58c9aeff4402bb50fc03c3790c8a96ad3e72b51a75e967c46dafe91a4ffee853
3
+ metadata.gz: 3d6deac98d910e2122e5d088e5f296d5862e0444d321f6020c074d339b2c7e1c
4
+ data.tar.gz: 32b680c577404846d787bf849f0a9c6b32cdcf857405c49b8c7d8177dd75edb7
5
5
  SHA512:
6
- metadata.gz: 87330dee8f7938f0afd81f19f8e3bed3935caeafa39d45f8e2d83548ef1b8d37067fc1a42534a6a8ffd7424313a6e33d9ac33851c2f357b980d891ee0cd1e156
7
- data.tar.gz: 6e9a856cf5679a24070e66c3d5832e4e68f7fe6c8cd4a091ce12dd89d2a41ff28ef5efe41578b7e48ee9a6ecb550dc1f1ffa33390ed33b3005ff6b587a9fd148
6
+ metadata.gz: d256705204b4c6823c7d729c47cfd4d2ad62cc9e66688e171033a437c8d84973c469fe35fc86197bcb5a14c6001db1995ca3e16b3f381c9831780f30a994b5ee
7
+ data.tar.gz: bb721e69e475031587bfedf6c3022640020d867fbb305dd452838a4a68d8dff56d31a2d7725574a6afb11227af3579af977036d86256524cbb105a14f7aefcee
@@ -0,0 +1,15 @@
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
+ elsif data['attributes'].is_a? Hash
8
+ # do nothing
9
+ else
10
+ raise "Strange attribute class #{data['attribute']}"
11
+ end
12
+ end
13
+ super data
14
+ end
15
+ end
@@ -1,14 +1,19 @@
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
+ conn.response :detailed_logger, logger
14
+ conn.request :curl, logger, :info
15
+ end
16
+
12
17
  conn.options.timeout = ENV.fetch('MOYSKLAD_HTTP_TIMEOUT', 120)
13
18
  if Faraday::VERSION.split('.').first.to_i < 2
14
19
  conn.request(:basic_auth, login, password)
@@ -34,6 +39,7 @@ class Moysklad::Client
34
39
  req.url path
35
40
  req.headers['Content-Type'] = 'application/json'
36
41
  req.headers['Accept'] = '*/*'
42
+ req.headers['Accept-Encoding'] = 'gzip'
37
43
  req.body = data
38
44
  end
39
45
  parse_response result
@@ -45,6 +51,7 @@ class Moysklad::Client
45
51
  req.url path
46
52
  req.headers['Content-Type'] = 'application/json'
47
53
  req.headers['Accept'] = '*/*'
54
+ req.headers['Accept-Encoding'] = 'gzip'
48
55
  req.body = data
49
56
  end
50
57
  parse_response result
@@ -56,6 +63,7 @@ class Moysklad::Client
56
63
  req.url path
57
64
  req.headers['Content-Type'] = 'application/json'
58
65
  req.headers['Accept'] = '*/*'
66
+ req.headers['Accept-Encoding'] = 'gzip'
59
67
  end
60
68
  parse_response result
61
69
  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.1'
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.1
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-15 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