Class: Megam::Promos
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
-
.show(params) ⇒ Object
Show a particular promo by name, Megam::Promos.
Instance Method Summary collapse
- #amount(arg = nil) ⇒ Object
- #code(arg = nil) ⇒ Object
-
#create ⇒ Object
Create the predef 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) ⇒ Promos
constructor
A new instance of Promos.
- #promos ⇒ Object
- #some_msg(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
Methods inherited from ServerAPI
Constructor Details
#initialize(email = nil, api_key = nil, host = nil) ⇒ Promos
Returns a new instance of Promos.
18 19 20 21 22 23 24 25 |
# File 'lib/megam/core/promos.rb', line 18 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 |
Class Method Details
.create(params) ⇒ Object
132 133 134 135 |
# File 'lib/megam/core/promos.rb', line 132 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) ⇒ Object
118 119 120 121 122 |
# File 'lib/megam/core/promos.rb', line 118 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) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/megam/core/promos.rb', line 104 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) ⇒ Object
142 143 144 145 |
# File 'lib/megam/core/promos.rb', line 142 def self.list(params) promos = self.new(params["email"], params["api_key"], params["host"]) promos.megam_rest.get_promos end |
.show(params) ⇒ Object
Show a particular promo by name, Megam::Promos
149 150 151 152 153 |
# File 'lib/megam/core/promos.rb', line 149 def self.show(params) puts "[x] Called show" pre = self.new(params["email"], params["api_key"]) pre.megam_rest.get_promos(params["code"]) end |
Instance Method Details
#amount(arg = nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/megam/core/promos.rb', line 47 def amount(arg=nil) if arg != nil @amount = arg else @amount end end |
#code(arg = nil) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/megam/core/promos.rb', line 39 def code(arg=nil) if arg != nil @code = arg else @code end end |
#create ⇒ Object
Create the predef via the REST API
138 139 140 |
# File 'lib/megam/core/promos.rb', line 138 def create megam_rest.post_promos(to_hash) #WONT BE USED AS OF NOW end |
#created_at(arg = nil) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/megam/core/promos.rb', line 55 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#error? ⇒ Boolean
73 74 75 |
# File 'lib/megam/core/promos.rb', line 73 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/megam/core/promos.rb', line 94 def for_json result = { "id" => id, "code" => code, "amount" => amount, "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/megam/core/promos.rb', line 124 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) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/megam/core/promos.rb', line 31 def id(arg=nil) if arg != nil @id = arg else @id end end |
#promos ⇒ Object
27 28 29 |
# File 'lib/megam/core/promos.rb', line 27 def promos self end |
#some_msg(arg = nil) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/megam/core/promos.rb', line 65 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
78 79 80 81 82 83 84 85 86 |
# File 'lib/megam/core/promos.rb', line 78 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) ⇒ Object
Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.
90 91 92 |
# File 'lib/megam/core/promos.rb', line 90 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
157 158 159 |
# File 'lib/megam/core/promos.rb', line 157 def to_s Megam::Stuff.styled_hash(to_hash) end |