Class: Io::Flow::V0::Clients::Attributes
- Inherits:
-
Object
- Object
- Io::Flow::V0::Clients::Attributes
- Defined in:
- lib/flow_commerce/flow_api_v0_client.rb
Instance Method Summary collapse
-
#delete_by_key(organization, key) ⇒ Object
Delete an attribute with the specified key.
-
#get(organization, incoming = {}) ⇒ Object
Search attributes.
-
#get_by_key(organization, key) ⇒ Object
Returns information about a specific attribute.
-
#get_versions(organization, incoming = {}) ⇒ Object
Provides visibility into recent changes of each object, including deletion.
-
#initialize(client) ⇒ Attributes
constructor
A new instance of Attributes.
-
#post(organization, attribute_form) ⇒ Object
Add attribute.
-
#put_by_key(organization, key, attribute_form) ⇒ Object
Create or update an attribute with the specified key.
Constructor Details
#initialize(client) ⇒ Attributes
Returns a new instance of Attributes.
389 390 391 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 389 def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client) end |
Instance Method Details
#delete_by_key(organization, key) ⇒ Object
Delete an attribute with the specified key.
434 435 436 437 438 439 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 434 def delete_by_key(organization, key) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('key', key, String) r = @client.request("/#{CGI.escape(organization)}/attributes/#{CGI.escape(key)}").delete nil end |
#get(organization, incoming = {}) ⇒ Object
Search attributes. Always paginated.
394 395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 394 def get(organization, incoming={}) HttpClient::Preconditions.assert_class('organization', organization, String) 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) }), :key => (x = opts.delete(:key); x.nil? ? nil : HttpClient::Preconditions.assert_class('key', x, Array).map { |v| HttpClient::Preconditions.assert_class('key', v, String) }), :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? ? "key" : x), String) }.delete_if { |k, v| v.nil? } r = @client.request("/#{CGI.escape(organization)}/attributes").with_query(query).get r.map { |x| ::Io::Flow::V0::Models::Attribute.new(x) } end |
#get_by_key(organization, key) ⇒ Object
Returns information about a specific attribute.
417 418 419 420 421 422 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 417 def get_by_key(organization, key) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('key', key, String) r = @client.request("/#{CGI.escape(organization)}/attributes/#{CGI.escape(key)}").get ::Io::Flow::V0::Models::Attribute.new(r) end |
#get_versions(organization, incoming = {}) ⇒ Object
Provides visibility into recent changes of each object, including deletion
442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 442 def get_versions(organization, incoming={}) HttpClient::Preconditions.assert_class('organization', organization, String) 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) }), :key => (x = opts.delete(:key); x.nil? ? nil : HttpClient::Preconditions.assert_class('key', x, Array).map { |v| HttpClient::Preconditions.assert_class('key', v, String) }), :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? ? "journal_timestamp" : x), String) }.delete_if { |k, v| v.nil? } r = @client.request("/#{CGI.escape(organization)}/attributes/versions").with_query(query).get r.map { |x| ::Io::Flow::V0::Models::AttributeVersion.new(x) } end |
#post(organization, attribute_form) ⇒ Object
Add attribute
409 410 411 412 413 414 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 409 def post(organization, attribute_form) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('attribute_form', attribute_form, ::Io::Flow::V0::Models::AttributeForm) r = @client.request("/#{CGI.escape(organization)}/attributes").with_json(attribute_form.to_json).post ::Io::Flow::V0::Models::Attribute.new(r) end |
#put_by_key(organization, key, attribute_form) ⇒ Object
Create or update an attribute with the specified key.
425 426 427 428 429 430 431 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 425 def put_by_key(organization, key, attribute_form) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('key', key, String) HttpClient::Preconditions.assert_class('attribute_form', attribute_form, ::Io::Flow::V0::Models::AttributeForm) r = @client.request("/#{CGI.escape(organization)}/attributes/#{CGI.escape(key)}").with_json(attribute_form.to_json).put ::Io::Flow::V0::Models::Attribute.new(r) end |