megam_api 0.15 → 0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -10
  3. data/lib/megam/api.rb +34 -20
  4. data/lib/megam/api/csars.rb +50 -0
  5. data/lib/megam/api/version.rb +1 -1
  6. data/lib/megam/builder/delete_node.rb +1 -1
  7. data/lib/megam/builder/make_node.rb +1 -1
  8. data/lib/megam/core/app_request.rb +1 -1
  9. data/lib/megam/core/app_request_collection.rb +1 -1
  10. data/lib/megam/core/appdefns.rb +1 -1
  11. data/lib/megam/core/appdefns_collection.rb +1 -1
  12. data/lib/megam/core/bolt_request.rb +1 -1
  13. data/lib/megam/core/bolt_request_collection.rb +1 -1
  14. data/lib/megam/core/boltdefns.rb +1 -1
  15. data/lib/megam/core/boltdefns_collection.rb +1 -1
  16. data/lib/megam/core/cloudinstruction.rb +1 -1
  17. data/lib/megam/core/cloudinstruction_collection.rb +1 -1
  18. data/lib/megam/core/cloudinstruction_group.rb +1 -1
  19. data/lib/megam/core/cloudtemplate.rb +1 -1
  20. data/lib/megam/core/cloudtemplate_collection.rb +1 -1
  21. data/lib/megam/core/cloudtool.rb +1 -1
  22. data/lib/megam/core/cloudtool_collection.rb +1 -1
  23. data/lib/megam/core/cloudtoolsetting.rb +1 -1
  24. data/lib/megam/core/cloudtoolsetting_collection.rb +1 -1
  25. data/lib/megam/core/config.rb +3 -3
  26. data/lib/megam/core/csar.rb +165 -0
  27. data/lib/megam/core/csar_collection.rb +148 -0
  28. data/lib/megam/core/json_compat.rb +12 -3
  29. data/lib/megam/core/konipai.rb +57 -0
  30. data/lib/megam/core/marketplace.rb +20 -20
  31. data/lib/megam/core/marketplace_addon.rb +8 -8
  32. data/lib/megam/core/marketplace_addon_collection.rb +1 -1
  33. data/lib/megam/core/marketplace_collection.rb +1 -1
  34. data/lib/megam/core/node.rb +1 -1
  35. data/lib/megam/core/node_collection.rb +1 -1
  36. data/lib/megam/core/predef.rb +1 -1
  37. data/lib/megam/core/predef_collection.rb +1 -1
  38. data/lib/megam/core/predefcloud.rb +1 -1
  39. data/lib/megam/core/predefcloud_collection.rb +1 -1
  40. data/lib/megam/core/request.rb +1 -1
  41. data/lib/megam/core/request_collection.rb +1 -1
  42. data/lib/megam/core/server_api.rb +4 -5
  43. data/lib/megam/core/sshkey.rb +1 -1
  44. data/lib/megam/core/sshkey_collection.rb +1 -1
  45. data/megam_api.gemspec +7 -7
  46. data/test/test_cloudtoolsettings.rb +3 -3
  47. data/test/test_csars.rb +21 -0
  48. data/test/test_helper.rb +1 -1
  49. data/test/test_marketplaces.rb +8 -8
  50. data/test/test_nodes.rb +4 -4
  51. data/test/test_predefclouds.rb +4 -4
  52. data/test/test_requests.rb +1 -1
  53. data/test/test_sshkeys.rb +1 -1
  54. metadata +19 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f70bad4104531f59a86d0a85bf96c1f855c0c96e
4
- data.tar.gz: 1ec8eb2603e2f632b47352f05be0407786d9f53c
3
+ metadata.gz: 09998b376d64a74fe84a95ed4cbb426827e7d853
4
+ data.tar.gz: 6e69181f6b9a5e77358f957d37b7c011c2efddda
5
5
  SHA512:
6
- metadata.gz: 8c01a6c03db68969107623032db64ee3c37d1ec706ea83478137a041ecb7844cdaf614bc4e28b76984533686b5fc6079667a51ac02489f8190ecacee88b0a978
7
- data.tar.gz: 71f7dc9c679c313976733140c50c049fb21577c98c4354fb3711dd549bc24154c447b201adc00ed4565da885b0f2c4889fc02a87560f566ee4a66f5f392d3100
6
+ metadata.gz: f1bd5cc89a3851223ddbb64e8a60fbda88cc68c60854f569715cd0eeb3ab10e67393697854dc9b7273e12c852385fa8e54a85794a2d356deccafcc019d6772cf
7
+ data.tar.gz: 69f3175a199fc9614099969ac8150ab78f56244f0b5ca27c2bbea545a524a6183de60e5e5c4276fc5653a1823264acff36b40ebd79bc1eb4d2d13f74067d519e
data/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
  Megam Ruby Client
2
2
  ==================
3
3
 
4
- The Megam Ruby Client is used to interact with the Megam API from Ruby.
4
+ [![Gem Version](https://badge.fury.io/rb/megam_api.svg)](http://badge.fury.io/rb/megam_api)
5
5
 
6
- For more about the Megam API see <http://docs.megam.co>.[Megam API server](https://github.com/indykish/megam_play.git)
6
+ Megam Ruby Client is used to interact with the Megam API Server.
7
+
8
+ For more about the Megam' REST API <http://gomegam.com/docs>.[Megam API server](https://github.com/indykish/megam_play.git)
7
9
 
8
10
  [![Build Status](https://travis-ci.org/indykish/megam_api.png)](https://travis-ci.org/indykish/megam_api)
9
11
 
10
- For early access [register at:](https://www.megam.co)
12
+ We are on beta [register at:](https://www.megam.co)
11
13
 
12
14
  Usage
13
15
  -----
@@ -32,14 +34,10 @@ For additional details about any of the commands, see the [API docs](http://docs
32
34
  megam.get_nodes # get a list of your nodes
33
35
  megam.get_node(POGO) # get info about the node named POGO
34
36
  megam.create_node('name' => POGO,
35
- 'type' => 'rails') # create an nodep with a generated name and the default type
37
+ 'type' => 'rails') # create an nodep with a generated name and the default type
36
38
  megam.delete_node(POGO) # delete the node named POGO
37
39
 
38
40
 
39
- ### Logs
40
-
41
- megam.get_logs('node' => POGO) # stream logs information for POGO Node
42
-
43
41
  ### Predefs
44
42
 
45
43
  megam.get_predefs # list all predefs
@@ -53,11 +51,11 @@ For additional details about any of the commands, see the [API docs](http://docs
53
51
 
54
52
  We are glad to help if you have questions, or request for new features.
55
53
 
56
- [twitter](http://twitter.com/indykish) [email](<alrin@megam.co.in>)
54
+ [twitter](http://twitter.com/megamsys) [email](<alrin@megam.co.in>)
57
55
 
58
56
  #### TO - DO
59
57
 
60
- * Interface to [megam_play](https://github.com/indykish/megam_play)
58
+ *
61
59
 
62
60
  # License
63
61
 
data/lib/megam/api.rb CHANGED
@@ -31,6 +31,7 @@ require "megam/api/cloud_tool_settings"
31
31
  require "megam/api/sshkeys"
32
32
  require "megam/api/marketplaces"
33
33
  require "megam/api/marketplace_addons"
34
+ require "megam/api/csars"
34
35
  require "megam/core/server_api"
35
36
  require "megam/core/config"
36
37
  require "megam/core/stuff"
@@ -73,10 +74,9 @@ require "megam/core/marketplace"
73
74
  require "megam/core/marketplace_collection"
74
75
  require "megam/core/marketplace_addon"
75
76
  require "megam/core/marketplace_addon_collection"
76
-
77
- #we may nuke logs out of the api
78
- #require "megam/api/logs"
79
-
77
+ require "megam/core/csar"
78
+ require "megam/core/csar_collection"
79
+ require "megam/core/konipai"
80
80
 
81
81
 
82
82
  module Megam
@@ -85,6 +85,13 @@ module Megam
85
85
  #text is used to print stuff in the terminal (message, log, info, warn etc.)
86
86
  attr_accessor :text
87
87
 
88
+ API_MEGAM_CO = "api.megam.co".freeze
89
+ API_VERSION2 = "/v2".freeze
90
+
91
+ X_Megam_DATE = "X-Megam-DATE".freeze
92
+ X_Megam_HMAC = "X-Megam-HMAC".freeze
93
+ X_Megam_OTTAI = "X-Megam-OTTAI".freeze
94
+
88
95
  HEADERS = {
89
96
  'Accept' => 'application/json',
90
97
  'Accept-Encoding' => 'gzip',
@@ -95,11 +102,11 @@ module Megam
95
102
 
96
103
  OPTIONS = {
97
104
  :headers => {},
98
- :host => 'api.megam.co',
105
+ :host => API_MEGAM_CO,
99
106
  :nonblock => false,
100
107
  :scheme => 'https'
101
108
  }
102
- API_VERSION1 = "/v1"
109
+
103
110
 
104
111
  def text
105
112
  @text ||= Megam::Text.new(STDOUT, STDERR, STDIN, {})
@@ -118,11 +125,11 @@ module Megam
118
125
  # 3. Upon merge of the options, the api_key, email as available in the @options is deleted.
119
126
  def initialize(options={})
120
127
  @options = OPTIONS.merge(options)
121
- if File.exist?("#{ENV['MEGAM_HOME']}/nilavu.yml")
122
- @common = YAML.load_file("#{ENV['MEGAM_HOME']}/nilavu.yml") #COMMON YML
123
- @options[:host] = "#{@common["api"]["host"]}"
124
- @options[:scheme] = "#{@common["api"]["scheme"]}"
125
- end
128
+ if File.exist?("#{ENV['MEGAM_HOME']}/nilavu.yml")
129
+ @common = YAML.load_file("#{ENV['MEGAM_HOME']}/nilavu.yml") #COMMON YML
130
+ @options[:host] = "#{@common["api"]["host"]}"
131
+ @options[:scheme] = "#{@common["api"]["scheme"]}"
132
+ end
126
133
  @api_key = @options.delete(:api_key) || ENV['MEGAM_API_KEY']
127
134
  @email = @options.delete(:email)
128
135
  raise ArgumentError, "You must specify [:email, :api_key]" if @email.nil? || @api_key.nil?
@@ -136,8 +143,8 @@ end
136
143
  Megam::Log.debug("> #{pkey}: #{pvalue}")
137
144
  end
138
145
 
139
- begin
140
- response = connection.request(params, &block)
146
+ begin
147
+ response = connection.request(params, &block)
141
148
  rescue Excon::Errors::HTTPStatusError => error
142
149
  klass = case error.response.status
143
150
 
@@ -170,14 +177,20 @@ end
170
177
 
171
178
  if response.body && !response.body.empty?
172
179
  if response.headers['Content-Encoding'] == 'gzip'
180
+ Megam::Log.debug("RESPONSE: Content-Encoding is gzip")
173
181
  response.body = Zlib::GzipReader.new(StringIO.new(response.body)).read
174
182
  end
175
183
  Megam::Log.debug("RESPONSE: HTTP Body(JSON)")
176
184
  Megam::Log.debug("#{response.body}")
177
185
 
178
186
  begin
179
- response.body = Megam::JSONCompat.from_json(response.body.chomp)
180
- Megam::Log.debug("RESPONSE: Ruby Object")
187
+ unless response.headers[X_Megam_OTTAI]
188
+ response.body = Megam::JSONCompat.from_json(response.body.chomp)
189
+ Megam::Log.debug("RESPONSE: Ruby Object")
190
+ else
191
+ response.body = Megam::KoniPai.new.koni(response.body.chomp)
192
+ Megam::Log.debug("RESPONSE: KoniPai Object ")
193
+ end
181
194
  Megam::Log.debug("#{response.body}")
182
195
  rescue Exception => jsonerr
183
196
  Megam::Log.error(jsonerr)
@@ -196,18 +209,19 @@ end
196
209
  text.msg "--> #{text.color('(#{path})', :cyan,:bold)}" # Why " inside "
197
210
  end
198
211
 
212
+
213
+
199
214
  #Make a lazy connection.
200
215
  def connection
201
- @options[:path] =API_VERSION1+ @options[:path]
216
+ @options[:path] =API_VERSION2+ @options[:path]
202
217
  encoded_api_header = encode_header(@options)
203
218
  @options[:headers] = HEADERS.merge({
204
- 'X-Megam-HMAC' => encoded_api_header[:hmac],
205
- 'X-Megam-Date' => encoded_api_header[:date],
219
+ X_Megam_HMAC => encoded_api_header[:hmac],
220
+ X_Megam_DATE => encoded_api_header[:date],
206
221
  }).merge(@options[:headers])
207
222
  #COMMON YML
208
223
  if @options[:scheme] == "https"
209
- puts "=====> if https =======>"
210
- Excon.defaults[:ssl_ca_file] = File.expand_path(File.join("#{ENV['MEGAM_HOME']}", "#{@common["api"]["pub_key"]}")) || File.expand_path(File.join(File.dirname(__FILE__), "..", "certs", "cacert.pem")) #COMMON YML
224
+ Excon.defaults[:ssl_ca_file] = File.expand_path(File.join("#{ENV['MEGAM_HOME']}", "#{@common["api"]["pub_key"]}")) || File.expand_path(File.join(File.dirname(__FILE__), "..", "certs", "cacert.pem")) #COMMON YML
211
225
 
212
226
  if !File.exist?(File.expand_path(File.join("#{ENV['MEGAM_HOME']}", "#{@common["api"]["pub_key"]}")))
213
227
  text.warn("Certificate file does not exist. SSL_VERIFY_PEER set as false")
@@ -0,0 +1,50 @@
1
+ module Megam
2
+ class API
3
+
4
+ # GET /csars
5
+ def get_csars
6
+ @options = {:path => '/csars',:body => ""}.merge(@options)
7
+
8
+ request(
9
+ :expects => 200,
10
+ :method => :get,
11
+ :body => @options[:body]
12
+ )
13
+ end
14
+
15
+ def get_csar(id)
16
+ @options = {:path => "/csars/#{id}",:body => ""}.merge(@options)
17
+
18
+ request(
19
+ :expects => 200,
20
+ :method => :get,
21
+ :body => @options[:body]
22
+ )
23
+ end
24
+
25
+ def post_csar(new_csar)
26
+ @options = {:path => '/csars/content',
27
+ :body => Megam::JSONCompat.to_json(new_node)}.merge(@options)
28
+
29
+ request(
30
+ :expects => 201,
31
+ :method => :post,
32
+ :body => @options[:body]
33
+ )
34
+ end
35
+
36
+ #Yet to be tested
37
+ # DELETE /marketplacess/:node_id
38
+ def delete_marketplaceapp(node_id)
39
+ @options = {:path => '/marketplaces/#{node_id}',
40
+ :body => ""}.merge(@options)
41
+
42
+ request(
43
+ :expects => 200,
44
+ :method => :delete,
45
+ :body => @options[:body]
46
+ )
47
+ end
48
+
49
+ end
50
+ end
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "0.15"
3
+ VERSION = "0.16"
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2012, 2013 Megam Systems
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,14 +20,14 @@ module Megam
20
20
  class Config
21
21
 
22
22
  extend Mixlib::Config
23
-
23
+
24
24
  def self.inspect
25
25
  configuration.inspect
26
26
  end
27
27
 
28
28
  megam_api_server_url "http://localhost:9000"
29
-
30
- megam_api_version "v1"
29
+
30
+ megam_api_version "v2"
31
31
 
32
32
  email nil
33
33
  api_key nil
@@ -0,0 +1,165 @@
1
+ # Copyright:: Copyright (c) 2012, 2014 Megam Systems
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ require 'hashie'
17
+
18
+ module Megam
19
+ class CSAR < Megam::ServerAPI
20
+ def initialize(email=nil, api_key=nil)
21
+ @id = nil
22
+ @desc = nil
23
+ @link = {}
24
+ @some_msg = {}
25
+ @created_at = nil
26
+ super(email, api_key)
27
+ end
28
+
29
+ def csar
30
+ self
31
+ end
32
+
33
+ def id(arg=nil)
34
+ if arg != nil
35
+ @id = arg
36
+ else
37
+ @id
38
+ end
39
+ end
40
+
41
+ def desc(arg=nil)
42
+ if arg != nil
43
+ @desc = arg
44
+ else
45
+ @desc
46
+ end
47
+ end
48
+
49
+
50
+ def link(arg=nil)
51
+ if arg != nil
52
+ @link = arg
53
+ else
54
+ @link
55
+ end
56
+ end
57
+
58
+
59
+ def created_at(arg=nil)
60
+ if arg != nil
61
+ @created_at = arg
62
+ else
63
+ @created_at
64
+ end
65
+ end
66
+
67
+ def some_msg(arg=nil)
68
+ if arg != nil
69
+ @some_msg = arg
70
+ else
71
+ @some_msg
72
+ end
73
+ end
74
+
75
+ def error?
76
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
77
+ end
78
+
79
+ # Transform the ruby obj -> to a Hash
80
+ def to_hash
81
+ index_hash = Hash.new
82
+ index_hash["json_claz"] = self.class.name
83
+ index_hash["id"] = id
84
+ index_hash["desc"] = desc
85
+ index_hash["link"] = link
86
+ index_hash["some_msg"] = some_msg
87
+ index_hash["created_at"] = created_at
88
+ index_hash
89
+ end
90
+
91
+ # Serialize this object as a hash: called from JsonCompat.
92
+ # Verify if this called from JsonCompat during testing.
93
+ def to_json(*a)
94
+ for_json.to_json(*a)
95
+ end
96
+
97
+ def for_json
98
+ result = {
99
+ "id" => id,
100
+ "desc" => desc,
101
+ "link" => link,
102
+ "created_at" => created_at
103
+ }
104
+ result
105
+ end
106
+
107
+ def self.json_create(o)
108
+ csarjslf = new
109
+ csarjslf.id(o["id"]) if o.has_key?("id")
110
+ csarjslf.desc(o["desc"]) if o.has_key?("desc")
111
+ csarjslf.link(o["link"]) if o.has_key?("link")
112
+
113
+ #success or error
114
+ csarjslf.some_msg[:code] = o["code"] if o.has_key?("code")
115
+ csarjslf.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
116
+ csarjslf.some_msg[:msg]= o["msg"] if o.has_key?("msg")
117
+ csarjslf.some_msg[:links] = o["links"] if o.has_key?("links")
118
+
119
+ csarjslf
120
+ end
121
+
122
+ def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
123
+ csarhslf = self.new(tmp_email, tmp_api_key)
124
+ csarhslf.from_hash(o)
125
+ csarhslf
126
+ end
127
+
128
+ def from_hash(o)
129
+ @id = o["id"] if o.has_key?("id")
130
+ @desc = o["desc"] if o.has_key?("desc")
131
+ @link = o["link"] if o.has_key?("link")
132
+ @created_at = o["created_at"] if o.has_key?("created_at")
133
+ self
134
+ end
135
+
136
+ #This won't work, as the body just needs the yaml string.
137
+ def self.create(o,tmp_email=nil, tmp_api_key=nil)
138
+ csarslf = from_hash(o, tmp_email, tmp_api_key)
139
+ csarslf.create
140
+ end
141
+
142
+ # Create the csar yaml
143
+ #This won't work, as the body just needs the yaml string.
144
+ def create
145
+ megam_rest.post_csar(to_hash)
146
+ end
147
+
148
+ # Load the yaml back from the link
149
+ def self.show(tmp_email=nil, tmp_api_key=nil, csarlink_name)
150
+ csarslf = self.new(tmp_email, tmp_api_key)
151
+ csarslf.megam_rest.get_csar(csarlink_name)
152
+ end
153
+
154
+ #list all csars (links)
155
+ def self.list(tmp_email=nil, tmp_api_key=nil)
156
+ csarslf = self.new(tmp_email, tmp_api_key)
157
+ csarslf.megam_rest.get_csars
158
+ end
159
+
160
+ def to_s
161
+ Megam::Stuff.styled_hash(to_hash)
162
+ end
163
+
164
+ end
165
+ end