Class: BeyondApi::ScriptTags

Inherits:
Base
  • Object
show all
Includes:
Utils
Defined in:
lib/beyond_api/resources/script_tags.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 inherited from Base

#initialize

Constructor Details

This class inherits a constructor from BeyondApi::Base

Instance Method Details

#all(params = {}) ⇒ OpenStruct

A GET request is used to retrieve a list of all script tags for a shop.

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

Examples:

@script_tags = session.script_tags.all(size: 20, page: 0)

Parameters:

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

    a customizable set of options

Options Hash (params):

  • :paginated (Boolean)
  • :only_own (Boolean)
  • :size (Integer)

    the page size

  • :page (Integer)

    the page number

Returns:

  • (OpenStruct)


25
26
27
28
29
30
31
# File 'lib/beyond_api/resources/script_tags.rb', line 25

def all(params = {})
  path = "/script-tags"

  params.merge!(client_id: BeyondApi.configuration.client_id) if params[:only_own]

  handle_all_request(path, :script_tags, params)
end

#create(script_tag_url) ⇒ OpenStruct

A POST request is used to create a script tag.

$ curl 'https://api-shop.beyondshop.cloud/api/script-tags' -i -X POST \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
    "scriptUrl": "https://example.org/js/fancy-script.js"
}'

Examples:

@script_tag = session.script_tags.create("https://example.org/js/fancy-script.js")

Parameters:

  • script_tag_url (String)

    the url of the script

Returns:

  • (OpenStruct)

Scopes:

  • sctg:m



75
76
77
78
79
80
81
82
83
# File 'lib/beyond_api/resources/script_tags.rb', line 75

def create(script_tag_url)
  path = "/script-tags"

  response, status = BeyondApi::Request.post(@session,
                                             path,
                                             { script_url: script_tag_url })

  handle_response(response, status)
end

#delete(script_tag_id) ⇒ Object

A DELETE request is used to delete a script tag. You can only delete a script tag created by your app.

$ curl 'https://api-shop.beyondshop.cloud/api/script-tags/4a9f7776-d74d-4311-8ddb-121bd5407520' -i -X DELETE \
    -H 'Authorization: Bearer <Access token>'

Examples:

session.script_tags.delete("4a9f7776-d74d-4311-8ddb-121bd5407520")

Parameters:

  • script_tag_id (String)

    the script tag UUID

Returns:

  • true

Scopes:

  • sctg:m



100
101
102
103
104
105
106
107
# File 'lib/beyond_api/resources/script_tags.rb', line 100

def delete(script_tag_id)
  path = "/script-tags/#{script_tag_id}"

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

  handle_response(response, status, respond_with_true: true)
end

#find(script_tag_id) ⇒ OpenStruct

A GET request is used to retrieve a single script tag.

$ curl 'https://api-shop.beyondshop.cloud/api/script-tags/df170ab1-13ae-4955-8b51-2478246acf59' -i -X GET \
    -H 'Authorization: Bearer <Access token>'

Examples:

@script_tag = session.script_tags.find("df170ab1-13ae-4955-8b51-2478246acf59")

Parameters:

  • script_tag_id (String)

    the script tag UUID

Returns:

  • (OpenStruct)


46
47
48
49
50
51
52
53
# File 'lib/beyond_api/resources/script_tags.rb', line 46

def find(script_tag_id)
  path = "/script-tags/#{script_tag_id}"

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

  handle_response(response, status)
end

#update(script_tag_id, script_tag_url) ⇒ OpenStruct

A PUT request is used to update an existing script tag. You can only update a script tag created by your app.

$ curl 'https://api-shop.beyondshop.cloud/api/script-tags/d6c7b3d2-4984-4fa6-b5f2-b0f5cfc63bd3' -i -X PUT \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
  "scriptUrl": "https://example.org/scripts/someOtherScript.js"
}'

Examples:

@script_tag = session.script_tags.create("https://example.org/scripts/someOtherScript.js")

Parameters:

  • script_tag_id (String)

    the script tag UUID

  • script_tag_url (String)

    the url of the script

Returns:

  • (OpenStruct)

Scopes:

  • sctg:m



130
131
132
133
134
135
136
137
138
# File 'lib/beyond_api/resources/script_tags.rb', line 130

def update(script_tag_id, script_tag_url)
  path = "/script-tags/#{script_tag_id}"

  response, status = BeyondApi::Request.put(@session,
                                            path,
                                            { script_url: script_tag_url })

  handle_response(response, status)
end