class Innologix::User
Attributes
client[RW]
created_at[RW]
email[RW]
error[RW]
first_name[RW]
id[RW]
last_name[RW]
status[RW]
updated_at[RW]
Public Class Methods
new(h = {})
click to toggle source
# File lib/innologix/user.rb, line 14 def initialize(h = {}) h.each { |k, v| public_send("#{k}=", v) } @client = Client.default end
Public Instance Methods
check_email(email)
click to toggle source
# File lib/innologix/user.rb, line 54 def check_email(email) path = '/users/check_email' method = 'post' options = {form_params: {email: email}} result = client.call_api(path, method, options) if result[:error].nil? from_hash(result) else RequestError.new(result) end end
create()
click to toggle source
# File lib/innologix/user.rb, line 66 def create path = '/users' method = 'post' form_params = {first_name: first_name, last_name: last_name, email: email} options = {form_params: {user: form_params}} result = client.call_api(path, method, options) if result[:error].nil? from_hash(result) else RequestError.new(result) end end
delete()
click to toggle source
# File lib/innologix/user.rb, line 92 def delete path = '/users/' + id.to_s method = 'delete' result = client.call_api(path, method) if result[:error].nil? from_hash(result) else RequestError.new(result) end end
from_hash(attributes)
click to toggle source
# File lib/innologix/user.rb, line 103 def from_hash(attributes) user = Innologix::User.new user.id = attributes[:id] user.first_name = attributes[:first_name] user.last_name = attributes[:last_name] user.email = attributes[:email] user.status = attributes[:status] user.created_at = attributes[:created_at] user.updated_at = attributes[:updated_at] user end
get(id)
click to toggle source
# File lib/innologix/user.rb, line 43 def get(id) path = '/users/' + id.to_s method = 'get' result = client.call_api(path, method) if result[:error].nil? from_hash(result) else RequestError.new(result) end end
list(offset = 0, limit = 10)
click to toggle source
# File lib/innologix/user.rb, line 19 def list(offset = 0, limit = 10) path = '/users' method = 'get' options = {query_params: {offset: offset, limit: limit}} result = client.call_api(path, method, options) if result[:error].nil? list =[] result[:users].each do |device| list.push(from_hash(device)) end meta = OpenStruct.new meta.offset = result[:meta][:offset] meta.limit = result[:meta][:limit] meta.total = result[:meta][:total] result = OpenStruct.new result.users = list result.meta = meta result else RequestError.new(result) end end
update()
click to toggle source
# File lib/innologix/user.rb, line 79 def update path = '/users/' + id.to_s method = 'put' form_params = {first_name: first_name, last_name: last_name, email: email} options = {form_params: {user: form_params}} result = client.call_api(path, method, options) if result[:error].nil? from_hash(result) else RequestError.new(result) end end