megam_api 1.5.rc7 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9846ceccd22bdecd8689f54914778e9ad4fede10
4
- data.tar.gz: 7199923ac196285d1ed0b228b973c1e5e64a1315
3
+ metadata.gz: 6f212867be9de6e8077970329184d74a8e21759b
4
+ data.tar.gz: 19d48baba4a7217658959da171443e36c04af4ef
5
5
  SHA512:
6
- metadata.gz: f3b971c02cfdb47a71307618b8b98646eb89021ecb8f3da28f49af3d55acc4ff77918b58bf4eeb42d0577a538e8622793b818cf9b68dc51b42d7b59873f0f2c8
7
- data.tar.gz: 309d8bdc0d58a9c44abf81888238040d47d262cfae31096cb68eccaa53a0490a77ff31060a896f7b3fa8fcfcfc70f91fae4c34d118a9a43f0c81e7d18bb0c2f6
6
+ metadata.gz: 3a6480d33505d5555147b1f1a12612e91c7189c0b5d86e08b84bc16036be4254c2f2539f0e9dbb7493268db626717b8bf265d152917690ac85fbd6cf70b4110e
7
+ data.tar.gz: b5b6ba4a58a848bf1cf7b293e8a44b964dc77f98978baf51abe000403b55b459c57ebe1c91a54f90c77c015959fb9c1500bfc69a54850650cc0efe374bf6ea05
data/lib/megam/api.rb CHANGED
@@ -28,6 +28,8 @@ require 'megam/api/eventscontainer'
28
28
  require 'megam/api/eventsbilling'
29
29
  require 'megam/api/eventsstorage'
30
30
  require 'megam/api/snapshots'
31
+ require 'megam/api/subscriptions'
32
+ require 'megam/api/addons'
31
33
  require 'megam/api/version'
32
34
 
33
35
  require 'megam/mixins/assemblies'
@@ -80,6 +82,10 @@ require 'megam/core/billedhistories_collection'
80
82
  require 'megam/core/billedhistories'
81
83
  require 'megam/core/billingtransactions_collection'
82
84
  require 'megam/core/billingtransactions'
85
+ require 'megam/core/subscriptions_collection'
86
+ require 'megam/core/subscriptions'
87
+ require 'megam/core/addons_collection'
88
+ require 'megam/core/addons'
83
89
  require 'megam/core/promos'
84
90
 
85
91
  module Megam
@@ -0,0 +1,27 @@
1
+
2
+ module Megam
3
+ class API
4
+
5
+ def get_addon(name)
6
+ @options = {:path => "/addons/#{name}",:body => ""}.merge(@options)
7
+
8
+ request(
9
+ :expects => 200,
10
+ :method => :get,
11
+ :body => @options[:body]
12
+ )
13
+ end
14
+
15
+ def post_addons(new_addon)
16
+ @options = {:path => '/addons/content',
17
+ :body => Megam::JSONCompat.to_json(new_addon)}.merge(@options)
18
+
19
+ request(
20
+ :expects => 201,
21
+ :method => :post,
22
+ :body => @options[:body]
23
+ )
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ module Megam
2
+ class API
3
+
4
+ def get_subscription
5
+ @options = {:path => "/subscriptions",:body => ""}.merge(@options)
6
+
7
+ request(
8
+ :expects => 200,
9
+ :method => :get,
10
+ :body => @options[:body]
11
+ )
12
+ end
13
+
14
+ def post_subscriptions(new_subscription)
15
+ @options = {:path => '/subscriptions/content',
16
+ :body => Megam::JSONCompat.to_json(new_subscription)}.merge(@options)
17
+
18
+ request(
19
+ :expects => 201,
20
+ :method => :post,
21
+ :body => @options[:body]
22
+ )
23
+ end
24
+
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "1.5.rc7"
3
+ VERSION = "1.5.4"
4
4
  end
5
5
  end
@@ -1,453 +1,213 @@
1
1
  module Megam
2
- class Account < Megam::RestAdapter
3
- def initialize(o)
4
- @id = nil
5
- @email = nil
6
- @api_key = nil
7
- @name = nil
8
- @phone = nil
9
- @password = nil
10
- @states = nil
11
- @approval = nil
12
- @suspend = nil
13
- @registration_ip_address = nil
14
- @dates = nil
15
- @some_msg = {}
16
- super({:email => o[:email], :api_key => o[:api_key], :host => o[:host], :password => o[:password], :org_id => o[:org_id]})
2
+ class Account < Megam::RestAdapter
3
+
4
+ attr_accessor :id
5
+ attr_accessor :email
6
+ attr_accessor :password
7
+ attr_accessor :api_key
8
+ attr_accessor :name
9
+ attr_accessor :phone
10
+ attr_accessor :states
11
+ attr_accessor :approval
12
+ attr_accessor :suspend
13
+ attr_accessor :registration_ip_address
14
+ attr_accessor :dates
15
+ attr_accessor :json_claz, :code, :msg_type, :msg, :links, :more
16
+ attr_accessor :some_msg
17
+
18
+
19
+ def initialize(o={})
20
+ @id = nil
21
+ @email = nil
22
+ @api_key = nil
23
+ @name = {}
24
+ @phone = {}
25
+ @password = {}
26
+ @states = {}
27
+ @approval = {}
28
+ @suspend = {}
29
+ @dates = {}
30
+ @some_msg = {}
31
+ super({ email: o[:email], api_key: o[:api_key],
32
+ host: o[:host], password: o[:password], org_id: o[:org_id] })
33
+ end
34
+
35
+ def account
36
+ self
37
+ end
38
+
39
+ def some_msg(arg = nil)
40
+ if !arg.nil?
41
+ @some_msg = arg
42
+ else
43
+ @some_msg
44
+ end
45
+ end
46
+
47
+ def error?
48
+ crocked = true if some_msg.key?(:msg_type) && some_msg[:msg_type] == 'error'
49
+ end
50
+
51
+ def to_json(*a)
52
+ for_json.to_json(*a)
53
+ end
54
+
55
+ def for_json
56
+ result = {
57
+ 'id' => @id,
58
+ 'email' => @email,
59
+ 'api_key' => @api_key,
60
+ 'name' => @name,
61
+ 'phone' => @phone,
62
+ 'password' => @password,
63
+ 'states' => @states,
64
+ 'approval' => @approval,
65
+ 'suspend' => @suspend,
66
+ 'registration_ip_address' => @registration_ip_address,
67
+ 'dates' => @dates
68
+ }
69
+ result
70
+ end
71
+
72
+ def self.json_create(o)
73
+ acct = new()
74
+ o.symbolize_keys!
75
+ o = o[:results] if o.has_key?(:results)
76
+
77
+ o.each { |k, v| acct.send("#{k}=", v) }
78
+
79
+ acct.some_msg[:code] = @code if @code
80
+ acct.some_msg[:msg_type] = @msg_type if @msg_type
81
+ acct.some_msg[:msg] = @msg if @msg
82
+ acct.some_msg[:more] = @more if @more
83
+ acct.some_msg[:links] = @links if @links
84
+
85
+ acct
86
+ end
87
+
88
+
89
+ #Can be used by the calling classes to get the full hash
90
+ # (eg: Nilavu: User model)
91
+ def expanded
92
+ h = Hash.new
93
+ [:id, :email, :api_key, :name, :phone, :password,:states, :approval, :suspend,
94
+ :registration_ip_address, :dates, :some_msg].each do |setting|
95
+ if grouped = self.send("#{setting}").is_a?(Hash)
96
+ self.send("#{setting}").each {|k,v| h[k.to_sym] = v}
97
+ else
98
+ h[setting] = self.send("#{setting}")
99
+ end
100
+ end
101
+ h
102
+ end
103
+
104
+
105
+ def self.from_hash(o)
106
+ acct = new(email: o[:email], api_key: o[:api_key], host: o[:host], password: o[:password], org_id: o[:org_id])
107
+ acct.from_hash(o)
108
+ acct
109
+ end
110
+
111
+ def from_hash(o)
112
+ @id = o[:id] if o.key?(:id)
113
+ @email = o[:email] if o.key?(:email)
114
+ @api_key = o[:api_key] if o.key?(:api_key)
115
+
116
+ @name[:first_name] = o[:first_name] if o.key?(:first_name)
117
+ @name[:last_name] = o[:last_name] if o.key?(:last_name)
118
+
119
+ @phone[:phone] = o[:phone] if o.key?(:phone)
120
+ @phone[:phone_verified] = o[:phone_verified] if o.key?(:phone_verified)
121
+
122
+ @password[:password] = o[:password] if o.key?(:password)
123
+ @password[:password_reset_key] = o[:password_reset_key] if o.key?(:password_reset_key)
124
+ @password[:password_reset_sent_at] = o[:password_reset_sent_at] if o.key?(:password_reset_sent_at)
125
+
126
+ @states[:authority] = o[:authority] if o.key?(:authority)
127
+ @states[:active] = o[:active] if o.key?(:active)
128
+ @states[:blocked] = o[:blocked] if o.key?(:blocked)
129
+ @states[:staged] = o[:staged] if o.key?(:staged)
130
+
131
+ @approval[:approved] = o[:approved] if o.key?(:approved)
132
+ @approval[:approved_by_id] = o[:approved_by_id] if o.key?(:approved_by_id)
133
+ @approval[:approved_at] = o[:approved_at] if o.key?(:approved_at)
134
+
135
+ @suspend[:suspended] = o[:suspended] if o.key?(:suspended)
136
+ @suspend[:suspended_at] = o[:suspend] if o.key?(:suspended_at)
137
+ @suspend[:suspended_till] = o[:suspended_till] if o.key?(:suspended_till)
138
+ @registration_ip_address = o[:registration_ip_address] if o.key?(:registration_ip_address)
139
+
140
+ @dates[:last_posted_at] = o[:last_posted_at] if o.key?(:last_posted_at)
141
+ @dates[:last_emailed_at] = o[:last_emailed_at] if o.key?(:last_emailed_at)
142
+ @dates[:previous_visit_at] = o[:previous_visit_at] if o.key?(:previous_visit_at)
143
+ @dates[:first_seen_at] = o[:first_seen_at] if o.key?(:first_seen_at)
144
+ @dates[:created_at] = o[:created_at] if o.key?(:created_at)
145
+ self
146
+ end
147
+
148
+ def self.create(o)
149
+ acct = from_hash(o)
150
+ acct.create
151
+ end
152
+
153
+ def create
154
+ megam_rest.post_accounts(to_hash)
155
+ end
156
+
157
+ def self.show(o)
158
+ acct = new(email: o[:email], api_key: o[:api_key], host: o[:host], password: o[:password], org_id: o[:org_id])
159
+ acct.megam_rest.get_accounts(o[:email])
160
+ end
161
+
162
+ def self.update(o)
163
+ acct = from_hash(o)
164
+ acct.update
165
+ end
166
+
167
+ def self.reset(o)
168
+ acct = from_hash(o)
169
+ acct.reset
170
+ end
171
+
172
+ def self.repassword(o)
173
+ acct = from_hash(o)
174
+ acct.repassword
175
+ end
176
+
177
+ def update
178
+ megam_rest.update_accounts(to_hash)
179
+ end
180
+
181
+ def reset
182
+ megam_rest.reset_accounts(to_hash)
183
+ end
184
+
185
+ def repassword
186
+ megam_rest.repassword_accounts(to_hash)
187
+ end
188
+
189
+ def to_s
190
+ Megam::Stuff.styled_hash(to_hash)
191
+ end
192
+
193
+ private
194
+
195
+ def to_hash
196
+ h = Hash.new
197
+ h['json_claz'] = self.class.name
198
+ h['id'] = @id
199
+ h['email'] = @email
200
+ h['api_key'] = @api_key
201
+ h['name'] = @name
202
+ h['phone'] = @phone
203
+ h['password'] = @password
204
+ h['states'] = @states
205
+ h['approval'] = @approval
206
+ h['suspend'] = @suspend
207
+ h['registration_ip_address'] = @registration_ip_address
208
+ h['dates'] = @dates
209
+ h['some_msg'] = some_msg
210
+ h
211
+ end
17
212
  end
18
-
19
- #used by resque workers and any other background job
20
- def account
21
- self
22
- end
23
-
24
- def id(arg=nil)
25
- if arg != nil
26
- @id = arg
27
- else
28
- @id
29
- end
30
- end
31
-
32
- def email(arg=nil)
33
- if arg != nil
34
- @email = arg
35
- else
36
- @email
37
- end
38
- end
39
-
40
- def api_key(arg=nil)
41
- if arg != nil
42
- @api_key = arg
43
- else
44
- @api_key
45
- end
46
- end
47
-
48
- def name(arg=nil)
49
- if arg != nil
50
- @name = arg
51
- else
52
- @name
53
- end
54
- end
55
- def first_name(arg = nil)
56
- if !arg.nil?
57
- @first_name = arg
58
- else
59
- @first_name
60
- end
61
- end
62
-
63
- def last_name(arg = nil)
64
- if !arg.nil?
65
- @last_name = arg
66
- else
67
- @last_name
68
- end
69
- end
70
-
71
- def phone(arg=nil)
72
- if arg != nil
73
- @phone = arg
74
- else
75
- @phone
76
- end
77
- end
78
-
79
- def phone_verified(arg=nil)
80
- if arg != nil
81
- @phone_verified = arg
82
- else
83
- @phone_verified
84
- end
85
- end
86
-
87
- def phone(arg=nil)
88
- if arg != nil
89
- @phone = arg
90
- else
91
- @phone
92
- end
93
- end
94
-
95
- def password(arg=nil)
96
- if arg != nil
97
- @password = arg
98
- else
99
- @password
100
- end
101
- end
102
-
103
-
104
- def password(arg=nil)
105
- if arg != nil
106
- @password = arg
107
- else
108
- @password
109
- end
110
- end
111
-
112
- def password_reset_key(arg=nil)
113
- if arg != nil
114
- @password_reset_key = arg
115
- else
116
- @password_reset_key
117
- end
118
- end
119
-
120
- def password_reset_sent_at(arg=nil)
121
- if arg != nil
122
- @password_reset_sent_at = arg
123
- else
124
- @password_reset_sent_at
125
- end
126
- end
127
-
128
- def states(arg = nil)
129
- if !arg.nil?
130
- @states = arg
131
- else
132
- @states
133
- end
134
- end
135
-
136
- def authority(arg=nil)
137
- if arg != nil
138
- @authority = arg
139
- else
140
- @authority
141
- end
142
- end
143
-
144
- def active(arg = nil)
145
- if !arg.nil?
146
- @active = arg
147
- else
148
- @active
149
- end
150
- end
151
-
152
- def blocked(arg = nil)
153
- if !arg.nil?
154
- @blocked = arg
155
- else
156
- @blocked
157
- end
158
- end
159
-
160
- def staged(arg = nil)
161
- if !arg.nil?
162
- @staged = arg
163
- else
164
- @staged
165
- end
166
- end
167
-
168
- def approval(arg = nil)
169
- if !arg.nil?
170
- @approval = arg
171
- else
172
- @approval
173
- end
174
- end
175
-
176
- def approved(arg = nil)
177
- if !arg.nil?
178
- @approved = arg
179
- else
180
- @approved
181
- end
182
- end
183
-
184
- def approved_by_id(arg = nil)
185
- if !arg.nil?
186
- @approved_by_id = arg
187
- else
188
- @approved_by_id
189
- end
190
- end
191
-
192
- def approved_at(arg = nil)
193
- if !arg.nil?
194
- @approved_at = arg
195
- else
196
- @approved_at
197
- end
198
- end
199
-
200
- def suspend(arg = nil)
201
- if !arg.nil?
202
- @suspend = arg
203
- else
204
- @suspend
205
- end
206
- end
207
-
208
- def suspended(arg = nil)
209
- if !arg.nil?
210
- @suspended = arg
211
- else
212
- @suspended
213
- end
214
- end
215
-
216
- def suspended_at(arg = nil)
217
- if !arg.nil?
218
- @suspended_at = arg
219
- else
220
- @suspended_at
221
- end
222
- end
223
-
224
- def suspended_till(arg = nil)
225
- if !arg.nil?
226
- @suspended_till = arg
227
- else
228
- @suspended_till
229
- end
230
- end
231
-
232
- def registration_ip_address(arg = nil)
233
- if !arg.nil?
234
- @registration_ip_address = arg
235
- else
236
- @registration_ip_address
237
- end
238
- end
239
-
240
- def dates(arg = nil)
241
- if !arg.nil?
242
- @dates = arg
243
- else
244
- @dates
245
- end
246
- end
247
-
248
- def last_posted_at(arg = nil)
249
- if !arg.nil?
250
- @last_posted_at = arg
251
- else
252
- @last_posted_at
253
- end
254
- end
255
-
256
- def last_emailed_at(arg = nil)
257
- if !arg.nil?
258
- @last_emailed_at = arg
259
- else
260
- @last_emailed_at
261
- end
262
- end
263
-
264
- def previous_visit_at(arg = nil)
265
- if !arg.nil?
266
- @previous_visit_at = arg
267
- else
268
- @previous_visit_at
269
- end
270
- end
271
-
272
- def first_seen_at(arg = nil)
273
- if !arg.nil?
274
- @first_seen_at = arg
275
- else
276
- @first_seen_at
277
- end
278
- end
279
-
280
- def created_at(arg=nil)
281
- if arg != nil
282
- @created_at = arg
283
- else
284
- @created_at
285
- end
286
- end
287
-
288
- def some_msg(arg=nil)
289
- if arg != nil
290
- @some_msg = arg
291
- else
292
- @some_msg
293
- end
294
- end
295
-
296
- def error?
297
- crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
298
- end
299
-
300
- # Transform the ruby obj -> to a Hash
301
- def to_hash
302
- index_hash = Hash.new
303
- index_hash["json_claz"] = self.class.name
304
- index_hash["id"] = id
305
- index_hash["email"] = email
306
- index_hash["api_key"] = api_key
307
- index_hash["name"] = name
308
- index_hash["phone"] = phone
309
- index_hash["password"] = password
310
- index_hash["states"] = states
311
- index_hash["approval"] = approval
312
- index_hash["suspend"] = suspend
313
- index_hash["registration_ip_address"] = registration_ip_address
314
- index_hash["dates"] = dates
315
- index_hash["some_msg"] = some_msg
316
- index_hash
317
- end
318
-
319
- # Serialize this object as a hash: called from JsonCompat.
320
- # Verify if this called from JsonCompat during testing.
321
- def to_json(*a)
322
- for_json.to_json(*a)
323
- end
324
-
325
- def for_json
326
- result = {
327
- "id" => id,
328
- "email" => email,
329
- "api_key" => api_key,
330
- "name" => name,
331
- "phone" => phone,
332
- "password" => password,
333
- "states" => states,
334
- "approval" => approval,
335
- "registration_ip_address" => registration_ip_address,
336
- "dates" => dates
337
- }
338
- result
339
- end
340
-
341
- # Create a Megam::Account from JSON (used by the backgroud job workers)
342
- def self.json_create(o)
343
- acct = new({})
344
- acct.id(o["id"]) if o.has_key?("id")
345
- acct.email(o["email"]) if o.has_key?("email")
346
- acct.api_key(o["api_key"]) if o.has_key?("api_key")
347
- na = o['name']
348
- acct.name[:first_name] = na['first_name'] if na && na.key?('first_name')
349
- acct.name[:last_name] = na['last_name'] if na && na.key?('last_name')
350
- ph = o['phone']
351
- acct.phone[:phone] = ph['phone'] if ph && ph.key?('phone')
352
- acct.phone[:phone_verified] = ph['phone_verified'] if ph && ph.key?('phone_verified')
353
- pwd = o['password']
354
- acct.password[:password] = pwd['password'] if pwd && pwd.key?('password')
355
- acct.password[:password_reset_key] = pwd['password_reset_key'] if pwd && pwd.key?('password_reset_key')
356
- acct.password[:password_reset_sent_at] = pwd['password_reset_sent_at'] if pwd && pwd.key?('password_reset_sent_at')
357
- st = o['states']
358
- acct.states[:authority] = st['authority'] if st && st.key?('authority')
359
- acct.states[:active] = st['active'] if st && st.key?('active')
360
- acct.states[:blocked] = st['blocked'] if st && st.key?('blocked')
361
- acct.states[:staged] = st['staged'] if st && st.key?('staged')
362
- al = o['approval']
363
- acct.approval[:approved] = al['approved'] if al && al.key?('approved')
364
- acct.approval[:approved_by_id] = al['approved_by_id'] if al && al.key?('approved_by_id')
365
- acct.approval[:approved_at] = al['approved_at'] if al && al.key?('approved_at')
366
- sp = o['suspend']
367
- acct.suspend[:suspended] = sp['suspended'] if sp && sp.key?('suspended')
368
- acct.suspend[:suspended_at] = sp['suspended_at'] if sp && sp.key?('suspended_at')
369
- acct.suspend[:suspended_till] = sp['suspended_till'] if sp && sp.key?('suspended_till')
370
- acct.registration_ip_address(o["registration_ip_address"]) if o.has_key?("registration_ip_address")
371
- dt = o['dates']
372
- acct.dates[:last_posted_at] = dt['last_posted_at'] if dt && dt.key?('last_posted_at')
373
- acct.dates[:last_emailed_at] = dt['last_emailed_at'] if dt && dt.key?('last_emailed_at')
374
- acct.dates[:previous_visit_at] = dt['previous_visit_at'] if dt && dt.key?('previous_visit_at')
375
- acct.dates[:first_seen_at] = dt['first_seen_at'] if dt && dt.key?('first_seen_at')
376
- acct.dates[:created_at] = dt['created_at'] if dt && dt.key?('created_at')
377
- acct.some_msg[:code] = o["code"] if o.has_key?("code")
378
- acct.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
379
- acct.some_msg[:msg]= o["msg"] if o.has_key?("msg")
380
- acct.some_msg[:links] = o["links"] if o.has_key?("links")
381
- acct
382
- end
383
-
384
- def self.from_hash(o)
385
- acct = self.new({:email => o[:email], :api_key => o[:api_key], :host => o[:host], :password => o[:password], :org_id => o[:org_id]})
386
- acct.from_hash(o)
387
- acct
388
- end
389
-
390
- def from_hash(o)
391
- @id = o[:id] if o.has_key?(:id)
392
- @email = o[:email] if o.has_key?(:email)
393
- @api_key = o[:api_key] if o.has_key?(:api_key)
394
- @name = o[:name] if o.has_key?(:name)
395
- @phone = o[:phone] if o.has_key?(:phone)
396
- @password = o[:password] if o.has_key?(:password)
397
- @states = o[:states] if o.has_key?(:states)
398
- @approval = o[:approval] if o.has_key?(:approval)
399
- @suspend = o[:suspend] if o.has_key?(:suspend)
400
- @registration_ip_address = o[:registration_ip_address] if o.has_key?(:registration_ip_address)
401
- @dates = o[:dates] if o.has_key?(:dates)
402
- self
403
- end
404
-
405
- def self.create(o)
406
- acct = from_hash(o)
407
- acct.create
408
- end
409
-
410
- # Create the node via the REST API
411
- def create
412
- megam_rest.post_accounts(to_hash)
413
- end
414
-
415
- # Load a account by email_p
416
- def self.show(o)
417
- acct = self.new({:email => o[:email], :api_key => o[:api_key], :host => o[:host], :password => o[:password], :org_id => o[:org_id]})
418
- acct.megam_rest.get_accounts(o[:email])
419
- end
420
-
421
- def self.update(o)
422
- acct = from_hash(o)
423
- acct.update
424
- end
425
-
426
- def self.reset(o)
427
- acct = from_hash(o)
428
- acct.reset
429
- end
430
-
431
- def self.repassword(o)
432
- acct = from_hash(o)
433
- acct.repassword
434
- end
435
-
436
- # Create the node via the REST API
437
- def update
438
- megam_rest.update_accounts(to_hash)
439
- end
440
-
441
- def reset
442
- megam_rest.reset_accounts(to_hash)
443
- end
444
-
445
- def repassword
446
- megam_rest.repassword_accounts(to_hash)
447
- end
448
-
449
- def to_s
450
- Megam::Stuff.styled_hash(to_hash)
451
- end
452
- end
453
213
  end