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

#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from Square::BaseApi

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/square/api/snippets_api.rb', line 15

def delete_snippet(site_id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/v2/sites/{site_id}/snippet',
                                 'default')
               .template_param(new_parameter(site_id, key: 'site_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/square/api/snippets_api.rb', line 44

def retrieve_snippet(site_id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/sites/{site_id}/snippet',
                                 'default')
               .template_param(new_parameter(site_id, key: 'site_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
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



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/square/api/snippets_api.rb', line 78

def upsert_snippet(site_id:,
                   body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/sites/{site_id}/snippet',
                                 'default')
               .template_param(new_parameter(site_id, key: 'site_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end