Class: CorePro::Connection

Inherits:
Object
  • Object
show all
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.message}"
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apiKey = nil, apiSecret = nil, domainName = nil, proxyServerName = nil, proxyPort = nil, proxyUser = nil, proxyPassword = nil) ⇒ Connection

Returns a new instance of Connection.



35
36
37
38
39
40
41
42
43
44
# File 'lib/corepro/connection.rb', line 35

def initialize(apiKey = nil, apiSecret = nil, domainName = nil, proxyServerName = nil, proxyPort = nil, proxyUser = nil, proxyPassword = nil)
  @apiKey = apiKey || @@config['CoreProApiKey']
  @apiSecret = apiSecret || @@config['CoreProApiSecret']
  @domainName = domainName || @@config['CoreProDomainName']
  @proxyServerName = proxyServerName || @@config['CoreProProxyServerName']
  @proxyPort = proxyPort || @@config['CoreProProxyPort']
  @proxyUser = proxyUser || @@config['CoreProProxyUser']
  @proxyPassword = proxyPassword || @@config['CoreProProxyPassword']
  @headerValue = ''
end

Instance Attribute Details

#proxyPasswordObject

Returns the value of attribute proxyPassword.



10
11
12
# File 'lib/corepro/connection.rb', line 10

def proxyPassword
  @proxyPassword
end

#proxyPortObject

Returns the value of attribute proxyPort.



8
9
10
# File 'lib/corepro/connection.rb', line 8

def proxyPort
  @proxyPort
end

#proxyServerNameObject

Returns the value of attribute proxyServerName.



7
8
9
# File 'lib/corepro/connection.rb', line 7

def proxyServerName
  @proxyServerName
end

#proxyUserObject

Returns the value of attribute proxyUser.



9
10
11
# File 'lib/corepro/connection.rb', line 9

def proxyUser
  @proxyUser
end

Class Method Details

.createFromConfig(apiKey = nil, apiSecret = nil, domainName = nil, proxyServerName = nil, proxyPort = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/corepro/connection.rb', line 25

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

#apiKeyObject



46
47
48
# File 'lib/corepro/connection.rb', line 46

def apiKey
  @apiKey
end

#apiKey=(value) ⇒ Object



50
51
52
53
# File 'lib/corepro/connection.rb', line 50

def apiKey=(value)
  @apiKey = value
  @headerValue = ''
end

#apiSecretObject



55
56
57
# File 'lib/corepro/connection.rb', line 55

def apiSecret
  @apiSecret
end

#apiSecret=(value) ⇒ Object



59
60
61
62
# File 'lib/corepro/connection.rb', line 59

def apiSecret=(value)
  @apiSecret = value
  @headerValue = ''
end

#domainNameObject



73
74
75
# File 'lib/corepro/connection.rb', line 73

def domainName
  @domainName
end

#domainName=(value) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/corepro/connection.rb', line 77

def domainName=(value)
  if value == nil
    @domainName = nil
  else
    value.gsub! 'https://', ''
    value.gsub! 'http://', ''
    value.gsub! 'www.', ''

    @domainName = value.split('/')[0]
  end
end

#headerValueObject



64
65
66
67
68
69
70
71
# File 'lib/corepro/connection.rb', line 64

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