Class: NgrokAPI::HttpClient
- Inherits:
-
Object
- Object
- NgrokAPI::HttpClient
- Defined in:
- lib/ngrokapi/http_client.rb
Overview
Low-level api client for communicating with Ngrok’s HTTP API using HTTP. You should not have to use this class directly, but use the individual clients to make your API calls.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
-
#delete(path, danger: false) ⇒ nil
Make a DELETE request to a given URI.
-
#get(path, danger: false, data: {}) ⇒ json
Make a GET request to a given URI with optional data.
-
#initialize(api_key:, base_url: 'https://api.ngrok.com') ⇒ HttpClient
constructor
A new instance of HttpClient.
-
#list(before_id: nil, limit: nil, path: nil, url: nil) ⇒ json
Make a GET request.
-
#patch(path, danger: false, data: {}) ⇒ json
Make a PATCH request to a given URI with optional data.
-
#post(path, danger: false, data: {}) ⇒ json
Make a POST request to a given URI with optional data.
Constructor Details
#initialize(api_key:, base_url: 'https://api.ngrok.com') ⇒ HttpClient
Returns a new instance of HttpClient.
11 12 13 14 15 16 17 |
# File 'lib/ngrokapi/http_client.rb', line 11 def initialize( api_key:, base_url: 'https://api.ngrok.com' ) @api_key = api_key @base_url = base_url end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/ngrokapi/http_client.rb', line 8 def api_key @api_key end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
8 9 10 |
# File 'lib/ngrokapi/http_client.rb', line 8 def base_url @base_url end |
Instance Method Details
#delete(path, danger: false) ⇒ nil
Make a DELETE request to a given URI
25 26 27 28 29 |
# File 'lib/ngrokapi/http_client.rb', line 25 def delete(path, danger: false) uri = get_uri(path) req = Net::HTTP::Delete.new(uri, headers) json_do(uri, req, danger: danger) end |
#get(path, danger: false, data: {}) ⇒ json
Make a GET request to a given URI with optional data
38 39 40 41 42 |
# File 'lib/ngrokapi/http_client.rb', line 38 def get(path, danger: false, data: {}) uri = get_uri(path, data: data) req = Net::HTTP::Get.new(uri, headers) json_do(uri, req, danger: danger) end |
#list(before_id: nil, limit: nil, path: nil, url: nil) ⇒ json
Make a GET request
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ngrokapi/http_client.rb', line 52 def list(before_id: nil, limit: nil, path: nil, url: nil) if url get(url) else data = {} data[:before_id] = before_id if before_id data[:limit] = limit if limit get(path, data: data) end end |
#patch(path, danger: false, data: {}) ⇒ json
Make a PATCH request to a given URI with optional data
70 71 72 73 74 |
# File 'lib/ngrokapi/http_client.rb', line 70 def patch(path, danger: false, data: {}) uri = get_uri(path) req = Net::HTTP::Patch.new(uri, headers_with_json) json_do(uri, req, danger: danger, data: data.to_json) end |
#post(path, danger: false, data: {}) ⇒ json
Make a POST request to a given URI with optional data
83 84 85 86 87 |
# File 'lib/ngrokapi/http_client.rb', line 83 def post(path, danger: false, data: {}) uri = get_uri(path) req = Net::HTTP::Post.new(uri, headers_with_json) json_do(uri, req, danger: danger, data: data.to_json) end |