Class: HookSniff::EndpointsResource
- Inherits:
-
Object
- Object
- HookSniff::EndpointsResource
- Defined in:
- lib/hooksniff/client.rb
Instance Method Summary collapse
- #create(url:, description: nil, retry_policy: nil) ⇒ Object
- #delete(endpoint_id) ⇒ Object
- #get(endpoint_id) ⇒ Object
-
#initialize(client) ⇒ EndpointsResource
constructor
A new instance of EndpointsResource.
- #list(page: 1, per_page: 20) ⇒ Object
- #rotate_secret(endpoint_id) ⇒ Object
Constructor Details
#initialize(client) ⇒ EndpointsResource
Returns a new instance of EndpointsResource.
84 85 86 |
# File 'lib/hooksniff/client.rb', line 84 def initialize(client) @client = client end |
Instance Method Details
#create(url:, description: nil, retry_policy: nil) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/hooksniff/client.rb', line 88 def create(url:, description: nil, retry_policy: nil) body = { url: url } body[:description] = description if description if retry_policy body[:retry_policy] = { max_attempts: retry_policy[:max_attempts], backoff: retry_policy[:backoff], initial_delay_secs: retry_policy[:initial_delay_secs], max_delay_secs: retry_policy[:max_delay_secs] }.compact end resp = @client.request(:post, "/endpoints", body: body) Models::Endpoint.new(resp) end |
#delete(endpoint_id) ⇒ Object
121 122 123 124 |
# File 'lib/hooksniff/client.rb', line 121 def delete(endpoint_id) resp = @client.request(:delete, "/endpoints/#{endpoint_id}") resp["deleted"] != false end |
#get(endpoint_id) ⇒ Object
104 105 106 107 |
# File 'lib/hooksniff/client.rb', line 104 def get(endpoint_id) resp = @client.request(:get, "/endpoints/#{endpoint_id}") Models::Endpoint.new(resp) end |
#list(page: 1, per_page: 20) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/hooksniff/client.rb', line 109 def list(page: 1, per_page: 20) params = { page: page.to_s, per_page: per_page.to_s } query = URI.encode_www_form(params) resp = @client.request(:get, "/endpoints?#{query}") { endpoints: (resp["endpoints"] || resp).map { |ep| Models::Endpoint.new(ep) }, total: resp["total"] || 0, page: resp["page"] || page, per_page: resp["per_page"] || per_page } end |
#rotate_secret(endpoint_id) ⇒ Object
126 127 128 |
# File 'lib/hooksniff/client.rb', line 126 def rotate_secret(endpoint_id) @client.request(:post, "/endpoints/#{endpoint_id}/rotate-secret") end |