Class: Io::Flow::V0::Clients::Memberships
- Inherits:
-
Object
- Object
- Io::Flow::V0::Clients::Memberships
- Defined in:
- lib/flow_commerce/flow_api_v0_client.rb
Instance Method Summary collapse
- #delete_by_id(id) ⇒ Object
-
#get(incoming = {}) ⇒ Object
Search memberships.
-
#get_by_id(id, incoming = {}) ⇒ Object
Returns information about a specific membership.
- #get_versions(incoming = {}) ⇒ Object
-
#initialize(client) ⇒ Memberships
constructor
A new instance of Memberships.
-
#post(membership_form) ⇒ Object
Create a new membership.
-
#put_by_id(id, membership_put_form) ⇒ Object
Change the role for a specific membership record.
Constructor Details
#initialize(client) ⇒ Memberships
Returns a new instance of Memberships.
7376 7377 7378 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7376 def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client) end |
Instance Method Details
#delete_by_id(id) ⇒ Object
7439 7440 7441 7442 7443 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7439 def delete_by_id(id) HttpClient::Preconditions.assert_class('id', id, String) r = @client.request("/memberships/#{CGI.escape(id)}").delete nil end |
#get(incoming = {}) ⇒ Object
Search memberships. Always paginated.
7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7381 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) }), :user => (x = opts.delete(:user); x.nil? ? nil : HttpClient::Preconditions.assert_class('user', x, String)), :organization => (x = opts.delete(:organization); x.nil? ? nil : HttpClient::Preconditions.assert_class('organization', x, String)), :role => (x = opts.delete(:role); x.nil? ? nil : HttpClient::Preconditions.assert_class('role', x, Array).map { |v| HttpClient::Preconditions.assert_class('role', 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? ? "-created_at" : x), String), :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) }) }.delete_if { |k, v| v.nil? } r = @client.request("/memberships").with_query(query).get r.map { |x| ::Io::Flow::V0::Models::Membership.new(x) } end |
#get_by_id(id, incoming = {}) ⇒ Object
Returns information about a specific membership.
7420 7421 7422 7423 7424 7425 7426 7427 7428 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7420 def get_by_id(id, incoming={}) HttpClient::Preconditions.assert_class('id', id, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) }) }.delete_if { |k, v| v.nil? } r = @client.request("/memberships/#{CGI.escape(id)}").with_query(query).get ::Io::Flow::V0::Models::Membership.new(r) end |
#get_versions(incoming = {}) ⇒ Object
7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7404 def get_versions(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) }), :membership => (x = opts.delete(:membership); x.nil? ? nil : HttpClient::Preconditions.assert_class('membership', x, Array).map { |v| HttpClient::Preconditions.assert_class('membership', v, String) }), :user => (x = opts.delete(:user); x.nil? ? nil : HttpClient::Preconditions.assert_class('user', x, String)), :organization => (x = opts.delete(:organization); x.nil? ? nil : HttpClient::Preconditions.assert_class('organization', x, 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("/memberships/versions").with_query(query).get r.map { |x| ::Io::Flow::V0::Models::MembershipVersion.new(x) } end |
#post(membership_form) ⇒ Object
Create a new membership.
7398 7399 7400 7401 7402 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7398 def post(membership_form) (x = membership_form; x.is_a?(::Io::Flow::V0::Models::MembershipForm) ? x : ::Io::Flow::V0::Models::MembershipForm.new(x)) r = @client.request("/memberships").with_json(membership_form.to_json).post ::Io::Flow::V0::Models::Membership.new(r) end |
#put_by_id(id, membership_put_form) ⇒ Object
Change the role for a specific membership record. If the user already has the specified role within the organization, does nothing.
7432 7433 7434 7435 7436 7437 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7432 def put_by_id(id, membership_put_form) HttpClient::Preconditions.assert_class('id', id, String) (x = membership_put_form; x.is_a?(::Io::Flow::V0::Models::MembershipPutForm) ? x : ::Io::Flow::V0::Models::MembershipPutForm.new(x)) r = @client.request("/memberships/#{CGI.escape(id)}").with_json(membership_put_form.to_json).put ::Io::Flow::V0::Models::Membership.new(r) end |