Class: Megam::Billings

Inherits:
ServerAPI show all
Defined in:
lib/megam/core/billings.rb

Instance Attribute Summary

Attributes inherited from ServerAPI

#api_key, #email

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ServerAPI

#megam_rest

Constructor Details

#initialize(email = nil, api_key = nil) ⇒ Billings

Returns a new instance of Billings.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/megam/core/billings.rb', line 19

def initialize(email=nil, api_key=nil)
  @id = nil
  @accounts_id = nil
  @line1 = nil
  @line2 = nil
  @country_code = nil
  @postal_code=nil
  @state=nil
  @phone = nil
  @bill_type = nil
  @created_at = nil
  @some_msg = {}
  super(email, api_key)
end

Class Method Details

.create(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object



212
213
214
215
# File 'lib/megam/core/billings.rb', line 212

def self.create(o,tmp_email=nil, tmp_api_key=nil)
  acct = from_hash(o,tmp_email, tmp_api_key)
  acct.create
end

.from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object



193
194
195
196
197
# File 'lib/megam/core/billings.rb', line 193

def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
  cts = self.new(tmp_email,tmp_api_key)
  cts.from_hash(o)
  cts
end

.json_create(o) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/megam/core/billings.rb', line 172

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.line1(o["line1"]) if o.has_key?("line1")
  cts.line2(o["line2"]) if o.has_key?("line2")
  cts.country_code(o["country_code"]) if o.has_key?("country_code")
  cts.postal_code(o["postal_code"]) if o.has_key?("postal_code")
  cts.state(o["state"]) if o.has_key?("state")
  cts.phone(o["phone"]) if o.has_key?("phone")
  cts.bill_type(o["bill_type"]) if o.has_key?("bill_type")

  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(tmp_email = nil, tmp_api_key = nil) ⇒ Object

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



225
226
227
228
# File 'lib/megam/core/billings.rb', line 225

def self.list(tmp_email=nil, tmp_api_key=nil)
  cts = self.new(tmp_email, tmp_api_key)
  cts.megam_rest.get_billings
end

.show(p_name, tmp_email = nil, tmp_api_key = nil) ⇒ Object

Show a particular billings by name, Megam::billings



232
233
234
235
# File 'lib/megam/core/billings.rb', line 232

def self.show(p_name,tmp_email=nil, tmp_api_key=nil)
  pre = self.new(tmp_email, tmp_api_key)
  pre.megam_rest.get_billing(p_name)
end

Instance Method Details

#accounts_id(arg = nil) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/megam/core/billings.rb', line 47

def accounts_id(arg=nil)
  if arg != nil
    @accounts_id= arg
  else
  @accounts_id
  end
end

#bill_type(arg = nil) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/megam/core/billings.rb', line 103

def bill_type(arg=nil)
  if arg != nil
    @bill_type = arg
  else
  @bill_type
  end
end

#billingsObject



34
35
36
# File 'lib/megam/core/billings.rb', line 34

def billings
  self
end

#country_code(arg = nil) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/megam/core/billings.rb', line 71

def country_code(arg=nil)
  if arg != nil
    @country_code = arg
  else
  @country_code
  end
end

#createObject

Create the billings via the REST API



218
219
220
# File 'lib/megam/core/billings.rb', line 218

def create
  megam_rest.post_billings(to_hash)
end

#created_at(arg = nil) ⇒ Object



111
112
113
114
115
116
117
# File 'lib/megam/core/billings.rb', line 111

def created_at(arg=nil)
  if arg != nil
    @created_at = arg
  else
  @created_at
  end
end

#error?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/megam/core/billings.rb', line 127

def error?
  crocked  = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end

#for_jsonObject



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/megam/core/billings.rb', line 155

def for_json
  result = {
    "id" => id,
    "accounts_id" => accounts_id,
    "line1" => line1,
    "line2" => line2,
    "country_code" => country_code,
    "postal_code" => postal_code,
    "state" => state,
    "phone" => phone,
    "bill_type" => bill_type,
    "created_at" => created_at
  }
  result
end

#from_hash(o) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/megam/core/billings.rb', line 199

def from_hash(o)
  @id        = o[:id] if o.has_key?(:id)
  @accounts_id = o[:accounts_id] if o.has_key?(:accounts_id)
  @line1   = o[:line1] if o.has_key?(:line1)
  @line2     = o[:line2] if o.has_key?(:line2)
  @country_code     = o[:country_code] if o.has_key?(:country_code)
  @postal_code   = o[:postal_code] if o.has_key?(:postal_code)
  @state   = o[:state] if o.has_key?(:state)
  @bill_type   = o[:bill_type] if o.has_key?(:bill_type)
  @created_at   = o[:created_at] if o.has_key?(:created_at)
  self
end

#id(arg = nil) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/megam/core/billings.rb', line 39

def id(arg=nil)
  if arg != nil
    @id = arg
  else
  @id
  end
end

#line1(arg = nil) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/megam/core/billings.rb', line 55

def line1(arg=nil)
  if arg != nil
    @line1 = arg
  else
  @line1
  end
end

#line2(arg = nil) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/megam/core/billings.rb', line 63

def line2(arg=nil)
  if arg != nil
    @line2 = arg
  else
  @line2
  end
end

#phone(arg = nil) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/megam/core/billings.rb', line 95

def phone(arg=nil)
  if arg != nil
    @phone= arg
  else
  @phone
  end
end

#postal_code(arg = nil) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/megam/core/billings.rb', line 79

def postal_code(arg=nil)
  if arg != nil
    @postal_code= arg
  else
  @postal_code
  end
end

#some_msg(arg = nil) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/megam/core/billings.rb', line 119

def some_msg(arg=nil)
  if arg != nil
    @some_msg = arg
  else
  @some_msg
  end
end

#state(arg = nil) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/megam/core/billings.rb', line 87

def state(arg=nil)
  if arg != nil
    @state= arg
  else
  @state
  end
end

#to_hashObject

Transform the ruby obj -> to a Hash



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/megam/core/billings.rb', line 132

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["line1"] = line1
  index_hash["line2"] = line2
  index_hash["country_code"] = country_code
  index_hash["postal_code"] = postal_code
  index_hash["state"] = state
  index_hash["phone"] = phone
  index_hash["bill_type"] = bill_type
  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.



151
152
153
# File 'lib/megam/core/billings.rb', line 151

def to_json(*a)
  for_json.to_json(*a)
end

#to_sObject



237
238
239
# File 'lib/megam/core/billings.rb', line 237

def to_s
  Megam::Stuff.styled_hash(to_hash)
end