Class: Megam::Discounts
- Defined in:
- lib/megam/core/discounts.rb
Instance Attribute Summary
Attributes inherited from ServerAPI
Class Method Summary collapse
- .create(params) ⇒ Object
- .from_hash(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
- .json_create(o) ⇒ Object
-
.list(params) ⇒ Object
Load all discounts - returns a discountsCollection don’t return self.
-
.show(p_name, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
Show a particular discounts by name, Megam::discounts.
- .update(o) ⇒ Object
Instance Method Summary collapse
- #accounts_id(arg = nil) ⇒ Object
- #bill_type(arg = nil) ⇒ Object
- #cloud_tool_setting ⇒ Object
- #code(arg = nil) ⇒ Object
-
#create ⇒ Object
Create the discounts via the REST API.
- #created_at(arg = nil) ⇒ Object
- #error? ⇒ Boolean
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
- #id(arg = nil) ⇒ Object
-
#initialize(email = nil, api_key = nil, host = nil) ⇒ Discounts
constructor
A new instance of Discounts.
- #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
-
#update ⇒ Object
Create the node via the REST API.
Methods inherited from ServerAPI
Constructor Details
#initialize(email = nil, api_key = nil, host = nil) ⇒ Discounts
Returns a new instance of Discounts.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/megam/core/discounts.rb', line 19 def initialize(email=nil, api_key=nil, host=nil) @id = nil @accounts_id = nil @bill_type = nil @code = nil @status = nil @created_at = nil @some_msg = {} super(email, api_key, host) end |
Class Method Details
.create(params) ⇒ Object
161 162 163 164 165 |
# File 'lib/megam/core/discounts.rb', line 161 def self.create(params) discount = from_hash(params, params[:email], params[:api_key], params[:host]) discount.create end |
.from_hash(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
145 146 147 148 149 |
# File 'lib/megam/core/discounts.rb', line 145 def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil) cts = self.new(tmp_email,tmp_api_key,tmp_host) cts.from_hash(o) cts end |
.json_create(o) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/megam/core/discounts.rb', line 128 def self.json_create(o) cts = new cts.id(o["id"]) if o.has_key?("id") cts.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id") cts.bill_type(o["bill_type"]) if o.has_key?("bill_type") cts.code(o["code"]) if o.has_key?("code") cts.status(o["status"]) if o.has_key?("status") cts.created_at(o["created_at"]) if o.has_key?("created_at") #success or error cts.some_msg[:code] = o["code"] if o.has_key?("code") cts.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type") cts.some_msg[:msg]= o["msg"] if o.has_key?("msg") cts.some_msg[:links] = o["links"] if o.has_key?("links") cts end |
.list(params) ⇒ Object
Load all discounts - returns a discountsCollection don’t return self. check if the Megam::discountsCollection is returned.
186 187 188 189 190 |
# File 'lib/megam/core/discounts.rb', line 186 def self.list(params) cts = self.new(params[:email], params[:api_key], params[:host]) cts.megam_rest.get_discounts end |
.show(p_name, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
Show a particular discounts by name, Megam::discounts
194 195 196 197 |
# File 'lib/megam/core/discounts.rb', line 194 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_discounts(p_name) end |
.update(o) ⇒ Object
173 174 175 176 |
# File 'lib/megam/core/discounts.rb', line 173 def self.update(o) discount = from_hash(o) discount.update end |
Instance Method Details
#accounts_id(arg = nil) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/megam/core/discounts.rb', line 43 def accounts_id(arg=nil) if arg != nil @accounts_id= arg else @accounts_id end end |
#bill_type(arg = nil) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/megam/core/discounts.rb', line 51 def bill_type(arg=nil) if arg != nil @bill_type = arg else @bill_type end end |
#cloud_tool_setting ⇒ Object
30 31 32 |
# File 'lib/megam/core/discounts.rb', line 30 def cloud_tool_setting self end |
#code(arg = nil) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/megam/core/discounts.rb', line 59 def code(arg=nil) if arg != nil @code = arg else @code end end |
#create ⇒ Object
Create the discounts via the REST API
168 169 170 171 |
# File 'lib/megam/core/discounts.rb', line 168 def create megam_rest.post_discounts(to_hash) end |
#created_at(arg = nil) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/megam/core/discounts.rb', line 75 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#error? ⇒ Boolean
91 92 93 |
# File 'lib/megam/core/discounts.rb', line 91 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/megam/core/discounts.rb', line 115 def for_json result = { "id" => id, "accounts_id" => accounts_id, "bill_type" => bill_type, "code" => code, "status" => status, "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
151 152 153 154 155 156 157 158 159 |
# File 'lib/megam/core/discounts.rb', line 151 def from_hash(o) @id = o[:id] if o.has_key?(:id) @accounts_id = o[:accounts_id] if o.has_key?(:accounts_id) @bill_type = o[:bill_type] if o.has_key?(:bill_type) @code = o[:code] if o.has_key?(:code) @status = o[:status] if o.has_key?(:status) @created_at = o[:created_at] if o.has_key?(:created_at) self end |
#id(arg = nil) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/megam/core/discounts.rb', line 35 def id(arg=nil) if arg != nil @id = arg else @id end end |
#some_msg(arg = nil) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/megam/core/discounts.rb', line 83 def some_msg(arg=nil) if arg != nil @some_msg = arg else @some_msg end end |
#status(arg = nil) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/megam/core/discounts.rb', line 67 def status(arg=nil) if arg != nil @status = arg else @status end end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/megam/core/discounts.rb', line 96 def to_hash index_hash = Hash.new index_hash["json_claz"] = self.class.name index_hash["id"] = id index_hash["accounts_id"] = accounts_id index_hash["bill_type"] = bill_type index_hash["code"] = code 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.
111 112 113 |
# File 'lib/megam/core/discounts.rb', line 111 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
199 200 201 |
# File 'lib/megam/core/discounts.rb', line 199 def to_s Megam::Stuff.styled_hash(to_hash) end |
#update ⇒ Object
Create the node via the REST API
179 180 181 |
# File 'lib/megam/core/discounts.rb', line 179 def update megam_rest.update_discounts(to_hash) end |