Class: Square::SnippetsApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/square/api/snippets_api.rb

Overview

SnippetsApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#execute_request, #validate_parameters

Constructor Details

#initialize(config, http_call_back: nil) ⇒ SnippetsApi

Returns a new instance of SnippetsApi.



4
5
6
# File 'lib/square/api/snippets_api.rb', line 4

def initialize(config, http_call_back: nil)
  super(config, http_call_back: http_call_back)
end

Instance Method Details

#delete_snippet(site_id:) ⇒ DeleteSnippetResponse Hash

Removes your snippet from a Square Online site. You can call [ListSites]($e/Sites/ListSites) to get the IDs of the sites that belong to a seller. Note: Square Online APIs are publicly available as part of an early access program. For more information, see [Early access program for Square Online APIs](developer.squareup.com/docs/online-api#early-access-program- for-square-online-apis). contains the snippet.

Parameters:

  • site_id (String)

    Required parameter: The ID of the site that

Returns:

  • (DeleteSnippetResponse Hash)

    response from the API call



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/square/api/snippets_api.rb', line 19

def delete_snippet(site_id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/sites/{site_id}/snippet'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'site_id' => { 'value' => site_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.delete(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#retrieve_snippet(site_id:) ⇒ RetrieveSnippetResponse Hash

Retrieves your snippet from a Square Online site. A site can contain snippets from multiple snippet applications, but you can retrieve only the snippet that was added by your application. You can call [ListSites]($e/Sites/ListSites) to get the IDs of the sites that belong to a seller. Note: Square Online APIs are publicly available as part of an early access program. For more information, see [Early access program for Square Online APIs](developer.squareup.com/docs/online-api#early-access-program- for-square-online-apis). contains the snippet.

Parameters:

  • site_id (String)

    Required parameter: The ID of the site that

Returns:

  • (RetrieveSnippetResponse Hash)

    response from the API call



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/square/api/snippets_api.rb', line 63

def retrieve_snippet(site_id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/sites/{site_id}/snippet'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'site_id' => { 'value' => site_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#upsert_snippet(site_id:, body:) ⇒ UpsertSnippetResponse Hash

Adds a snippet to a Square Online site or updates the existing snippet on the site. The snippet code is appended to the end of the `head` element on every page of the site, except checkout pages. A snippet application can add one snippet to a given site. You can call [ListSites]($e/Sites/ListSites) to get the IDs of the sites that belong to a seller. Note: Square Online APIs are publicly available as part of an early access program. For more information, see [Early access program for Square Online APIs](developer.squareup.com/docs/online-api#early-access-program- for-square-online-apis). want to add or update the snippet. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • site_id (String)

    Required parameter: The ID of the site where you

  • body (UpsertSnippetRequest)

    Required parameter: An object

Returns:

  • (UpsertSnippetResponse Hash)

    response from the API call



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/square/api/snippets_api.rb', line 112

def upsert_snippet(site_id:,
                   body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/sites/{site_id}/snippet'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'site_id' => { 'value' => site_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'content-type' => 'application/json; charset=utf-8'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end