Class: Megam::Snapshots
- Inherits:
-
RestAdapter
- Object
- RestAdapter
- Megam::Snapshots
- Defined in:
- lib/megam/core/snapshots.rb
Class Method Summary collapse
- .create(params) ⇒ Object
- .from_hash(o) ⇒ Object
- .json_create(o) ⇒ Object
- .list(params) ⇒ Object
-
.show(o) ⇒ Object
Load a account by email_p.
Instance Method Summary collapse
- #account_id(arg = nil) ⇒ Object
- #asm_id(arg = nil) ⇒ Object
-
#create ⇒ Object
Create the node via the REST API.
- #created_at(arg = nil) ⇒ Object
- #error? ⇒ Boolean
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
-
#initialize(o) ⇒ Snapshots
constructor
A new instance of Snapshots.
- #name(arg = nil) ⇒ Object
- #org_id(arg = nil) ⇒ Object
- #snap_id(arg = nil) ⇒ Object
- #snapshots ⇒ Object
- #some_msg(arg = nil) ⇒ Object
- #status(arg = nil) ⇒ 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
Constructor Details
#initialize(o) ⇒ Snapshots
Returns a new instance of Snapshots.
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/megam/core/snapshots.rb', line 3 def initialize(o) @snap_id = nil @account_id = nil @asm_id = nil @org_id = nil @name= nil @status=nil @created_at = nil @some_msg = {} super(o) end |
Class Method Details
.create(params) ⇒ Object
155 156 157 158 |
# File 'lib/megam/core/snapshots.rb', line 155 def self.create(params) sps = from_hash(params) sps.create end |
.from_hash(o) ⇒ Object
138 139 140 141 142 |
# File 'lib/megam/core/snapshots.rb', line 138 def self.from_hash(o) sps = self.new(o) sps.from_hash(o) sps end |
.json_create(o) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/megam/core/snapshots.rb', line 122 def self.json_create(o) sps = new({}) sps.snap_id(o["snap_id"]) if o.has_key?("snap_id") sps.account_id(o["account_id"]) if o.has_key?("account_id") sps.asm_id(o["asm_id"]) if o.has_key?("asm_id") sps.org_id(o["org_id"]) if o.has_key?("org_id") #this will be an array? can hash store array? sps.name(o["name"]) if o.has_key?("name") sps.name(o["status"]) if o.has_key?("status") sps.created_at(o["created_at"]) if o.has_key?("created_at") sps.some_msg[:code] = o["code"] if o.has_key?("code") sps.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type") sps.some_msg[:msg]= o["msg"] if o.has_key?("msg") sps.some_msg[:links] = o["links"] if o.has_key?("links") sps end |
.list(params) ⇒ Object
171 172 173 174 |
# File 'lib/megam/core/snapshots.rb', line 171 def self.list(params) sps = self.new(params) sps.megam_rest.list_snapshots end |
.show(o) ⇒ Object
Load a account by email_p
166 167 168 169 |
# File 'lib/megam/core/snapshots.rb', line 166 def self.show(o) sps = self.new(o) sps.megam_rest.get_snapshots(o[:id]) end |
Instance Method Details
#account_id(arg = nil) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/megam/core/snapshots.rb', line 26 def account_id(arg=nil) if arg != nil @account_id = arg else @account_id end end |
#asm_id(arg = nil) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/megam/core/snapshots.rb', line 34 def asm_id(arg=nil) if arg != nil @asm_id = arg else @asm_id end end |
#create ⇒ Object
Create the node via the REST API
161 162 163 |
# File 'lib/megam/core/snapshots.rb', line 161 def create megam_rest.post_snapshots(to_hash) end |
#created_at(arg = nil) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/megam/core/snapshots.rb', line 66 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#error? ⇒ Boolean
74 75 76 |
# File 'lib/megam/core/snapshots.rb', line 74 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/megam/core/snapshots.rb', line 109 def for_json result = { "snap_id" => snap_id, "account_id" => account_id, "asm_id" => asm_id, "org_id" => org_id, "name" => name, "status" => status, "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/megam/core/snapshots.rb', line 144 def from_hash(o) @snap_id = o[:snap_id] if o.has_key?(:snap_id) @account_id = o[:account_id] if o.has_key?(:account_id) @asm_id = o[:asm_id] if o.has_key?(:asm_id) @org_id = o[:org_id] if o.has_key?(:org_id) @name = o[:name] if o.has_key?(:name) @status = o[:status] if o.has_key?(:status) @created_at = o[:created_at] if o.has_key?(:created_at) self end |
#name(arg = nil) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/megam/core/snapshots.rb', line 50 def name(arg=nil) if arg != nil @name = arg else @name end end |
#org_id(arg = nil) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/megam/core/snapshots.rb', line 42 def org_id(arg=nil) if arg != nil @org_id = arg else @org_id end end |
#snap_id(arg = nil) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/megam/core/snapshots.rb', line 18 def snap_id(arg=nil) if arg != nil @snap_id = arg else @snap_id end end |
#snapshots ⇒ Object
15 16 17 |
# File 'lib/megam/core/snapshots.rb', line 15 def snapshots self end |
#some_msg(arg = nil) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/megam/core/snapshots.rb', line 79 def some_msg(arg=nil) if arg != nil @some_msg = arg else @some_msg end end |
#status(arg = nil) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/megam/core/snapshots.rb', line 58 def status(arg=nil) if arg != nil @status = arg else @status end end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/megam/core/snapshots.rb', line 89 def to_hash index_hash = Hash.new index_hash["json_claz"] = self.class.name index_hash["snap_id"] = snap_id index_hash["account_id"] = account_id index_hash["asm_id"] = asm_id index_hash["org_id"] = org_id index_hash["name"] = name index_hash["status"] = status index_hash["created_at"] = created_at index_hash["some_msg"] = some_msg index_hash end |
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.
105 106 107 |
# File 'lib/megam/core/snapshots.rb', line 105 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
176 177 178 |
# File 'lib/megam/core/snapshots.rb', line 176 def to_s Megam::Stuff.styled_hash(to_hash) end |