Class: CorePro::Connection
- Inherits:
-
Object
- Object
- CorePro::Connection
- Defined in:
- lib/corepro/connection.rb
Constant Summary collapse
- @@config =
begin if File.exists?('config.yml') YAML.load(File.open('config.yml')) else {} end rescue ArgumentError => e puts "Could not parse YAML: #{e.message}" end
Class Method Summary collapse
Instance Method Summary collapse
- #apiKey ⇒ Object
- #apiKey=(value) ⇒ Object
- #apiSecret ⇒ Object
- #apiSecret=(value) ⇒ Object
- #domainName ⇒ Object
- #domainName=(value) ⇒ Object
- #headerValue ⇒ Object
-
#initialize(apiKey = nil, apiSecret = nil, domainName = nil) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(apiKey = nil, apiSecret = nil, domainName = nil) ⇒ Connection
Returns a new instance of Connection.
25 26 27 28 29 30 |
# File 'lib/corepro/connection.rb', line 25 def initialize(apiKey = nil, apiSecret = nil, domainName = nil) @apiKey = apiKey || @@config['CoreProApiKey'] @apiSecret = apiSecret || @@config['CoreProApiSecret'] @domainName = domainName || @@config['CoreProDomainName'] @headerValue = '' end |
Class Method Details
.createFromConfig(apiKey = nil, apiSecret = nil, domainName = nil) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/corepro/connection.rb', line 17 def self.createFromConfig(apiKey = nil, apiSecret = nil, domainName = nil) c = Connection.new c.apiKey = apiKey || @@config['CoreProApiKey'] c.apiSecret = apiSecret || @@config['CoreProApiSecret'] c.domainName = domainName || @@config['CoreProDomainName'] c end |
Instance Method Details
#apiKey ⇒ Object
32 33 34 |
# File 'lib/corepro/connection.rb', line 32 def apiKey @apiKey end |
#apiKey=(value) ⇒ Object
36 37 38 39 |
# File 'lib/corepro/connection.rb', line 36 def apiKey=(value) @apiKey = value @headerValue = '' end |
#apiSecret ⇒ Object
41 42 43 |
# File 'lib/corepro/connection.rb', line 41 def apiSecret @apiSecret end |
#apiSecret=(value) ⇒ Object
45 46 47 48 |
# File 'lib/corepro/connection.rb', line 45 def apiSecret=(value) @apiSecret = value @headerValue = '' end |
#domainName ⇒ Object
59 60 61 |
# File 'lib/corepro/connection.rb', line 59 def domainName @domainName end |
#domainName=(value) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/corepro/connection.rb', line 63 def domainName=(value) if value == nil @domainName = nil else value.gsub! 'https://', '' value.gsub! 'http://', '' value.gsub! 'www.', '' @domainName = value.split('/')[0] end end |
#headerValue ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/corepro/connection.rb', line 50 def headerValue if (@headerValue || '' == '') utf8Value = "#{@apiKey}:#{@apiSecret}".force_encoding('iso-8859-1').encode('utf-8') b64 = Base64.encode64(utf8Value) @headerValue = "Basic #{b64}" end @headerValue end |