Class: Megam::SshKey
Instance Attribute Summary
Attributes inherited from ServerAPI
Class Method Summary collapse
- .create(params) ⇒ Object
- .from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object
- .json_create(o) ⇒ Object
-
.list(params) ⇒ Object
Load all sshkeys - returns a sshkeysCollection don’t return self.
-
.show(params) ⇒ Object
Show a particular sshKey by name, Megam::SshKey.
Instance Method Summary collapse
- #accounts_id(arg = nil) ⇒ Object
-
#create ⇒ Object
Create the predef via the REST API.
- #created_at(arg = nil) ⇒ Object
- #error? ⇒ Boolean
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
- #id(arg = nil) ⇒ Object
-
#initialize(email = nil, api_key = nil) ⇒ SshKey
constructor
A new instance of SshKey.
- #name(arg = nil) ⇒ Object
- #path(arg = nil) ⇒ Object
- #some_msg(arg = nil) ⇒ Object
- #sshkey ⇒ Object
-
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash.
-
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat.
- #to_s ⇒ Object
Methods inherited from ServerAPI
Constructor Details
#initialize(email = nil, api_key = nil) ⇒ SshKey
Returns a new instance of SshKey.
18 19 20 21 22 23 24 25 26 |
# File 'lib/megam/core/sshkey.rb', line 18 def initialize(email=nil, api_key=nil) @id = nil @name = nil @accounts_id = nil @path=nil @created_at = nil @some_msg = {} super(email, api_key) end |
Class Method Details
.create(params) ⇒ Object
142 143 144 145 |
# File 'lib/megam/core/sshkey.rb', line 142 def self.create(params) acct = from_hash(params, params["email"], params["api_key"]) acct.create end |
.from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object
128 129 130 131 132 |
# File 'lib/megam/core/sshkey.rb', line 128 def self.from_hash(o,tmp_email=nil, tmp_api_key=nil) sshKey = self.new(tmp_email, tmp_api_key) sshKey.from_hash(o) sshKey end |
.json_create(o) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/megam/core/sshkey.rb', line 114 def self.json_create(o) sshKey = new sshKey.id(o["id"]) if o.has_key?("id") sshKey.name(o["name"]) if o.has_key?("name") sshKey.path(o["path"]) if o.has_key?("path") sshKey.created_at(o["created_at"]) if o.has_key?("created_at") #success or error sshKey.some_msg[:code] = o["code"] if o.has_key?("code") sshKey.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type") sshKey.some_msg[:msg]= o["msg"] if o.has_key?("msg") sshKey.some_msg[:links] = o["links"] if o.has_key?("links") sshKey end |
.list(params) ⇒ Object
Load all sshkeys - returns a sshkeysCollection don’t return self. check if the Megam::SshKeyCollection is returned.
155 156 157 158 |
# File 'lib/megam/core/sshkey.rb', line 155 def self.list(params) sshKey = self.new(params["email"], params["api_key"]) sshKey.megam_rest.get_sshkeys end |
.show(params) ⇒ Object
Show a particular sshKey by name, Megam::SshKey
162 163 164 165 |
# File 'lib/megam/core/sshkey.rb', line 162 def self.show(params) pre = self.new(params["email"], params["api_key"]) pre.megam_rest.get_sshkey(params["name"]) end |
Instance Method Details
#accounts_id(arg = nil) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/megam/core/sshkey.rb', line 48 def accounts_id(arg=nil) if arg != nil @accounts_id= arg else @accounts_id end end |
#create ⇒ Object
Create the predef via the REST API
148 149 150 |
# File 'lib/megam/core/sshkey.rb', line 148 def create megam_rest.post_sshkey(to_hash) end |
#created_at(arg = nil) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/megam/core/sshkey.rb', line 64 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#error? ⇒ Boolean
80 81 82 |
# File 'lib/megam/core/sshkey.rb', line 80 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/megam/core/sshkey.rb', line 102 def for_json result = { "id" => id, "name" => name, "accounts_id" => accounts_id, "path" => path, "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/megam/core/sshkey.rb', line 134 def from_hash(o) @id = o[:id] if o.has_key?(:id) @name = o[:name] if o.has_key?(:name) @path = o[:path] if o.has_key?(:path) @created_at = o[:created_at] if o.has_key?(:created_at) self end |
#id(arg = nil) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/megam/core/sshkey.rb', line 32 def id(arg=nil) if arg != nil @id = arg else @id end end |
#name(arg = nil) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/megam/core/sshkey.rb', line 40 def name(arg=nil) if arg != nil @name = arg else @name end end |
#path(arg = nil) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/megam/core/sshkey.rb', line 56 def path(arg=nil) if arg != nil @path= arg else @path end end |
#some_msg(arg = nil) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/megam/core/sshkey.rb', line 72 def some_msg(arg=nil) if arg != nil @some_msg = arg else @some_msg end end |
#sshkey ⇒ Object
28 29 30 |
# File 'lib/megam/core/sshkey.rb', line 28 def sshkey self end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/megam/core/sshkey.rb', line 85 def to_hash index_hash = Hash.new index_hash["json_claz"] = self.class.name index_hash["id"] = id index_hash["name"] = name index_hash["accounts_id"] = accounts_id index_hash["path"] = path index_hash["created_at"] = created_at index_hash end |
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.
98 99 100 |
# File 'lib/megam/core/sshkey.rb', line 98 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
167 168 169 170 |
# File 'lib/megam/core/sshkey.rb', line 167 def to_s Megam::Stuff.styled_hash(to_hash) #"---> Megam::Account:[error=#{error?}]\n"+ end |