Class: Megam::EventsStorage
- Inherits:
-
RestAdapter
- Object
- RestAdapter
- Megam::EventsStorage
- Defined in:
- lib/megam/core/eventsstorage.rb
Class Method Summary collapse
- .create(params) ⇒ Object
- .from_hash(o) ⇒ Object
- .index(params) ⇒ Object
- .json_create(o) ⇒ Object
-
.list(params) ⇒ Object
Load a account by email_p.
Instance Method Summary collapse
- #account_id(arg = nil) ⇒ Object
-
#create ⇒ Object
Create the node via the REST API.
- #created_at(arg = nil) ⇒ Object
- #data(arg = []) ⇒ Object
- #error? ⇒ Boolean
- #event_type(arg = nil) ⇒ Object
- #eventsstorage ⇒ Object
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
-
#initialize(o) ⇒ EventsStorage
constructor
A new instance of EventsStorage.
- #limit(arg = []) ⇒ Object
- #some_msg(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) ⇒ EventsStorage
Returns a new instance of EventsStorage.
3 4 5 6 7 8 9 10 11 |
# File 'lib/megam/core/eventsstorage.rb', line 3 def initialize(o) @account_id = nil @event_type = nil @data = [] @created_at = nil @limit = nil @some_msg = {} super(o) end |
Class Method Details
.create(params) ⇒ Object
130 131 132 133 |
# File 'lib/megam/core/eventsstorage.rb', line 130 def self.create(params) evt = from_hash(params) evt.create end |
.from_hash(o) ⇒ Object
115 116 117 118 119 |
# File 'lib/megam/core/eventsstorage.rb', line 115 def self.from_hash(o) evt = self.new(o) evt.from_hash(o) evt end |
.index(params) ⇒ Object
146 147 148 149 |
# File 'lib/megam/core/eventsstorage.rb', line 146 def self.index(params) asm = self.new(params) asm.megam_rest.index_eventsstorage end |
.json_create(o) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/megam/core/eventsstorage.rb', line 101 def self.json_create(o) evt = new({}) evt.account_id(o["account_id"]) if o.has_key?("account_id") evt.event_type(o["event_type"]) if o.has_key?("event_type") #this will be an array? can hash store array? evt.data(o["data"]) if o.has_key?("data") evt.limit(o["limit"]) if o.has_key?("limit") evt.created_at(o["created_at"]) if o.has_key?("created_at") evt.some_msg[:code] = o["code"] if o.has_key?("code") evt.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type") evt.some_msg[:msg]= o["msg"] if o.has_key?("msg") evt.some_msg[:links] = o["links"] if o.has_key?("links") evt end |
.list(params) ⇒ Object
Load a account by email_p
141 142 143 144 |
# File 'lib/megam/core/eventsstorage.rb', line 141 def self.list(params) asm = self.new(params) asm.megam_rest.list_eventsstorage(params[:limit]) end |
Instance Method Details
#account_id(arg = nil) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/megam/core/eventsstorage.rb', line 17 def account_id(arg=nil) if arg != nil @account_id = arg else @account_id end end |
#create ⇒ Object
Create the node via the REST API
136 137 138 |
# File 'lib/megam/core/eventsstorage.rb', line 136 def create megam_rest.post_events(to_hash) end |
#created_at(arg = nil) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/megam/core/eventsstorage.rb', line 49 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#data(arg = []) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/megam/core/eventsstorage.rb', line 33 def data(arg=[]) if arg != [] @data = arg else @data end end |
#error? ⇒ Boolean
57 58 59 |
# File 'lib/megam/core/eventsstorage.rb', line 57 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#event_type(arg = nil) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/megam/core/eventsstorage.rb', line 25 def event_type(arg=nil) if arg != nil @event_type = arg else @event_type end end |
#eventsstorage ⇒ Object
13 14 15 |
# File 'lib/megam/core/eventsstorage.rb', line 13 def eventsstorage self end |
#for_json ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/megam/core/eventsstorage.rb', line 90 def for_json result = { "account_id" => account_id, "event_type" => event_type, "data" => data, "limit" => limit, "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/megam/core/eventsstorage.rb', line 121 def from_hash(o) @account_id = o[:account_id] if o.has_key?(:account_id) @event_type = o[:event_type] if o.has_key?(:event_type) @data = o[:data] if o.has_key?(:data) @limit = o[:limit] if o.has_key?(:limit) @created_at = o[:created_at] if o.has_key?(:created_at) self end |
#limit(arg = []) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/megam/core/eventsstorage.rb', line 41 def limit(arg=[]) if arg != [] @limit = arg else @limit end end |
#some_msg(arg = nil) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/megam/core/eventsstorage.rb', line 62 def some_msg(arg=nil) if arg != nil @some_msg = arg else @some_msg end end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/megam/core/eventsstorage.rb', line 72 def to_hash index_hash = Hash.new index_hash["json_claz"] = self.class.name index_hash["account_id"] = account_id index_hash["event_type"] = event_type index_hash["data"] = data index_hash["limit"] = limit 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.
86 87 88 |
# File 'lib/megam/core/eventsstorage.rb', line 86 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
151 152 153 |
# File 'lib/megam/core/eventsstorage.rb', line 151 def to_s Megam::Stuff.styled_hash(to_hash) end |