Module: BeyondApi::ShopImages

Included in:
Shop
Defined in:
lib/beyond_api/resources/shops/images.rb

Instance Method Summary collapse

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"
}'

Examples:

body = {
  "data_uri" => "file.png?hash=212-2323-4343",
  "label" => "logo"
}

session.shop.create_image(body)

Parameters:

  • body (Hash)

    the request body

Returns:

  • true

Scopes:

  • shim:c



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>'

Examples:

session.shop.delete_image("6a7646dc-7f26-4730-a98f-52f9b63978fb")

Parameters:

  • image_id (String)

    the image UUID

Returns:

  • true

Scopes:

  • shim:d



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'

Examples:

@image = session.shop.image("2feee7ac-f1cb-4faf-9488-f3ce07394141")

Parameters:

  • image_id (String)

    the image UUID

Returns:

  • (OpenStruct)


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'

Examples:

@images = session.shop.images(size: 5, page: 1)

Parameters:

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

    a customizable set of options

Options Hash (params):

  • :size (Integer)

    the page size

  • :page (Integer)

    the page number

Returns:

  • (OpenStruct)


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'

Examples:

session.shop.search_images_by_label("logo")

Parameters:

  • label (String)

    the image label

Returns:

  • (OpenStruct)


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>'

Examples:

session.shop.upload_image("/home/epages/sample.png", "sample.png", "invoice logo")

Parameters:

  • image_path (String)

    the image path

  • image_name (String)

    the image name

  • label (String)

    the image label

Returns:

  • true

Scopes:

  • shim:c



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