Class: Io::Flow::V0::Clients::Users
- Inherits:
-
Object
- Object
- Io::Flow::V0::Clients::Users
- Defined in:
- lib/flow_commerce/flow_api_v0_client.rb
Instance Method Summary collapse
-
#delete_passwords_by_id(id) ⇒ Object
Deletes a password for the given user.
-
#get(incoming = {}) ⇒ Object
Search users.
-
#get_by_id(id) ⇒ Object
Returns information about a specific user.
-
#get_versions(incoming = {}) ⇒ Object
Provides visibility into recent changes of each object, including deletion.
-
#initialize(client) ⇒ Users
constructor
A new instance of Users.
-
#patch_passwords_by_id(id, password_change_form) ⇒ Object
Update the password for a user.
-
#post(user_form) ⇒ Object
Create a new user.
-
#post_authenticate(authentication_form) ⇒ Object
Authenticates a user by email / password.
-
#put_by_id(id, user_put_form) ⇒ Object
Update a user.
Constructor Details
#initialize(client) ⇒ Users
Returns a new instance of Users.
4512 4513 4514 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4512 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.
4564 4565 4566 4567 4568 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4564 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. Always paginated.
4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4517 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.
4541 4542 4543 4544 4545 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4541 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 |
#get_versions(incoming = {}) ⇒ Object
Provides visibility into recent changes of each object, including deletion
4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4579 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) }), :user_id => (x = opts.delete(:user_id); x.nil? ? nil : HttpClient::Preconditions.assert_class('user_id', x, Array).map { |v| HttpClient::Preconditions.assert_class('user_id', 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("/users/versions").with_query(query).get r.map { |x| ::Io::Flow::V0::Models::UserVersion.new(x) } end |
#patch_passwords_by_id(id, password_change_form) ⇒ Object
Update the password for a user.
4556 4557 4558 4559 4560 4561 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4556 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.
4534 4535 4536 4537 4538 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4534 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.
4572 4573 4574 4575 4576 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4572 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.
4548 4549 4550 4551 4552 4553 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4548 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 |