Class: DynamicService::ServiceCaller
- Inherits:
-
Object
- Object
- DynamicService::ServiceCaller
- Defined in:
- lib/dynamic_service.rb
Overview
Class to call services
Constant Summary collapse
- GEM_ROOT =
File.('../..', __FILE__)
Class Method Summary collapse
Class Method Details
.call_service(service_url, params = {}, method = 'post', headers = {}, destiny = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dynamic_service.rb', line 18 def self.call_service(service_url, params = {}, method = 'post', headers = {}, destiny = nil) http = HTTPClient.new http.connect_timeout = 10 if service_url.start_with? 'https' http.ssl_config.set_trust_ca("#{GEM_ROOT}/lib/cacert.pem") end headers['User-Agent'] = 'Dynamicloud Client' headers['API-Version'] = Configuration::PROPERTIES.get_property :version headers['Dynamicloud-API'] = 'Ruby' headers['Accept-Encoding'] = 'deflate' # download file if destiny destiny.write(http.get_content(service_url, headers)) return end if method.eql? 'post' return handle_response(http.post service_url, params, headers) end if method.eql? 'get' return handle_response(http.get service_url, params, headers) end if method.eql? 'delete' return handle_response(http.delete service_url, params, headers) else raise 'Unsupported Http Method - "' << method.to_s << '"' end end |