Class: FsCommunicator

Inherits:
Object
  • Object
show all
Defined in:
lib/fs_communicator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FsCommunicator

Returns a new instance of FsCommunicator.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fs_communicator.rb', line 7

def initialize(options = {})
  # merge default options with options hash
  o = {
    :domain => 'http://www.dev.usys.org',
    :key => '',
    :user_agent => 'FsCommunicator/0.1 (Ruby)',
    :session => nil
  }.merge(options)
  @domain = o[:domain]
  @key = o[:key]
  @user_agent = o[:user_agent]
  @session = o[:session]
end

Instance Attribute Details

#domainObject

Returns the value of attribute domain.



5
6
7
# File 'lib/fs_communicator.rb', line 5

def domain
  @domain
end

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/fs_communicator.rb', line 5

def key
  @key
end

#sessionObject

Returns the value of attribute session.



5
6
7
# File 'lib/fs_communicator.rb', line 5

def session
  @session
end

#user_agentObject

Returns the value of attribute user_agent.



5
6
7
# File 'lib/fs_communicator.rb', line 5

def user_agent
  @user_agent
end

Instance Method Details

#get(url, credentials = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fs_communicator.rb', line 38

def get(url,credentials = {})
  uri = URI.parse(self.domain+url)
  full_url = set_extra_params(uri,credentials)
  request = Net::HTTP::Get.new(full_url)
  if credentials[:username] && credentials[:password]
    request.basic_auth credentials[:username], credentials[:password]
    request['User-Agent'] = self.user_agent
  end
  http = Net::HTTP.new(uri.host, uri.port)
  if uri.scheme == 'https'
    http.use_ssl = true 
    http.ca_file = File.join File.dirname(__FILE__), 'assets','entrust-ca.crt'
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  end
  res = http.start do |ht|
    ht.request(request)
  end
end

#post(url, payload) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fs_communicator.rb', line 21

def post(url,payload)
  uri = URI.parse(self.domain+url)
  full_url = set_extra_params(uri)
  request = Net::HTTP::Post.new(full_url)
  request.body = payload
  request['Content-Type'] = "text/xml"
  http = Net::HTTP.new(uri.host, uri.port)
  if uri.scheme == 'https'
    http.use_ssl = true 
    http.ca_file = File.join File.dirname(__FILE__), 'assets','entrust-ca.crt'
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  end
  res = http.start do |ht|
    ht.request(request)
  end
end