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.



3170
3171
3172
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3170

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

Instance Method Details

#delete_by_id(id) ⇒ Object



3218
3219
3220
3221
3222
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3218

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.



3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3175

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.



3199
3200
3201
3202
3203
3204
3205
3206
3207
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3199

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



3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3224

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.



3192
3193
3194
3195
3196
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3192

def post(membership_form)
  HttpClient::Preconditions.assert_class('membership_form', membership_form, ::Io::Flow::V0::Models::MembershipForm)
  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.



3211
3212
3213
3214
3215
3216
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3211

def put_by_id(id, membership_put_form)
  HttpClient::Preconditions.assert_class('id', id, String)
  HttpClient::Preconditions.assert_class('membership_put_form', membership_put_form, ::Io::Flow::V0::Models::MembershipPutForm)
  r = @client.request("/memberships/#{CGI.escape(id)}").with_json(membership_put_form.to_json).put
  ::Io::Flow::V0::Models::Membership.new(r)
end