class Megam::Promos
Public Class Methods
create(params)
click to toggle source
# File lib/megam/core/promos.rb, line 117 def self.create(params) promo = from_hash(params,params["email"], params["api_key"], params["host"]) promo.create end
from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
click to toggle source
# File lib/megam/core/promos.rb, line 103 def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil) promos = self.new(tmp_email, tmp_api_key, tmp_host) promos.from_hash(o) promos end
json_create(o)
click to toggle source
# File lib/megam/core/promos.rb, line 89 def self.json_create(o) promos = new promos.id(o["id"]) if o.has_key?("id") promos.code(o["code"]) if o.has_key?("code") promos.amount(o["amount"]) if o.has_key?("amount") promos.created_at(o["created_at"]) if o.has_key?("created_at") #success or error promos.some_msg[:code] = o["code"] if o.has_key?("code") promos.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type") promos.some_msg[:msg]= o["msg"] if o.has_key?("msg") promos.some_msg[:links] = o["links"] if o.has_key?("links") promos end
list(params)
click to toggle source
# File lib/megam/core/promos.rb, line 127 def self.list(params) promos = self.new(params["email"], params["api_key"], params["host"]) promos.megam_rest.get_promos end
new(email=nil, api_key=nil, host=nil)
click to toggle source
Calls superclass method
Megam::RestAdapter::new
# File lib/megam/core/promos.rb, line 3 def initialize(email=nil, api_key=nil, host=nil) @id = nil @code = nil @amount = nil @created_at = nil @some_msg = {} super(email, api_key, host) end
show(params)
click to toggle source
Show a particular promo by name, Megam::Promos
# File lib/megam/core/promos.rb, line 134 def self.show(params) pre = self.new(params["email"], params["api_key"], params["host"]) pre.megam_rest.get_promos(params["code"]) end
Public Instance Methods
amount(arg=nil)
click to toggle source
# File lib/megam/core/promos.rb, line 32 def amount(arg=nil) if arg != nil @amount = arg else @amount end end
code(arg=nil)
click to toggle source
# File lib/megam/core/promos.rb, line 24 def code(arg=nil) if arg != nil @code = arg else @code end end
create()
click to toggle source
Create the predef via the REST API
# File lib/megam/core/promos.rb, line 123 def create megam_rest.post_promos(to_hash) #WONT BE USED AS OF NOW end
created_at(arg=nil)
click to toggle source
# File lib/megam/core/promos.rb, line 40 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end
error?()
click to toggle source
# File lib/megam/core/promos.rb, line 58 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end
for_json()
click to toggle source
# File lib/megam/core/promos.rb, line 79 def for_json result = { "id" => id, "code" => code, "amount" => amount, "created_at" => created_at } result end
from_hash(o)
click to toggle source
# File lib/megam/core/promos.rb, line 109 def from_hash(o) @id = o[:id] if o.has_key?(:id) @code = o[:name] if o.has_key?(:name) @amount = o[:credit] if o.has_key?(:credit) @created_at = o[:created_at] if o.has_key?(:created_at) self end
id(arg=nil)
click to toggle source
# File lib/megam/core/promos.rb, line 16 def id(arg=nil) if arg != nil @id = arg else @id end end
promos()
click to toggle source
# File lib/megam/core/promos.rb, line 12 def promos self end
some_msg(arg=nil)
click to toggle source
# File lib/megam/core/promos.rb, line 50 def some_msg(arg=nil) if arg != nil @some_msg = arg else @some_msg end end
to_hash()
click to toggle source
Transform the ruby obj -> to a Hash
# File lib/megam/core/promos.rb, line 63 def to_hash index_hash = Hash.new index_hash["json_claz"] = self.class.name index_hash["id"] = id index_hash["code"] = code index_hash["amount"] = amount index_hash["created_at"] = created_at index_hash end
to_json(*a)
click to toggle source
Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.
# File lib/megam/core/promos.rb, line 75 def to_json(*a) for_json.to_json(*a) end
to_s()
click to toggle source
# File lib/megam/core/promos.rb, line 140 def to_s Megam::Stuff.styled_hash(to_hash) end