megam_api 0.14 → 0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 648894d0115816c314368168eea83b0652a95aec
4
- data.tar.gz: 83dd55046ccfc9dcbd92fe5a93c5ec37bb780275
3
+ metadata.gz: f70bad4104531f59a86d0a85bf96c1f855c0c96e
4
+ data.tar.gz: 1ec8eb2603e2f632b47352f05be0407786d9f53c
5
5
  SHA512:
6
- metadata.gz: f4c050bba42496e59abcb765f6fab5f664f2b07d104f47737579f82a806279b08dfb636925ba4a062884c2f09c555992d9f03afe12ae8d2e482cd7be8adb50b9
7
- data.tar.gz: aa046a0bd7cbc4b2e1760218739c26e57e9377d8f8c7f63fab83fa6b009c729f1ea3cee620c6c72143912b5b38682e1c430f4ce96c784e43399f592aa59a6aa3
6
+ metadata.gz: 8c01a6c03db68969107623032db64ee3c37d1ec706ea83478137a041ecb7844cdaf614bc4e28b76984533686b5fc6079667a51ac02489f8190ecacee88b0a978
7
+ data.tar.gz: 71f7dc9c679c313976733140c50c049fb21577c98c4354fb3711dd549bc24154c447b201adc00ed4565da885b0f2c4889fc02a87560f566ee4a66f5f392d3100
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "0.14"
3
+ VERSION = "0.15"
4
4
  end
5
5
  end
data/lib/megam/api.rb CHANGED
@@ -4,6 +4,7 @@ require "excon"
4
4
  require "uri"
5
5
  require "zlib"
6
6
  require 'openssl'
7
+ require 'yaml' #COMMON YML
7
8
 
8
9
  # open it up when needed. This will be needed when a new customer onboarded via pug.
9
10
  require "securerandom"
@@ -98,7 +99,6 @@ module Megam
98
99
  :nonblock => false,
99
100
  :scheme => 'https'
100
101
  }
101
-
102
102
  API_VERSION1 = "/v1"
103
103
 
104
104
  def text
@@ -118,6 +118,11 @@ module Megam
118
118
  # 3. Upon merge of the options, the api_key, email as available in the @options is deleted.
119
119
  def initialize(options={})
120
120
  @options = OPTIONS.merge(options)
121
+ if File.exist?("#{ENV['MEGAM_HOME']}/nilavu.yml")
122
+ @common = YAML.load_file("#{ENV['MEGAM_HOME']}/nilavu.yml") #COMMON YML
123
+ @options[:host] = "#{@common["api"]["host"]}"
124
+ @options[:scheme] = "#{@common["api"]["scheme"]}"
125
+ end
121
126
  @api_key = @options.delete(:api_key) || ENV['MEGAM_API_KEY']
122
127
  @email = @options.delete(:email)
123
128
  raise ArgumentError, "You must specify [:email, :api_key]" if @email.nil? || @api_key.nil?
@@ -188,7 +193,7 @@ module Megam
188
193
  private
189
194
 
190
195
  def just_color_debug(path)
191
- text.msg "--> #{text.color("(#{path})", :cyan,:bold)}"
196
+ text.msg "--> #{text.color('(#{path})', :cyan,:bold)}" # Why " inside "
192
197
  end
193
198
 
194
199
  #Make a lazy connection.
@@ -199,16 +204,22 @@ module Megam
199
204
  'X-Megam-HMAC' => encoded_api_header[:hmac],
200
205
  'X-Megam-Date' => encoded_api_header[:date],
201
206
  }).merge(@options[:headers])
207
+ #COMMON YML
208
+ if @options[:scheme] == "https"
209
+ puts "=====> if https =======>"
210
+ Excon.defaults[:ssl_ca_file] = File.expand_path(File.join("#{ENV['MEGAM_HOME']}", "#{@common["api"]["pub_key"]}")) || File.expand_path(File.join(File.dirname(__FILE__), "..", "certs", "cacert.pem")) #COMMON YML
202
211
 
203
- Excon.defaults[:ssl_ca_file] = File.expand_path(File.join(File.dirname(__FILE__), "..", "certs", "cacert.pem"))
204
-
205
- if !File.exist?(File.expand_path(File.join(File.dirname(__FILE__), "..", "certs", "cacert.pem")))
212
+ if !File.exist?(File.expand_path(File.join("#{ENV['MEGAM_HOME']}", "#{@common["api"]["pub_key"]}")))
213
+ text.warn("Certificate file does not exist. SSL_VERIFY_PEER set as false")
214
+ Excon.defaults[:ssl_verify_peer] = false
215
+ elsif !File.exist?(File.expand_path(File.join(File.dirname(__FILE__), "..", "certs", "cacert.pem")))
206
216
  text.warn("Certificate file does not exist. SSL_VERIFY_PEER set as false")
207
217
  Excon.defaults[:ssl_verify_peer] = false
208
218
  else
209
219
  Megam::Log.debug("Certificate found")
210
220
  Excon.defaults[:ssl_verify_peer] = true
211
221
  end
222
+ end
212
223
 
213
224
  Megam::Log.debug("HTTP Request Data:")
214
225
  Megam::Log.debug("> HTTP #{@options[:scheme]}://#{@options[:host]}")
@@ -216,7 +227,13 @@ module Megam
216
227
  Megam::Log.debug("> #{key}: #{value}")
217
228
  end
218
229
  Megam::Log.debug("End HTTP Request Data.")
230
+ if @options[:scheme] == "https"
219
231
  @connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}",@options)
232
+ else
233
+ Excon.defaults[:ssl_verify_peer] = false
234
+ @connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}:9000",@options)
235
+ end
236
+ @connection
220
237
  end
221
238
 
222
239
  ## encode header as per rules.
@@ -42,4 +42,4 @@ class TestAccounts < MiniTest::Unit::TestCase
42
42
  response.body.to_s
43
43
  end
44
44
  end
45
- end
45
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: megam_api
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.14'
4
+ version: '0.15'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kishorekumar Neelamegam, Thomas Alrin, Subash Sethurajan, Rajthilak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-02 00:00:00.000000000 Z
11
+ date: 2014-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -234,4 +234,3 @@ signing_key:
234
234
  specification_version: 4
235
235
  summary: Ruby Client for the Megam Cloud
236
236
  test_files: []
237
- has_rdoc: