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')) elsif File.exists?('../config.yml') YAML.load(File.open('../config.yml')) else {} end rescue ArgumentError => e puts "Could not parse YAML: #{e.}" end
Instance Attribute Summary collapse
-
#proxyPort ⇒ Object
Returns the value of attribute proxyPort.
-
#proxyServerName ⇒ Object
Returns the value of attribute proxyServerName.
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, proxyServerName = nil, proxyPort = nil) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(apiKey = nil, apiSecret = nil, domainName = nil, proxyServerName = nil, proxyPort = nil) ⇒ Connection
Returns a new instance of Connection.
33 34 35 36 37 38 39 40 |
# File 'lib/corepro/connection.rb', line 33 def initialize(apiKey = nil, apiSecret = nil, domainName = nil, proxyServerName = nil, proxyPort = nil) @apiKey = apiKey || @@config['CoreProApiKey'] @apiSecret = apiSecret || @@config['CoreProApiSecret'] @domainName = domainName || @@config['CoreProDomainName'] @proxyServerName = proxyServerName || @@config['CoreProProxyServerName'] @proxyPort = proxyPort || @@config['CoreProProxyPort'] @headerValue = '' end |
Instance Attribute Details
#proxyPort ⇒ Object
Returns the value of attribute proxyPort.
8 9 10 |
# File 'lib/corepro/connection.rb', line 8 def proxyPort @proxyPort end |
#proxyServerName ⇒ Object
Returns the value of attribute proxyServerName.
7 8 9 |
# File 'lib/corepro/connection.rb', line 7 def proxyServerName @proxyServerName end |
Class Method Details
.createFromConfig(apiKey = nil, apiSecret = nil, domainName = nil, proxyServerName = nil, proxyPort = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/corepro/connection.rb', line 23 def self.createFromConfig(apiKey = nil, apiSecret = nil, domainName = nil, proxyServerName = nil, proxyPort = nil) c = Connection.new c.apiKey = apiKey || @@config['CoreProApiKey'] c.apiSecret = apiSecret || @@config['CoreProApiSecret'] c.domainName = domainName || @@config['CoreProDomainName'] c.proxyServerName = proxyServerName || @@config['CoreProProxyServerName'] c.proxyPort = proxyPort || @@config['CoreProProxyPort'] c end |
Instance Method Details
#apiKey ⇒ Object
42 43 44 |
# File 'lib/corepro/connection.rb', line 42 def apiKey @apiKey end |
#apiKey=(value) ⇒ Object
46 47 48 49 |
# File 'lib/corepro/connection.rb', line 46 def apiKey=(value) @apiKey = value @headerValue = '' end |
#apiSecret ⇒ Object
51 52 53 |
# File 'lib/corepro/connection.rb', line 51 def apiSecret @apiSecret end |
#apiSecret=(value) ⇒ Object
55 56 57 58 |
# File 'lib/corepro/connection.rb', line 55 def apiSecret=(value) @apiSecret = value @headerValue = '' end |
#domainName ⇒ Object
69 70 71 |
# File 'lib/corepro/connection.rb', line 69 def domainName @domainName end |
#domainName=(value) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/corepro/connection.rb', line 73 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
60 61 62 63 64 65 66 67 |
# File 'lib/corepro/connection.rb', line 60 def headerValue if (@headerValue || '' == '') utf8Value = "#{@apiKey}:#{@apiSecret}".force_encoding('iso-8859-1').encode('utf-8') b64 = Base64.strict_encode64(utf8Value) @headerValue = "Basic #{b64}" end @headerValue end |