class Megam::Balances

Public Class Methods

create(params) click to toggle source
# File lib/megam/core/balances.rb, line 142
def self.create(params)
    acct = from_hash(params,params["email"], params["api_key"], params["host"])
    acct.create
end
delete(p_name,tmp_email=nil, tmp_api_key=nil, tmp_host=nil) click to toggle source
# File lib/megam/core/balances.rb, line 167
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_balance(p_name)
end
from_hash(o) click to toggle source
# File lib/megam/core/balances.rb, line 126
def self.from_hash(o)
    balances = self.new(o)
    balances.from_hash(o)
    balances
end
json_create(o) click to toggle source
# File lib/megam/core/balances.rb, line 110
def self.json_create(o)
    balances = new({})
    balances.id(o["id"]) if o.has_key?("id")
    balances.account_id(o["account_id"]) if o.has_key?("account_id")
    balances.credit(o["credit"]) if o.has_key?("credit")
    balances.biller_credit(o["biller_credit"]) if o.has_key?("biller_credit")
    balances.created_at(o["created_at"]) if o.has_key?("created_at")
    balances.updated_at(o["updated_at"]) if o.has_key?("updated_at")
    #success or error
    balances.some_msg[:code] = o["code"] if o.has_key?("code")
    balances.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
    balances.some_msg[:msg]= o["msg"] if o.has_key?("msg")
    balances.some_msg[:links] = o["links"] if o.has_key?("links")
    balances
end
list(params) click to toggle source

Load all balances - returns a BalanceCollection don’t return self. check if the Megam::BalanceCollection is returned.

# File lib/megam/core/balances.rb, line 155
def self.list(params)
    balance = self.new(params)
    balance.megam_rest.get_balances
end
new(o) click to toggle source
Calls superclass method Megam::RestAdapter::new
# File lib/megam/core/balances.rb, line 3
def initialize(o)
    @id = nil
    @account_id = nil
    @credit = nil
    @biller_credit = nil
    @created_at = nil
    @updated_at = nil
    @some_msg = {}
    super(o)
end
show(params) click to toggle source

Show a particular balance by name, Megam::Balance

# File lib/megam/core/balances.rb, line 162
def self.show(params)
    pre = self.new(params)
    pre.megam_rest.get_balance(params["email"])
end
update(params) click to toggle source
# File lib/megam/core/balances.rb, line 172
def self.update(params)
    asm = from_hash(params)
    asm.update
end

Public Instance Methods

account_id(arg=nil) click to toggle source
# File lib/megam/core/balances.rb, line 26
def account_id(arg=nil)
    if arg != nil
        @account_id= arg
    else
        @account_id
    end
end
balances() click to toggle source
# File lib/megam/core/balances.rb, line 14
def balances
    self
end
biller_credit(arg=nil) click to toggle source
# File lib/megam/core/balances.rb, line 43
def biller_credit(arg=nil)
    if arg != nil
        @biller_credit = arg
    else
        @biller_credit
    end
end
create() click to toggle source

Create the predef via the REST API

# File lib/megam/core/balances.rb, line 148
def create
    megam_rest.post_balances(to_hash)
end
created_at(arg=nil) click to toggle source
# File lib/megam/core/balances.rb, line 51
def created_at(arg=nil)
    if arg != nil
        @created_at = arg
    else
        @created_at
    end
end
credit(arg=nil) click to toggle source
# File lib/megam/core/balances.rb, line 35
def credit(arg=nil)
    if arg != nil
        @credit = arg
    else
        @credit
    end
end
error?() click to toggle source
# File lib/megam/core/balances.rb, line 75
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/balances.rb, line 98
def for_json
    result = {
        "id" => id,
        "account_id" => account_id,
        "credit" => credit,
        "biller_credit" => biller_credit,
        "created_at" => created_at,
        "updated_at" => updated_at
    }
    result
end
from_hash(o) click to toggle source
# File lib/megam/core/balances.rb, line 132
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)
    @biller_credit   = o[:biller_credit] if o.has_key?(:biller_credit)
    @created_at   = o[:created_at] if o.has_key?(:created_at)
    @updated_at   = o[:updated_at] if o.has_key?(:updated_at)
    self
end
id(arg=nil) click to toggle source
# File lib/megam/core/balances.rb, line 18
def id(arg=nil)
    if arg != nil
        @id = arg
    else
        @id
    end
end
some_msg(arg=nil) click to toggle source
# File lib/megam/core/balances.rb, line 67
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/balances.rb, line 80
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["biller_credit"] = biller_credit
    index_hash["created_at"] = created_at
    index_hash["updated_at"] = updated_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/balances.rb, line 94
def to_json(*a)
    for_json.to_json(*a)
end
to_s() click to toggle source
# File lib/megam/core/balances.rb, line 182
def to_s
    Megam::Stuff.styled_hash(to_hash)
end
update() click to toggle source

Create the node via the REST API

# File lib/megam/core/balances.rb, line 178
def update
    megam_rest.update_balance(to_hash)
end
updated_at(arg=nil) click to toggle source
# File lib/megam/core/balances.rb, line 59
def updated_at(arg=nil)
    if arg != nil
        @updated_at = arg
    else
        @updated_at
    end
end