Class: Io::Flow::V0::Clients::Memberships

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Memberships

Returns a new instance of Memberships.



4331
4332
4333
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4331

def initialize(client)
  @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client)
end

Instance Method Details

#delete_by_id(id) ⇒ Object



4379
4380
4381
4382
4383
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4379

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.



4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4336

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| (x = v; x.is_a?(::Io::Flow::V0::Models::Role) ? x : ::Io::Flow::V0::Models::Role.apply(x)).value }),
    :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.



4360
4361
4362
4363
4364
4365
4366
4367
4368
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4360

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



4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4385

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.



4353
4354
4355
4356
4357
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4353

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.



4372
4373
4374
4375
4376
4377
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4372

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