Class: BeyondApi::Variations

Inherits:
Base
  • Object
show all
Includes:
Utils, VariationAvailability, VariationImages
Defined in:
lib/beyond_api/resources/variations.rb

Instance Attribute Summary

Attributes inherited from Base

#session

Instance Method Summary collapse

Methods included from Utils

#file_content_type, #handle_all_request, #handle_error, #handle_response, #sanitize_key, #sanitize_response, #to_object_struct

Methods included from VariationAvailability

#adjust_stock_level, #availability, #disable_purchasability, #enable_purchasability

Methods included from VariationImages

#add_image, #delete_image, #image, #images, #sort_images, #upload_image, #upload_multiple_images

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from BeyondApi::Base

Instance Method Details

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

A GET request is used to retrieve the variations of a product.

$ curl 'https://api-shop.beyondshop.cloud/api/products/dc1b5caf-51ea-4fcd-b1ba-0c5128e91d17/variations' -i -X GET \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@variations = session.variations.all("dc1b5caf-51ea-4fcd-b1ba-0c5128e91d17", { size: 100, page: 0 })

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:

  • prod:r



31
32
33
34
35
36
37
38
39
# File 'lib/beyond_api/resources/variations.rb', line 31

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

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

  handle_response(response, status)
end

#find(product_id, variation_id) ⇒ OpenStruct

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

$ curl 'https://api-shop.beyondshop.cloud/api/products/5f6e426e-c8d9-48ba-9b37-9a8eb6381373/variations/f6e5bb16-af2e-440f-acd3-a883ad3c1922' -i -X GET \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@variation = session.variations.find("5f6e426e-c8d9-48ba-9b37-9a8eb6381373", "f6e5bb16-af2e-440f-acd3-a883ad3c1922")

Parameters:

  • product_id (String)

    the product UUID

  • variation_id (String)

    the variation UUID

Returns:

  • (OpenStruct)

Scopes:

  • prod:r



59
60
61
62
63
64
65
66
# File 'lib/beyond_api/resources/variations.rb', line 59

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

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

  handle_response(response, status)
end

#update(product_id, variation_id, body) ⇒ OpenStruct

A PATCH request is used to update a variation partially with json content type.

$ curl 'https://api-shop.beyondshop.cloud/api/products/7cf4b5b1-b141-4869-96d1-4eaee8bf7563/variations/9f93fdd0-2d21-4ea9-b9d7-e9a53edb091b' -i -X PATCH \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
    "salesPrice" : {
      "taxModel" : "NET",
      "amount" : 8.7,
      "currency" : "EUR"
    },
    "listPrice" : {
      "taxModel" : "NET",
      "amount" : 10.95,
      "currency" : "EUR"
    },
    "manufacturerPrice" : {
      "taxModel" : "NET",
      "amount" : 99.95,
      "currency" : "EUR"
    },
    "refPrice" : {
      "refQuantity" : 1,
      "unit" : "LITER",
      "quantity" : 0.75,
      "price" : {
        "taxModel" : "NET",
        "amount" : 11.6,
        "currency" : "EUR"
      }
    },
    "sku" : "my-new-sku",
    "productIdentifiers" : [ {
      "type" : "EAN",
      "value" : "9780134308135"
    } ]
}'

Examples:

body = {
  "sales_price" => {
    "taxModel": "NET",
    "amount": 8.7,
    "currency": "EUR"
  },
  "list_price" => {
    "taxModel": "NET",
    "amount": 10.95,
    "currency": "EUR"
  },
  "manufacturer_price" => {
    "taxModel": "NET",
    "amount": 99.95,
    "currency": "EUR"
  },
  "ref_price" => {
    "refQuantity": 1,
    "unit": "LITER",
    "quantity": 0.75,
    "price": {
      "taxModel": "NET",
      "amount": 11.6,
      "currency": "EUR"
    }
  },
  "sku" => "my-new-sku",
  "product_identifiers" => [{
    "type": "EAN",
    "value": "9780134308135"
  }]
}

@variation = session.variations.update("7cf4b5b1-b141-4869-96d1-4eaee8bf7563", "9f93fdd0-2d21-4ea9-b9d7-e9a53edb091b", body)

Parameters:

  • product_id (String)

    the product UUID

  • variation_id (String)

    the variation UUID

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • prod:u



152
153
154
155
156
157
158
159
160
# File 'lib/beyond_api/resources/variations.rb', line 152

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

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

  handle_response(response, status)
end