Class: Square::Snippets::Client
- Inherits:
-
Object
- Object
- Square::Snippets::Client
- Defined in:
- lib/square/snippets/client.rb
Instance Method Summary collapse
-
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteSnippetResponse
Removes your snippet from a Square Online site.
-
#get(request_options: {}, **params) ⇒ Square::Types::GetSnippetResponse
Retrieves your snippet from a Square Online site.
- #initialize(client:) ⇒ void constructor
-
#upsert(request_options: {}, **params) ⇒ Square::Types::UpsertSnippetResponse
Adds a snippet to a Square Online site or updates the existing snippet on the site.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/square/snippets/client.rb', line 9 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).
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/square/snippets/client.rb', line 122 def delete(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "v2/sites/#{params[:site_id]}/snippet", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::DeleteSnippetResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end 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).
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/square/snippets/client.rb', line 33 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/sites/#{params[:site_id]}/snippet", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::GetSnippetResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end 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).
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/square/snippets/client.rb', line 76 def upsert(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request_data = Square::Snippets::Types::UpsertSnippetRequest.new(params).to_h non_body_param_names = ["site_id"] body = request_data.except(*non_body_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/sites/#{params[:site_id]}/snippet", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::UpsertSnippetResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |