Module: BeyondApi::VariationImages

Included in:
Variations
Defined in:
lib/beyond_api/resources/variations/images.rb

Instance Method Summary collapse

Instance Method Details

#add_image(product_id, variation_id, body) ⇒ OpenStruct

A POST request is used to create an image and add it to a variation. The URL of the image will be assigned to the variation. The image URL has to be provided in body of the request.

$ curl 'https://api-shop.beyondshop.cloud/api/products/a08ca814-52e9-4e00-82a2-3e9b012e5f9d/variations/4b58cdb7-4d3d-419a-ae27-8469f8b04276/images' -i -X POST \
    -H 'Content-Type: application/hal+json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
    "dataUri" : "photostore-2.JPG?hash=8a627f655c68f56dfbbf217ab7d5563281225998",
    "width" : 100,
    "height" : 200
}'

Examples:

body = {
  "data_uri" => "photostore-2.JPG?hash=8a627f655c68f56dfbbf217ab7d5563281225998",
  "width" => 100,
  "height" => 200
}
@image = session.variations.add_image("a08ca814-52e9-4e00-82a2-3e9b012e5f9d", "4b58cdb7-4d3d-419a-ae27-8469f8b04276", body)

Parameters:

  • product_id (String)

    the product UUID

  • variation_id (String)

    the variation UUID

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • prod:u



36
37
38
39
40
41
42
43
44
# File 'lib/beyond_api/resources/variations/images.rb', line 36

def add_image(product_id, variation_id, body)
  path = "/products/#{product_id}/variations/#{variation_id}/images"

  response, status = BeyondApi::Request.post(@session,
                                             path,
                                             body)

  handle_response(response, status)
end

#delete_image(product_id, variation_id, image_id) ⇒ true

A DELETE request is used to delete a variation image

$ curl 'https://api-shop.beyondshop.cloud/api/products/8f5736f8-0a5f-4c08-bbac-3c524e2a6294/variations/86f3047c-ff29-4906-83c1-93e24ef88f3e/images/193d2ba4-3cf0-4326-a655-ef46e8a97c6a' -i -X DELETE \
    -H 'Content-Type: application/hal+json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

session.variations.delete_image("8f5736f8-0a5f-4c08-bbac-3c524e2a6294", "86f3047c-ff29-4906-83c1-93e24ef88f3e", "193d2ba4-3cf0-4326-a655-ef46e8a97c6a")

Parameters:

  • product_id (String)

    the product UUID

  • variation_id (String)

    the variation UUID

  • image_id (String)

    the image UUID

Returns:

  • (true)

Scopes:

  • prod:u



65
66
67
68
69
70
71
72
# File 'lib/beyond_api/resources/variations/images.rb', line 65

def delete_image(product_id, variation_id, image_id)
  path = "/products/#{product_id}/variations/#{variation_id}/images/#{image_id}"

  response, status = BeyondApi::Request.delete(@session,
                                               path)

  handle_response(response, status, respond_with_true: true)
end

#image(product_id, image_id) ⇒ OpenStruct

A GET request is used to retrieve a single image of a variation.

$ curl 'https://api-shop.beyondshop.cloud/api/products/8665fc36-003e-4120-8a74-a9d6449644ae/variations/9163db42-92e7-418c-a3d8-651e7aaca569/images/86fc2691-5dfb-47e1-aae7-4bc2f658a80b' -i -X GET \
    -H 'Content-Type: application/hal+json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@image = session.variations.image("8665fc36-003e-4120-8a74-a9d6449644ae", "a9163db42-92e7-418c-a3d8-651e7aaca569", "86fc2691-5dfb-47e1-aae7-4bc2f658a80b")

Parameters:

  • product_id (String)

    the product UUID

  • variation_id (String)

    the variation UUID

  • image_id (String)

    the image UUID

Returns:

  • (OpenStruct)

Scopes:

  • prod:r



93
94
95
96
97
98
99
100
# File 'lib/beyond_api/resources/variations/images.rb', line 93

def image(product_id, image_id)
  path = "/products/#{product_id}/variations/#{variation_id}/images/#{image_id}"

  response, status = BeyondApi::Request.get(@session,
                                            path)

  handle_response(response, status)
end

#images(product_id, variation_id, params = {}) ⇒ OpenStruct

A GET request is used to retrieve the images of a variation.

$ curl 'https://api-shop.beyondshop.cloud/api/products/b4948e53-05af-4e0b-8877-28bc8811f73e/variations/50c5bf45-5dd6-4bae-babf-813c7cdca488/images' -i -X GET \
    -H 'Content-Type: application/hal+json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@images = session.variations.images("b4948e53-05af-4e0b-8877-28bc8811f73e", "50c5bf45-5dd6-4bae-babf-813c7cdca488", size: 100, page: 0)

Parameters:

  • product_id (String)

    the product UUID

  • variation_id (String)

    the variation UUID

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :size (Integer)

    the page size

  • :page (Integer)

    the page number

Returns:

  • (OpenStruct)

Scopes:

  • prod:r



122
123
124
125
126
127
128
129
130
# File 'lib/beyond_api/resources/variations/images.rb', line 122

def images(product_id, variation_id, params = {})
  path = "/products/#{product_id}/variations/#{variation_id}/images"

  response, status = BeyondApi::Request.get(@session,
                                            path,
                                            params)

  handle_response(response, status)
end

#sort_images(product_id, variation_id, image_ids) ⇒ Object

A PUT request is used to sort the variation images. This is done by passing the self-links of the images to the desired variation. The request must contain URIs for all images of the given page.

$ curl 'https://api-shop.beyondshop.cloud/api/products/8a8a7002-f864-4011-9991-d6ffb1bd1085/variations/60c2c2a5-ece0-4d04-b90d-f38ee710961c/images' -i -X PUT \
  -H 'Content-Type: text/uri-list' \
  -H 'Authorization: Bearer <Access token>' \
  -d 'https://api-shop.beyondshop.cloud/api/products/8a8a7002-f864-4011-9991-d6ffb1bd1085/variations/60c2c2a5-ece0-4d04-b90d-f38ee710961c/images/a12cae49-3efb-4874-989e-37df6981a4db
      https://api-shop.beyondshop.cloud/api/products/8a8a7002-f864-4011-9991-d6ffb1bd1085/variations/60c2c2a5-ece0-4d04-b90d-f38ee710961c/images/4f562165-968c-42fd-a245-1dcc045f8151
      https://api-shop.beyondshop.cloud/api/products/8a8a7002-f864-4011-9991-d6ffb1bd1085/variations/60c2c2a5-ece0-4d04-b90d-f38ee710961c/images/93cd0802-15db-4772-b524-e1c4c6c27b77'

Examples:

body = [
  "c9082802-a0d0-416e-9039-02fa465a027e",
  "78e9993d-8db3-45d8-8f76-6b8f2aea9c45",
  "9233ee97-5dbb-4c00-a7b2-e1512c69a938"
]
session.variations.sort_images("3f4b2b56-c22d-4d80-b4ed-d5b33ed161eb", body)

Parameters:

  • product_id (String)

    the product UUID

  • variation_id (String)

    the variation UUID

  • images (Array)

    the image UUIDS

Returns:

  • true

Scopes:

  • prod:u



157
158
159
160
161
162
# File 'lib/beyond_api/resources/variations/images.rb', line 157

def sort_images(product_id, variation_id, image_ids)
  body = image_ids.map { |image_id| "#{@session.api_url}/products/#{product_id}/variations/#{variation_id}/images/#{image_id}" }
  response, status = BeyondApi::Request.put(@session, "/products/#{product_id}/variations/#{variation_id}/images", body.join("\n"), {}, 'text/uri-list')

  handle_response(response, status, respond_with_true: true)
end

#upload_image(product_id, variation_id, image_path, image_name) ⇒ OpenStruct

A POST request is used to upload an image to the image storage and assign the URL of the image to the variation. The body of the request must contain the content of the image.

$ curl --data-binary '@/home/epages/file.png' 'https://api-shop.beyondshop.cloud/api/products/4125b993-49fc-47c8-b9b3-76d8871e4e06/variations/d7fecf94-2e57-4122-8c94-a0acd840c111/images?fileName=file.png' -X POST \
    -H 'Content-Type: image/png' \
    -H 'Authorization: Bearer <Access token>'

Examples:

body = {
  "type" => "VIMEO",
  "source" => "https://vimeo.com/7265982"
}

session.variations.upload_image("4125b993-49fc-47c8-b9b3-76d8871e4e06", "d7fecf94-2e57-4122-8c94-a0acd840c111", "/home/epages/file.png", "file.png")

Parameters:

  • product_id (String)

    the product UUID

  • variation_id (String)

    the variation UUID

  • images_path (Array)

    the images path

  • images_name (Array)

    the images name

Returns:

  • (OpenStruct)

Scopes:

  • prod:u



188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/beyond_api/resources/variations/images.rb', line 188

def upload_image(product_id, variation_id, image_path, image_name)
  content_type = file_content_type(image_path)
  path = "/products/#{product_id}/variations/#{variation_id}/images"

  image_binary = File.binread(image_path)

  response, status = BeyondApi::Request.upload(@session,
                                               path,
                                               image_binary,
                                               content_type,
                                               { file_name: image_name })

  handle_response(response, status, respond_with_true: true)
end

#upload_multiple_images(product_id, variation_id, images_path, images_name) ⇒ OpenStruct

A POST request is used to upload up to 10 images to the image storage and assign the URL of the images to up to 30 variations. The body of the request must contain the content of the images.

$ curl 'https://api-shop.beyondshop.cloud/api/products/4125b993-49fc-47c8-b9b3-76d8871e4e06/variations/images?fileName=file.png&fileName=file2.png&variation=ca53ae26-e7c6-44a4-8070-9fca08cc87ed&variation=ab63fa3a-c2ac-4074-aaa3-b547217b042d' -i -X POST \
    -H 'Content-Type: multipart/form-data' \
    -H 'Authorization: Bearer <Access token>' \
    -F 'image=@/home/epages/file.png' \
    -F 'image=@/home/epages/file2.png'

Examples:

session.variations.upload_multiple_images("4125b993-49fc-47c8-b9b3-76d8871e4e06", "d7fecf94-2e57-4122-8c94-a0acd840c111",
                                          ["/home/epages/file.png", "/home/epages/file2.png"], ["file.png", "file2.png"])

Parameters:

  • product_id (String)

    the product UUID

  • variation_id (String)

    the variation UUID

  • images_path (String)

    the image path

  • images_name (String)

    the image name

Returns:

  • (OpenStruct)

Scopes:

  • prod:u



225
226
227
228
229
230
231
232
# File 'lib/beyond_api/resources/variations/images.rb', line 225

def upload_multiple_images(product_id, variation_id, images_path, images_name)
  response, status = BeyondApi::Request.upload_by_form(@session,
                                                       "/products/#{product_id}/variations/#{variation_id}/images",
                                                       images_path,
                                                       file_name: images_name.map { |e| URI.encode_www_form([e]) })

  handle_response(response, status)
end