Class: HTTPS_Client
- Inherits:
-
Object
- Object
- HTTPS_Client
- Defined in:
- lib/external_api_service/https_client.rb
Instance Method Summary collapse
- #get(endpoint_uri) ⇒ Object
- #get_queue(url_queue) ⇒ Object
- #get_request(endpoint) ⇒ Object
- #parse_response(response) ⇒ Object
Instance Method Details
#get(endpoint_uri) ⇒ Object
11 12 13 14 |
# File 'lib/external_api_service/https_client.rb', line 11 def get(endpoint_uri) response = get_request(endpoint_uri) parse_response(response) end |
#get_queue(url_queue) ⇒ Object
7 8 9 |
# File 'lib/external_api_service/https_client.rb', line 7 def get_queue(url_queue) url_queue.map{|uri| get(uri)} end |
#get_request(endpoint) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/external_api_service/https_client.rb', line 16 def get_request(endpoint) Net::HTTP.start(endpoint.host, endpoint.port, :use_ssl => endpoint.scheme == 'https') do |client| retries = 5 begin new_request = Net::HTTP::Get.new(endpoint) client.request(new_request) rescue Exception => ex retries -= 1 retries > 0 ? retry : error_response(422, ex) end end end |
#parse_response(response) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/external_api_service/https_client.rb', line 29 def parse_response(response) if (response.code != "200" || response.code == nil) { error: response } else JSON.parse(response.body, symbolize_names: true) end end |