megam_api 1.6.8 → 1.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acf9806f47fab932ce69e0db128474d8c9f0f182
4
- data.tar.gz: dbfc46c378ac00c0170b56e11e7aef94e079a422
3
+ metadata.gz: 18bbd9e96c718b62b88f6db3596e5271ac932332
4
+ data.tar.gz: 2a98f3d72705ce5617b4a25bab75ba6284f1af91
5
5
  SHA512:
6
- metadata.gz: 955ae148705c0df26622687a41681c7874eed2cb4a10b0c4e8e471c136f513513e9a04a635dee6ee1d7a21a75769f44f06bd05bf7ba125759a476f936161ab70
7
- data.tar.gz: 03965dbfff7f7d7dd4fdb3e3f680f92b5a14b1fe4a0eb983fbda81bc014ff2908072740073d73badadde7150c7374d52fcdd5c0e882c35527289a734053248b3
6
+ metadata.gz: 323ea0ed3d5e70e205687c71da0eb67957071e3722f3ecb9b557831572a0bcb30ea3c9dd9ba36fab1cb14486a24de52be213b6cf1ea48bd19219bad948eee6d8
7
+ data.tar.gz: 25c694febd7b2c4470dfbd6f81e299d16c5caec5edc3d7a5cc0d2471969d0987d4d1ee8b3deb923b0b73ec625d8ba693881a1558c7339600c1220ac8abc6e3ae
data/README.md CHANGED
@@ -20,7 +20,7 @@ For more implementation details [see nilavu](http://github.com/megamsys/nilavu.g
20
20
 
21
21
  # License
22
22
 
23
- Apache V2
23
+ MIT
24
24
 
25
25
  # Author
26
26
 
data/lib/megam/api.rb CHANGED
@@ -93,66 +93,54 @@ require 'megam/core/promos'
93
93
 
94
94
  module Megam
95
95
  class API
96
-
97
- # text is used to print stuff in the terminal (message, log, info, warn etc.)
98
96
  attr_accessor :text
97
+ attr_accessor :email, :api_key, :password_hash, :org_id
98
+ attr_accessor :api_url, :api_version
99
+ attr_reader :last_response
100
+
101
+ API_VERSION2 = '/v2'.freeze
99
102
 
100
- API_VERSION2 = '/v2'.freeze
101
-
102
- X_Megam_DATE = 'X-Megam-DATE'.freeze
103
- X_Megam_HMAC = 'X-Megam-HMAC'.freeze
104
- X_Megam_OTTAI = 'X-Megam-OTTAI'.freeze
105
- X_Megam_ORG = 'X-Megam-ORG'.freeze
103
+ X_Megam_DATE = 'X-Megam-DATE'.freeze
104
+ X_Megam_HMAC = 'X-Megam-HMAC'.freeze
105
+ X_Megam_OTTAI = 'X-Megam-OTTAI'.freeze
106
+ X_Megam_ORG = 'X-Megam-ORG'.freeze
106
107
  X_Megam_PUTTUSAVI = 'X-Megam-PUTTUSAVI'.freeze
107
108
 
108
109
  HEADERS = {
109
- 'Accept' => 'application/json',
110
+ 'Accept' => 'application/json',
110
111
  'Accept-Encoding' => 'gzip',
111
- 'User-Agent' => "megam-api/#{Megam::API::VERSION}",
112
- 'X-Ruby-Version' => RUBY_VERSION,
112
+ 'User-Agent' => "megam-api/#{Megam::API::VERSION}",
113
+ 'X-Ruby-Version' => RUBY_VERSION,
113
114
  'X-Ruby-Platform' => RUBY_PLATFORM
114
115
  }
115
116
 
116
117
  OPTIONS = {
117
118
  headers: {},
118
- host: '127.0.0.1',
119
- nonblock: false,
120
- scheme: 'http'
119
+ nonblock: false
121
120
  }
122
121
 
123
- def text
124
- @text ||= Megam::Text.new(STDOUT, STDERR, STDIN, {})
125
- end
126
-
127
- attr_reader :last_response
128
-
129
- # It is assumed that every API call will use an API_KEY/email. This ensures validity of the person
130
- # really the same guy on who he claims.
131
- # 3 levels of options exits
132
- # 1. The global OPTIONS as available inside the API (OPTIONS)
133
- # 2. The options as passed via the instantiation of API will override global options. The ones that are passed are :email and :api_key and will
134
- # be merged into a class variable @options
135
- # 3. Upon merge of the options, the api_key, email as available in the @options is deleted.
136
122
  def initialize(options = {})
137
123
  @options = OPTIONS.merge(options)
138
- @api_key = @options.delete(:api_key) || ENV['MEGAM_API_KEY']
139
- @email = @options.delete(:email)
140
- @password_hash = @options.delete(:password_hash)
141
- @org_id = @options.delete(:org_id)
142
- unless !@options.delete(:reset_flag)
143
- fail Megam::API::Errors::AuthKeysMissing if (@email.nil? && @api_key.nil?) || (@email.nil? && @password_hash.nil?)
144
- end
124
+
125
+ assign_credentials
126
+
127
+ ensure_host_is_flattened
128
+
129
+ ensure_authkeys unless is_passthru?
130
+
131
+ turn_off_ssl_verify
132
+ end
133
+
134
+
135
+ def text
136
+ @text ||= Megam::Text.new(STDOUT, STDERR, STDIN, {})
145
137
  end
146
138
 
147
139
  def request(params, &block)
148
-
149
140
  just_color_debug("#{@options[:path]}")
150
141
  start = Time.now
151
142
  Megam::Log.debug('START')
152
- params.each do |pkey, pvalue|
153
- Megam::Log.debug("> #{pkey}: #{pvalue}")
154
- end
155
-
143
+
156
144
  begin
157
145
  response = connection.request(params, &block)
158
146
  rescue Excon::Errors::HTTPStatusError => error
@@ -169,110 +157,131 @@ module Megam
169
157
  end
170
158
  reerror = klass.new(error.message, error.response)
171
159
  reerror.set_backtrace(error.backtrace)
172
- Megam::Log.debug("#{reerror.response.body}")
173
160
  reerror.response.body = Megam::JSONCompat.from_json(reerror.response.body.chomp)
174
- Megam::Log.debug('RESPONSE ERR: Ruby Object')
175
- Megam::Log.debug("#{reerror.response.body}")
176
161
  raise(reerror)
177
162
  end
178
163
 
179
164
  @last_response = response
180
- Megam::Log.debug('RESPONSE: HTTP Status and Header Data')
181
- Megam::Log.debug("> HTTP #{response.remote_ip} #{response.status}")
182
-
183
- response.headers.each do |header, value|
184
- Megam::Log.debug("> #{header}: #{value}")
185
- end
186
- Megam::Log.debug('End HTTP Status/Header Data.')
187
-
165
+
188
166
  if response.body && !response.body.empty?
189
167
  if response.headers['Content-Encoding'] == 'gzip'
190
- Megam::Log.debug('RESPONSE: Content-Encoding is gzip')
191
168
  response.body = Zlib::GzipReader.new(StringIO.new(response.body)).read
192
169
  end
193
- Megam::Log.debug('RESPONSE: HTTP Body(JSON)')
194
- Megam::Log.debug("#{response.body}")
195
170
 
196
171
  begin
197
172
  unless response.headers[X_Megam_OTTAI]
198
173
  response.body = Megam::JSONCompat.from_json(response.body.chomp)
199
- Megam::Log.debug('RESPONSE: Ruby Object')
200
174
  else
201
175
  response.body = Megam::KoniPai.new.koni(response.body.chomp)
202
- Megam::Log.debug('RESPONSE: KoniPai Object ')
203
176
  end
204
- Megam::Log.debug("#{response.body}")
205
177
  rescue Exception => jsonerr
206
- Megam::Log.error(jsonerr)
207
178
  raise(jsonerr)
208
179
  end
209
180
  end
181
+
210
182
  Megam::Log.debug("END(#{(Time.now - start)}s)")
211
- # reset (non-persistent) connection
183
+
212
184
  @connection.reset
213
185
  response
214
186
  end
215
187
 
216
188
  private
189
+
190
+ def assign_credentials
191
+ @api_key = @options.delete(:api_key) || ENV['MEGAM_API_KEY']
192
+ @email = @options.delete(:email)
193
+ @password_hash = @options.delete(:password_hash)
194
+ @org_id = @options.delete(:org_id)
195
+ end
196
+
197
+ def ensure_host_is_flattened
198
+ uri = URI(@options.delete(:host)) if @options.has_key?(:host)
199
+
200
+ scheme = (uri && uri.scheme) ? uri.scheme : 'http'
201
+
202
+ host = (uri && uri.host) ? uri.host : '127.0.0.1'
203
+
204
+ port = (uri && uri.port) ? uri.port.to_s : '9000'
205
+
206
+ @api_version = (uri && uri.path) ? uri.path : API_VERSION2
207
+
208
+ @api_url = scheme + "://" + host + ":" + port + @api_version
209
+ end
210
+
211
+ def is_passthru?
212
+ @options[:passthru]
213
+ end
214
+
215
+ def ensure_authkeys
216
+ if api_combo_missing? && pw_combo_missing?
217
+ fail Megam::API::Errors::AuthKeysMissing
218
+ end
219
+ end
220
+
221
+ def api_combo_missing?
222
+ (!@email.nil? && !@api_key.nil?)
223
+ end
224
+
225
+
226
+
227
+ def pw_combo_missing?
228
+ (!@email.nil? && !@password_hash.nil?)
229
+ end
230
+
231
+ def turn_off_ssl_verify
232
+ Excon.defaults[:ssl_verify_peer] = false unless @api_url.include?("https")
233
+
234
+ end
217
235
 
218
236
  def just_color_debug(path)
219
- text.msg "--> #{text.color("(#{path})", :cyan, :bold)}" # Why " inside "
237
+ text.msg "--> #{text.color("(#{path})", :cyan, :bold)}"
220
238
  end
221
239
 
222
- # Make a lazy connection.
223
240
  def connection
224
- @options[:path] = API_VERSION2 + @options[:path]
225
- encoded_api_header = encode_header(@options)
226
- @options[:headers] = HEADERS.merge(X_Megam_HMAC => encoded_api_header[:hmac],
227
- X_Megam_DATE => encoded_api_header[:date], X_Megam_ORG => "#{@org_id}").merge(@options[:headers])
228
- if (@api_key == "" || @api_key.nil?)
229
- Megam::Log.debug("> PWH #{@password_hash}")
230
- @options[:headers] = @options[:headers].merge(X_Megam_PUTTUSAVI => "true") unless (@password_hash == "" || @password_hash.nil?)
231
- end
241
+ @options[:path] = @api_version + @options[:path]
242
+
243
+ build_headers
232
244
 
233
- Megam::Log.debug('HTTP Request Data:')
234
- Megam::Log.debug("> HTTP #{@options[:scheme]}://#{@options[:host]}")
235
- @options.each do |key, value|
236
- Megam::Log.debug("> #{key}: #{value}")
237
- end
238
- Megam::Log.debug('End HTTP Request Data.')
239
- if @options[:scheme] == 'https'
240
- @connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}", @options)
241
- else
242
- Excon.defaults[:ssl_verify_peer] = false
243
- @connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}:9000", @options)
244
- end
245
- @connection
245
+ @connection = Excon.new(@api_url, @options)
246
246
  end
247
+
248
+
249
+ def build_headers
250
+ encoded = encode_header
251
+
252
+ @options[:headers] = HEADERS.merge(X_Megam_HMAC => encoded[:hmac],
253
+ X_Megam_DATE => encoded[:date],
254
+ X_Megam_ORG => @org_id).merge(@options[:headers])
255
+
256
+
257
+ build_header_puttusavi
258
+ end
247
259
 
248
- ## encode header as per rules.
249
- # The input hash will have
250
- # :api_key, :email, :body, :path
251
- # The output will have
252
- # :hmac
253
- # :date
254
- def encode_header(cmd_parms)
255
- header_params = {}
256
- body_digest = OpenSSL::Digest::MD5.digest(cmd_parms[:body])
257
- body_base64 = Base64.urlsafe_encode64(body_digest)
260
+ def encode_header
261
+ body_base64 = Base64.urlsafe_encode64(OpenSSL::Digest::MD5.digest(@options[:body]))
258
262
 
259
263
  current_date = Time.now.strftime('%Y-%m-%d %H:%M')
260
264
 
261
- data = "#{current_date}" + "\n" + "#{cmd_parms[:path]}" + "\n" + "#{body_base64}"
265
+ movingFactor = "#{current_date}" + "\n" + "#{@options[:path]}" + "\n" + "#{body_base64}"
262
266
 
263
- digest = OpenSSL::Digest.new('sha1')
267
+ digest = OpenSSL::Digest.new('sha256')
264
268
 
265
- movingFactor = data
266
-
267
- if !(@password_hash.nil?) && @api_key.nil?
269
+ if pw_combo_missing?
268
270
  hash = OpenSSL::HMAC.hexdigest(digest, Base64.strict_decode64(@password_hash), movingFactor)
269
- elsif !(@api_key.nil?)
271
+ elsif api_combo_missing?
270
272
  hash = OpenSSL::HMAC.hexdigest(digest, @api_key, movingFactor)
271
273
  else
272
274
  hash = OpenSSL::HMAC.hexdigest(digest, "", movingFactor)
273
275
  end
274
- final_hmac = @email + ':' + hash
275
- header_params = { hmac: final_hmac, date: current_date }
276
+
277
+ { hmac: (@email + ':' + hash), date: current_date }
278
+ end
279
+
280
+ def build_header_puttusavi
281
+ if pw_combo_missing?
282
+ @options[:headers] = @options[:headers].merge(X_Megam_PUTTUSAVI => "true")
283
+ end
276
284
  end
285
+
277
286
  end
278
287
  end
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "1.6.8"
3
+ VERSION = "1.7.1"
4
4
  end
5
5
  end
@@ -1,15 +1,14 @@
1
1
 
2
2
  # Wrapper class for interacting with JSON.
3
-
4
3
  require "ffi_yajl"
5
4
  # We're requiring this to prevent breaking consumers using Hash.to_json
6
5
  require "json"
7
6
 
8
7
  module Megam
9
8
  class JSONCompat
9
+
10
10
  JSON_MAX_NESTING = 1000
11
11
 
12
-
13
12
  JSON_CLAZ = 'json_claz'.freeze
14
13
 
15
14
  MEGAM_ACCOUNT = 'Megam::Account'.freeze
@@ -50,13 +49,13 @@ module Megam
50
49
  MEGAM_EVENTSBILLINGCOLLECTION = 'Megam::EventsBillingCollection'.freeze
51
50
  MEGAM_EVENTSSTORAGE = 'Megam::EventsStorage'.freeze
52
51
  MEGAM_EVENTSSTORAGECOLLECTION = 'Megam::EventsStorageCollection'.freeze
53
- MEGAM_SUBSCRIPTIONS = 'Megam::Subscriptions'.freeze
54
- MEGAM_SUBSCRIPTIONSCOLLECTION = 'Megam::SubscriptionsCollection'.freeze
55
- MEGAM_ADDONS = 'Megam::Addons'.freeze
56
- MEGAM_ADDONSCOLLECTION = 'Megam::AddonsCollection'.freeze
52
+ MEGAM_SUBSCRIPTIONS = 'Megam::Subscriptions'.freeze
53
+ MEGAM_SUBSCRIPTIONSCOLLECTION = 'Megam::SubscriptionsCollection'.freeze
54
+ MEGAM_ADDONS = 'Megam::Addons'.freeze
55
+ MEGAM_ADDONSCOLLECTION = 'Megam::AddonsCollection'.freeze
57
56
  MEGAM_PROMOS = 'Megam::Promos'.freeze
58
57
 
59
- class <<self
58
+ class << self
60
59
  # API to use to avoid create_addtions
61
60
  def parse(source, opts = {})
62
61
  begin
data/megam_api.gemspec CHANGED
@@ -5,20 +5,20 @@ require "megam/api/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "megam_api"
7
7
  s.version = Megam::API::VERSION
8
- s.authors = ["Rajthilak, Kishorekumar Neelamegam, Ranjitha R, Rajesh Rajagopalan, Thomas Alrin, Yeshwanth Kumar, Subash Sethurajan, Arunkumar sekar"]
9
- s.email = ["rajthilak@megam.io","nkishore@megam.io","ranjithar@megam.io","rajeshr@megam.io","thomasalrin@megam.io","getyesh@megam.io","subash.avc@gmail.com","arunkumar.sekar@megam.io"]
8
+ s.authors = ["Rajthilak, Kishorekumar Neelamegam, Ranjitha R, Vinodhini V, Rathish VBR, Rajesh Rajagopalan, Thomas Alrin, Yeshwanth Kumar, Subash Sethurajan, Arunkumar sekar"]
9
+ s.email = ["rajthilak@megam.io","nkishore@megam.io","ranjithar@megam.io","vino.v@megam.io","rathishvbr@megam.io","rajeshr@megam.io","thomasalrin@gmail.com","morpheyesh@gmail.com","subash.avc@gmail.com","arunkumar.sekar@megam.io"]
10
10
  s.homepage = "http://github.com/megamsys/megam_api"
11
- s.license = "Apache-2.0"
11
+ s.license = "MIT"
12
12
  s.extra_rdoc_files = ["README.md", "LICENSE" ]
13
- s.summary = %q{Ruby Client for the Megam}
14
- s.description = %q{Ruby Client for the Megam vertice platform. Performs REST calls to Vertice Gateway - http://github.com/megamsys/vertice_gateway.git}
13
+ s.summary = %q{Ruby Client for the Megam Vertice}
14
+ s.description = %q{Ruby Client for the Megam vertice. Performs REST calls to Vertice Gateway - http://github.com/megamsys/vertice_gateway.git}
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
- s.add_runtime_dependency 'excon', '~> 0.51.0'
19
+ s.add_runtime_dependency 'excon', '~> 0.52.0'
20
20
  s.add_runtime_dependency 'highline', '~> 1.7'
21
- s.add_runtime_dependency 'ffi-yajl', '~> 2.2'
21
+ s.add_runtime_dependency 'ffi-yajl', '~> 2.3'
22
22
  s.add_runtime_dependency 'mixlib-config', '~> 2.2'
23
23
  s.add_runtime_dependency 'mixlib-log', '~> 1.6'
24
24
  s.add_development_dependency 'minitest', '~> 5.9'
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: megam_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.8
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
- - Rajthilak, Kishorekumar Neelamegam, Ranjitha R, Rajesh Rajagopalan, Thomas Alrin,
8
- Yeshwanth Kumar, Subash Sethurajan, Arunkumar sekar
7
+ - Rajthilak, Kishorekumar Neelamegam, Ranjitha R, Vinodhini V, Rathish VBR, Rajesh
8
+ Rajagopalan, Thomas Alrin, Yeshwanth Kumar, Subash Sethurajan, Arunkumar sekar
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-16 00:00:00.000000000 Z
12
+ date: 2016-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: excon
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 0.51.0
20
+ version: 0.52.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 0.51.0
27
+ version: 0.52.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: highline
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '2.2'
48
+ version: '2.3'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '2.2'
55
+ version: '2.3'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: mixlib-config
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -109,15 +109,17 @@ dependencies:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: '11.2'
112
- description: Ruby Client for the Megam vertice platform. Performs REST calls to Vertice
113
- Gateway - http://github.com/megamsys/vertice_gateway.git
112
+ description: Ruby Client for the Megam vertice. Performs REST calls to Vertice Gateway
113
+ - http://github.com/megamsys/vertice_gateway.git
114
114
  email:
115
115
  - rajthilak@megam.io
116
116
  - nkishore@megam.io
117
117
  - ranjithar@megam.io
118
+ - vino.v@megam.io
119
+ - rathishvbr@megam.io
118
120
  - rajeshr@megam.io
119
- - thomasalrin@megam.io
120
- - getyesh@megam.io
121
+ - thomasalrin@gmail.com
122
+ - morpheyesh@gmail.com
121
123
  - subash.avc@gmail.com
122
124
  - arunkumar.sekar@megam.io
123
125
  executables: []
@@ -247,7 +249,7 @@ files:
247
249
  - test/test_subscriptions.rb
248
250
  homepage: http://github.com/megamsys/megam_api
249
251
  licenses:
250
- - Apache-2.0
252
+ - MIT
251
253
  metadata: {}
252
254
  post_install_message:
253
255
  rdoc_options: []
@@ -268,5 +270,31 @@ rubyforge_project:
268
270
  rubygems_version: 2.5.1
269
271
  signing_key:
270
272
  specification_version: 4
271
- summary: Ruby Client for the Megam
272
- test_files: []
273
+ summary: Ruby Client for the Megam Vertice
274
+ test_files:
275
+ - test/mixins/test_assemblies.rb
276
+ - test/mixins/test_assembly.rb
277
+ - test/mixins/test_component.rb
278
+ - test/test_accounts.rb
279
+ - test/test_addons.rb
280
+ - test/test_assemblies.rb
281
+ - test/test_assembly.rb
282
+ - test/test_balances.rb
283
+ - test/test_billedhistories.rb
284
+ - test/test_billingtranscations.rb
285
+ - test/test_components.rb
286
+ - test/test_disks.rb
287
+ - test/test_domains.rb
288
+ - test/test_eventsbilling.rb
289
+ - test/test_eventscontainer.rb
290
+ - test/test_eventsstorage.rb
291
+ - test/test_eventsvm.rb
292
+ - test/test_helper.rb
293
+ - test/test_marketplaces.rb
294
+ - test/test_organizations.rb
295
+ - test/test_promos.rb
296
+ - test/test_requests.rb
297
+ - test/test_sensors.rb
298
+ - test/test_snapshots.rb
299
+ - test/test_sshkeys.rb
300
+ - test/test_subscriptions.rb