Module: BeyondApi::ShopImages
- Included in:
- Shop
- Defined in:
- lib/beyond_api/resources/shops/images.rb
Instance Method Summary collapse
-
#create_image(body) ⇒ Object
A
POST
request is used to create a shop image. -
#delete_image(image_id) ⇒ Object
A
DELETE
request is used to delete a shop image. -
#image(image_id) ⇒ OpenStruct
A
GET
request is used to retrieve a single shop image. -
#images(params = {}) ⇒ OpenStruct
A
GET
request is used to retrieve the images of a shop. -
#search_images_by_label(label) ⇒ OpenStruct
A
GET
request is issued to search for shop images by label. -
#upload_image(image_path, image_name, label) ⇒ Object
A
POST
request is used to upload a shop image.
Instance Method Details
#create_image(body) ⇒ Object
A POST
request is used to create a shop image.
$ curl 'https://api-shop.beyondshop.cloud/api/shop/images' -i -X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json' \
-H 'Authorization: Bearer <Access token>' \
-d '{
"dataUri" : "file.png?hash=212-2323-4343",
"label" : "logo"
}'
33 34 35 36 37 |
# File 'lib/beyond_api/resources/shops/images.rb', line 33 def create_image(body) response, status = BeyondApi::Request.post(@session, "/shop/images", body) handle_response(response, status, respond_with_true: true) end |
#delete_image(image_id) ⇒ Object
A DELETE
request is used to delete a shop image.
$ curl 'https://api-shop.beyondshop.cloud/api/shop/images/6a7646dc-7f26-4730-a98f-52f9b63978fb' -i -X DELETE \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json' \
-H 'Authorization: Bearer <Access token>'
56 57 58 59 60 |
# File 'lib/beyond_api/resources/shops/images.rb', line 56 def delete_image(image_id) response, status = BeyondApi::Request.delete(@session, "/shop/images/#{image_id}") handle_response(response, status, respond_with_true: true) end |
#image(image_id) ⇒ OpenStruct
A GET
request is used to retrieve a single shop image.
$ curl 'https://api-shop.beyondshop.cloud/api/shop/images/2feee7ac-f1cb-4faf-9488-f3ce07394141' -i -X GET \
-H 'Accept: application/hal+json'
75 76 77 78 79 |
# File 'lib/beyond_api/resources/shops/images.rb', line 75 def image(image_id) response, status = BeyondApi::Request.get(@session, "/shop/images/#{image_id}") handle_response(response, status) end |
#images(params = {}) ⇒ OpenStruct
A GET
request is used to retrieve the images of a shop.
$ curl 'https://api-shop.beyondshop.cloud/api/shop/images' -i -X GET \
-H 'Accept: application/hal+json'
95 96 97 98 99 |
# File 'lib/beyond_api/resources/shops/images.rb', line 95 def images(params = {}) response, status = BeyondApi::Request.get(@session, "/shop/images", params) handle_response(response, status) end |
#search_images_by_label(label) ⇒ OpenStruct
A GET
request is issued to search for shop images by label.
$ curl 'https://api-shop.beyondshop.cloud/api/shop/images/search/find-by-label?label=logo' -i -X GET \
-H 'Accept: application/hal+json'
114 115 116 117 118 |
# File 'lib/beyond_api/resources/shops/images.rb', line 114 def search_images_by_label(label) response, status = BeyondApi::Request.get(@session, "/shop/images/search/find-by-label", { label: label }) handle_response(response, status) end |
#upload_image(image_path, image_name, label) ⇒ Object
A POST
request is used to upload a shop image. The body of the request must contain the content of the image.
$ curl --data-binary '@/home/epages/sample.png' 'https://api-shop.beyondshop.cloud/api/shop/images?fileName=sample.png&label=invoice logo' -X POST \
-H 'Content-Type: image/png' \
-H 'Authorization: Bearer <Access token>'
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/beyond_api/resources/shops/images.rb', line 138 def upload_image(image_path, image_name, label) content_type = case File.extname(image_path) when ".png" "image/png" when ".jpg", ".jpeg" "image/jpeg" when ".gif" "image/gif" end image_binary = File.binread(image_path) response, status = BeyondApi::Request.upload(@session, "/shop/images", image_binary, content_type, { file_name: image_name, label: label }) handle_response(response, status, respond_with_true: true) end |