megam_api 0.96 → 0.97

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: bf28e37d2d592a57c4ebefeb2a2bccc316da5089
4
- data.tar.gz: 8ddc56a28e21d535fe1140d76755a876e1c11959
3
+ metadata.gz: ca6cd3eb4822d02d8d0ebaf7f2bc063c271e5053
4
+ data.tar.gz: 3a824875e7938afaa20b48b6a8fbd9cff05d8b0c
5
5
  SHA512:
6
- metadata.gz: ffb1be4ce1f8e5463e04f13bf67f5894eb05aa2590585c8a46e65cb1ad4e649febaeeb2a2c78eea66e41b28ed390dfc1eb209d78c63543e9ab23cc00574a8964
7
- data.tar.gz: ac923ced56d8882276ab74d70b2c71c96b15502548ee2710a3f7d4f8f2cf1edb93550d4b1f4be159d2ae2f79efd49706bf966f6ba00c9c64860d058507117a3f
6
+ metadata.gz: 3f6438fa9333d4e5e578e73ab4c9bea324d3ec04fc0ab8f6ded905aa54a8245ce43b79afaf272a09772cac5ae9b07ebe9b0798100440975a0289ba762a52e6d6
7
+ data.tar.gz: e22ee5fca62c1f2b171313ee733a1a9216736d43d5c0a65323a38e736d6c759c59d1655812360bc90207b98953f5f201db7d985c6ccaa5cf571b32933189f3b3
data/lib/megam/api.rb CHANGED
@@ -148,7 +148,9 @@ module Megam
148
148
  @email = @options.delete(:email)
149
149
  @password = @options.delete(:password)
150
150
  @org_id = @options.delete(:org_id)
151
- fail Megam::API::Errors::AuthKeysMissing if (@email.nil? && @api_key.nil?) || (@email.nil? && @password.nil?)
151
+ unless !@options.delete(:reset_flag)
152
+ fail Megam::API::Errors::AuthKeysMissing if (@email.nil? && @api_key.nil?) || (@email.nil? && @password.nil?)
153
+ end
152
154
  end
153
155
 
154
156
  def request(params, &block)
@@ -232,7 +234,10 @@ module Megam
232
234
  encoded_api_header = encode_header(@options)
233
235
  @options[:headers] = HEADERS.merge(X_Megam_HMAC => encoded_api_header[:hmac],
234
236
  X_Megam_DATE => encoded_api_header[:date], X_Megam_ORG => "#{@org_id}").merge(@options[:headers])
235
- @options[:headers] = @options[:headers].merge('X-Megam-PUTTUSAVI' => "true") unless (@password == "" || @password.nil?)
237
+ if (@api_key == "" || @api_key.nil?)
238
+ @options[:headers] = @options[:headers].merge('X-Megam-PUTTUSAVI' => "true") unless (@password == "" || @password.nil?)
239
+ end
240
+
236
241
  Megam::Log.debug('HTTP Request Data:')
237
242
  Megam::Log.debug("> HTTP #{@options[:scheme]}://#{@options[:host]}")
238
243
  @options.each do |key, value|
@@ -266,13 +271,15 @@ module Megam
266
271
 
267
272
  digest = OpenSSL::Digest.new('sha1')
268
273
  movingFactor = data.rstrip!
269
- if !(@password.nil?)
274
+ if !(@password.nil?) && @api_key.nil?
270
275
  hash = OpenSSL::HMAC.hexdigest(digest, Base64.strict_decode64(@password), movingFactor)
271
- else
276
+ elsif !(@api_key.nil?)
272
277
  hash = OpenSSL::HMAC.hexdigest(digest, @api_key, movingFactor)
278
+ else
279
+ hash = OpenSSL::HMAC.hexdigest(digest, "", movingFactor)
273
280
  end
274
281
  final_hmac = @email + ':' + hash
275
282
  header_params = { hmac: final_hmac, date: current_date }
276
283
  end
277
284
  end
278
- end
285
+ end
@@ -45,14 +45,34 @@ module Megam
45
45
  @options = {:path => '/accounts/update',
46
46
  :body => Megam::JSONCompat.to_json(update_account)}.merge(@options)
47
47
 
48
- request(
48
+ request(
49
49
  :expects => 201,
50
50
  :method => :post,
51
51
  :body => @options[:body]
52
52
  )
53
53
  end
54
54
 
55
+ def reset_accounts(account)
56
+ @options = {:path => "/accounts/reset/#{account["email"]}",
57
+ :body => ''}.merge(@options)
58
+
59
+ request(
60
+ :expects => 201,
61
+ :method => :get,
62
+ :body => @options[:body]
63
+ )
64
+ end
65
+
66
+ def repassword_accounts(account)
67
+ @options = {:path => "/accounts/repassword",
68
+ :body => Megam::JSONCompat.to_json(account)}.merge(@options)
55
69
 
70
+ request(
71
+ :expects => 201,
72
+ :method => :post,
73
+ :body => @options[:body]
74
+ )
75
+ end
56
76
 
57
77
  end
58
78
  end
@@ -15,6 +15,6 @@
15
15
  #
16
16
  module Megam
17
17
  class API
18
- VERSION = "0.96"
18
+ VERSION = "0.97"
19
19
  end
20
20
  end
@@ -231,14 +231,6 @@ module Megam
231
231
  megam_rest.post_accounts(to_hash)
232
232
  end
233
233
 
234
- =begin
235
- # Load a account by email_p
236
- def self.show(email,api_key,host=nil,password=nil)
237
- acct = self.new(email, api_key, host, password)
238
- acct.megam_rest.get_accounts(email)
239
- end
240
- =end
241
-
242
234
  # Load a account by email_p
243
235
  def self.show(o)
244
236
  acct = self.new({:email => o[:email], :api_key => o[:api_key], :host => o[:host], :password => o[:password], :org_id => o[:org_id]})
@@ -249,11 +241,29 @@ module Megam
249
241
  acct = from_hash(o)
250
242
  acct.update
251
243
  end
244
+
245
+ def self.reset(o)
246
+ acct = from_hash(o)
247
+ acct.reset
248
+ end
249
+
250
+ def self.repassword(o)
251
+ acct = from_hash(o)
252
+ acct.repassword
253
+ end
252
254
 
253
255
  # Create the node via the REST API
254
256
  def update
255
257
  megam_rest.update_accounts(to_hash)
256
258
  end
259
+
260
+ def reset
261
+ megam_rest.reset_accounts(to_hash)
262
+ end
263
+
264
+ def repassword
265
+ megam_rest.repassword_accounts(to_hash)
266
+ end
257
267
 
258
268
  def to_s
259
269
  Megam::Stuff.styled_hash(to_hash)
@@ -13,7 +13,7 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
- require 'hashie'
16
+
17
17
 
18
18
  module Megam
19
19
  class MarketPlace < Megam::ServerAPI
@@ -74,7 +74,7 @@ module Megam
74
74
  @flavor
75
75
  end
76
76
  end
77
-
77
+
78
78
  def catorder(arg = nil)
79
79
  if !arg.nil?
80
80
  @catorder = arg
@@ -1,29 +1,49 @@
1
1
  require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
2
 
3
3
  class TestAccounts < MiniTest::Unit::TestCase
4
- def test_signin_auth
5
- response = megams.get_accounts("test@megam.io")
4
+
5
+ $admin = "admin-tom"
6
+ $normal = "normal-tom"
7
+ $tom_email = "tom@gomegam.com"
8
+ $bob_email = "bob@gomegam.com"
9
+ #=begin
10
+
11
+ def test_signin_auth
12
+ response =megams.get_accounts("test@megam.io")
13
+ response.body.to_s
14
+ assert_equal(200, response.status)
15
+ end
16
+
17
+ def test_get_accounts_good
18
+ response =megams.get_accounts(sandbox_email)
6
19
  response.body.to_s
7
20
  assert_equal(200, response.status)
8
21
  end
9
22
 
23
+
24
+ =begin
25
+
10
26
  def test_post_accounts_good
11
27
  tmp_hash = {
28
+ "id" => "000099090909000",
12
29
  "first_name" => "Darth",
13
30
  "last_name" => "Vader",
14
- "email" => "test@megam.io",
31
+ "email" => "coolvader@iamswag.com",
15
32
  "phone" => "19090909090",
16
33
  "api_key" => "IamAtlas{74}NobdyCanSedfefdeME#07",
17
34
  "authority" => "admin",
18
- "password" => Base64.strict_encode64("megam"),
35
+ "password" => "",
19
36
  "password_reset_key" => "",
20
37
  "password_reset_sent_at" => "",
21
- }
22
- response =megams_new.post_accounts(tmp_hash)
38
+ "created_at" => "2014-10-29 13:24:06 +0000"
39
+ }
40
+ response =megams.post_accounts(tmp_hash)
23
41
  response.body.to_s
24
42
  assert_equal(201, response.status)
25
43
  end
44
+ =end
26
45
 
46
+ =begin
27
47
  def test_update_accounts_good
28
48
  tmp_hash = {
29
49
  "id" => "w3423",
@@ -32,21 +52,45 @@ class TestAccounts < MiniTest::Unit::TestCase
32
52
  "email" => "super@test.com",
33
53
  "phone" => "19090909090011111111",
34
54
  "api_key" => "IamAtlas{74}NobdyCanSedfefdeME#07",
35
- "password" => "tset",
36
55
  "authority" => "admin",
56
+ "password" => "tset",
37
57
  "password_reset_key" => "",
58
+ "password_reset_sent_at" => "",
38
59
  "created_at" => "2014-10-29 13:24:06 +0000"
39
- }
40
- response = megams.update_accounts(tmp_hash)
60
+ }
61
+ response = megams.update_accounts(tmp_hash)
62
+ response.body.to_s
63
+ assert_equal(201, response.status)
64
+ end
65
+ =end
66
+ =begin
67
+ def test_get_accounts_bad
68
+ assert_raises(Megam::API::Errors::NotFound) do
69
+ response =megams.get_accounts(sandbox_email+"_bad")
70
+ response.body.to_s
71
+ end
72
+ end
73
+ def test_post_accounts_admin
74
+ response =megams.post_accounts(
75
+ {:id => random_id, :email => $tom_email, :api_key => sandbox_apikey, :authority => $admin})
41
76
  response.body.to_s
42
77
  assert_equal(201, response.status)
43
78
  end
44
79
 
45
- def test_get_accounts_bad
46
- assert_raises(Megam::API::Errors::NotFound) do
47
- response =megams.get_accounts(sandbox_email+"_bad")
48
- response.body.to_s
49
- end
80
+ def test_post_accounts_normal
81
+ response =megams.post_accounts(
82
+ {:id => random_id, :email => $bob_email, :api_key => sandbox_apikey, :authority => $normal})
83
+ response.body.to_s
84
+ assert_equal(201, response.status)
50
85
  end
51
86
 
52
- end
87
+ def test_post_accounts_normal_bad
88
+ assert_raises(ArgumentError) do
89
+ response =megam.post_accounts(
90
+ {:id => random_id, :emailo => sandbox_email,
91
+ :apik_key => sandbox_apikey, :authority => $admin})
92
+ response.body.to_s
93
+ end
94
+ end
95
+ =end
96
+ end
@@ -77,8 +77,10 @@ class TestApps < MiniTest::Unit::TestCase
77
77
  {"key"=>"status","value"=>"error"}]
78
78
  }
79
79
 
80
- response = megams.post_assemblies(tmp_hash)
81
- assert_equal(200, response.status)
82
- end
80
+
81
+ response = megams.post_assemblies(tmp_hash)
82
+ assert_equal(201, response.status)
83
+ end
84
+
83
85
  #=end
84
86
  end
@@ -11,7 +11,7 @@ class TestApps < MiniTest::Unit::TestCase
11
11
  assert_equal(201, response.status)
12
12
  end
13
13
  #=end
14
- #=begin
14
+ =begin
15
15
  def test_update_balances
16
16
  tmp_hash = {:id=>"BAL5611523197067225006",
17
17
  :accounts_id=>"ACT119501563472393011",
@@ -22,7 +22,7 @@ def test_update_balances
22
22
  response = megams.update_balance(tmp_hash)
23
23
  assert_equal(201, response.status)
24
24
  end
25
- #=end
25
+ =end
26
26
  =begin
27
27
  def test_get_balances
28
28
  response = megams.get_balances
@@ -1,7 +1,7 @@
1
1
  require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
2
 
3
3
  class TestApps < MiniTest::Unit::TestCase
4
- #=begin
4
+ =begin
5
5
  def test_post_billings
6
6
  tmp_hash = { :accounts_id => "ACT93476985797",
7
7
  :line1 => "paypal",
@@ -16,7 +16,7 @@ class TestApps < MiniTest::Unit::TestCase
16
16
  response = megams.post_billings(tmp_hash)
17
17
  assert_equal(201, response.status)
18
18
  end
19
- #=end
19
+ =end
20
20
 
21
21
  =begin
22
22
  def test_get_billings
@@ -10,11 +10,11 @@ class TestApps < MiniTest::Unit::TestCase
10
10
  "category" => "control"
11
11
  }
12
12
 
13
-
13
+ =begin
14
14
  def test_request_app_start
15
15
  response = megams.post_catrequest(@@tmp_hash)
16
16
  assert_equal(201, response.status)
17
17
  end
18
- #=end
18
+ =end
19
19
 
20
20
  end
@@ -35,7 +35,7 @@ class TestApps < MiniTest::Unit::TestCase
35
35
  "created_at" => "2014-10-29 14:06:39 +0000"
36
36
  }
37
37
  response = megams.update_component(tmp_hash)
38
- assert_equal(201, response.status)
38
+ assert_equal(200, response.status)
39
39
  end
40
40
  #=end
41
41
  end
data/test/test_login.rb CHANGED
@@ -1,12 +1,10 @@
1
1
  require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
2
 
3
3
  class TestLogin < MiniTest::Unit::TestCase
4
-
4
+ =begin
5
5
  def test_post_login
6
6
  response =megams.post_auth()
7
7
  assert_equal(200, response.status)
8
8
  end
9
-
9
+ =end
10
10
  end
11
-
12
-
@@ -1,7 +1,7 @@
1
1
  require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
2
 
3
3
  class TestApps < MiniTest::Unit::TestCase
4
- #=begin
4
+ =begin
5
5
  def test_post_addon
6
6
  @com = {
7
7
  "disaster"=>{
@@ -41,5 +41,6 @@ end
41
41
  # def test_get_nodes
42
42
  # response = megams.get_addons("appsample1.megam.co")
43
43
  # assert_equal(200, response.status)
44
- # end
44
+ #=end
45
+ =end
45
46
  end
@@ -53,13 +53,13 @@ class TestApps < MiniTest::Unit::TestCase
53
53
  assert_equal(201, response.status)
54
54
  end
55
55
  =end
56
- #=begin
56
+ =begin
57
57
 
58
58
  def test_get_predefclouds
59
59
  response = megams.get_predefclouds
60
60
  assert_equal(200, response.status)
61
61
  end
62
- #=end
62
+ =end
63
63
  =begin
64
64
  def test_get_predefcloud2
65
65
  response = megams.get_predefcloud("rkspce_sundown_play")
@@ -78,4 +78,3 @@ end
78
78
  end
79
79
  =end
80
80
  end
81
-
data/test/test_promos.rb CHANGED
@@ -1,12 +1,11 @@
1
1
  require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
2
 
3
3
  class TestApps < MiniTest::Unit::TestCase
4
-
4
+ =begin
5
5
  def test_get_promos()
6
6
  response = megams.get_promos("megamfree5")
7
7
  assert_equal(200, response.status)
8
-
9
- end
10
8
 
9
+ end
10
+ =end
11
11
  end
12
-
data/test/test_sensors.rb CHANGED
@@ -15,7 +15,7 @@ class TestApps < MiniTest::Unit::TestCase
15
15
  end
16
16
  =end
17
17
 
18
- #=begin
18
+ =begin
19
19
  def test_post_sensors
20
20
  tmp_hash = {
21
21
 
@@ -46,5 +46,5 @@ class TestApps < MiniTest::Unit::TestCase
46
46
  response = megams.post_sensors(tmp_hash)
47
47
  assert_equal(200, response.status)
48
48
  end
49
- #=end
49
+ =end
50
50
  end
data/test/test_sshkeys.rb CHANGED
@@ -5,7 +5,7 @@ class TestApps < MiniTest::Unit::TestCase
5
5
  #=begin
6
6
  def test_post_sshkey2
7
7
  tmp_hash = {
8
- :name => "test_sample",
8
+ :name => "a@b.com_rtr",
9
9
  :org_id => "ORG123",
10
10
  :privatekey => "-----BEGIN RSA PRIVATE KEY-----
11
11
  MIIEpQIBAAKCAQEAz9g/LhHB7fDo85vm2O9F1oDzJhTs6PI3N6WDayZEzG4xmrZd
@@ -1,9 +1,9 @@
1
1
  require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
2
 
3
3
  class TestApps < MiniTest::Unit::TestCase
4
- #=begin
4
+ =begin
5
5
  def test_post_subscriptions
6
- tmp_hash = { :accounts_id => "ACT93476985797",
6
+ tmp_hash = { :accounts_id => "ACT93476985797",
7
7
  :assembly_id => "ASMkh9879847",
8
8
  :start_date => "45",
9
9
  :end_date => ""
@@ -12,7 +12,7 @@ class TestApps < MiniTest::Unit::TestCase
12
12
  response = megams.post_subscriptions(tmp_hash)
13
13
  assert_equal(201, response.status)
14
14
  end
15
- #=end
15
+ =end
16
16
 
17
17
  =begin
18
18
  def test_get_subscriptions
@@ -27,4 +27,3 @@ class TestApps < MiniTest::Unit::TestCase
27
27
  end
28
28
  =end
29
29
  end
30
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: megam_api
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.96'
4
+ version: '0.97'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajthilak, Kishorekumar Neelamegam, Thomas Alrin, Yeshwanth Kumar, Subash Sethurajan,
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-01 00:00:00.000000000 Z
12
+ date: 2016-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: excon