Class: FsCommunicator
- Inherits:
-
Object
- Object
- FsCommunicator
- Defined in:
- lib/fs_communicator.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#key ⇒ Object
Returns the value of attribute key.
-
#session ⇒ Object
Returns the value of attribute session.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #get(url, credentials = {}) ⇒ Object
-
#initialize(options = {}) ⇒ FsCommunicator
constructor
A new instance of FsCommunicator.
- #post(url, payload) ⇒ Object
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( = {}) # merge default options with options hash o = { :domain => 'http://www.dev.usys.org', :key => '', :user_agent => 'FsCommunicator/0.1 (Ruby)', :session => nil }.merge() @domain = o[:domain] @key = o[:key] @user_agent = o[:user_agent] @session = o[:session] end |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
5 6 7 |
# File 'lib/fs_communicator.rb', line 5 def domain @domain end |
#key ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/fs_communicator.rb', line 5 def key @key end |
#session ⇒ Object
Returns the value of attribute session.
5 6 7 |
# File 'lib/fs_communicator.rb', line 5 def session @session end |
#user_agent ⇒ Object
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 |