Module: Continuum::NetworkUtil
- Defined in:
- src/lib/continuum/network_util.rb
Overview
This module encapsulates all network requests Continuum itself makes to the Internet.
Class Method Summary collapse
-
.get_from_amp(url_endpoint_path, query_params, include_token) ⇒ Hash
Performs a GET request to the specified AMP API endpoint.
-
.post_to_amp(url_endpoint_path, body_params, include_token) ⇒ Hash
Performs a POST request to the specified AMP API endpoint.
-
.post_to_level_access_platform(url_endpoint_path, body_params) ⇒ Hash
Performs a POST request to the specified Level Access Platform API endpoint.
Class Method Details
.get_from_amp(url_endpoint_path, query_params, include_token) ⇒ Hash
Performs a GET request to the specified AMP API endpoint.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'src/lib/continuum/network_util.rb', line 26 def self.get_from_amp(url_endpoint_path, query_params, include_token) uri = URI.join(Continuum.configuration.amp_instance_url, url_endpoint_path) start_request(uri, query_params, include_token) do |http| request = Net::HTTP::Get.new(uri.request_uri) request['Content-Type'] = 'application/json; charset=UTF-8' response = http.request(request) if response.is_a?(Net::HTTPSuccess) return DataUtil.parse_json(response.body) end raise HttpErrorException.new(%{ Unexpectedly encountered a non-200 status code (#{response.code} #{response.}) while attempting to GET data from #{uri.request_uri} Response: #{response.body} }) end end |
.post_to_amp(url_endpoint_path, body_params, include_token) ⇒ Hash
Performs a POST request to the specified AMP API endpoint.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'src/lib/continuum/network_util.rb', line 54 def self.post_to_amp(url_endpoint_path, body_params, include_token) uri = URI.join(Continuum.configuration.amp_instance_url, url_endpoint_path) start_request(uri, {}, include_token) do |http| request = Net::HTTP::Post.new(uri.request_uri) request.body = body_params.to_json if body_params request['Content-Type'] = 'application/json; charset=UTF-8' response = http.request(request) if response.is_a?(Net::HTTPSuccess) return DataUtil.parse_json(response.body) end raise HttpErrorException.new(%{ Unexpectedly encountered a non-200 status code (#{response.code} #{response.}) while attempting to POST data to #{uri.request_uri}, with: #{request.body} Response: #{response.body} }) end end |
.post_to_level_access_platform(url_endpoint_path, body_params) ⇒ Hash
Performs a POST request to the specified Level Access Platform API endpoint.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'src/lib/continuum/network_util.rb', line 82 def self.post_to_level_access_platform(url_endpoint_path, body_params) uri = URI.join(Continuum.configuration.level_access_platform_configuration.org_instance_url, url_endpoint_path) start_request(uri, {}, false) do |http| request = Net::HTTP::Post.new(uri.request_uri) request.body = body_params.to_json if body_params request['Content-Type'] = 'application/json; charset=UTF-8' request['x-auth-token'] = Continuum.configuration.level_access_platform_configuration.api_key response = http.request(request) if response.is_a?(Net::HTTPSuccess) return DataUtil.parse_json(response.body) end raise HttpErrorException.new(%{ Unexpectedly encountered a non-200 status code (#{response.code} #{response.}) while attempting to POST data to #{uri.request_uri}, with: #{request.body} Response: #{response.body} }) end end |