Class: Innologix::User
- Inherits:
-
Object
- Object
- Innologix::User
- Defined in:
- lib/innologix/user.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#email ⇒ Object
Returns the value of attribute email.
-
#error ⇒ Object
Returns the value of attribute error.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#status ⇒ Object
Returns the value of attribute status.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #check_email(email) ⇒ Object
- #create ⇒ Object
- #delete ⇒ Object
- #from_hash(attributes) ⇒ Object
- #get(id) ⇒ Object
-
#initialize(h = {}) ⇒ User
constructor
A new instance of User.
- #list(offset = 0, limit = 10) ⇒ Object
- #update ⇒ Object
Constructor Details
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
11 12 13 |
# File 'lib/innologix/user.rb', line 11 def client @client end |
#created_at ⇒ Object
Returns the value of attribute created_at.
8 9 10 |
# File 'lib/innologix/user.rb', line 8 def created_at @created_at end |
#email ⇒ Object
Returns the value of attribute email.
6 7 8 |
# File 'lib/innologix/user.rb', line 6 def email @email end |
#error ⇒ Object
Returns the value of attribute error.
12 13 14 |
# File 'lib/innologix/user.rb', line 12 def error @error end |
#first_name ⇒ Object
Returns the value of attribute first_name.
4 5 6 |
# File 'lib/innologix/user.rb', line 4 def first_name @first_name end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/innologix/user.rb', line 3 def id @id end |
#last_name ⇒ Object
Returns the value of attribute last_name.
5 6 7 |
# File 'lib/innologix/user.rb', line 5 def last_name @last_name end |
#status ⇒ Object
Returns the value of attribute status.
7 8 9 |
# File 'lib/innologix/user.rb', line 7 def status @status end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
9 10 11 |
# File 'lib/innologix/user.rb', line 9 def updated_at @updated_at end |
Instance Method Details
#check_email(email) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/innologix/user.rb', line 54 def check_email(email) path = '/users/check_email' method = 'post' = {form_params: {email: email}} result = client.call_api(path, method, ) if result[:error].nil? from_hash(result) else RequestError.new(result) end end |
#create ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# 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} = {form_params: {user: form_params}} result = client.call_api(path, method, ) if result[:error].nil? from_hash(result) else RequestError.new(result) end end |
#delete ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# 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) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# 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) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# 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) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/innologix/user.rb', line 19 def list(offset = 0, limit = 10) path = '/users' method = 'get' = {query_params: {offset: offset, limit: limit}} result = client.call_api(path, method, ) if result[:error].nil? list =[] result[:users].each do |device| list.push(from_hash(device)) end = OpenStruct.new .offset = result[:meta][:offset] .limit = result[:meta][:limit] .total = result[:meta][:total] result = OpenStruct.new result.users = list result. = result else RequestError.new(result) end end |
#update ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# 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} = {form_params: {user: form_params}} result = client.call_api(path, method, ) if result[:error].nil? from_hash(result) else RequestError.new(result) end end |