moysklad 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/moysklad/attributes_converter.rb +16 -0
- data/lib/moysklad/client.rb +13 -4
- data/lib/moysklad/entities/base.rb +0 -5
- data/lib/moysklad/entities/custom_entity.rb +6 -11
- data/lib/moysklad/entities/meta.rb +3 -3
- data/lib/moysklad/entities/organization.rb +1 -0
- data/lib/moysklad/entities/price.rb +1 -1
- data/lib/moysklad/entities/product.rb +1 -0
- data/lib/moysklad/entities/resource_metadata.rb +1 -0
- data/lib/moysklad/entities/store.rb +1 -0
- data/lib/moysklad/entities.rb +2 -2
- data/lib/moysklad/universe.rb +4 -11
- data/lib/moysklad/version.rb +1 -1
- data/lib/moysklad.rb +1 -0
- data/moysklad.gemspec +2 -0
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac800af878e9eda7d3452b7b4b416dfd9e88b834bec446e18f77a12a8a1d7f08
|
4
|
+
data.tar.gz: e70f8fed1d9a27dc108380900037517c818e73e8d3456f33b76b82ee59a6a3ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/moysklad/client.rb
CHANGED
@@ -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
|
-
|
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,
|
5
|
-
attribute :accountId,
|
6
|
-
attribute :id,
|
7
|
-
attribute :name,
|
8
|
-
attribute :externalCode,
|
9
|
-
attribute :description,
|
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,
|
3
|
+
attribute :href, String
|
4
4
|
attribute :metadataHref, String
|
5
|
-
attribute :type,
|
6
|
-
attribute :mediaType,
|
5
|
+
attribute :type, String
|
6
|
+
attribute :mediaType, String # application/json
|
7
7
|
|
8
8
|
def id
|
9
9
|
@id ||= href.split('/').last
|
@@ -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,
|
5
|
+
attribute :priceType, PriceType # Цена продажи/ Распродажа
|
6
6
|
|
7
7
|
def self.from_money money
|
8
8
|
raise 'not implemented'
|
data/lib/moysklad/entities.rb
CHANGED
@@ -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
|
data/lib/moysklad/universe.rb
CHANGED
@@ -15,25 +15,20 @@ module Moysklad
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def company_settings_metadata
|
18
|
-
Moysklad::Entities::CompanySettingsMetadata.build client.get('
|
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
|
-
|
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
|
data/lib/moysklad/version.rb
CHANGED
data/lib/moysklad.rb
CHANGED
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.
|
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-
|
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
|