Class: Io::Flow::V0::Clients::Tokens
- Inherits:
-
Object
- Object
- Io::Flow::V0::Clients::Tokens
- Defined in:
- lib/flow_commerce/flow_api_v0_client.rb
Instance Method Summary collapse
- #delete_by_id(id) ⇒ Object
-
#get(incoming = {}) ⇒ Object
Get all tokens that you are authorized to view.
-
#get_by_id(id) ⇒ Object
Get metadata for the token with this ID.
-
#get_cleartext_by_id(id) ⇒ Object
Retrieves the token with the actual string token in cleartext.
-
#initialize(client) ⇒ Tokens
constructor
A new instance of Tokens.
-
#post(token_form) ⇒ Object
Create a new token for the requesting user.
-
#post_authentications(token_authentication_form) ⇒ Object
Preferred method to validate a token, obtaining specific information if the token is valid (or a 404 if the token does not exist).
Constructor Details
#initialize(client) ⇒ Tokens
Returns a new instance of Tokens.
4201 4202 4203 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4201 def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client) end |
Instance Method Details
#delete_by_id(id) ⇒ Object
4237 4238 4239 4240 4241 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4237 def delete_by_id(id) HttpClient::Preconditions.assert_class('id', id, String) r = @client.request("/tokens/#{CGI.escape(id)}").delete nil end |
#get(incoming = {}) ⇒ Object
Get all tokens that you are authorized to view. Note that the cleartext token value is never sent. To view the API token itself, see the resource path /tokens/:id/cleartext
4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4208 def get(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }), :organization => (x = opts.delete(:organization); x.nil? ? nil : HttpClient::Preconditions.assert_class('organization', x, String)), :partner => (x = opts.delete(:partner); x.nil? ? nil : HttpClient::Preconditions.assert_class('partner', x, String)), :mine => (x = opts.delete(:mine); x.nil? ? nil : HttpClient::Preconditions.assert_boolean('mine', x)), :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer), :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer), :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "-created_at" : x), String) }.delete_if { |k, v| v.nil? } r = @client.request("/tokens").with_query(query).get r.map { |x| ::Io::Flow::V0::Models::Token.from_json(x) } end |
#get_by_id(id) ⇒ Object
Get metadata for the token with this ID
4231 4232 4233 4234 4235 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4231 def get_by_id(id) HttpClient::Preconditions.assert_class('id', id, String) r = @client.request("/tokens/#{CGI.escape(id)}").get ::Io::Flow::V0::Models::Token.from_json(r) end |
#get_cleartext_by_id(id) ⇒ Object
Retrieves the token with the actual string token in cleartext
4244 4245 4246 4247 4248 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4244 def get_cleartext_by_id(id) HttpClient::Preconditions.assert_class('id', id, String) r = @client.request("/tokens/#{CGI.escape(id)}/cleartext").get ::Io::Flow::V0::Models::Cleartext.new(r) end |
#post(token_form) ⇒ Object
Create a new token for the requesting user
4224 4225 4226 4227 4228 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4224 def post(token_form) HttpClient::Preconditions.assert_class('token_form', token_form, ::Io::Flow::V0::Models::TokenForm) r = @client.request("/tokens").with_json(token_form.to_json).post ::Io::Flow::V0::Models::Token.from_json(r) end |
#post_authentications(token_authentication_form) ⇒ Object
Preferred method to validate a token, obtaining specific information if the token is valid (or a 404 if the token does not exist). We use an HTTP POST with a form body to enusre that the token itself is not logged in the request logs.
4254 4255 4256 4257 4258 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4254 def post_authentications(token_authentication_form) HttpClient::Preconditions.assert_class('token_authentication_form', token_authentication_form, ::Io::Flow::V0::Models::TokenAuthenticationForm) r = @client.request("/tokens/authentications").with_json(token_authentication_form.to_json).post ::Io::Flow::V0::Models::TokenReference.from_json(r) end |