innologix 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a573c76809e490fe00699089ffa782830cd74e1b
4
+ data.tar.gz: fd49e03274f1ee28b5c6b0791e033e47eef777b2
5
+ SHA512:
6
+ metadata.gz: b1765857e3dcba9459be64c81a94099f0e150447e927f30d2836cb0c8bcabde0a3d6482f72b8b65f06d33ab314feaaf783bc1c45b33188f361d02f92dfeafbb1
7
+ data.tar.gz: ec3dc90e747707b8be2b95b7bc934163859e6de93e22b61684cdb909fe35f05fe036344869dbb4d562c8e6089b2c25be2471afa29abf91a45685f641847c9b4d
@@ -0,0 +1,7 @@
1
+ module Innologix
2
+ class Authorization
3
+ def initialize(client)
4
+ @client = client
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,63 @@
1
+ module Innologix
2
+ class Client
3
+ attr_accessor :client_id, :client_secret, :innologix_url, :access_token, :auth, :logger, :sso_url, :timeout, :default_headers
4
+
5
+ def initialize (options = {})
6
+ @client_id = options[:client_id] || Innologix.config['client_id']
7
+ @client_secret = options[:client_secret] || Innologix.config['client_secret']
8
+ @innologix_url = options[:innologix_url] || Innologix.config['innologix_url']
9
+ @sso_url = options[:sso_url] || Innologix.config['sso_url']
10
+ @timeout = options[:timeout] || Innologix.config['timeout']
11
+ @default_headers = {:'Content-Type' => "application/json",
12
+ :'Authorization' => 'Bearer ' + current_token}
13
+
14
+ return true
15
+ end
16
+
17
+ def self.default
18
+ @default ||= Client.new
19
+ end
20
+
21
+ def current_token
22
+ @access_token ||= get_token
23
+ end
24
+
25
+ def get_token
26
+ url = @sso_url + '/oauth/access_token'
27
+ begin
28
+ RestClient.post url, {client_id: client_id, client_secret: client_secret, grant_type: 'client_credentials'} do |response, request, result, &block|
29
+ case response.code
30
+ when 200
31
+ result = JSON.parse response, :symbolize_names => true
32
+ if result[:access_token].nil?
33
+ nil
34
+ else
35
+ result[:access_token]
36
+ end
37
+ else
38
+ nil
39
+ end
40
+ end
41
+ rescue Exception => e
42
+ Innologix::Logger.error e.message
43
+ nil
44
+ end
45
+ end
46
+
47
+ def call_api(path, method, options = {})
48
+ url = innologix_url + path
49
+ header_params ||= @default_headers.merge(options[:header_params] || {})
50
+ query_params = options[:query_params] || {}
51
+ header_params[:params] = query_params
52
+ form_params = options[:form_params] || {}
53
+ RestClient::Request.execute(method: method.to_sym.downcase,
54
+ url: url, payload: form_params,
55
+ timeout: timeout, headers: header_params) do |response, request, result, &block|
56
+
57
+ JSON.parse response, :symbolize_names => true
58
+ end
59
+ rescue Exception => e
60
+ {error: 500, message: e.message}
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,115 @@
1
+ module Innologix
2
+ class Device
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ attr_accessor :address
6
+ attr_accessor :fwd_proto
7
+ attr_accessor :status
8
+ attr_accessor :device_type_id
9
+ attr_accessor :m2m_id
10
+ attr_accessor :created_at
11
+ attr_accessor :updated_at
12
+
13
+ attr_accessor :supervisor
14
+ attr_accessor :group
15
+ attr_accessor :m2m
16
+ attr_accessor :device_type
17
+
18
+ attr_accessor :client
19
+ attr_accessor :error
20
+
21
+ def initialize(h = {})
22
+ h.each { |k, v| public_send("#{k}=", v) }
23
+ @client = Client.default
24
+ end
25
+
26
+ def list(offset = 0, limit = 10)
27
+ path = '/devices'
28
+ method = 'get'
29
+ options = {query_params: {offset: offset, limit: limit}}
30
+ result = client.call_api(path, method, options)
31
+ if result[:error].nil?
32
+ list =[]
33
+ result[:devices].each do |device|
34
+ list.push(from_hash(device))
35
+ end
36
+ meta = OpenStruct.new
37
+ meta.offset = result[:meta][:offset]
38
+ meta.limit = result[:meta][:limit]
39
+ meta.total = result[:meta][:total]
40
+
41
+ result = OpenStruct.new
42
+ result.devices = list
43
+ result.meta = meta
44
+ result
45
+ else
46
+ RequestError.new(result)
47
+ end
48
+ end
49
+
50
+ def get(id)
51
+ path = '/devices/' + id.to_s
52
+ method = 'get'
53
+ result = client.call_api(path, method)
54
+ if result[:error].nil?
55
+ from_hash(result)
56
+ else
57
+ RequestError.new(result)
58
+ end
59
+ end
60
+
61
+ def create
62
+ path = '/devices'
63
+ method = 'post'
64
+ form_params = {name: name, address: address, device_type_id: device_type_id, fwd_proto: fwd_proto}
65
+ options = {form_params: {device: form_params}}
66
+ result = client.call_api(path, method, options)
67
+ if result[:error].nil?
68
+ from_hash(result)
69
+ else
70
+ RequestError.new(result)
71
+ end
72
+ end
73
+
74
+ def update
75
+ path = '/devices/' + id.to_s
76
+ method = 'put'
77
+ form_params = {name: name, address: address, device_type_id: device_type_id, fwd_proto: fwd_proto}
78
+ options = {form_params: {device: form_params}}
79
+ result = client.call_api(path, method, options)
80
+ if result[:error].nil?
81
+ from_hash(result)
82
+ else
83
+ RequestError.new(result)
84
+ end
85
+ end
86
+
87
+ def delete
88
+ path = '/devices/' + id.to_s
89
+ method = 'delete'
90
+ result = client.call_api(path, method)
91
+ if result[:error].nil?
92
+ from_hash(result)
93
+ else
94
+ RequestError.new(result)
95
+ end
96
+ end
97
+
98
+ def from_hash(attributes)
99
+ device = Innologix::Device.new
100
+ device.id = attributes[:id]
101
+ device.name = attributes[:name]
102
+ device.address = attributes[:address]
103
+ device.fwd_proto = attributes[:fwd_proto]
104
+ device.status = attributes[:status]
105
+ device.device_type_id = attributes[:device_type_id]
106
+ device.m2m_id = attributes[:m2m_id]
107
+ device.created_at = attributes[:created_at]
108
+ device.updated_at = attributes[:updated_at]
109
+
110
+ device.device_type = DeviceType.new(attributes[:device_type])
111
+
112
+ device
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,95 @@
1
+ module Innologix
2
+ class DeviceType
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ attr_accessor :created_at
6
+ attr_accessor :updated_at
7
+
8
+ attr_accessor :client
9
+ attr_accessor :error
10
+
11
+ def initialize(h = {})
12
+ h.each { |k, v| public_send("#{k}=", v) }
13
+ @client = Client.default
14
+ end
15
+
16
+ def list(offset = 0, limit = 10)
17
+ path = '/device_types'
18
+ method = 'get'
19
+ options = {query_params: {offset: offset, limit: limit}}
20
+ result = client.call_api(path, method, options)
21
+ if result[:error].nil?
22
+ list =[]
23
+ result[:device_types].each do |device_type|
24
+ list.push(from_hash(device_type))
25
+ end
26
+ meta = OpenStruct.new
27
+ meta.offset = result[:meta][:offset]
28
+ meta.limit = result[:meta][:limit]
29
+ meta.total = result[:meta][:total]
30
+
31
+ result = OpenStruct.new
32
+ result.device_types = list
33
+ result.meta = meta
34
+ result
35
+ else
36
+ RequestError.new(result)
37
+ end
38
+ end
39
+
40
+ def get(id)
41
+ path = '/device_types/' + id.to_s
42
+ method = 'get'
43
+ result = client.call_api(path, method)
44
+ if result[:error].nil?
45
+ from_hash(result)
46
+ else
47
+ RequestError.new(result)
48
+ end
49
+ end
50
+
51
+ def create
52
+ path = '/device_types'
53
+ method = 'post'
54
+ options = {form_params: {device_type: {name: name}}}
55
+ result = client.call_api(path, method, options)
56
+ if result[:error].nil?
57
+ from_hash(result)
58
+ else
59
+ RequestError.new(result)
60
+ end
61
+ end
62
+
63
+ def update
64
+ path = '/device_types/' + id.to_s
65
+ method = 'put'
66
+ options = {form_params: {device_type: {name: name}}}
67
+ result = client.call_api(path, method, options)
68
+ if result[:error].nil?
69
+ from_hash(result)
70
+ else
71
+ RequestError.new(result)
72
+ end
73
+ end
74
+
75
+ def delete
76
+ path = '/device_types/' + id.to_s
77
+ method = 'delete'
78
+ result = client.call_api(path, method)
79
+ if result[:error].nil?
80
+ from_hash(result)
81
+ else
82
+ RequestError.new(result)
83
+ end
84
+ end
85
+
86
+ def from_hash(attributes)
87
+ device_type = Innologix::DeviceType.new
88
+ device_type.id = attributes[:id]
89
+ device_type.name = attributes[:name]
90
+ device_type.created_at = attributes[:created_at]
91
+ device_type.updated_at = attributes[:updated_at]
92
+ device_type
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,102 @@
1
+ module Innologix
2
+ class Group
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ attr_accessor :supervisor_id
6
+ attr_accessor :created_at
7
+ attr_accessor :updated_at
8
+
9
+ attr_accessor :supervisor
10
+ attr_accessor :m2ms
11
+
12
+ attr_accessor :client
13
+ attr_accessor :error
14
+
15
+ def initialize(h = {})
16
+ h.each { |k, v| public_send("#{k}=", v) }
17
+ @client = Client.default
18
+ end
19
+
20
+ def list(offset = 0, limit = 10)
21
+ path = '/groups'
22
+ method = 'get'
23
+ options = {query_params: {offset: offset, limit: limit}}
24
+ result = client.call_api(path, method, options)
25
+ if result[:error].nil?
26
+ list =[]
27
+ result[:groups].each do |group|
28
+ list.push(from_hash(group))
29
+ end
30
+ meta = OpenStruct.new
31
+ meta.offset = result[:meta][:offset]
32
+ meta.limit = result[:meta][:limit]
33
+ meta.total = result[:meta][:total]
34
+
35
+ result = OpenStruct.new
36
+ result.groups = list
37
+ result.meta = meta
38
+ result
39
+ else
40
+ RequestError.new(result)
41
+ end
42
+ end
43
+
44
+ def get(id)
45
+ path = '/groups/' + id.to_s
46
+ method = 'get'
47
+ result = client.call_api(path, method)
48
+ if result[:error].nil?
49
+ from_hash(result)
50
+ else
51
+ RequestError.new(result)
52
+ end
53
+ end
54
+
55
+ def create
56
+ path = '/groups'
57
+ method = 'post'
58
+ form_params = {name: name, supervisor_id: supervisor_id}
59
+ options = {form_params: {group: form_params}}
60
+ result = client.call_api(path, method, options)
61
+ if result[:error].nil?
62
+ from_hash(result)
63
+ else
64
+ RequestError.new(result)
65
+ end
66
+ end
67
+
68
+ def update
69
+ path = '/groups/' + id.to_s
70
+ method = 'put'
71
+ form_params = {name: name, supervisor_id: supervisor_id}
72
+ options = {form_params: {group: form_params}}
73
+ result = client.call_api(path, method, options)
74
+ if result[:error].nil?
75
+ from_hash(result)
76
+ else
77
+ RequestError.new(result)
78
+ end
79
+ end
80
+
81
+ def delete
82
+ path = '/groups/' + id.to_s
83
+ method = 'delete'
84
+ result = client.call_api(path, method)
85
+ if result[:error].nil?
86
+ from_hash(result)
87
+ else
88
+ RequestError.new(result)
89
+ end
90
+ end
91
+
92
+ def from_hash(attributes)
93
+ group = Innologix::Group.new
94
+ group.id = attributes[:id]
95
+ group.name = attributes[:name]
96
+ group.supervisor_id = attributes[:supervisor_id]
97
+ group.created_at = attributes[:created_at]
98
+ group.updated_at = attributes[:updated_at]
99
+ group
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,15 @@
1
+ module Innologix
2
+ class Logger
3
+ def self.info(msg)
4
+ puts msg
5
+ end
6
+
7
+ def self.warn(msg)
8
+ puts msg
9
+ end
10
+
11
+ def self.error(msg)
12
+ puts msg
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,166 @@
1
+ module Innologix
2
+ class M2m
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ attr_accessor :ip
6
+ attr_accessor :status
7
+ attr_accessor :group_id
8
+ attr_accessor :created_at
9
+ attr_accessor :updated_at
10
+
11
+ attr_accessor :group
12
+ attr_accessor :devices
13
+
14
+ attr_accessor :client
15
+ attr_accessor :error
16
+
17
+ def initialize(h = {})
18
+ h.each { |k, v| public_send("#{k}=", v) }
19
+ @client = Client.default
20
+ end
21
+
22
+ def list(offset = 0, limit = 10)
23
+ path = '/m2ms'
24
+ method = 'get'
25
+ options = {query_params: {offset: offset, limit: limit}}
26
+ result = client.call_api(path, method, options)
27
+ if result[:error].nil?
28
+ list =[]
29
+ result[:m2ms].each do |m2m|
30
+ list.push(from_hash(m2m))
31
+ end
32
+ meta = OpenStruct.new
33
+ meta.offset = result[:meta][:offset]
34
+ meta.limit = result[:meta][:limit]
35
+ meta.total = result[:meta][:total]
36
+
37
+ result = OpenStruct.new
38
+ result.m2ms = list
39
+ result.meta = meta
40
+ result
41
+ else
42
+ RequestError.new(result)
43
+ end
44
+ end
45
+
46
+ def get(id)
47
+ path = '/m2ms/' + id.to_s
48
+ method = 'get'
49
+ result = client.call_api(path, method)
50
+ if result[:error].nil?
51
+ from_hash(result)
52
+ else
53
+ RequestError.new(result)
54
+ end
55
+ end
56
+
57
+ def create
58
+ path = '/m2ms'
59
+ method = 'post'
60
+ form_params = {name: name, ip: ip, group_id: group_id}
61
+ options = {form_params: {m2m: form_params}}
62
+ result = client.call_api(path, method, options)
63
+ if result[:error].nil?
64
+ from_hash(result)
65
+ else
66
+ RequestError.new(result)
67
+ end
68
+ end
69
+
70
+ def update
71
+ path = '/m2ms/' + id.to_s
72
+ method = 'put'
73
+ form_params = {name: name, ip: ip, group_id: group_id}
74
+ options = {form_params: {m2m: form_params}}
75
+ result = client.call_api(path, method, options)
76
+ if result[:error].nil?
77
+ from_hash(result)
78
+ else
79
+ RequestError.new(result)
80
+ end
81
+ end
82
+
83
+ def delete
84
+ path = '/m2ms/' + id.to_s
85
+ method = 'delete'
86
+ result = client.call_api(path, method)
87
+ if result[:error].nil?
88
+ from_hash(result)
89
+ else
90
+ RequestError.new(result)
91
+ end
92
+ end
93
+
94
+ def add_devices(devices = [], callback = nil)
95
+ path = '/m2ms/' + id.to_s + '/add_devices'
96
+ method = 'patch'
97
+ form_params = {devices: devices, callback: callback}
98
+ options = {form_params: form_params}
99
+ result = client.call_api(path, method, options)
100
+ if result[:error].nil?
101
+ from_hash(result)
102
+ else
103
+ RequestError.new(result)
104
+ end
105
+ end
106
+
107
+ def remove_devices(devices = [], callback = nil)
108
+ path = '/m2ms/' + id.to_s + '/remove_devices'
109
+ method = 'patch'
110
+ form_params = {devices: devices, callback: callback}
111
+ options = {form_params: form_params}
112
+ result = client.call_api(path, method, options)
113
+ if result[:error].nil?
114
+ from_hash(result)
115
+ else
116
+ RequestError.new(result)
117
+ end
118
+ end
119
+
120
+ def restart(callback = nil)
121
+ path = '/m2ms/' + id.to_s + '/restart'
122
+ method = 'patch'
123
+ form_params = {callback: callback}
124
+ options = {form_params: form_params}
125
+ result = client.call_api(path, method, options)
126
+ if result[:error].nil?
127
+ result[:message]
128
+ else
129
+ RequestError.new(result)
130
+ end
131
+ end
132
+
133
+ def check_status(callback = nil)
134
+ path = '/m2ms/' + id.to_s + '/check_status'
135
+ method = 'patch'
136
+ form_params = {callback: callback}
137
+ options = {form_params: form_params}
138
+ result = client.call_api(path, method, options)
139
+ if result[:error].nil?
140
+ result[:message]
141
+ else
142
+ RequestError.new(result)
143
+ end
144
+ end
145
+
146
+ def from_hash(attributes)
147
+ m2m = Innologix::M2m.new
148
+ m2m.id = attributes[:id]
149
+ m2m.name = attributes[:name]
150
+ m2m.ip = attributes[:ip]
151
+ m2m.group_id = attributes[:group_id]
152
+ m2m.created_at = attributes[:created_at]
153
+ m2m.updated_at = attributes[:updated_at]
154
+ if attributes[:group] != nil
155
+ m2m.group = Innologix::Group.new(attributes[:group])
156
+ end
157
+ m2m.devices = []
158
+ if attributes[:devices] != nil
159
+ attributes[:devices].each do |device|
160
+ m2m.devices.push(Innologix::Device.new(device))
161
+ end
162
+ end
163
+ m2m
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,11 @@
1
+ module Innologix
2
+ class RequestError
3
+ attr_accessor :error
4
+ attr_accessor :message
5
+
6
+ def initialize(hash)
7
+ @error = hash[:error]
8
+ @message = hash[:message]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,101 @@
1
+ module Innologix
2
+ class Storage
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ attr_accessor :ip
6
+ attr_accessor :port
7
+ attr_accessor :created_at
8
+ attr_accessor :updated_at
9
+
10
+ attr_accessor :client
11
+ attr_accessor :error
12
+
13
+ def initialize(h = {})
14
+ h.each { |k, v| public_send("#{k}=", v) }
15
+ @client = Client.default
16
+ end
17
+
18
+ def list(offset = 0, limit = 10)
19
+ path = '/storages'
20
+ method = 'get'
21
+ options = {query_params: {offset: offset, limit: limit}}
22
+ result = client.call_api(path, method, options)
23
+ if result[:error].nil?
24
+ list =[]
25
+ result[:storages].each do |storage|
26
+ list.push(from_hash(storage))
27
+ end
28
+ meta = OpenStruct.new
29
+ meta.offset = result[:meta][:offset]
30
+ meta.limit = result[:meta][:limit]
31
+ meta.total = result[:meta][:total]
32
+
33
+ result = OpenStruct.new
34
+ result.storages = list
35
+ result.meta = meta
36
+ result
37
+ else
38
+ RequestError.new(result)
39
+ end
40
+ end
41
+
42
+ def get(id)
43
+ path = '/storages/' + id.to_s
44
+ method = 'get'
45
+ result = client.call_api(path, method)
46
+ if result[:error].nil?
47
+ from_hash(result)
48
+ else
49
+ RequestError.new(result)
50
+ end
51
+ end
52
+
53
+ def create
54
+ path = '/storages'
55
+ method = 'post'
56
+ form_params = {name: name, ip: ip, port: port}
57
+ options = {form_params: {storage: form_params}}
58
+ result = client.call_api(path, method, options)
59
+ if result[:error].nil?
60
+ from_hash(result)
61
+ else
62
+ RequestError.new(result)
63
+ end
64
+ end
65
+
66
+ def update
67
+ path = '/storages/' + id.to_s
68
+ method = 'put'
69
+ form_params = {name: name, ip: ip, port: port}
70
+ options = {form_params: {storage: form_params}}
71
+ result = client.call_api(path, method, options)
72
+ if result[:error].nil?
73
+ from_hash(result)
74
+ else
75
+ RequestError.new(result)
76
+ end
77
+ end
78
+
79
+ def delete
80
+ path = '/storages/' + id.to_s
81
+ method = 'delete'
82
+ result = client.call_api(path, method)
83
+ if result[:error].nil?
84
+ from_hash(result)
85
+ else
86
+ RequestError.new(result)
87
+ end
88
+ end
89
+
90
+ def from_hash(attributes)
91
+ storage = Innologix::Storage.new
92
+ storage.id = attributes[:id]
93
+ storage.name = attributes[:name]
94
+ storage.ip = attributes[:ip]
95
+ storage.port = attributes[:port]
96
+ storage.created_at = attributes[:created_at]
97
+ storage.updated_at = attributes[:updated_at]
98
+ storage
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,145 @@
1
+ module Innologix
2
+ class Supervisor
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ attr_accessor :ip
6
+ attr_accessor :status
7
+ attr_accessor :storage_id
8
+ attr_accessor :created_at
9
+ attr_accessor :updated_at
10
+
11
+ attr_accessor :client
12
+ attr_accessor :error
13
+
14
+ def initialize(h = {})
15
+ h.each { |k, v| public_send("#{k}=", v) }
16
+ @client = Client.default
17
+ end
18
+
19
+ def list(offset = 0, limit = 10)
20
+ path = '/supervisors'
21
+ method = 'get'
22
+ options = {query_params: {offset: offset, limit: limit}}
23
+ result = client.call_api(path, method, options)
24
+ if result[:error].nil?
25
+ list =[]
26
+ result[:supervisors].each do |device|
27
+ list.push(from_hash(device))
28
+ end
29
+ meta = OpenStruct.new
30
+ meta.offset = result[:meta][:offset]
31
+ meta.limit = result[:meta][:limit]
32
+ meta.total = result[:meta][:total]
33
+
34
+ result = OpenStruct.new
35
+ result.supervisors = list
36
+ result.meta = meta
37
+ result
38
+ else
39
+ RequestError.new(result)
40
+ end
41
+ end
42
+
43
+ def get(id)
44
+ path = '/supervisors/' + id.to_s
45
+ method = 'get'
46
+ result = client.call_api(path, method)
47
+ if result[:error].nil?
48
+ from_hash(result)
49
+ else
50
+ RequestError.new(result)
51
+ end
52
+ end
53
+
54
+ def create
55
+ path = '/supervisors'
56
+ method = 'post'
57
+ form_params = {name: name, ip: ip, storage_id: storage_id}
58
+ options = {form_params: {supervisor: form_params}}
59
+ result = client.call_api(path, method, options)
60
+ if result[:error].nil?
61
+ from_hash(result)
62
+ else
63
+ RequestError.new(result)
64
+ end
65
+ end
66
+
67
+ def update
68
+ path = '/supervisors/' + id.to_s
69
+ method = 'put'
70
+ form_params = {name: name, ip: ip, storage_id: storage_id}
71
+ options = {form_params: {supervisor: form_params}}
72
+ result = client.call_api(path, method, options)
73
+ if result[:error].nil?
74
+ from_hash(result)
75
+ else
76
+ RequestError.new(result)
77
+ end
78
+ end
79
+
80
+ def delete
81
+ path = '/supervisors/' + id.to_s
82
+ method = 'delete'
83
+ result = client.call_api(path, method)
84
+ if result[:error].nil?
85
+ from_hash(result)
86
+ else
87
+ RequestError.new(result)
88
+ end
89
+ end
90
+
91
+ def update_configs
92
+ path = '/supervisors/' + id.to_s + '/update_configs'
93
+ method = 'patch'
94
+ result = client.call_api(path, method)
95
+ if result[:error].nil?
96
+ supervisor = from_hash(result[:supervisor])
97
+ meta = result[:meta]
98
+ result = OpenStruct.new
99
+ result.supervisor = supervisor
100
+ result.meta = meta
101
+ result
102
+ else
103
+ RequestError.new(result)
104
+ end
105
+ end
106
+
107
+ def restart(callback = nil)
108
+ path = '/supervisors/' + id.to_s + '/restart'
109
+ method = 'patch'
110
+ form_params = {callback: callback}
111
+ options = {form_params: form_params}
112
+ result = client.call_api(path, method, options)
113
+ if result[:error].nil?
114
+ result[:message]
115
+ else
116
+ RequestError.new(result)
117
+ end
118
+ end
119
+
120
+ def check_status(callback = nil)
121
+ path = '/supervisors/' + id.to_s + '/check_status'
122
+ method = 'patch'
123
+ form_params = {callback: callback}
124
+ options = {form_params: form_params}
125
+ result = client.call_api(path, method, options)
126
+ if result[:error].nil?
127
+ result[:message]
128
+ else
129
+ RequestError.new(result)
130
+ end
131
+ end
132
+
133
+ def from_hash(attributes)
134
+ supervisor = Innologix::Supervisor.new
135
+ supervisor.id = attributes[:id]
136
+ supervisor.name = attributes[:name]
137
+ supervisor.ip = attributes[:ip]
138
+ supervisor.status = attributes[:status]
139
+ supervisor.storage_id = attributes[:storage_id]
140
+ supervisor.created_at = attributes[:created_at]
141
+ supervisor.updated_at = attributes[:updated_at]
142
+ supervisor
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,115 @@
1
+ module Innologix
2
+ class User
3
+ attr_accessor :id
4
+ attr_accessor :first_name
5
+ attr_accessor :last_name
6
+ attr_accessor :email
7
+ attr_accessor :status
8
+ attr_accessor :created_at
9
+ attr_accessor :updated_at
10
+
11
+ attr_accessor :client
12
+ attr_accessor :error
13
+
14
+ def initialize(h = {})
15
+ h.each { |k, v| public_send("#{k}=", v) }
16
+ @client = Client.default
17
+ end
18
+
19
+ def list(offset = 0, limit = 10)
20
+ path = '/users'
21
+ method = 'get'
22
+ options = {query_params: {offset: offset, limit: limit}}
23
+ result = client.call_api(path, method, options)
24
+ if result[:error].nil?
25
+ list =[]
26
+ result[:users].each do |device|
27
+ list.push(from_hash(device))
28
+ end
29
+ meta = OpenStruct.new
30
+ meta.offset = result[:meta][:offset]
31
+ meta.limit = result[:meta][:limit]
32
+ meta.total = result[:meta][:total]
33
+
34
+ result = OpenStruct.new
35
+ result.users = list
36
+ result.meta = meta
37
+ result
38
+ else
39
+ RequestError.new(result)
40
+ end
41
+ end
42
+
43
+ def get(id)
44
+ path = '/users/' + id.to_s
45
+ method = 'get'
46
+ result = client.call_api(path, method)
47
+ if result[:error].nil?
48
+ from_hash(result)
49
+ else
50
+ RequestError.new(result)
51
+ end
52
+ end
53
+
54
+ def check_email(email)
55
+ path = '/users/check_email'
56
+ method = 'post'
57
+ options = {form_params: {email: email}}
58
+ result = client.call_api(path, method, options)
59
+ if result[:error].nil?
60
+ from_hash(result)
61
+ else
62
+ RequestError.new(result)
63
+ end
64
+ end
65
+
66
+ def create
67
+ path = '/users'
68
+ method = 'post'
69
+ form_params = {first_name: first_name, last_name: last_name, email: email}
70
+ options = {form_params: {user: form_params}}
71
+ result = client.call_api(path, method, options)
72
+ if result[:error].nil?
73
+ from_hash(result)
74
+ else
75
+ RequestError.new(result)
76
+ end
77
+ end
78
+
79
+ def update
80
+ path = '/users/' + id.to_s
81
+ method = 'put'
82
+ form_params = {first_name: first_name, last_name: last_name, email: email}
83
+ options = {form_params: {user: form_params}}
84
+ result = client.call_api(path, method, options)
85
+ if result[:error].nil?
86
+ from_hash(result)
87
+ else
88
+ RequestError.new(result)
89
+ end
90
+ end
91
+
92
+ def delete
93
+ path = '/users/' + id.to_s
94
+ method = 'delete'
95
+ result = client.call_api(path, method)
96
+ if result[:error].nil?
97
+ from_hash(result)
98
+ else
99
+ RequestError.new(result)
100
+ end
101
+ end
102
+
103
+ def from_hash(attributes)
104
+ user = Innologix::User.new
105
+ user.id = attributes[:id]
106
+ user.first_name = attributes[:first_name]
107
+ user.last_name = attributes[:last_name]
108
+ user.email = attributes[:email]
109
+ user.status = attributes[:status]
110
+ user.created_at = attributes[:created_at]
111
+ user.updated_at = attributes[:updated_at]
112
+ user
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,3 @@
1
+ module Innologix
2
+ VERSION = "0.0.2"
3
+ end
data/lib/innologix.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require "bundler/setup"
3
+ require 'yaml'
4
+ require 'json'
5
+ require 'rest_client'
6
+ require 'ostruct'
7
+
8
+ require 'innologix/client'
9
+ require 'innologix/request_error'
10
+ require 'innologix/logger'
11
+ require 'innologix/device_type'
12
+ require 'innologix/device'
13
+ require 'innologix/group'
14
+ require 'innologix/m2m'
15
+ require 'innologix/storage'
16
+ require 'innologix/supervisor'
17
+ require 'innologix/user'
18
+
19
+ module Innologix
20
+ @config = nil
21
+
22
+ class << self
23
+ def config
24
+ @config ||= load_config(config_path)
25
+ end
26
+
27
+ def config_path
28
+ if defined?(Rails)
29
+ File.join(Rails.root, 'config', 'innologix.yml')
30
+ else
31
+ 'innologix.yml'
32
+ end
33
+ end
34
+
35
+ def load_config(yaml_file)
36
+ return {} unless File.exist?(yaml_file)
37
+ cfg = YAML::load(File.open(yaml_file))
38
+ if defined? Rails
39
+ cfg = cfg[Rails.env]
40
+ end
41
+ cfg
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: innologix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - SkyLab Innogram
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Innologix SDK for Ruby. Innologix SDK implements Innologix API. For all
42
+ of list APIs!
43
+ email: duong.nguyen@innogram.co
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/innologix.rb
49
+ - lib/innologix/authorization.rb
50
+ - lib/innologix/client.rb
51
+ - lib/innologix/device.rb
52
+ - lib/innologix/device_type.rb
53
+ - lib/innologix/group.rb
54
+ - lib/innologix/logger.rb
55
+ - lib/innologix/m2m.rb
56
+ - lib/innologix/request_error.rb
57
+ - lib/innologix/storage.rb
58
+ - lib/innologix/supervisor.rb
59
+ - lib/innologix/user.rb
60
+ - lib/innologix/version.rb
61
+ homepage: http://rubygems.org/gems/innologix
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.6.7
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Innologix SDK for Ruby
85
+ test_files: []