Skip to content

Commit

Permalink
Add product images support
Browse files Browse the repository at this point in the history
  • Loading branch information
dapi committed Dec 6, 2023
1 parent 82d9dcf commit 041aef7
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/moysklad/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Entities
price_type
price
image
images
employee
context
product
Expand Down
1 change: 0 additions & 1 deletion lib/moysklad/entities/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Image < Base
attribute :title, String
attribute :filename, String
attribute :size, Integer

attribute :updated, Time
attribute :miniature, Meta
attribute :tiny, Meta
Expand Down
15 changes: 15 additions & 0 deletions lib/moysklad/entities/images.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Moysklad::Entities
class ImagesMeta < Base
attribute :href, String
attribute :type, String
attribute :mediaType, String
attribute :size, Integer
attribute :limit, Integer
attribute :offset, Integer
end

class Images < Base
attribute :meta, ImagesMeta
end
end

1 change: 1 addition & 0 deletions lib/moysklad/entities/meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Meta < Base
attribute :metadataHref, String
attribute :type, String
attribute :mediaType, String # application/json
attribute :downloadHref, String

def id
@id ||= href.split('/').last
Expand Down
6 changes: 5 additions & 1 deletion lib/moysklad/entities/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Product < Entity
attribute :buyPrice, Currency
attribute :salePrices, Array[Price]

attribute :image, Image
attribute :images, Images # MetaArray

attribute :article, String
attribute :weighed, Boolean
Expand All @@ -44,5 +44,9 @@ def features universe
universe.features.where goodUuid: uuid
end
end

def product_images(universe)
Moysklad::Resources::ProductImages.new(client: universe.client, list_path: images.meta.href).list
end
end
end
1 change: 1 addition & 0 deletions lib/moysklad/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def self.register_resource resource_class
assortments
custom_entities
custom_entity_metadata
product_images
embedded_entity_metadata
where_filter
indexed_cache
Expand Down
14 changes: 14 additions & 0 deletions lib/moysklad/resources/product_images.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Moysklad::Resources
class ProductImages < Base
# Публичный чтобы был доступен из индекса
def cache_key
[list_path].join(':')
end

private

def item_path
raise
end
end
end

0 comments on commit 041aef7

Please sign in to comment.