Module: BeyondApi::ShopAttributes

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

Instance Method Summary collapse

Instance Method Details

#attribute(attribute_name) ⇒ OpenStruct

A GET request is used to retrieve a particular shop attribute by its name.

$ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes/second-unknown-attribute-name' -i -X GET \
    -H 'Authorization: Bearer <Access token>'

Examples:

@shop_attribute = session.shop.attribute("second-unknown-attribute-name")

Parameters:

  • attribute_name (String)

    the attribute name

Returns:

  • (OpenStruct)

Scopes:

  • shat:r



22
23
24
25
26
# File 'lib/beyond_api/resources/shops/attributes.rb', line 22

def attribute(attribute_name)
  response, status = BeyondApi::Request.get(@session, "/shop/attributes/#{attribute_name}")

  handle_response(response, status)
end

#attributes(params = {}) ⇒ OpenStruct

A GET request is used to retrieve a list of all shop attributes.

$ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes' -i -X GET \
    -H 'Authorization: Bearer <Access token>'

Examples:

@shop_attributes = session.shop.attributes(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)

Scopes:

  • shat:r



44
45
46
47
48
# File 'lib/beyond_api/resources/shops/attributes.rb', line 44

def attributes(params = {})
  response, status = BeyondApi::Request.get(@session, "/shop/attributes", params)

  handle_response(response, status)
end

#create_attribute(body) ⇒ OpenStruct

A POST request is used to create a shop attribute.

$ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes' -i -X POST \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
  "name" : "second-unknown-attribute-name",
  "value" : "correct-value",
  "public" : false
}'

Examples:

body = {
  "name" => "second-unknown-attribute-name",
  "value" => "correct-value",
  "public" => false
}

session.shop.create_attribute(body)

Parameters:

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • shat:c



77
78
79
80
81
# File 'lib/beyond_api/resources/shops/attributes.rb', line 77

def create_attribute(body)
  response, status = BeyondApi::Request.post(@session, "/shop/attributes", body)

  handle_response(response, status)
end

#delete_attribute(attribute_name) ⇒ Object

A DELETE request is used to delete an shop attribute.

$ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes/second-unknown-attribute-name' -i -X DELETE \
    -H 'Authorization: Bearer <Access token>'

Examples:

session.shop.delete_attribute("second-unknown-attribute-name")

Parameters:

  • attribute_name (String)

    the attribute name

Returns:

  • true

Scopes:

  • shat:d



98
99
100
101
102
# File 'lib/beyond_api/resources/shops/attributes.rb', line 98

def delete_attribute(attribute_name)
  response, status = BeyondApi::Request.delete(@session, "/shop/attributes/#{attribute_name}")

  handle_response(response, status, respond_with_true: true)
end

#update_attribute(attribute_name, body) ⇒ OpenStruct

A PUT request is used to update a shop attribute. This operation is idempotent and will create a new shop attribute if required.

$ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes/second-unknown-attribute-name' -i -X PUT \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
  "value" : "new-value",
  "public" : false
}'

Examples:

body = {
  "value" => "new-value",
  "public" => false
}

session.shop.update_attribute("second-unknown-attribute-name", body)

Parameters:

  • attribute_name (String)

    the attribute name

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • shat:u



130
131
132
133
134
# File 'lib/beyond_api/resources/shops/attributes.rb', line 130

def update_attribute(attribute_name, body)
  response, status = BeyondApi::Request.put(@session, "/shop/attributes/#{attribute_name}", body)

  handle_response(response, status)
end