moysklad 0.4.5 → 0.4.7

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: eba3855e983122b5158c941697b4dc46309d9a7fa81bac691a90d4dbbed6238b
4
- data.tar.gz: 4edcfda4ffd7ff9156251a5f0f5e7d2de51c2c40c3b1fec1f5d84f77e407d9e5
3
+ metadata.gz: 11853c0cd626e6f922838a5d91e0cb83a48092f359ddc8b1437374d0ccf0c29a
4
+ data.tar.gz: 61dbc0e2db3b56ba8ed1200dd8b2d91b5e7500a926bd32c839c92d2e73ce58a4
5
5
  SHA512:
6
- metadata.gz: 4f19a54c763da441522e474ecd87bfbdfac9656af8e9c598132b7e8101d7dfc71a7d570386fbd78e4c188a1c4038f24c1f3c8c69878f9ab3181a9fd887ba7863
7
- data.tar.gz: 1531d71f523c7b0d51f07b1c7beed2be02dad3b1094e714e6917aa69b9c187fa4687b71b1a54e6639350725e84178f32305729a12c7d4a7994627c2499634e38
6
+ metadata.gz: 5aeaa2c2892de2abed0dcabe6f30a88428bbe0635a67a548330aa049af6b303be2743394ceb8e2a41f73407addaa9bc606b26b51ca8c4dd43b62dbec701b8759
7
+ data.tar.gz: c177b77a933b4ae86d18a353f7eb96d2a1e370707251cce96e22ef7138e04a531ef9aac159593fc7410e64ed784fd7a78bdd3e5575e72e0b0771d68f3a4c8be1
@@ -2,6 +2,7 @@ require 'faraday'
2
2
  require 'faraday/detailed_logger'
3
3
  require 'faraday_curl'
4
4
  require 'faraday/gzip'
5
+ require 'faraday/encoding'
5
6
 
6
7
  require_relative 'client/errors'
7
8
 
@@ -14,6 +15,8 @@ class Moysklad::Client
14
15
  conn.response :detailed_logger, logger
15
16
  conn.request :curl, logger, :info
16
17
  end
18
+ conn.request :gzip
19
+ conn.response :encoding
17
20
 
18
21
  conn.options.timeout = ENV.fetch('MOYSKLAD_HTTP_TIMEOUT', 120)
19
22
  if Faraday::VERSION.split('.').first.to_i < 2
@@ -21,29 +24,25 @@ class Moysklad::Client
21
24
  else
22
25
  conn.request(:authorization, :basic, login, password)
23
26
  end
27
+
28
+ conn.adapter Faraday.default_adapter
24
29
  end
25
30
  end
26
31
 
27
32
  def download(path, filename)
28
- response = client.get path do |req|
29
- req.request :gzip
30
- end
33
+ response = client.get path
31
34
  File.open(filename, 'wb') { |fp| fp.write(response.body) }
32
35
  end
33
36
 
34
37
  def get path, params={}
35
38
  logger.debug "Client: GET #{path} #{params}"
36
- result = client.get path, params do |req|
37
- req.request :gzip
38
- end
39
- parse_response result
39
+ parse_response client.get path, params
40
40
  end
41
41
 
42
42
  def post path, data
43
43
  logger.debug "Client: POST #{path}"
44
44
  result = client.post do |req|
45
45
  req.url path
46
- req.request :gzip
47
46
  req.headers['Content-Type'] = 'application/json'
48
47
  req.headers['Accept'] = '*/*'
49
48
  req.body = data
@@ -54,7 +53,6 @@ class Moysklad::Client
54
53
  def put path, data
55
54
  logger.debug "Client: PUT #{path}"
56
55
  result = client.put do |req|
57
- req.request :gzip
58
56
  req.url path
59
57
  req.headers['Content-Type'] = 'application/json'
60
58
  req.headers['Accept'] = '*/*'
@@ -66,7 +64,6 @@ class Moysklad::Client
66
64
  def delete path
67
65
  logger.debug "Client: DELETE #{path}"
68
66
  result = client.delete do |req|
69
- req.request :gzip
70
67
  req.url path
71
68
  req.headers['Content-Type'] = 'application/json'
72
69
  req.headers['Accept'] = '*/*'
@@ -84,6 +81,7 @@ class Moysklad::Client
84
81
 
85
82
  def parse_response res
86
83
  body = res.body
84
+ body.force_encoding 'utf-8' if res.body.encoding.to_s == "ASCII-8BIT" && res.headers['content-type'].include?('charset=utf-8')
87
85
  Moysklad.logger.debug "Response [#{res.status}] with body #{body}"
88
86
 
89
87
  if res.status == 200
@@ -4,7 +4,6 @@ module Moysklad::Entities
4
4
  attribute :title, String
5
5
  attribute :filename, String
6
6
  attribute :size, Integer
7
-
8
7
  attribute :updated, Time
9
8
  attribute :miniature, Meta
10
9
  attribute :tiny, Meta
@@ -0,0 +1,15 @@
1
+ module Moysklad::Entities
2
+ class ImagesMeta < Base
3
+ attribute :href, String
4
+ attribute :type, String
5
+ attribute :mediaType, String
6
+ attribute :size, Integer
7
+ attribute :limit, Integer
8
+ attribute :offset, Integer
9
+ end
10
+
11
+ class Images < Base
12
+ attribute :meta, ImagesMeta
13
+ end
14
+ end
15
+
@@ -4,6 +4,7 @@ module Moysklad::Entities
4
4
  attribute :metadataHref, String
5
5
  attribute :type, String
6
6
  attribute :mediaType, String # application/json
7
+ attribute :downloadHref, String
7
8
 
8
9
  def id
9
10
  @id ||= href.split('/').last
@@ -17,7 +17,7 @@ module Moysklad::Entities
17
17
  attribute :buyPrice, Currency
18
18
  attribute :salePrices, Array[Price]
19
19
 
20
- attribute :image, Image
20
+ attribute :images, Images # MetaArray
21
21
 
22
22
  attribute :article, String
23
23
  attribute :weighed, Boolean
@@ -44,5 +44,9 @@ module Moysklad::Entities
44
44
  universe.features.where goodUuid: uuid
45
45
  end
46
46
  end
47
+
48
+ def product_images(universe)
49
+ Moysklad::Resources::ProductImages.new(client: universe.client, list_path: images.meta.href).list
50
+ end
47
51
  end
48
52
  end
@@ -17,6 +17,7 @@ module Moysklad
17
17
  price_type
18
18
  price
19
19
  image
20
+ images
20
21
  employee
21
22
  context
22
23
  product
@@ -0,0 +1,14 @@
1
+ module Moysklad::Resources
2
+ class ProductImages < Base
3
+ # Публичный чтобы был доступен из индекса
4
+ def cache_key
5
+ [list_path].join(':')
6
+ end
7
+
8
+ private
9
+
10
+ def item_path
11
+ raise
12
+ end
13
+ end
14
+ end
@@ -13,6 +13,7 @@ module Moysklad::Resources
13
13
  assortments
14
14
  custom_entities
15
15
  custom_entity_metadata
16
+ product_images
16
17
  embedded_entity_metadata
17
18
  where_filter
18
19
  indexed_cache
@@ -1,3 +1,3 @@
1
1
  module Moysklad
2
- VERSION = '0.4.5'
2
+ VERSION = '0.4.7'
3
3
  end
data/moysklad.gemspec CHANGED
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_runtime_dependency 'faraday'
24
24
  spec.add_runtime_dependency 'faraday-gzip'
25
+ spec.add_runtime_dependency 'faraday-encoding'
25
26
  spec.add_runtime_dependency 'virtus'
26
- # spec.add_runtime_dependency 'nokogiri-happymapper'
27
27
  spec.add_runtime_dependency 'activesupport', '>=3.0.0'
28
28
 
29
29
  spec.add_development_dependency "bundler"
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.5
4
+ version: 0.4.7
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-19 00:00:00.000000000 Z
11
+ date: 2023-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday-encoding
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: virtus
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -308,6 +322,7 @@ files:
308
322
  - lib/moysklad/entities/entity.rb
309
323
  - lib/moysklad/entities/group.rb
310
324
  - lib/moysklad/entities/image.rb
325
+ - lib/moysklad/entities/images.rb
311
326
  - lib/moysklad/entities/meta.rb
312
327
  - lib/moysklad/entities/organization.rb
313
328
  - lib/moysklad/entities/owner.rb
@@ -337,6 +352,7 @@ files:
337
352
  - lib/moysklad/resources/indexed_cache.rb
338
353
  - lib/moysklad/resources/load_all.rb
339
354
  - lib/moysklad/resources/positions.rb
355
+ - lib/moysklad/resources/product_images.rb
340
356
  - lib/moysklad/resources/products.rb
341
357
  - lib/moysklad/resources/stock.rb
342
358
  - lib/moysklad/resources/subresource.rb