megam_api 0.36 → 0.38

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -3
  3. data/lib/megam/api.rb +22 -3
  4. data/lib/megam/api/accounts.rb +15 -1
  5. data/lib/megam/api/availableunits.rb +35 -0
  6. data/lib/megam/api/balances.rb +46 -0
  7. data/lib/megam/api/billinghistories.rb +35 -0
  8. data/lib/megam/api/billings.rb +35 -0
  9. data/lib/megam/api/components.rb +2 -2
  10. data/lib/megam/api/credithistories.rb +35 -0
  11. data/lib/megam/api/discounts.rb +35 -0
  12. data/lib/megam/api/profile.rb +42 -0
  13. data/lib/megam/api/subscriptions.rb +35 -0
  14. data/lib/megam/api/version.rb +1 -1
  15. data/lib/megam/core/account.rb +85 -8
  16. data/lib/megam/core/assembly.rb +5 -9
  17. data/lib/megam/core/availableunits.rb +181 -0
  18. data/lib/megam/core/availableunits_collection.rb +144 -0
  19. data/lib/megam/core/balances.rb +201 -0
  20. data/lib/megam/core/balances_collection.rb +144 -0
  21. data/lib/megam/core/billinghistories.rb +206 -0
  22. data/lib/megam/core/billinghistories_collection.rb +144 -0
  23. data/lib/megam/core/billings.rb +242 -0
  24. data/lib/megam/core/billings_collection.rb +144 -0
  25. data/lib/megam/core/credithistories.rb +191 -0
  26. data/lib/megam/core/credithistories_collection.rb +144 -0
  27. data/lib/megam/core/discounts.rb +191 -0
  28. data/lib/megam/core/discounts_collection.rb +144 -0
  29. data/lib/megam/core/json_compat.rb +57 -15
  30. data/lib/megam/core/subscriptions.rb +191 -0
  31. data/lib/megam/core/subscriptions_collection.rb +144 -0
  32. data/megam_api.gemspec +2 -2
  33. data/test/test_accounts.rb +19 -0
  34. data/test/test_availableunits.rb +29 -0
  35. data/test/test_balances.rb +39 -0
  36. data/test/test_billinghistories.rb +31 -0
  37. data/test/test_billings.rb +34 -0
  38. data/test/test_credithistories.rb +30 -0
  39. data/test/test_discounts.rb +30 -0
  40. data/test/test_helper.rb +2 -2
  41. data/test/test_subscriptions.rb +30 -0
  42. metadata +61 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbd4ffa63fecbfe5d3ab29cac888381c44bbbddb
4
- data.tar.gz: 137a76192ae6c04f4adad619e061ce5b56ae10e3
3
+ metadata.gz: 7361e07644b404b7797ed86aa2565c19263e26e3
4
+ data.tar.gz: 0e73c2a890458e6e8ce11569e3f550c7a301b1a1
5
5
  SHA512:
6
- metadata.gz: f8e299ecc9867a6163a33ce88a822ff37fadba0631ea101a906d72062cf1b5f90cb721aff032ba58227ac430e87a536f30da781dad29a70f1bc63b4f22accc66
7
- data.tar.gz: 9b39eb75519b6301ebdef61693a2263acb746bf8f81be849f51f77b31e1a39453d38d053302784f6ed81158196530ad3c0a878dcbb0a387eb5faf07d91088e8b
6
+ metadata.gz: 0dd2c90bbc8f04d39254fea1df0d5fda081bc1672a4c609a3edbeb75e975c6c679c7e036029be20fbdff086793f78684efc150ae6e5e9cf3c4c76124fb404290
7
+ data.tar.gz: 8303cdba71805cfe4c80d6a1e606eb6a9c31f8e1a06e4cc2096553911c77e7f92a0a267b448d4dce1a31ee2aad5f1497baa64e79e25fbc8f72c025aff4dc1991
data/.travis.yml CHANGED
@@ -3,9 +3,9 @@ language: ruby
3
3
  notifications:
4
4
  email:
5
5
  recipients:
6
- - nkishore@megam.co.in
6
+ - info@megam.io
7
7
 
8
8
  rvm:
9
- - 2.0.0
10
-
9
+ - 2.2.2
10
+
11
11
  script: bundle exec rake
data/lib/megam/api.rb CHANGED
@@ -31,6 +31,13 @@ require "megam/api/assemblies"
31
31
  require "megam/api/assembly"
32
32
  require "megam/api/components"
33
33
  require "megam/api/event"
34
+ require "megam/api/availableunits"
35
+ require "megam/api/balances"
36
+ require "megam/api/billinghistories"
37
+ require "megam/api/billings"
38
+ require "megam/api/credithistories"
39
+ require "megam/api/discounts"
40
+ require "megam/api/subscriptions"
34
41
 
35
42
  require "megam/core/server_api"
36
43
  require "megam/core/config"
@@ -69,8 +76,20 @@ require "megam/core/app_request"
69
76
  require "megam/core/app_request_collection"
70
77
  require "megam/core/event"
71
78
 
72
-
73
-
79
+ require "megam/core/availableunits_collection"
80
+ require "megam/core/availableunits"
81
+ require "megam/core/balances_collection"
82
+ require "megam/core/balances"
83
+ require "megam/core/billinghistories_collection"
84
+ require "megam/core/billinghistories"
85
+ require "megam/core/billings_collection"
86
+ require "megam/core/billings"
87
+ require "megam/core/credithistories_collection"
88
+ require "megam/core/credithistories"
89
+ require "megam/core/discounts_collection"
90
+ require "megam/core/discounts"
91
+ require "megam/core/subscriptions_collection"
92
+ require "megam/core/subscriptions"
74
93
 
75
94
  module Megam
76
95
  class API
@@ -215,7 +234,7 @@ module Megam
215
234
  X_Megam_DATE => encoded_api_header[:date],
216
235
  }).merge(@options[:headers])
217
236
 
218
-
237
+
219
238
  if @options[:scheme] == "https"
220
239
 
221
240
  if !File.exist?(File.expand_path(File.join("#{ENV['MEGAM_HOME']}", "#{@common["api"]["pub_key"]}")))
@@ -24,6 +24,20 @@ module Megam
24
24
  :method => :post,
25
25
  :body => @options[:body]
26
26
  )
27
+ end
28
+
29
+
30
+ # The body content needs to be a json.
31
+ def update_accounts(new_account)
32
+ @options = {:path => '/accounts/update',
33
+ :body => Megam::JSONCompat.to_json(new_account)}.merge(@options)
34
+
35
+ request(
36
+ :expects => 201,
37
+ :method => :post,
38
+ :body => @options[:body]
39
+ )
40
+ end
27
41
  end
28
- end
42
+
29
43
  end
@@ -0,0 +1,35 @@
1
+ module Megam
2
+ class API
3
+ def get_availableunits
4
+ @options = {:path => '/availableunits',:body => ""}.merge(@options)
5
+
6
+ request(
7
+ :expects => 200,
8
+ :method => :get,
9
+ :body => @options[:body]
10
+ )
11
+ end
12
+
13
+ def get_availableunit(id)
14
+ @options = {:path => "/availableunits/#{id}",:body => ""}.merge(@options)
15
+
16
+ request(
17
+ :expects => 200,
18
+ :method => :get,
19
+ :body => @options[:body]
20
+ )
21
+ end
22
+
23
+ def post_availableunits(new_availableunit)
24
+ @options = {:path => '/availableunits/content',
25
+ :body => Megam::JSONCompat.to_json(new_availableunit)}.merge(@options)
26
+
27
+ request(
28
+ :expects => 201,
29
+ :method => :post,
30
+ :body => @options[:body]
31
+ )
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,46 @@
1
+ module Megam
2
+ class API
3
+ def get_balances
4
+ @options = {:path => '/balances',:body => ""}.merge(@options)
5
+
6
+ request(
7
+ :expects => 200,
8
+ :method => :get,
9
+ :body => @options[:body]
10
+ )
11
+ end
12
+
13
+ def get_balance(id)
14
+ @options = {:path => "/balances/#{id}",:body => ""}.merge(@options)
15
+
16
+ request(
17
+ :expects => 200,
18
+ :method => :get,
19
+ :body => @options[:body]
20
+ )
21
+ end
22
+
23
+ def post_balances(new_balance)
24
+ @options = {:path => '/balances/content',
25
+ :body => Megam::JSONCompat.to_json(new_balance)}.merge(@options)
26
+
27
+ request(
28
+ :expects => 201,
29
+ :method => :post,
30
+ :body => @options[:body]
31
+ )
32
+ end
33
+
34
+ def update_balance(new_balance)
35
+ @options = {:path => '/balances/update',
36
+ :body => Megam::JSONCompat.to_json(new_balance)}.merge(@options)
37
+
38
+ request(
39
+ :expects => 201,
40
+ :method => :post,
41
+ :body => @options[:body]
42
+ )
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ module Megam
2
+ class API
3
+ def get_billinghistories
4
+ @options = {:path => '/billinghistories',:body => ""}.merge(@options)
5
+
6
+ request(
7
+ :expects => 200,
8
+ :method => :get,
9
+ :body => @options[:body]
10
+ )
11
+ end
12
+
13
+ def get_billinghistory(id)
14
+ @options = {:path => "/billinghistories/#{id}",:body => ""}.merge(@options)
15
+
16
+ request(
17
+ :expects => 200,
18
+ :method => :get,
19
+ :body => @options[:body]
20
+ )
21
+ end
22
+
23
+ def post_billinghistories(new_billinghistory)
24
+ @options = {:path => '/billinghistories/content',
25
+ :body => Megam::JSONCompat.to_json(new_billinghistory)}.merge(@options)
26
+
27
+ request(
28
+ :expects => 201,
29
+ :method => :post,
30
+ :body => @options[:body]
31
+ )
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ module Megam
2
+ class API
3
+ def get_billings
4
+ @options = {:path => '/billings',:body => ""}.merge(@options)
5
+
6
+ request(
7
+ :expects => 200,
8
+ :method => :get,
9
+ :body => @options[:body]
10
+ )
11
+ end
12
+
13
+ def get_billing(id)
14
+ @options = {:path => "/billings/#{id}",:body => ""}.merge(@options)
15
+
16
+ request(
17
+ :expects => 200,
18
+ :method => :get,
19
+ :body => @options[:body]
20
+ )
21
+ end
22
+
23
+ def post_billings(new_billing)
24
+ @options = {:path => '/billings/content',
25
+ :body => Megam::JSONCompat.to_json(new_billing)}.merge(@options)
26
+
27
+ request(
28
+ :expects => 201,
29
+ :method => :post,
30
+ :body => @options[:body]
31
+ )
32
+ end
33
+
34
+ end
35
+ end
@@ -9,13 +9,13 @@ module Megam
9
9
  :body => @options[:body]
10
10
  )
11
11
  end
12
-
12
+
13
13
  def update_component(new_asm)
14
14
  @options = {:path => '/components/update',
15
15
  :body => Megam::JSONCompat.to_json(new_asm)}.merge(@options)
16
16
 
17
17
  request(
18
- :expects => 200,
18
+ :expects => 201,
19
19
  :method => :post,
20
20
  :body => @options[:body]
21
21
  )
@@ -0,0 +1,35 @@
1
+ module Megam
2
+ class API
3
+ def get_credithistories
4
+ @options = {:path => '/credithistories',:body => ""}.merge(@options)
5
+
6
+ request(
7
+ :expects => 200,
8
+ :method => :get,
9
+ :body => @options[:body]
10
+ )
11
+ end
12
+
13
+ def get_credithistories(id)
14
+ @options = {:path => "/credithistories/#{id}",:body => ""}.merge(@options)
15
+
16
+ request(
17
+ :expects => 200,
18
+ :method => :get,
19
+ :body => @options[:body]
20
+ )
21
+ end
22
+
23
+ def post_credithistories(new_credithistories)
24
+ @options = {:path => '/credithistories/content',
25
+ :body => Megam::JSONCompat.to_json(new_credithistories)}.merge(@options)
26
+
27
+ request(
28
+ :expects => 201,
29
+ :method => :post,
30
+ :body => @options[:body]
31
+ )
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ module Megam
2
+ class API
3
+ def get_discounts
4
+ @options = {:path => '/discounts',:body => ""}.merge(@options)
5
+
6
+ request(
7
+ :expects => 200,
8
+ :method => :get,
9
+ :body => @options[:body]
10
+ )
11
+ end
12
+
13
+ def get_discounts(id)
14
+ @options = {:path => "/discounts/#{id}",:body => ""}.merge(@options)
15
+
16
+ request(
17
+ :expects => 200,
18
+ :method => :get,
19
+ :body => @options[:body]
20
+ )
21
+ end
22
+
23
+ def post_discounts(new_discount)
24
+ @options = {:path => '/discounts/content',
25
+ :body => Megam::JSONCompat.to_json(new_discount)}.merge(@options)
26
+
27
+ request(
28
+ :expects => 201,
29
+ :method => :post,
30
+ :body => @options[:body]
31
+ )
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,42 @@
1
+ module Megam
2
+ class API
3
+
4
+ def get_profile
5
+
6
+ @options = {:path => '/profile',:body => ''}.merge(@options)
7
+
8
+ request(
9
+ :expects => 200,
10
+ :method => :get,
11
+ :body => @options[:body]
12
+
13
+ )
14
+ end
15
+
16
+ def get_profile(email)
17
+
18
+ @options = {:path => "/profile/#{email}",
19
+ :body => ''}.merge(@options)
20
+
21
+ request(
22
+ :expects => 200,
23
+ :method => :get,
24
+ :body => @options[:body]
25
+ )
26
+ end
27
+
28
+
29
+ def post_profile(new_profile_details)
30
+
31
+ @options = {:path => '/profile/content',
32
+ :body => Megam::JSONCompat.to_json(new_profile_details)}.merge(@options)
33
+
34
+
35
+ request(
36
+ :expects => 201,
37
+ :method => :post,
38
+ :body => @options[:body]
39
+ )
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,35 @@
1
+ module Megam
2
+ class API
3
+ def get_subscriptions
4
+ @options = {:path => '/subscriptions',:body => ""}.merge(@options)
5
+
6
+ request(
7
+ :expects => 200,
8
+ :method => :get,
9
+ :body => @options[:body]
10
+ )
11
+ end
12
+
13
+ def get_subscriptions(id)
14
+ @options = {:path => "/subscriptions/#{id}",:body => ""}.merge(@options)
15
+
16
+ request(
17
+ :expects => 200,
18
+ :method => :get,
19
+ :body => @options[:body]
20
+ )
21
+ end
22
+
23
+ def post_subscriptions(new_subscription)
24
+ @options = {:path => '/subscriptions/content',
25
+ :body => Megam::JSONCompat.to_json(new_subscription)}.merge(@options)
26
+
27
+ request(
28
+ :expects => 201,
29
+ :method => :post,
30
+ :body => @options[:body]
31
+ )
32
+ end
33
+
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "0.36"
3
+ VERSION = "0.38"
4
4
  end
5
5
  end
@@ -19,7 +19,12 @@ module Megam
19
19
  @id = nil
20
20
  @email = nil
21
21
  @api_key = nil
22
+ @first_name = nil
23
+ @last_name = nil
24
+ @phone = nil
25
+ @password = nil
22
26
  @authority = nil
27
+ @password_reset_key = nil
23
28
  @created_at = nil
24
29
  @some_msg = {}
25
30
  super(email, api_key)
@@ -54,6 +59,38 @@ module Megam
54
59
  end
55
60
  end
56
61
 
62
+ def first_name(arg=nil)
63
+ if arg != nil
64
+ @first_name = arg
65
+ else
66
+ @first_name
67
+ end
68
+ end
69
+
70
+ def last_name(arg=nil)
71
+ if arg != nil
72
+ @last_name = arg
73
+ else
74
+ @last_name
75
+ end
76
+ end
77
+
78
+ def phone(arg=nil)
79
+ if arg != nil
80
+ @phone = arg
81
+ else
82
+ @phone
83
+ end
84
+ end
85
+
86
+ def password(arg=nil)
87
+ if arg != nil
88
+ @password = arg
89
+ else
90
+ @password
91
+ end
92
+ end
93
+
57
94
  def authority(arg=nil)
58
95
  if arg != nil
59
96
  @authority = arg
@@ -62,6 +99,14 @@ module Megam
62
99
  end
63
100
  end
64
101
 
102
+ def password_reset_key(arg=nil)
103
+ if arg != nil
104
+ @password_reset_key = arg
105
+ else
106
+ @password_reset_key
107
+ end
108
+ end
109
+
65
110
  def created_at(arg=nil)
66
111
  if arg != nil
67
112
  @created_at = arg
@@ -89,6 +134,11 @@ module Megam
89
134
  index_hash["id"] = id
90
135
  index_hash["email"] = email
91
136
  index_hash["api_key"] = api_key
137
+ index_hash["first_name"] = first_name
138
+ index_hash["last_name"] = last_name
139
+ index_hash["phone"] = phone
140
+ index_hash["password"] = password
141
+ index_hash["password_reset_key"] = password_reset_key
92
142
  index_hash["authority"] = authority
93
143
  index_hash["created_at"] = created_at
94
144
  index_hash["some_msg"] = some_msg
@@ -106,6 +156,11 @@ module Megam
106
156
  "id" => id,
107
157
  "email" => email,
108
158
  "api_key" => api_key,
159
+ "first_name" => first_name,
160
+ "last_name" => last_name,
161
+ "phone" => phone,
162
+ "password" => password,
163
+ "password_reset_key" => password_reset_key,
109
164
  "authority" => authority,
110
165
  "created_at" => created_at
111
166
  }
@@ -119,6 +174,11 @@ module Megam
119
174
  acct.email(o["email"]) if o.has_key?("email")
120
175
  acct.api_key(o["api_key"]) if o.has_key?("api_key")
121
176
  acct.authority(o["authority"]) if o.has_key?("authority")
177
+ acct.first_name(o["first_name"]) if o.has_key?("first_name")
178
+ acct.last_name(o["last_name"]) if o.has_key?("last_name")
179
+ acct.phone(o["phone"]) if o.has_key?("phone")
180
+ acct.password(o["password"]) if o.has_key?("password")
181
+ acct.password_reset_key(o["password_reset_key"]) if o.has_key?("password_reset_key")
122
182
  acct.created_at(o["created_at"]) if o.has_key?("created_at")
123
183
  acct.some_msg[:code] = o["code"] if o.has_key?("code")
124
184
  acct.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
@@ -134,10 +194,15 @@ module Megam
134
194
  end
135
195
 
136
196
  def from_hash(o)
137
- @id = o[:id] if o.has_key?(:id)
138
- @email = o[:email] if o.has_key?(:email)
139
- @api_key = o[:api_key] if o.has_key?(:api_key)
140
- @authority = o[:authority] if o.has_key?(:authority)
197
+ @id = o[:id] if o.has_key?(:id)
198
+ @email = o[:email] if o.has_key?(:email)
199
+ @api_key = o[:api_key] if o.has_key?(:api_key)
200
+ @authority = o[:authority] if o.has_key?(:authority)
201
+ @first_name = o[:first_name] if o.has_key?(:first_name)
202
+ @last_name = o[:last_name] if o.has_key?(:last_name)
203
+ @phone = o[:phone] if o.has_key?(:phone)
204
+ @password = o[:password] if o.has_key?(:password)
205
+ @password_reset_key = o[:password_reset_key] if o.has_key?(:password_reset_key)
141
206
  @created_at = o[:created_at] if o.has_key?(:created_at)
142
207
  self
143
208
  end
@@ -147,16 +212,28 @@ module Megam
147
212
  acct.create
148
213
  end
149
214
 
215
+ # Create the node via the REST API
216
+ def create
217
+ megam_rest.post_accounts(to_hash)
218
+ end
219
+
220
+
150
221
  # Load a account by email_p
151
222
  def self.show(email,api_key=nil)
152
223
  acct = self.new(email, api_key)
153
224
  acct.megam_rest.get_accounts(email)
154
225
  end
155
226
 
156
- # Create the node via the REST API
157
- def create
158
- megam_rest.post_accounts(to_hash)
159
- end
227
+
228
+ def self.update(o,tmp_email=nil, tmp_api_key=nil)
229
+ acct = from_hash(o, tmp_email, tmp_api_key)
230
+ acct.update
231
+ end
232
+
233
+ # Create the node via the REST API
234
+ def update
235
+ megam_rest.update_accounts(to_hash)
236
+ end
160
237
 
161
238
  def to_s
162
239
  Megam::Stuff.styled_hash(to_hash)