Class: Megam::Availableunits
Instance Attribute Summary
Attributes inherited from ServerAPI
#api_key, #email, #host, #org_id, #password
Class Method Summary
collapse
-
.create(o, tmp_email = nil, tmp_api_key = nil, tmp_host) ⇒ Object
-
.delete(p_name, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
-
.from_hash(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
-
.json_create(o) ⇒ Object
-
.list(tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
Load all available units - returns a AvailableUnitsCollection don’t return self.
-
.show(p_name, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
Show a particular available units by name, Megam::Availables.
Instance Method Summary
collapse
Methods inherited from ServerAPI
#megam_rest
Constructor Details
#initialize(email = nil, api_key = nil, host = nil) ⇒ Availableunits
Returns a new instance of Availableunits.
18
19
20
21
22
23
24
25
26
|
# File 'lib/megam/core/availableunits.rb', line 18
def initialize(email=nil, api_key=nil, host=nil)
@id = nil
@name = nil
@duration = nil
@charges_per_duration = nil
@created_at = nil
@some_msg = {}
super(email, api_key, host)
end
|
Class Method Details
.create(o, tmp_email = nil, tmp_api_key = nil, tmp_host) ⇒ Object
145
146
147
148
|
# File 'lib/megam/core/availableunits.rb', line 145
def self.create(o,tmp_email=nil, tmp_api_key=nil, tmp_host)
acct = from_hash(o,tmp_email, tmp_api_key, tmp_host)
acct.create
end
|
.delete(p_name, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
170
171
172
173
|
# File 'lib/megam/core/availableunits.rb', line 170
def self.delete(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
pre = self.new(tmp_email,tmp_api_key,tmp_host)
pre.megam_rest.delete_availableunit(p_name)
end
|
.from_hash(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
130
131
132
133
134
|
# File 'lib/megam/core/availableunits.rb', line 130
def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
aunit = self.new(tmp_email, tmp_api_key, tmp_host)
aunit.from_hash(o)
aunit
end
|
.json_create(o) ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/megam/core/availableunits.rb', line 115
def self.json_create(o)
aunit = new({})
aunit.id(o["id"]) if o.has_key?("id")
aunit.name(o["name"]) if o.has_key?("name")
aunit.duration(o["duration"]) if o.has_key?("duration")
aunit.charges_per_duration(o["charges_per_duration"]) if o.has_key?("charges_per_duration")
aunit.created_at(o["created_at"]) if o.has_key?("created_at")
aunit.some_msg[:code] = o["code"] if o.has_key?("code")
aunit.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
aunit.some_msg[:msg]= o["msg"] if o.has_key?("msg")
aunit.some_msg[:links] = o["links"] if o.has_key?("links")
aunit
end
|
.list(tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
Load all available units - returns a AvailableUnitsCollection don’t return self. check if the Megam::AvailableUnitsCollection is returned.
158
159
160
161
|
# File 'lib/megam/core/availableunits.rb', line 158
def self.list(tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
aunit = self.new(tmp_email,tmp_api_key,tmp_host)
aunit.megam_rest.get_availableunits
end
|
.show(p_name, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
Show a particular available units by name, Megam::Availables
165
166
167
168
|
# File 'lib/megam/core/availableunits.rb', line 165
def self.show(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
pre = self.new(tmp_email,tmp_api_key, tmp_host)
pre.megam_rest.get_availableunit(p_name)
end
|
Instance Method Details
#availableunits ⇒ Object
28
29
30
|
# File 'lib/megam/core/availableunits.rb', line 28
def availableunits
self
end
|
#charges_per_duration(arg = nil) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/megam/core/availableunits.rb', line 57
def charges_per_duration(arg=nil)
if arg != nil
@charges_per_duration = arg
else
@charges_per_duration
end
end
|
#create ⇒ Object
Create the predef via the REST API
151
152
153
|
# File 'lib/megam/core/availableunits.rb', line 151
def create
megam_rest.post_availableunits(to_hash)
end
|
#created_at(arg = nil) ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/megam/core/availableunits.rb', line 65
def created_at(arg=nil)
if arg != nil
@created_at = arg
else
@created_at
end
end
|
#duration(arg = nil) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/megam/core/availableunits.rb', line 49
def duration(arg=nil)
if arg != nil
@duration= arg
else
@duration
end
end
|
#error? ⇒ Boolean
81
82
83
|
# File 'lib/megam/core/availableunits.rb', line 81
def error?
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end
|
#for_json ⇒ Object
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/megam/core/availableunits.rb', line 103
def for_json
result = {
"id" => id,
"name" => name,
"duration" => duration,
"charges_per_duration" => charges_per_duration,
"created_at" => created_at
}
result
end
|
#from_hash(o) ⇒ Object
136
137
138
139
140
141
142
143
|
# File 'lib/megam/core/availableunits.rb', line 136
def from_hash(o)
@id = o[:id] if o.has_key?(:id)
@name = o[:name] if o.has_key?(:name)
@duration = o[:duration] if o.has_key?(:duration)
@charges_per_duration = o[:charges_per_duration] if o.has_key?(:charges_per_duration)
@created_at = o[:created_at] if o.has_key?(:created_at)
self
end
|
#id(arg = nil) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/megam/core/availableunits.rb', line 33
def id(arg=nil)
if arg != nil
@id = arg
else
@id
end
end
|
#name(arg = nil) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/megam/core/availableunits.rb', line 41
def name(arg=nil)
if arg != nil
@name = arg
else
@name
end
end
|
#some_msg(arg = nil) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/megam/core/availableunits.rb', line 73
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
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/megam/core/availableunits.rb', line 86
def to_hash
index_hash = Hash.new
index_hash["json_claz"] = self.class.name
index_hash["id"] = id
index_hash["name"] = name
index_hash["duration"] = duration
index_hash["charges_per_duration"] = charges_per_duration
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.
99
100
101
|
# File 'lib/megam/core/availableunits.rb', line 99
def to_json(*a)
for_json.to_json(*a)
end
|
#to_s ⇒ Object
175
176
177
178
|
# File 'lib/megam/core/availableunits.rb', line 175
def to_s
Megam::Stuff.styled_hash(to_hash)
end
|