Module: ExternalApiService
- Defined in:
- lib/external_api_service.rb,
lib/external_api_service/version.rb
Constant Summary collapse
- VERSION =
"0.2.1"
Class Method Summary collapse
-
.get_service(url, queries = {}, credentials = {}) ⇒ Object
Make a GET request to external endpoint You must format it as a hash with string key/value => “password”.
-
.post_service(url, data_to_post, credentials, http_header_params = {}) ⇒ Object
Make a JSON POST request to external endpoint You must format it as a hash of strings (both key and value) e.g.
Class Method Details
.get_service(url, queries = {}, credentials = {}) ⇒ Object
Make a GET request to external endpoint You must format it as a hash with string key/value => “password”
ExternalApiService.get_service(“sample_endpoint”, “sample_request”)
17 18 19 20 21 |
# File 'lib/external_api_service.rb', line 17 def self.get_service(url, queries = {}, credentials = {}) credentials_formatted_for_auth = credentials.to_a.flatten uri = URI_Builder.build_uri(url, queries) HTTP_Client.new.get(uri, credentials_formatted_for_auth) end |
.post_service(url, data_to_post, credentials, http_header_params = {}) ⇒ Object
Note:
You have to have the trailing ‘/’ for the path for Ruby to POST properly e.g. sample.com/
Make a JSON POST request to external endpoint You must format it as a hash of strings (both key and value) e.g. => “password” You get several free headers with the Net/HTTP class, but it is there if you want it. Must be a hash
43 44 45 46 47 48 |
# File 'lib/external_api_service.rb', line 43 def self.post_service(url, data_to_post, credentials, http_header_params = {}) credentials_formatted_for_auth = credentials.to_a.flatten uri = URI_Builder.build_uri(url) http_params = { uri: uri, data: data_to_post, credentials: credentials_formatted_for_auth, header_params: http_header_params } HTTP_Client.new.post(http_params) end |