Class: DeltavistaCrifDvaInterface::RestfulService
- Inherits:
-
Object
- Object
- DeltavistaCrifDvaInterface::RestfulService
- Defined in:
- lib/deltavista_crif_dva_interface/restful_service.rb
Direct Known Subclasses
Instance Method Summary collapse
- #check_response!(response) ⇒ Object
- #create_http_request(url) ⇒ Object
- #get_http_response(url_string) {|data| ... } ⇒ Object
- #post_http_request(url_string, data, headers = nil) {|body| ... } ⇒ Object
- #put_http_request(url_string, data, headers = nil) {|body| ... } ⇒ Object
- #to_url(url_string) ⇒ Object
- #valid_response?(response) ⇒ Boolean
Instance Method Details
#check_response!(response) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/deltavista_crif_dva_interface/restful_service.rb', line 46 def check_response!(response) unless valid_response? response raise NotFoundError if response.class == Net::HTTPNotFound raise ServiceNotAvailableError end response end |
#create_http_request(url) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/deltavista_crif_dva_interface/restful_service.rb', line 36 def create_http_request(url) http = Net::HTTP.new(url.host, url.port) if url.scheme == 'https' #Impac::Logger.log.debug "Use SSL for request" http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end http end |
#get_http_response(url_string) {|data| ... } ⇒ Object
7 8 9 10 11 12 |
# File 'lib/deltavista_crif_dva_interface/restful_service.rb', line 7 def get_http_response(url_string) resp, data = Net::HTTP.get_response(to_url(url_string)) ##Impac::Logger.log.debug "GET Response: #{resp.inspect}\n #{data.inspect}" check_response! resp yield data end |
#post_http_request(url_string, data, headers = nil) {|body| ... } ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/deltavista_crif_dva_interface/restful_service.rb', line 14 def post_http_request(url_string, data, headers = nil) url = to_url url_string http = create_http_request url resp, body = http.post(url.path, data, headers) ##Impac::Logger.log.debug "POST Response: #{resp.inspect}\n #{body.inspect}" check_response! resp yield body end |
#put_http_request(url_string, data, headers = nil) {|body| ... } ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/deltavista_crif_dva_interface/restful_service.rb', line 23 def put_http_request(url_string, data, headers = nil) url = to_url url_string http = create_http_request url resp, body = http.put(url.path, data, headers) check_response! resp yield body end |
#to_url(url_string) ⇒ Object
31 32 33 34 |
# File 'lib/deltavista_crif_dva_interface/restful_service.rb', line 31 def to_url(url_string) #Impac::Logger.log.debug "Request URL: #{url_string}" URI.parse(url_string) end |
#valid_response?(response) ⇒ Boolean
54 55 56 |
# File 'lib/deltavista_crif_dva_interface/restful_service.rb', line 54 def valid_response?(response) response.class == Net::HTTPOK ? true : false end |