Class: Io::Flow::V0::Clients::Users

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Users

Returns a new instance of Users.



6163
6164
6165
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6163

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

Instance Method Details

#delete_passwords_by_id(id) ⇒ Object

Deletes a password for the given user.



6223
6224
6225
6226
6227
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6223

def delete_passwords_by_id(id)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/users/#{CGI.escape(id)}/passwords").delete
  nil
end

#get(incoming = {}) ⇒ Object

Search users. Must specify an id or email.



6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6168

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) }),
    :email => (x = opts.delete(:email); x.nil? ? nil : HttpClient::Preconditions.assert_class('email', x, String)),
    :status => (x = opts.delete(:status); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::UserStatus) ? x : ::Io::Flow::V0::Models::UserStatus.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)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/users").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::User.new(x) }
end

#get_by_id(id) ⇒ Object

Returns information about a specific user.



6200
6201
6202
6203
6204
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6200

def get_by_id(id)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/users/#{CGI.escape(id)}").get
  ::Io::Flow::V0::Models::User.new(r)
end

#patch_passwords_by_id(id, password_change_form) ⇒ Object

Update the password for a user.



6215
6216
6217
6218
6219
6220
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6215

def patch_passwords_by_id(id, password_change_form)
  HttpClient::Preconditions.assert_class('id', id, String)
  (x = password_change_form; x.is_a?(::Io::Flow::V0::Models::PasswordChangeForm) ? x : ::Io::Flow::V0::Models::PasswordChangeForm.new(x))
  r = @client.request("/users/#{CGI.escape(id)}/passwords").with_json(password_change_form.to_json).patch
  nil
end

#post(user_form) ⇒ Object

Create a new user. Note that new users will be created with a status of pending and will not be able to authenticate until approved by a member of the Flow team.



6185
6186
6187
6188
6189
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6185

def post(user_form)
  (x = user_form; x.is_a?(::Io::Flow::V0::Models::UserForm) ? x : ::Io::Flow::V0::Models::UserForm.new(x))
  r = @client.request("/users").with_json(user_form.to_json).post
  ::Io::Flow::V0::Models::User.new(r)
end

#post_authenticate(authentication_form) ⇒ Object

Authenticates a user by email / password. Note only users that have a status of active will be authorized.



6193
6194
6195
6196
6197
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6193

def post_authenticate(authentication_form)
  (x = authentication_form; x.is_a?(::Io::Flow::V0::Models::AuthenticationForm) ? x : ::Io::Flow::V0::Models::AuthenticationForm.new(x))
  r = @client.request("/users/authenticate").with_json(authentication_form.to_json).post
  ::Io::Flow::V0::Models::User.new(r)
end

#put_by_id(id, user_put_form) ⇒ Object

Update a user.



6207
6208
6209
6210
6211
6212
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6207

def put_by_id(id, user_put_form)
  HttpClient::Preconditions.assert_class('id', id, String)
  (x = user_put_form; x.is_a?(::Io::Flow::V0::Models::UserPutForm) ? x : ::Io::Flow::V0::Models::UserPutForm.new(x))
  r = @client.request("/users/#{CGI.escape(id)}").with_json(user_put_form.to_json).put
  ::Io::Flow::V0::Models::User.new(r)
end