Class: Megam::Credits
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) ⇒ Credits
Returns a new instance of Credits.
3
4
5
6
7
8
9
10
|
# File 'lib/megam/core/credits.rb', line 3
def initialize(o)
@id = nil
@account_id = nil
@credit = nil
@created_at = nil
@some_msg = {}
super(o)
end
|
Class Method Details
.create(params) ⇒ Object
116
117
118
119
|
# File 'lib/megam/core/credits.rb', line 116
def self.create(params)
acct = from_hash(params)
acct.create
end
|
.from_hash(o) ⇒ Object
102
103
104
105
106
|
# File 'lib/megam/core/credits.rb', line 102
def self.from_hash(o)
cr = self.new(o)
cr.from_hash(o)
cr
end
|
.json_create(o) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/megam/core/credits.rb', line 88
def self.json_create(o)
cr = new({})
cr.id(o["id"]) if o.has_key?("id")
cr.account_id(o["account_id"]) if o.has_key?("account_id")
cr.credit(o["credit"]) if o.has_key?("credit")
cr.created_at(o["created_at"]) if o.has_key?("created_at")
cr.some_msg[:code] = o["code"] if o.has_key?("code")
cr.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
cr.some_msg[:msg]= o["msg"] if o.has_key?("msg")
cr.some_msg[:links] = o["links"] if o.has_key?("links")
cr
end
|
.list(params) ⇒ Object
Load all credit - returns a creditCollection don’t return self. check if the Megam::CreditCollection is returned.
129
130
131
132
|
# File 'lib/megam/core/credits.rb', line 129
def self.list(params)
cr = self.new(params)
cr.megam_rest.list_credits
end
|
.show(params) ⇒ Object
Show a particular balance by name, Megam::Balance
136
137
138
139
|
# File 'lib/megam/core/credits.rb', line 136
def self.show(params)
pre = self.new(params)
pre.megam_rest.get_credits(params["account_id"])
end
|
Instance Method Details
#account_id(arg = nil) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/megam/core/credits.rb', line 24
def account_id(arg=nil)
if arg != nil
@account_id= arg
else
@account_id
end
end
|
#create ⇒ Object
Create the predef via the REST API
122
123
124
|
# File 'lib/megam/core/credits.rb', line 122
def create
megam_rest.post_credits(to_hash)
end
|
#created_at(arg = nil) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/megam/core/credits.rb', line 41
def created_at(arg=nil)
if arg != nil
@created_at = arg
else
@created_at
end
end
|
#credit(arg = nil) ⇒ Object
12
13
14
|
# File 'lib/megam/core/credits.rb', line 12
def credit
self
end
|
#error? ⇒ Boolean
57
58
59
|
# File 'lib/megam/core/credits.rb', line 57
def error?
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end
|
#for_json ⇒ Object
78
79
80
81
82
83
84
85
86
|
# File 'lib/megam/core/credits.rb', line 78
def for_json
result = {
"id" => id,
"account_id" => account_id,
"credit" => credit,
"created_at" => created_at,
}
result
end
|
#from_hash(o) ⇒ Object
108
109
110
111
112
113
114
|
# File 'lib/megam/core/credits.rb', line 108
def from_hash(o)
@id = o[:id] if o.has_key?(:id)
@account_id = o[:account_id] if o.has_key?(:account_id)
@credit = o[:credit] if o.has_key?(:credit)
@created_at = o[:created_at] if o.has_key?(:created_at)
self
end
|
#id(arg = nil) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/megam/core/credits.rb', line 16
def id(arg=nil)
if arg != nil
@id = arg
else
@id
end
end
|
#some_msg(arg = nil) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/megam/core/credits.rb', line 49
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
62
63
64
65
66
67
68
69
70
|
# File 'lib/megam/core/credits.rb', line 62
def to_hash
index_hash = Hash.new
index_hash["json_claz"] = self.class.name
index_hash["id"] = id
index_hash["account_id"] = account_id
index_hash["credit"] = credit
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.
74
75
76
|
# File 'lib/megam/core/credits.rb', line 74
def to_json(*a)
for_json.to_json(*a)
end
|