megam_api 0.100 → 1.5.beta2

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.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -69
  3. data/lib/megam/api.rb +15 -37
  4. data/lib/megam/api/errors.rb +19 -19
  5. data/lib/megam/api/version.rb +1 -1
  6. data/lib/megam/core/account.rb +1 -1
  7. data/lib/megam/core/assemblies.rb +1 -1
  8. data/lib/megam/core/assemblies_collection.rb +7 -15
  9. data/lib/megam/core/assembly.rb +1 -1
  10. data/lib/megam/core/assembly_collection.rb +7 -15
  11. data/lib/megam/core/balances.rb +1 -1
  12. data/lib/megam/core/balances_collection.rb +8 -16
  13. data/lib/megam/core/billedhistories.rb +1 -1
  14. data/lib/megam/core/billedhistories_collection.rb +7 -15
  15. data/lib/megam/core/components.rb +1 -1
  16. data/lib/megam/core/components_collection.rb +103 -110
  17. data/lib/megam/core/domain_collection.rb +102 -109
  18. data/lib/megam/core/domains.rb +1 -1
  19. data/lib/megam/core/error.rb +1 -15
  20. data/lib/megam/core/json_compat.rb +170 -208
  21. data/lib/megam/core/marketplace.rb +1 -1
  22. data/lib/megam/core/marketplace_collection.rb +7 -16
  23. data/lib/megam/core/organizations.rb +1 -1
  24. data/lib/megam/core/organizations_collection.rb +8 -40
  25. data/lib/megam/core/promos.rb +1 -1
  26. data/lib/megam/core/request.rb +1 -1
  27. data/lib/megam/core/request_collection.rb +7 -16
  28. data/lib/megam/core/rest_adapter.rb +54 -0
  29. data/lib/megam/core/sensors.rb +1 -1
  30. data/lib/megam/core/sensors_collection.rb +7 -14
  31. data/lib/megam/core/sshkey.rb +1 -1
  32. data/lib/megam/core/sshkey_collection.rb +103 -110
  33. data/lib/megam/core/stuff.rb +2 -34
  34. data/lib/megam/core/text.rb +1 -0
  35. data/lib/megam/core/text_formatter.rb +2 -1
  36. data/megam_api.gemspec +2 -2
  37. metadata +10 -56
  38. data/lib/megam/api/availableunits.rb +0 -50
  39. data/lib/megam/api/billings.rb +0 -50
  40. data/lib/megam/api/credithistories.rb +0 -50
  41. data/lib/megam/api/csars.rb +0 -75
  42. data/lib/megam/api/discounts.rb +0 -50
  43. data/lib/megam/api/invoices.rb +0 -50
  44. data/lib/megam/api/login.rb +0 -29
  45. data/lib/megam/api/subscriptions.rb +0 -50
  46. data/lib/megam/core/auth.rb +0 -91
  47. data/lib/megam/core/availableunits.rb +0 -182
  48. data/lib/megam/core/availableunits_collection.rb +0 -144
  49. data/lib/megam/core/billings.rb +0 -242
  50. data/lib/megam/core/billings_collection.rb +0 -144
  51. data/lib/megam/core/config.rb +0 -41
  52. data/lib/megam/core/credithistories.rb +0 -191
  53. data/lib/megam/core/credithistories_collection.rb +0 -144
  54. data/lib/megam/core/csar.rb +0 -179
  55. data/lib/megam/core/csar_collection.rb +0 -148
  56. data/lib/megam/core/discounts.rb +0 -204
  57. data/lib/megam/core/discounts_collection.rb +0 -164
  58. data/lib/megam/core/invoices.rb +0 -231
  59. data/lib/megam/core/invoices_collection.rb +0 -144
  60. data/lib/megam/core/server_api.rb +0 -52
  61. data/lib/megam/core/subscriptions.rb +0 -191
  62. data/lib/megam/core/subscriptions_collection.rb +0 -144
  63. data/test/test_availableunits.rb +0 -28
  64. data/test/test_billings.rb +0 -33
  65. data/test/test_cat_requests.rb +0 -20
  66. data/test/test_credithistories.rb +0 -29
  67. data/test/test_csars.rb +0 -22
  68. data/test/test_discounts.rb +0 -31
  69. data/test/test_invoices.rb +0 -31
  70. data/test/test_login.rb +0 -10
  71. data/test/test_marketplaceaddons.rb +0 -46
  72. data/test/test_predefclouds.rb +0 -80
  73. data/test/test_subscriptions.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b09c53165c228fc561185aaf1710885cd091833
4
- data.tar.gz: 90ab69ccb037c5592fd85f71847dde4c3446a2fd
3
+ metadata.gz: e3c1c1f8eda74d69c6e721b36a1d4266a35c013b
4
+ data.tar.gz: e601f5d38a95771f9640f208c3b4978df0c4404d
5
5
  SHA512:
6
- metadata.gz: 7440f2e7f807e534c016c0f6ad5cb0061486e5467ae126be9bcc62fb1a94e7715e01af6a5b35cdbf32ac319184663b3bb3d6b57774583d7567198c88ca1cc92b
7
- data.tar.gz: 37c99aec1dc1ccbf9ccb17c9d0d141ddf7d4b1805b47f94841b312452ed03d222b78a23a3cb06de235bd9a82e02bd2a7c11720c3944878b097a718fb7bc6cdbc
6
+ metadata.gz: 4fcb38fe7ddcd5df82f7dd441f24e000ed8df47ed946f09941aa3904631017d74174ea9c346b308dd662da5d72ed41773a5ac541ba4d9f2d3b376174e448136e
7
+ data.tar.gz: 292a610d1c3d11c95c20e05af0b9dde48f2f33b37ce4abdd0be76c6fc7bc6e236b74264cc243a42d26d55efe7b3280b31f4198b0f5316926c965480d52553cee
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
- Megam api for ruby
2
- ==================
1
+ Vertice api for ruby
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 api is used to talk to console.megam.io
6
+ Vertice api is used to talk to the vertice gateway server.
7
7
 
8
- For more about the REST API <http://docs.megam.io/v1.0/docs/assemblies>
8
+ For more about the REST API <http://docs.megam.io>
9
9
 
10
10
  [![Build Status](https://travis-ci.org/megamsys/megam_api.png)](https://travis-ci.org/megamsys/megam_api)
11
11
 
@@ -19,70 +19,7 @@ gem install megam_api
19
19
 
20
20
  ```
21
21
 
22
- * Let us show an account with email = "your_email_id"
23
-
24
- ```ruby
25
-
26
- require 'megam_api'
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)
22
+ For more implementation details [see nilavu](http://github.com/megamsys/nilavu.git)
86
23
 
87
24
  We are glad to help if you have questions, or request for new features..
88
25
 
@@ -90,7 +27,6 @@ We are glad to help if you have questions, or request for new features..
90
27
 
91
28
 
92
29
 
93
-
94
30
  # License
95
31
 
96
32
  | | |
data/lib/megam/api.rb CHANGED
@@ -23,28 +23,21 @@ require 'openssl'
23
23
  __LIB_DIR__ = File.expand_path(File.join(File.dirname(__FILE__), '..'))
24
24
  $LOAD_PATH.unshift(__LIB_DIR__) unless $LOAD_PATH.include?(__LIB_DIR__)
25
25
 
26
- require 'megam/api/errors'
27
- require 'megam/api/version'
28
26
  require 'megam/api/accounts'
29
- require 'megam/api/requests'
30
- require 'megam/api/sshkeys'
31
- require 'megam/api/marketplaces'
32
- require 'megam/api/organizations'
33
- require 'megam/api/domains'
34
- require 'megam/api/csars'
35
27
  require 'megam/api/assemblies'
36
28
  require 'megam/api/assembly'
37
- require 'megam/api/components'
38
- require 'megam/api/sensors'
39
- require 'megam/api/availableunits'
40
29
  require 'megam/api/balances'
41
30
  require 'megam/api/billedhistories'
42
- require 'megam/api/billings'
43
- require 'megam/api/credithistories'
44
- require 'megam/api/discounts'
45
- require 'megam/api/subscriptions'
31
+ require 'megam/api/components'
32
+ require 'megam/api/domains'
33
+ require 'megam/api/errors'
34
+ require 'megam/api/marketplaces'
35
+ require 'megam/api/organizations'
46
36
  require 'megam/api/promos'
47
- require 'megam/api/invoices'
37
+ require 'megam/api/requests'
38
+ require 'megam/api/sensors'
39
+ require 'megam/api/sshkeys'
40
+ require 'megam/api/version'
48
41
 
49
42
  require 'megam/mixins/assemblies'
50
43
  require 'megam/mixins/assembly'
@@ -54,13 +47,11 @@ require 'megam/mixins/megam_attributes'
54
47
  require 'megam/mixins/outputs'
55
48
  require 'megam/mixins/policies'
56
49
 
57
- require 'megam/core/server_api'
58
- require 'megam/core/config'
50
+ require 'megam/core/rest_adapter'
59
51
  require 'megam/core/stuff'
60
52
  require 'megam/core/text'
61
53
  require 'megam/core/log'
62
54
  require 'megam/core/json_compat'
63
- require 'megam/core/auth'
64
55
  require 'megam/core/error'
65
56
  require 'megam/core/account'
66
57
  require 'megam/core/request'
@@ -75,8 +66,6 @@ require 'megam/core/domains'
75
66
  require 'megam/core/domain_collection'
76
67
  require 'megam/core/assemblies'
77
68
  require 'megam/core/assemblies_collection'
78
- require 'megam/core/csar'
79
- require 'megam/core/csar_collection'
80
69
  require 'megam/core/konipai'
81
70
  require 'megam/core/assembly'
82
71
  require 'megam/core/assembly_collection'
@@ -84,26 +73,15 @@ require 'megam/core/components'
84
73
  require 'megam/core/components_collection'
85
74
  require 'megam/core/sensors'
86
75
  require 'megam/core/sensors_collection'
87
- require 'megam/core/availableunits_collection'
88
- require 'megam/core/availableunits'
89
76
  require 'megam/core/balances_collection'
90
77
  require 'megam/core/balances'
91
78
  require 'megam/core/billedhistories_collection'
92
79
  require 'megam/core/billedhistories'
93
- require 'megam/core/billings_collection'
94
- require 'megam/core/billings'
95
- require 'megam/core/credithistories_collection'
96
- require 'megam/core/credithistories'
97
- require 'megam/core/discounts_collection'
98
- require 'megam/core/discounts'
99
- require 'megam/core/subscriptions_collection'
100
- require 'megam/core/subscriptions'
101
80
  require 'megam/core/promos'
102
- require 'megam/core/invoices_collection'
103
- require 'megam/core/invoices'
104
81
 
105
82
  module Megam
106
83
  class API
84
+
107
85
  # text is used to print stuff in the terminal (message, log, info, warn etc.)
108
86
  attr_accessor :text
109
87
 
@@ -113,6 +91,7 @@ module Megam
113
91
  X_Megam_HMAC = 'X-Megam-HMAC'.freeze
114
92
  X_Megam_OTTAI = 'X-Megam-OTTAI'.freeze
115
93
  X_Megam_ORG = 'X-Megam-ORG'.freeze
94
+ X_Megam_PUTTUSAVI = 'X-Megam-PUTTUSAVI'.freeze
116
95
 
117
96
  HEADERS = {
118
97
  'Accept' => 'application/json',
@@ -235,7 +214,7 @@ module Megam
235
214
  @options[:headers] = HEADERS.merge(X_Megam_HMAC => encoded_api_header[:hmac],
236
215
  X_Megam_DATE => encoded_api_header[:date], X_Megam_ORG => "#{@org_id}").merge(@options[:headers])
237
216
  if (@api_key == "" || @api_key.nil?)
238
- @options[:headers] = @options[:headers].merge('X-Megam-PUTTUSAVI' => "true") unless (@password == "" || @password.nil?)
217
+ @options[:headers] = @options[:headers].merge(X_Megam_PUTTUSAVI => "true") unless (@password == "" || @password.nil?)
239
218
  end
240
219
 
241
220
  Megam::Log.debug('HTTP Request Data:')
@@ -259,7 +238,6 @@ module Megam
259
238
  # The output will have
260
239
  # :hmac
261
240
  # :date
262
- # (Refer https://github.com/indykish/megamplay.git/test/AuthenticateSpec.scala)
263
241
  def encode_header(cmd_parms)
264
242
  header_params = {}
265
243
  body_digest = OpenSSL::Digest::MD5.digest(cmd_parms[:body])
@@ -275,11 +253,11 @@ module Megam
275
253
  hash = OpenSSL::HMAC.hexdigest(digest, Base64.strict_decode64(@password), movingFactor)
276
254
  elsif !(@api_key.nil?)
277
255
  hash = OpenSSL::HMAC.hexdigest(digest, @api_key, movingFactor)
278
- else
256
+ else
279
257
  hash = OpenSSL::HMAC.hexdigest(digest, "", movingFactor)
280
258
  end
281
259
  final_hmac = @email + ':' + hash
282
260
  header_params = { hmac: final_hmac, date: current_date }
283
261
  end
284
262
  end
285
- end
263
+ end
@@ -14,31 +14,31 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  module Megam
17
- class API
18
- module Errors
19
- class Error < StandardError; end
17
+ class API
18
+ module Errors
19
+ class Error < StandardError; end
20
20
 
21
- class ErrorWithResponse < Error
22
- attr_reader :response
21
+ class ErrorWithResponse < Error
22
+ attr_reader :response
23
23
 
24
- def initialize(message, response)
25
- super message
26
- @response = response
27
- end
24
+ def initialize(message, response)
25
+ super message
26
+ @response = response
27
+ end
28
28
 
29
29
 
30
- end
30
+ end
31
31
 
32
- class Unauthorized < ErrorWithResponse; end
33
- class Forbidden < ErrorWithResponse; end
34
- class NotFound < ErrorWithResponse; end
35
- class Timeout < ErrorWithResponse; end
36
- class Locked < ErrorWithResponse; end
37
- class Socket < ErrorWithResponse; end
38
- class RequestFailed < ErrorWithResponse; end
32
+ class Unauthorized < ErrorWithResponse; end
33
+ class Forbidden < ErrorWithResponse; end
34
+ class NotFound < ErrorWithResponse; end
35
+ class Timeout < ErrorWithResponse; end
36
+ class Locked < ErrorWithResponse; end
37
+ class Socket < ErrorWithResponse; end
38
+ class RequestFailed < ErrorWithResponse; end
39
39
 
40
- class AuthKeysMissing < ArgumentError; end
40
+ class AuthKeysMissing < ArgumentError; end
41
41
 
42
+ end
42
43
  end
43
- end
44
44
  end
@@ -15,6 +15,6 @@
15
15
  #
16
16
  module Megam
17
17
  class API
18
- VERSION = "0.100"
18
+ VERSION = "1.5.beta2"
19
19
  end
20
20
  end
@@ -14,7 +14,7 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  module Megam
17
- class Account < Megam::ServerAPI
17
+ class Account < Megam::RestAdapter
18
18
  def initialize(o)
19
19
  @id = nil
20
20
  @email = nil
@@ -15,7 +15,7 @@
15
15
  #
16
16
 
17
17
  module Megam
18
- class Assemblies < Megam::ServerAPI
18
+ class Assemblies < Megam::RestAdapter
19
19
  def initialize(o)
20
20
  @id = nil
21
21
  @accounts_id = nil
@@ -101,19 +101,16 @@ module Megam
101
101
  @assemblies[res]
102
102
  end
103
103
 
104
- # Transform the ruby obj -> to a Hash
105
- def to_hash
106
- index_hash = Hash.new
107
- self.each do |assemblies|
108
- index_hash[assemblies.name] = assemblies.to_s
109
- end
110
- index_hash
104
+ def to_s
105
+ @assemblies.join(", ")
106
+ end
107
+
108
+ def for_json
109
+ to_a.map { |item| item.to_s }
111
110
  end
112
111
 
113
- # Serialize this object as a hash: called from JsonCompat.
114
- # Verify if this called from JsonCompat during testing.
115
112
  def to_json(*a)
116
- for_json.to_json(*a)
113
+ Megam::JSONCompat.to_json(for_json, *a)
117
114
  end
118
115
 
119
116
  def self.json_create(o)
@@ -136,10 +133,5 @@ module Megam
136
133
  end
137
134
  true
138
135
  end
139
-
140
- def to_s
141
- Megam::Stuff.styled_hash(to_hash)
142
- end
143
-
144
136
  end
145
137
  end
@@ -15,7 +15,7 @@
15
15
  #
16
16
 
17
17
  module Megam
18
- class Assembly < Megam::ServerAPI
18
+ class Assembly < Megam::RestAdapter
19
19
  def initialize(o)
20
20
  @id = nil
21
21
  @asms_id = nil
@@ -101,19 +101,16 @@ module Megam
101
101
  @assemblys[res]
102
102
  end
103
103
 
104
- # Transform the ruby obj -> to a Hash
105
- def to_hash
106
- index_hash = Hash.new
107
- self.each do |assemblys|
108
- index_hash[assemblys.name] = assemblys.to_s
109
- end
110
- index_hash
104
+ def to_s
105
+ @assemblys.join(", ")
106
+ end
107
+
108
+ def for_json
109
+ to_a.map { |item| item.to_s }
111
110
  end
112
111
 
113
- # Serialize this object as a hash: called from JsonCompat.
114
- # Verify if this called from JsonCompat during testing.
115
112
  def to_json(*a)
116
- for_json.to_json(*a)
113
+ Megam::JSONCompat.to_json(for_json, *a)
117
114
  end
118
115
 
119
116
  def self.json_create(o)
@@ -136,10 +133,5 @@ module Megam
136
133
  end
137
134
  true
138
135
  end
139
-
140
- def to_s
141
- Megam::Stuff.styled_hash(to_hash)
142
- end
143
-
144
136
  end
145
137
  end
@@ -14,7 +14,7 @@
14
14
  ## limitations under the License.
15
15
  ##
16
16
  module Megam
17
- class Balances < Megam::ServerAPI
17
+ class Balances < Megam::RestAdapter
18
18
  def initialize(o)
19
19
  @id = nil
20
20
  @accounts_id = nil
@@ -101,19 +101,16 @@ module Megam
101
101
  @balance[res]
102
102
  end
103
103
 
104
- # Transform the ruby obj -> to a Hash
105
- def to_hash
106
- index_hash = Hash.new
107
- self.each do |balance|
108
- index_hash[balance.name] = balance.to_s
109
- end
110
- index_hash
104
+ def to_s
105
+ @balance.join(", ")
106
+ end
107
+
108
+ def for_json
109
+ to_a.map { |item| item.to_s }
111
110
  end
112
111
 
113
- # Serialize this object as a hash: called from JsonCompat.
114
- # Verify if this called from JsonCompat during testing.
115
112
  def to_json(*a)
116
- for_json.to_json(*a)
113
+ Megam::JSONCompat.to_json(for_json, *a)
117
114
  end
118
115
 
119
116
  def self.json_create(o)
@@ -135,10 +132,5 @@ module Megam
135
132
  end
136
133
  true
137
134
  end
138
-
139
- def to_s
140
- Megam::Stuff.styled_hash(to_hash)
141
- end
142
-
143
135
  end
144
- end
136
+ end