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