Class: Square::Snippets::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/square/snippets/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::Snippets::Client



7
8
9
# File 'lib/square/snippets/client.rb', line 7

def initialize(client:)
  @client = client
end

Instance Method Details

#delete(request_options: {}, **params) ⇒ Square::Types::DeleteSnippetResponse

Removes your snippet from a Square Online site.

You can call [ListSites](api-endpoint: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).



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/square/snippets/client.rb', line 67

def delete(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "DELETE",
    path: "v2/sites/#{params[:site_id]}/snippet"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::DeleteSnippetResponse.load(_response.body)
  end

  raise _response.body
end

#get(request_options: {}, **params) ⇒ Square::Types::GetSnippetResponse

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](api-endpoint: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).



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/square/snippets/client.rb', line 19

def get(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/sites/#{params[:site_id]}/snippet"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::GetSnippetResponse.load(_response.body)
  end

  raise _response.body
end

#upsert(request_options: {}, **params) ⇒ Square::Types::UpsertSnippetResponse

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](api-endpoint: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).



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/square/snippets/client.rb', line 42

def upsert(request_options: {}, **params)
  _path_param_names = ["site_id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/sites/#{params[:site_id]}/snippet",
    body: params.except(*_path_param_names)
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::UpsertSnippetResponse.load(_response.body)
  end

  raise _response.body
end