Module: BeyondApi::ProductAttachments

Included in:
Products
Defined in:
lib/beyond_api/resources/products/attachments.rb

Instance Method Summary collapse

Instance Method Details

#add_attachment(product_id, body) ⇒ OpenStruct

A POST request is used to create an attachment and add it to a product.

$ curl 'https://api-shop.beyondshop.cloud/api/products/ecb997ce-79c3-4367-9373-058089a313e3/attachments' -i -X POST \
    -H 'Content-Type: application/hal+json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
    "mimeType" : "application/pdf",
    "length" : 1,
    "label" : "Handbuch",
    "dataUri" : "my_document_1.pdf?hash=8a627f655c68f56dfbbf217ab7d5563281225666"
}'

Examples:

body = {
  "mime_type" => "application/pdf",
  "length" => 1,
  "label" => "Handbuch",
  "data_uri" => "my_document_1.pdf?hash=8a627f655c68f56dfbbf217ab7d5563281225666"
}
@attachment = session.products.add_attachment("ecb997ce-79c3-4367-9373-058089a313e3", body)

Parameters:

  • product_id (String)

    the product UUID

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • prod:u



37
38
39
40
41
# File 'lib/beyond_api/resources/products/attachments.rb', line 37

def add_attachment(product_id, body)
  response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/attachments", body)

  handle_response(response, status)
end

#attachment(product_id, attachment_id) ⇒ OpenStruct

A GET request is used to retrieve a single attachment of a product.

$ curl 'https://api-shop.beyondshop.cloud/api/products/eb11b53a-5017-4ae7-9ba1-c02c12c80b61/attachments/36933722-f13f-4ee2-858c-0835ae0a884e' -i -X GET \
    -H 'Content-Type: application/hal+json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@attachment = session.products.attachment("eb11b53a-5017-4ae7-9ba1-c02c12c80b61", "36933722-f13f-4ee2-858c-0835ae0a884e")

Parameters:

  • product_id (String)

    the product UUID

  • attachment_id (String)

    the attachment UUID

Returns:

  • (OpenStruct)

Scopes:

  • prod:r



61
62
63
64
65
# File 'lib/beyond_api/resources/products/attachments.rb', line 61

def attachment(product_id, attachment_id)
  response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/attachments/#{attachment_id}")

  handle_response(response, status)
end

#attachments(product_id, params = {}) ⇒ OpenStruct

A GET request is used to list all the attachments of a product.

$ curl 'https://api-shop.beyondshop.cloud/api/products/fd60a63e-c4c0-496d-af49-c4ed224cca2a/attachments' -i -X GET \
    -H 'Content-Type: application/hal+json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@attachments = session.products.attachments("fd60a63e-c4c0-496d-af49-c4ed224cca2a", {size: 100, page: 0})

Parameters:

  • product_id (String)

    the product 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



86
87
88
89
90
# File 'lib/beyond_api/resources/products/attachments.rb', line 86

def attachments(product_id, params = {})
  response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/attachments", params)

  handle_response(response, status)
end

#delete_attachment(product_id, attachment_id) ⇒ true

A DELETE request is used to delete a product attachment

$ curl 'https://api-shop.beyondshop.cloud/api/products/00add006-beaa-46fe-bb73-f8ebae15082d/attachments/9a44e585-571a-4253-9248-54a4c418c7e2' -i -X DELETE \
    -H 'Content-Type: application/hal+json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

session.products.delete_attachment("00add006-beaa-46fe-bb73-f8ebae15082d", "9a44e585-571a-4253-9248-54a4c418c7e2")

Parameters:

  • product_id (String)

    the product UUID

  • attachment_id (String)

    the attachment UUID

Returns:

  • (true)

Scopes:

  • prod:u



110
111
112
113
114
# File 'lib/beyond_api/resources/products/attachments.rb', line 110

def delete_attachment(product_id, attachment_id)
  response, status = BeyondApi::Request.delete(@session, "/products/#{product_id}/attachments/#{attachment_id}")

  handle_response(response, status, respond_with_true: true)
end