Class: Megam::EventsBilling

Inherits:
RestAdapter show all
Defined in:
lib/megam/core/eventsbilling.rb

Instance Attribute Summary

Attributes inherited from RestAdapter

#api_key, #email, #headers, #host, #master_key, #org_id, #password_hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RestAdapter

#megam_rest

Constructor Details

#initialize(o) ⇒ EventsBilling

Returns a new instance of EventsBilling.



3
4
5
6
7
8
9
10
11
12
# File 'lib/megam/core/eventsbilling.rb', line 3

def initialize(o)
    @account_id = nil
    @assembly_id = nil
    @event_type = nil
    @data = []
    @created_at = nil
    @limit = nil
    @some_msg = {}
    super(o)
end

Class Method Details

.create(params) ⇒ Object



143
144
145
146
# File 'lib/megam/core/eventsbilling.rb', line 143

def self.create(params)
    evt = from_hash(params)
    evt.create
end

.from_hash(o) ⇒ Object



127
128
129
130
131
# File 'lib/megam/core/eventsbilling.rb', line 127

def self.from_hash(o)
    evt = self.new(o)
    evt.from_hash(o)
    evt
end

.index(params) ⇒ Object



164
165
166
167
# File 'lib/megam/core/eventsbilling.rb', line 164

def self.index(params)
    asm = self.new(params)
    asm.megam_rest.index_eventsbilling
end

.json_create(o) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/megam/core/eventsbilling.rb', line 112

def self.json_create(o)
    evt = new({})
    evt.(o["account_id"]) if o.has_key?("account_id")
    evt.assembly_id(o["assembly_id"]) if o.has_key?("assembly_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



159
160
161
162
# File 'lib/megam/core/eventsbilling.rb', line 159

def self.list(params)
    asm = self.new(params)
    asm.megam_rest.list_eventsbilling(params[:limit])
end

.show(o) ⇒ Object

Load a account by email_p



154
155
156
157
# File 'lib/megam/core/eventsbilling.rb', line 154

def self.show(o)
    evt = self.new(o)
    evt.megam_rest.get_eventsbilling(o[:limit], to_hash)
end

Instance Method Details

#account_id(arg = nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/megam/core/eventsbilling.rb', line 18

def (arg=nil)
    if arg != nil
        @account_id = arg
    else
        @account_id
    end
end

#assembly_id(arg = nil) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/megam/core/eventsbilling.rb', line 26

def assembly_id(arg=nil)
    if arg != nil
        @assembly_id = arg
    else
        @assembly_id
    end
end

#createObject

Create the node via the REST API



149
150
151
# File 'lib/megam/core/eventsbilling.rb', line 149

def create
    megam_rest.post_events(to_hash)
end

#created_at(arg = nil) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/megam/core/eventsbilling.rb', line 58

def created_at(arg=nil)
    if arg != nil
        @created_at = arg
    else
        @created_at
    end
end

#data(arg = []) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/megam/core/eventsbilling.rb', line 43

def data(arg=[])
    if arg != []
        @data = arg
    else
        @data
    end
end

#error?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/megam/core/eventsbilling.rb', line 66

def error?
    crocked  = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end

#event_type(arg = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/megam/core/eventsbilling.rb', line 34

def event_type(arg=nil)
    if arg != nil
        @event_type = arg
    else
        @event_type
    end
end

#eventsbillingObject



14
15
16
# File 'lib/megam/core/eventsbilling.rb', line 14

def eventsbilling
    self
end

#for_jsonObject



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/megam/core/eventsbilling.rb', line 100

def for_json
    result = {
        "account_id" => ,
        "assembly_id" => assembly_id,
        "event_type" => event_type,
        "data" => data,
        "limit"  => limit,
        "created_at" => created_at
    }
    result
end

#from_hash(o) ⇒ Object



133
134
135
136
137
138
139
140
141
# File 'lib/megam/core/eventsbilling.rb', line 133

def from_hash(o)
    @account_id       = o[:account_id] if o.has_key?(:account_id)
    @assembly_id      = o[:assembly_id] if o.has_key?(:assembly_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



51
52
53
54
55
56
57
# File 'lib/megam/core/eventsbilling.rb', line 51

def limit(arg=[])
    if arg != []
        @limit = arg
    else
        @limit
    end
end

#some_msg(arg = nil) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/megam/core/eventsbilling.rb', line 71

def some_msg(arg=nil)
    if arg != nil
        @some_msg = arg
    else
        @some_msg
    end
end

#to_hashObject

Transform the ruby obj -> to a Hash



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/megam/core/eventsbilling.rb', line 81

def to_hash
    index_hash = Hash.new
    index_hash["json_claz"] = self.class.name
    index_hash["account_id"] = 
    index_hash["assembly_id"] = assembly_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.



96
97
98
# File 'lib/megam/core/eventsbilling.rb', line 96

def to_json(*a)
    for_json.to_json(*a)
end

#to_sObject



169
170
171
# File 'lib/megam/core/eventsbilling.rb', line 169

def to_s
    Megam::Stuff.styled_hash(to_hash)
end