Class: DynamicService::ServiceCaller
- Inherits:
-
Object
- Object
- DynamicService::ServiceCaller
- Defined in:
- lib/dynamic_service.rb
Overview
Class to call services
Class Method Summary collapse
Class Method Details
.call_service(service_url, params = {}, method = 'post', headers = {}, destiny = nil) ⇒ Object
16 17 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 |
# File 'lib/dynamic_service.rb', line 16 def self.call_service(service_url, params = {}, method = 'post', headers = {}, destiny = nil) http = HTTPClient.new http.connect_timeout = 10 headers['User-Agent'] = 'Dynamicloud client' headers['API_Version'] = Configuration::PROPERTIES.get_property :version headers['Dynamicloud_API'] = 'Ruby' headers['Accept-Encoding'] = 'gzip, 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 |