megam_api 0.60 → 0.61

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1a0cdb5d59b8121bacce77444aa19f1f09f5b2b
4
- data.tar.gz: 8fd06bd4747a2173d48975a5174616d2514fd912
3
+ metadata.gz: 8c3994fb43d32666338188b374d5029e3b5a3445
4
+ data.tar.gz: a68bfea9975a0d9054d17bccb3696ef0bdd45775
5
5
  SHA512:
6
- metadata.gz: 29c412146699c468d6e8dad37f87c6e5c660178a15aa27d0a3d265f16af4dbff67f1e531d8859ed9ee11cea48002db6d7842d84f7b4e4cef14de107cded92fb5
7
- data.tar.gz: e7454a68624ee2bc14383fc5f567f590c865d6205d668f6585cbd24ec68a78f4fb24fc5338b80851875376224862d8bbf548812b0da654436617667c9178e0a4
6
+ metadata.gz: c1b639e61e7ae38b8dd0cf6070b561f9cb0e6291a9e687e64a59caf21ed1b6d9ba893bcf5cc38cf6f14d8be11b8734bb9bba5b0baa89a750bd8a53d608ad3c65
7
+ data.tar.gz: 44c5272ec3c87e63db416f3c480ab990b8b527c0fe679c2e2bdd67e1c1042c83c6ebf8c04346d1380789921899c2ca333afe3dec0457a0b289078e920d7b833f
data/README.md CHANGED
@@ -1,37 +1,88 @@
1
- Megam Ruby Client
1
+ Megam api for ruby
2
2
  ==================
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/megam_api.svg)](http://badge.fury.io/rb/megam_api)
5
5
 
6
- Megam Ruby Client is used to interact with the Megam API Server.
6
+ Megam api is used to talk to console.megam.io
7
7
 
8
- For more about the Megam' REST API <http://gomegam.com/docs>.[Megam API server](https://github.com/indykish/megam_play.git)
8
+ For more about the REST API <http://docs.megam.io/v1.0/docs/assemblies>
9
9
 
10
- [![Build Status](https://travis-ci.org/indykish/megam_api.png)](https://travis-ci.org/indykish/megam_api)
10
+ [![Build Status](https://travis-ci.org/megamsys/megam_api.png)](https://travis-ci.org/megamsys/megam_api)
11
11
 
12
12
 
13
13
  Usage
14
14
  -----
15
15
 
16
- Start by creating a connection to Megam with your credentials:
16
+ ```shell
17
17
 
18
- require 'megam_api'
19
-
20
- megam = Megam::API.new(:headers => {:api_key => API_KEY, :email => EMAIL})
21
-
22
- Now you can make requests to the api.
23
-
24
- Requests
25
- --------
18
+ gem install megam_api
26
19
 
27
- An overview of the commands you can run can be found in our documentation.
20
+ ```
28
21
 
22
+ * Let us show an account with email = "your_email_id"
29
23
 
30
- ### Documentation
31
-
32
- Refer [documentation] (http://www.gomegam.com/docs)
24
+ ```ruby
33
25
 
26
+ require 'megam_api'
34
27
 
28
+ require 'meggy/meg'
29
+ require 'megam/core/server_api'
30
+ require 'command_line_reporter'
31
+
32
+ class Meggy
33
+ class Meg
34
+ class AccountShow < Meg
35
+ include CommandLineReporter
36
+
37
+ banner "meg account show"
38
+ def run
39
+ begin
40
+ Megam::Config[:email] = Meggy::Config[:email]
41
+ Megam::Config[:api_key] = Meggy::Config[:api_key]
42
+ @excon_res = Megam::Account.show(Megam::Config[:email])
43
+ acct_res = @excon_res.data[:body]
44
+ report(acct_res)
45
+ rescue Megam::API::Errors::ErrorWithResponse => ewr
46
+ res = ewr.response.data[:body].some_msg
47
+ text.error(res[:msg])
48
+ text.msg("#{text.color("Retry Again", :white, :bold)}")
49
+ text.info(res[:links])
50
+ end
51
+ end
52
+
53
+ def report(acct_res)
54
+ table :border => true do
55
+ row :header => true, :color => 'green' do
56
+ column 'Account', :width => 15
57
+ column 'Information', :width => 32, :align => 'left'
58
+ end
59
+ row do
60
+ column 'email'
61
+ column acct_res.email
62
+ end
63
+ row do
64
+ column 'api_key'
65
+ column acct_res.api_key
66
+ end
67
+ row do
68
+ column 'authority'
69
+ column acct_res.authority
70
+ end
71
+ row do
72
+ column 'created_at'
73
+ column acct_res.created_at
74
+ end
75
+ end
76
+ end
77
+
78
+ end
79
+ end
80
+ end
81
+ ```
82
+
83
+ * See [meggy](https://github.com/megamsys/meggy.git) where the files like `Meg` are there.
84
+
85
+ For more implementation details [see meggy](https://github.com/megamsys/meggy.git)
35
86
 
36
87
  We are glad to help if you have questions, or request for new features..
37
88
 
@@ -39,16 +90,16 @@ We are glad to help if you have questions, or request for new features..
39
90
 
40
91
 
41
92
 
42
-
93
+
43
94
  # License
44
95
 
45
96
  | | |
46
97
  |:---------------------|:-----------------------------------------|
47
- | **Author:** | Kishorekumar Neelamegam (<nkishore@megam.co.in>)
48
- | | Raj Thilak (<rajthilak@megam.co.in>)
49
- | | Yeshwanth Kumar (<getyesh@megam.co.in>)
98
+ | **Author:** | Kishorekumar Neelamegam (<nkishore@megam.io>)
99
+ | | Raj Thilak (<rajthilak@megam.io>)
100
+ | | Yeshwanth Kumar (<getyesh@megam.io>)
50
101
  | | Subash Sethurajan (<subash.avc@gmail.com>)
51
- | | Thomas Alrin (<alrin@megam.co.in>)
102
+ | | Thomas Alrin (<thomasalrin@megam.io>)
52
103
  | **Copyright:** | Copyright (c) 2012-2014 Megam Systems.
53
104
  | **License:** | Apache License, Version 2.0
54
105
 
@@ -63,4 +114,3 @@ distributed under the License is distributed on an "AS IS" BASIS,
63
114
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
64
115
  See the License for the specific language governing permissions and
65
116
  limitations under the License.
66
-
data/lib/megam/api.rb CHANGED
@@ -1,110 +1,105 @@
1
- require "base64"
2
- require "time"
3
- require "excon"
4
- require "uri"
5
- require "zlib"
1
+ require 'base64'
2
+ require 'time'
3
+ require 'excon'
4
+ require 'uri'
5
+ require 'zlib'
6
6
  require 'openssl'
7
- require 'yaml' #COMMON YML
8
7
  # open it up when needed. This will be needed when a new customer onboarded via pug.
9
- require "securerandom"
10
-
11
- __LIB_DIR__ = File.expand_path(File.join(File.dirname(__FILE__), ".."))
12
- unless $LOAD_PATH.include?(__LIB_DIR__)
13
- $LOAD_PATH.unshift(__LIB_DIR__)
14
- end
15
-
16
- require "megam/api/errors"
17
- require "megam/api/version"
18
- require "megam/api/accounts"
19
- require "megam/api/requests"
20
- require "megam/api/cat_requests"
21
- require "megam/api/predef_clouds"
22
- require "megam/api/cloud_tool_settings"
23
- require "megam/api/sshkeys"
24
- require "megam/api/marketplaces"
25
- require "megam/api/marketplace_addons"
26
- require "megam/api/organizations"
27
- require "megam/api/domains"
28
- require "megam/api/csars"
29
- require "megam/api/assemblies"
30
- require "megam/api/assembly"
31
- require "megam/api/components"
32
- require "megam/api/event"
33
- require "megam/api/availableunits"
34
- require "megam/api/balances"
35
- require "megam/api/billinghistories"
36
- require "megam/api/billings"
37
- require "megam/api/credithistories"
38
- require "megam/api/discounts"
39
- require "megam/api/subscriptions"
40
- require "megam/api/promos"
41
-
42
- require "megam/core/server_api"
43
- require "megam/core/config"
44
- require "megam/core/stuff"
45
- require "megam/core/text"
46
- require "megam/core/log"
47
- require "megam/core/json_compat"
48
- require "megam/core/auth"
49
- require "megam/core/error"
50
- require "megam/core/account"
51
- require "megam/core/request"
52
- require "megam/core/request_collection"
53
- require "megam/core/predefcloud"
54
- require "megam/core/predefcloud_collection"
55
- require "megam/core/cloudtoolsetting"
56
- require "megam/core/cloudtoolsetting_collection"
57
- require "megam/core/sshkey"
58
- require "megam/core/sshkey_collection"
59
- require "megam/core/marketplace"
60
- require "megam/core/marketplace_collection"
61
- require "megam/core/marketplace_addon"
62
- require "megam/core/marketplace_addon_collection"
63
- require "megam/core/organizations"
64
- require "megam/core/organizations_collection"
65
- require "megam/core/domains"
66
- require "megam/core/assemblies"
67
- require "megam/core/assemblies_collection"
68
- require "megam/core/csar"
69
- require "megam/core/csar_collection"
70
- require "megam/core/konipai"
71
- require "megam/core/assembly"
72
- require "megam/core/assembly_collection"
73
- require "megam/core/components"
74
- require "megam/core/components_collection"
75
- require "megam/core/cat_requests"
76
- require "megam/core/cat_requests_collection"
77
- require "megam/core/event"
78
-
79
-
80
- require "megam/core/availableunits_collection"
81
- require "megam/core/availableunits"
82
- require "megam/core/balances_collection"
83
- require "megam/core/balances"
84
- require "megam/core/billinghistories_collection"
85
- require "megam/core/billinghistories"
86
- require "megam/core/billings_collection"
87
- require "megam/core/billings"
88
- require "megam/core/credithistories_collection"
89
- require "megam/core/credithistories"
90
- require "megam/core/discounts_collection"
91
- require "megam/core/discounts"
92
- require "megam/core/subscriptions_collection"
93
- require "megam/core/subscriptions"
94
- require "megam/core/promos"
8
+ require 'securerandom'
9
+
10
+ __LIB_DIR__ = File.expand_path(File.join(File.dirname(__FILE__), '..'))
11
+ $LOAD_PATH.unshift(__LIB_DIR__) unless $LOAD_PATH.include?(__LIB_DIR__)
12
+
13
+ require 'megam/api/errors'
14
+ require 'megam/api/version'
15
+ require 'megam/api/accounts'
16
+ require 'megam/api/requests'
17
+ require 'megam/api/cat_requests'
18
+ require 'megam/api/predef_clouds'
19
+ require 'megam/api/cloud_tool_settings'
20
+ require 'megam/api/sshkeys'
21
+ require 'megam/api/marketplaces'
22
+ require 'megam/api/marketplace_addons'
23
+ require 'megam/api/organizations'
24
+ require 'megam/api/domains'
25
+ require 'megam/api/csars'
26
+ require 'megam/api/assemblies'
27
+ require 'megam/api/assembly'
28
+ require 'megam/api/components'
29
+ require 'megam/api/event'
30
+ require 'megam/api/availableunits'
31
+ require 'megam/api/balances'
32
+ require 'megam/api/billinghistories'
33
+ require 'megam/api/billings'
34
+ require 'megam/api/credithistories'
35
+ require 'megam/api/discounts'
36
+ require 'megam/api/subscriptions'
37
+ require 'megam/api/promos'
38
+
39
+ require 'megam/core/server_api'
40
+ require 'megam/core/config'
41
+ require 'megam/core/stuff'
42
+ require 'megam/core/text'
43
+ require 'megam/core/log'
44
+ require 'megam/core/json_compat'
45
+ require 'megam/core/auth'
46
+ require 'megam/core/error'
47
+ require 'megam/core/account'
48
+ require 'megam/core/request'
49
+ require 'megam/core/request_collection'
50
+ require 'megam/core/predefcloud'
51
+ require 'megam/core/predefcloud_collection'
52
+ require 'megam/core/cloudtoolsetting'
53
+ require 'megam/core/cloudtoolsetting_collection'
54
+ require 'megam/core/sshkey'
55
+ require 'megam/core/sshkey_collection'
56
+ require 'megam/core/marketplace'
57
+ require 'megam/core/marketplace_collection'
58
+ require 'megam/core/marketplace_addon'
59
+ require 'megam/core/marketplace_addon_collection'
60
+ require 'megam/core/organizations'
61
+ require 'megam/core/organizations_collection'
62
+ require 'megam/core/domains'
63
+ require 'megam/core/assemblies'
64
+ require 'megam/core/assemblies_collection'
65
+ require 'megam/core/csar'
66
+ require 'megam/core/csar_collection'
67
+ require 'megam/core/konipai'
68
+ require 'megam/core/assembly'
69
+ require 'megam/core/assembly_collection'
70
+ require 'megam/core/components'
71
+ require 'megam/core/components_collection'
72
+ require 'megam/core/cat_requests'
73
+ require 'megam/core/cat_requests_collection'
74
+ require 'megam/core/event'
75
+
76
+ require 'megam/core/availableunits_collection'
77
+ require 'megam/core/availableunits'
78
+ require 'megam/core/balances_collection'
79
+ require 'megam/core/balances'
80
+ require 'megam/core/billinghistories_collection'
81
+ require 'megam/core/billinghistories'
82
+ require 'megam/core/billings_collection'
83
+ require 'megam/core/billings'
84
+ require 'megam/core/credithistories_collection'
85
+ require 'megam/core/credithistories'
86
+ require 'megam/core/discounts_collection'
87
+ require 'megam/core/discounts'
88
+ require 'megam/core/subscriptions_collection'
89
+ require 'megam/core/subscriptions'
90
+ require 'megam/core/promos'
95
91
 
96
92
  module Megam
97
93
  class API
98
-
99
- #text is used to print stuff in the terminal (message, log, info, warn etc.)
94
+ # text is used to print stuff in the terminal (message, log, info, warn etc.)
100
95
  attr_accessor :text
101
96
 
102
- API_MEGAM_IO = "api.megam.io".freeze
103
- API_VERSION2 = "/v2".freeze
97
+ API_MEGAM_IO = 'api.megam.io'.freeze
98
+ API_VERSION2 = '/v2'.freeze
104
99
 
105
- X_Megam_DATE = "X-Megam-DATE".freeze
106
- X_Megam_HMAC = "X-Megam-HMAC".freeze
107
- X_Megam_OTTAI = "X-Megam-OTTAI".freeze
100
+ X_Megam_DATE = 'X-Megam-DATE'.freeze
101
+ X_Megam_HMAC = 'X-Megam-HMAC'.freeze
102
+ X_Megam_OTTAI = 'X-Megam-OTTAI'.freeze
108
103
 
109
104
  HEADERS = {
110
105
  'Accept' => 'application/json',
@@ -115,20 +110,17 @@ module Megam
115
110
  }
116
111
 
117
112
  OPTIONS = {
118
- :headers => {},
119
- :host => '127.0.0.1',
120
- :nonblock => false,
121
- :scheme => 'http'
113
+ headers: {},
114
+ host: '127.0.0.1',
115
+ nonblock: false,
116
+ scheme: 'http'
122
117
  }
123
118
 
124
-
125
119
  def text
126
120
  @text ||= Megam::Text.new(STDOUT, STDERR, STDIN, {})
127
121
  end
128
122
 
129
- def last_response
130
- @last_response
131
- end
123
+ attr_reader :last_response
132
124
 
133
125
  # It is assumed that every API call will use an API_KEY/email. This ensures validity of the person
134
126
  # really the same guy on who he claims.
@@ -137,17 +129,17 @@ module Megam
137
129
  # 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
138
130
  # be merged into a class variable @options
139
131
  # 3. Upon merge of the options, the api_key, email as available in the @options is deleted.
140
- def initialize(options={})
132
+ def initialize(options = {})
141
133
  @options = OPTIONS.merge(options)
142
134
  @api_key = @options.delete(:api_key) || ENV['MEGAM_API_KEY']
143
135
  @email = @options.delete(:email)
144
- raise ArgumentError, "You must specify [:email, :api_key]" if @email.nil? || @api_key.nil?
136
+ fail ArgumentError, 'You must specify [:email, :api_key]' if @email.nil? || @api_key.nil?
145
137
  end
146
138
 
147
- def request(params,&block)
139
+ def request(params, &block)
148
140
  just_color_debug("#{@options[:path]}")
149
141
  start = Time.now
150
- Megam::Log.debug("START")
142
+ Megam::Log.debug('START')
151
143
  params.each do |pkey, pvalue|
152
144
  Megam::Log.debug("> #{pkey}: #{pvalue}")
153
145
  end
@@ -170,35 +162,35 @@ module Megam
170
162
  reerror.set_backtrace(error.backtrace)
171
163
  Megam::Log.debug("#{reerror.response.body}")
172
164
  reerror.response.body = Megam::JSONCompat.from_json(reerror.response.body.chomp)
173
- Megam::Log.debug("RESPONSE ERR: Ruby Object")
165
+ Megam::Log.debug('RESPONSE ERR: Ruby Object')
174
166
  Megam::Log.debug("#{reerror.response.body}")
175
167
  raise(reerror)
176
168
  end
177
169
 
178
170
  @last_response = response
179
- Megam::Log.debug("RESPONSE: HTTP Status and Header Data")
171
+ Megam::Log.debug('RESPONSE: HTTP Status and Header Data')
180
172
  Megam::Log.debug("> HTTP #{response.remote_ip} #{response.status}")
181
173
 
182
174
  response.headers.each do |header, value|
183
175
  Megam::Log.debug("> #{header}: #{value}")
184
176
  end
185
- Megam::Log.debug("End HTTP Status/Header Data.")
177
+ Megam::Log.debug('End HTTP Status/Header Data.')
186
178
 
187
179
  if response.body && !response.body.empty?
188
180
  if response.headers['Content-Encoding'] == 'gzip'
189
- Megam::Log.debug("RESPONSE: Content-Encoding is gzip")
181
+ Megam::Log.debug('RESPONSE: Content-Encoding is gzip')
190
182
  response.body = Zlib::GzipReader.new(StringIO.new(response.body)).read
191
183
  end
192
- Megam::Log.debug("RESPONSE: HTTP Body(JSON)")
184
+ Megam::Log.debug('RESPONSE: HTTP Body(JSON)')
193
185
  Megam::Log.debug("#{response.body}")
194
186
 
195
187
  begin
196
188
  unless response.headers[X_Megam_OTTAI]
197
189
  response.body = Megam::JSONCompat.from_json(response.body.chomp)
198
- Megam::Log.debug("RESPONSE: Ruby Object")
190
+ Megam::Log.debug('RESPONSE: Ruby Object')
199
191
  else
200
192
  response.body = Megam::KoniPai.new.koni(response.body.chomp)
201
- Megam::Log.debug("RESPONSE: KoniPai Object ")
193
+ Megam::Log.debug('RESPONSE: KoniPai Object ')
202
194
  end
203
195
  Megam::Log.debug("#{response.body}")
204
196
  rescue Exception => jsonerr
@@ -206,7 +198,7 @@ module Megam
206
198
  raise(jsonerr)
207
199
  end
208
200
  end
209
- Megam::Log.debug("END(#{(Time.now - start).to_s}s)")
201
+ Megam::Log.debug("END(#{(Time.now - start)}s)")
210
202
  # reset (non-persistent) connection
211
203
  @connection.reset
212
204
  response
@@ -215,31 +207,27 @@ module Megam
215
207
  private
216
208
 
217
209
  def just_color_debug(path)
218
- text.msg "--> #{text.color("(#{path})", :cyan,:bold)}" # Why " inside "
210
+ text.msg "--> #{text.color("(#{path})", :cyan, :bold)}" # Why " inside "
219
211
  end
220
212
 
221
-
222
- #Make a lazy connection.
213
+ # Make a lazy connection.
223
214
  def connection
224
- @options[:path] =API_VERSION2 + @options[:path]
215
+ @options[:path] = API_VERSION2 + @options[:path]
225
216
  encoded_api_header = encode_header(@options)
226
- @options[:headers] = HEADERS.merge({
227
- X_Megam_HMAC => encoded_api_header[:hmac],
228
- X_Megam_DATE => encoded_api_header[:date],
229
- }).merge(@options[:headers])
230
-
217
+ @options[:headers] = HEADERS.merge(X_Megam_HMAC => encoded_api_header[:hmac],
218
+ X_Megam_DATE => encoded_api_header[:date]).merge(@options[:headers])
231
219
 
232
- Megam::Log.debug("HTTP Request Data:")
220
+ Megam::Log.debug('HTTP Request Data:')
233
221
  Megam::Log.debug("> HTTP #{@options[:scheme]}://#{@options[:host]}")
234
222
  @options.each do |key, value|
235
223
  Megam::Log.debug("> #{key}: #{value}")
236
224
  end
237
- Megam::Log.debug("End HTTP Request Data.")
238
- if @options[:scheme] == "https"
239
- @connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}",@options)
225
+ Megam::Log.debug('End HTTP Request Data.')
226
+ if @options[:scheme] == 'https'
227
+ @connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}", @options)
240
228
  else
241
- Excon.defaults[:ssl_verify_peer] = false
242
- @connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}:9000",@options)
229
+ Excon.defaults[:ssl_verify_peer] = false
230
+ @connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}:9000", @options)
243
231
  end
244
232
  @connection
245
233
  end
@@ -252,21 +240,19 @@ module Megam
252
240
  # :date
253
241
  # (Refer https://github.com/indykish/megamplay.git/test/AuthenticateSpec.scala)
254
242
  def encode_header(cmd_parms)
255
- header_params ={}
243
+ header_params = {}
256
244
  body_digest = OpenSSL::Digest::MD5.digest(cmd_parms[:body])
257
245
  body_base64 = Base64.encode64(body_digest)
258
246
 
259
- current_date = Time.now.strftime("%Y-%m-%d %H:%M")
247
+ current_date = Time.now.strftime('%Y-%m-%d %H:%M')
260
248
 
261
- data="#{current_date}"+"\n"+"#{cmd_parms[:path]}"+"\n"+"#{body_base64}"
249
+ data = "#{current_date}" + "\n" + "#{cmd_parms[:path]}" + "\n" + "#{body_base64}"
262
250
 
263
251
  digest = OpenSSL::Digest.new('sha1')
264
252
  movingFactor = data.rstrip!
265
253
  hash = OpenSSL::HMAC.hexdigest(digest, @api_key, movingFactor)
266
- final_hmac = @email+':' + hash
267
- header_params = { :hmac => final_hmac, :date => current_date}
254
+ final_hmac = @email + ':' + hash
255
+ header_params = { hmac: final_hmac, date: current_date }
268
256
  end
269
-
270
257
  end
271
-
272
258
  end
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "0.60"
3
+ VERSION = "0.61"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: megam_api
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.60'
4
+ version: '0.61'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajthilak, Kishorekumar Neelamegam, Thomas Alrin, Yeshwanth Kumar, Subash Sethurajan