ask-honeybadger 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 30842eefeba7cdd4bc71ad4958755872c84f36f935259717824d235f51ccac99
4
+ data.tar.gz: c177120c6ee8d243ad0559a935ffb66797aaa896f9cbd096725c3f5acd6e6a6a
5
+ SHA512:
6
+ metadata.gz: be92b43b9113fa04f1b378b53dcb6c39dd4ce4f6a4dd75dfee2567cd39ae79a57558c5b393fe6c2ec6f7913ae47c1ac7831f3680fc6cdb7d1596abc7db5fbadf
7
+ data.tar.gz: 6625078687f978f71a36bc32788200f4383f815d83d6ae42d0a7dc6586484c07e30585a8529442aa06ca0b4a47c0b375af86f264c13f094b86cda07cc27ed516
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## v0.1.0 (2026-06-10)
4
+
5
+ - Initial release
6
+ - context.rb: DESCRIPTION, QUICK_START, AUTH_NAME, and auth instructions
7
+ - client.rb: Faraday-based HTTP client with Basic Auth and retry middleware
8
+ - error_guide.rb: Structured error knowledge for common API errors
9
+ - Convenience methods: recent_faults, fault_summary, fault, projects
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kaka Ruto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # ask-honeybadger
2
+
3
+ Honeybadger — error tracking via the Honeybadger API
4
+
5
+ Part of the [ask-rb](https://github.com/ask-rb) ecosystem.
6
+
7
+ ## Installation
8
+
9
+ ```ruby
10
+ gem "ask-honeybadger"
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ require "ask-honeybadger"
17
+
18
+ # Get an authenticated client:
19
+ client = Ask::Honeybadger.client
20
+
21
+ # List faults for a project:
22
+ faults = client.get("/v2/projects/PROJECT_ID/faults")
23
+
24
+ # Or use the convenience helpers:
25
+ Ask::Honeybadger.recent_faults(project_id: "PROJECT_ID", limit: 10)
26
+ Ask::Honeybadger.fault_summary(project_id: "PROJECT_ID")
27
+ Ask::Honeybadger.fault(project_id: "PROJECT_ID", fault_id: 42)
28
+ Ask::Honeybadger.projects
29
+ ```
30
+
31
+ ## Authentication
32
+
33
+ Set your Honeybadger API token in the environment:
34
+
35
+ ```bash
36
+ export HONEYBADGER_TOKEN=your_token_here
37
+ ```
38
+
39
+ Or add it to `~/.ask/credentials.yml`:
40
+
41
+ ```yaml
42
+ honeybadger_token: your_token_here
43
+ ```
44
+
45
+ Get your token at https://app.honeybadger.io/users/edit
46
+
47
+ ## Development
48
+
49
+ ```bash
50
+ bundle exec rake test
51
+ ```
52
+
53
+ ## License
54
+
55
+ MIT
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday/retry"
5
+ require "ask/auth"
6
+
7
+ module Ask
8
+ module Honeybadger
9
+ # Base URL for the Honeybadger Data API.
10
+ BASE_URL = "https://app.honeybadger.io/v2"
11
+
12
+ # Returns an authenticated Faraday client for the Honeybadger Data API.
13
+ #
14
+ # Resolves the Honeybadger API token via +Ask::Auth.resolve(:honeybadger_token)+
15
+ # and configures the client with sensible defaults:
16
+ #
17
+ # - +request+: JSON encoding
18
+ # - +response+: JSON decoding
19
+ # - +retry+: Faraday retry middleware (3 retries, exponential backoff)
20
+ # - +auth+: HTTP Basic Auth with token as username and blank password
21
+ #
22
+ # The client is wrapped in a +ClientProxy+ that converts
23
+ # +Faraday::UnauthorizedError+ into +Ask::Auth::InvalidCredential+.
24
+ #
25
+ # @example
26
+ # client = Ask::Honeybadger.client
27
+ # client.get("/v2/projects/ID/faults")
28
+ #
29
+ # @return [Faraday::Connection] an authenticated HTTP client
30
+ # @raise [Ask::Auth::MissingCredential] if no Honeybadger token is configured
31
+ # @raise [Ask::Auth::InvalidCredential] if the token is rejected (401)
32
+ def self.client
33
+ token = Ask::Auth.resolve(:honeybadger_token)
34
+
35
+ conn = Faraday.new(url: BASE_URL) do |f|
36
+ # HTTP Basic Auth: token is the username, password is blank
37
+ f.request :authorization, :basic, token, ""
38
+
39
+ # JSON request/response handling
40
+ f.request :json
41
+ f.response :json
42
+
43
+ # Retry middleware for transient failures
44
+ f.request :retry, max: 3, interval: 1, backoff_factor: 2,
45
+ retry_statuses: [429, 500, 502, 503]
46
+
47
+ f.adapter Faraday.default_adapter
48
+ end
49
+
50
+ ClientProxy.new(conn)
51
+ end
52
+
53
+ # Convenience: fetch recent faults for a project.
54
+ #
55
+ # @param project_id [String, Integer] The Honeybadger project ID
56
+ # @param limit [Integer] Number of faults to return (max 25)
57
+ # @param params [Hash] Additional query parameters (q, order, environment, etc.)
58
+ # @return [Hash] Response with +results+ array and +links+
59
+ def self.recent_faults(project_id:, limit: 25, **params)
60
+ params[:limit] = limit
61
+ client.get("/v2/projects/#{project_id}/faults", params).body
62
+ end
63
+
64
+ # Convenience: get a fault summary (counts grouped by environment, status, etc.).
65
+ #
66
+ # @param project_id [String, Integer] The Honeybadger project ID
67
+ # @param params [Hash] Additional query parameters
68
+ # @return [Hash] Fault summary with counts
69
+ def self.fault_summary(project_id:, **params)
70
+ client.get("/v2/projects/#{project_id}/faults/summary", params).body
71
+ end
72
+
73
+ # Convenience: fetch a single fault by ID.
74
+ #
75
+ # @param project_id [String, Integer] The Honeybadger project ID
76
+ # @param fault_id [String, Integer] The fault ID
77
+ # @return [Hash] Fault details
78
+ def self.fault(project_id:, fault_id:)
79
+ client.get("/v2/projects/#{project_id}/faults/#{fault_id}").body
80
+ end
81
+
82
+ # Convenience: list all projects accessible with this token.
83
+ #
84
+ # @return [Hash] Response with +results+ array and +links+
85
+ def self.projects
86
+ client.get("/v2/projects").body
87
+ end
88
+
89
+ # Proxies method calls to a +Faraday::Connection+, converting
90
+ # authentication errors into +Ask::Auth::InvalidCredential+.
91
+ class ClientProxy < BasicObject
92
+ def initialize(client)
93
+ @client = client
94
+ end
95
+
96
+ def method_missing(name, ...)
97
+ @client.public_send(name, ...)
98
+ rescue ::Faraday::UnauthorizedError
99
+ ::Kernel.raise ::Ask::Auth::InvalidCredential, :honeybadger_token
100
+ end
101
+
102
+ def respond_to_missing?(name, include_private = false)
103
+ @client.respond_to?(name, include_private) || super
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ask
4
+ module Honeybadger
5
+ # Human-readable description of the Honeybadger service context.
6
+ DESCRIPTION = "Honeybadger — error tracking via the Honeybadger API"
7
+
8
+ # Base URL for Honeybadger API documentation.
9
+ DOCS_URL = "https://docs.honeybadger.io/api/"
10
+
11
+ # Credential name used with Ask::Auth.resolve.
12
+ AUTH_NAME = :honeybadger_token
13
+
14
+ # Instructions for obtaining a Honeybadger API token.
15
+ AUTH_HOW = "https://app.honeybadger.io/users/edit"
16
+
17
+ # Gem name for the Honeybadger Ruby integration.
18
+ GEM_NAME = "honeybadger-ruby"
19
+
20
+ # Quick-start Ruby code snippet for agents to copy-paste.
21
+ QUICK_START = <<~RUBY
22
+ client = Ask::Honeybadger.client
23
+
24
+ # List faults for a project:
25
+ faults = client.get("/v2/projects/PROJECT_ID/faults")
26
+
27
+ # Get fault details:
28
+ fault = client.get("/v2/projects/PROJECT_ID/faults/FAULT_ID")
29
+
30
+ # List projects:
31
+ projects = client.get("/v2/projects")
32
+
33
+ # Convenience helpers:
34
+ Ask::Honeybadger.recent_faults(project_id: "PROJECT_ID", limit: 10)
35
+ Ask::Honeybadger.fault_summary(project_id: "PROJECT_ID")
36
+ RUBY
37
+ end
38
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ask
4
+ module Honeybadger
5
+ # Structured error knowledge for AI agents working with the Honeybadger API.
6
+ #
7
+ # Provides human-readable guidance for common HTTP status codes, rate
8
+ # limiting, pagination, and authentication errors encountered when
9
+ # using the Honeybadger Data API.
10
+ module Errors
11
+ # Rate limit information.
12
+ #
13
+ # - Authenticated requests: 360 requests per hour
14
+ #
15
+ # When rate-limited, the API returns HTTP 403 (Forbidden). The agent
16
+ # should check the +X-RateLimit-Reset+ header and wait until that
17
+ # timestamp before retrying.
18
+ RATE_LIMIT = {
19
+ authenticated: "360 requests per hour (using API token)",
20
+ error_class: "Faraday::ForbiddenError",
21
+ action: "Check the X-RateLimit-Reset header, wait until that Unix timestamp, then retry the request.",
22
+ headers: {
23
+ limit: "X-RateLimit-Limit — number of requests you can make per hour",
24
+ remaining: "X-RateLimit-Remaining — number of requests remaining in the current window",
25
+ reset: "X-RateLimit-Reset — Unix timestamp when the rate limit resets"
26
+ }
27
+ }.freeze
28
+
29
+ # Common HTTP status codes returned by the Honeybadger API and how to handle them.
30
+ STATUS_CODES = {
31
+ 200 => "OK — Request succeeded.",
32
+ 201 => "Created — Resource was created successfully.",
33
+ 204 => "No Content — Request succeeded, no response body.",
34
+ 301 => "Moved Permanently — The resource URL has changed; update your reference.",
35
+ 400 => "Bad Request — The request was malformed. Check parameters.",
36
+ 401 => "Unauthorized — Token is missing, invalid, or revoked. Re-authenticate.",
37
+ 403 => "Forbidden — Token lacks permissions or rate limit exceeded. Check token or retry later.",
38
+ 404 => "Not Found — Resource does not exist or is private.",
39
+ 409 => "Conflict — Resource state conflict.",
40
+ 422 => "Unprocessable Entity — Validation failed. Check request parameters.",
41
+ 429 => "Too Many Requests — Rate limit exceeded. Wait before retrying.",
42
+ 500 => "Internal Server Error — Honeybadger server issue. Retry with backoff.",
43
+ 502 => "Bad Gateway — Honeybadger upstream issue. Retry with backoff.",
44
+ 503 => "Service Unavailable — Honeybadger is down for maintenance. Retry later."
45
+ }.freeze
46
+
47
+ # Pagination guidance for the Honeybadger API.
48
+ PAGINATION = {
49
+ links: "List responses include a links hash with 'self', 'next', and 'prev' URLs.",
50
+ next_page: "Load the next page by following the URL in the 'next' link.",
51
+ prev_page: "Load the previous page by following the URL in the 'prev' link.",
52
+ results_key: "Results are in the 'results' array within the response body.",
53
+ missing_links: "If next or prev links are missing, there is no further page in that direction."
54
+ }.freeze
55
+
56
+ # Map of exception classes to human-readable guidance.
57
+ EXCEPTIONS = {
58
+ "Faraday::UnauthorizedError" => {
59
+ message: "Your Honeybadger API token is invalid or has been revoked.",
60
+ action: "Generate a new token at https://app.honeybadger.io/users/edit"
61
+ },
62
+ "Faraday::ForbiddenError" => {
63
+ message: "Your token lacks the required permissions, or the rate limit has been exceeded.",
64
+ action: "Check your token permissions. If rate-limited, wait until the X-RateLimit-Reset timestamp."
65
+ },
66
+ "Faraday::ResourceNotFound" => {
67
+ message: "The requested project or fault does not exist or is not accessible.",
68
+ action: "Verify the project ID or fault ID. Ensure the token has access to this resource."
69
+ },
70
+ "Faraday::ParsingError" => {
71
+ message: "Failed to parse the API response.",
72
+ action: "The API may have returned an unexpected format. Check the raw response body."
73
+ },
74
+ "Faraday::TimeoutError" => {
75
+ message: "The request timed out.",
76
+ action: "Retry with exponential backoff. If the issue persists, check https://status.honeybadger.io."
77
+ },
78
+ "Faraday::ConnectionFailed" => {
79
+ message: "Failed to connect to the Honeybadger API.",
80
+ action: "Check your network connection and verify that https://app.honeybadger.io is reachable."
81
+ },
82
+ "Faraday::ServerError" => {
83
+ message: "Honeybadger encountered a server error (5xx).",
84
+ action: "Retry with exponential backoff. If the issue persists, check https://status.honeybadger.io."
85
+ }
86
+ }.freeze
87
+
88
+ # Look up guidance for an exception class name.
89
+ #
90
+ # @param exception_class [String] The exception class name (e.g., "Faraday::ResourceNotFound")
91
+ # @return [Hash, nil] A hash with +:message+ and +:action+ keys, or nil if unknown
92
+ def self.for(exception_class)
93
+ EXCEPTIONS[exception_class]
94
+ end
95
+
96
+ # Describe an HTTP status code.
97
+ #
98
+ # @param code [Integer] HTTP status code
99
+ # @return [String, nil] Description of the status code
100
+ def self.status_code_description(code)
101
+ STATUS_CODES[code]
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ask
4
+ module Honeybadger
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ask/honeybadger/version"
4
+ require_relative "ask/honeybadger/context"
5
+ require_relative "ask/honeybadger/client"
6
+ require_relative "ask/honeybadger/error_guide"
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ask-honeybadger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kaka Ruto
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: ask-core
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: ask-auth
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.1'
40
+ - !ruby/object:Gem::Dependency
41
+ name: faraday
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: faraday-retry
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: minitest
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '5.25'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '5.25'
82
+ - !ruby/object:Gem::Dependency
83
+ name: mocha
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.1'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.1'
96
+ - !ruby/object:Gem::Dependency
97
+ name: vcr
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '6.3'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '6.3'
110
+ - !ruby/object:Gem::Dependency
111
+ name: webmock
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '3.23'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '3.23'
124
+ - !ruby/object:Gem::Dependency
125
+ name: rake
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '13.0'
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '13.0'
138
+ description: Error context for agents via Honeybadger for the ask-rb ecosystem.
139
+ email:
140
+ - kaka@myrrlabs.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - CHANGELOG.md
146
+ - LICENSE
147
+ - README.md
148
+ - lib/ask-honeybadger.rb
149
+ - lib/ask/honeybadger/client.rb
150
+ - lib/ask/honeybadger/context.rb
151
+ - lib/ask/honeybadger/error_guide.rb
152
+ - lib/ask/honeybadger/version.rb
153
+ homepage: https://github.com/ask-rb/ask-honeybadger
154
+ licenses:
155
+ - MIT
156
+ metadata:
157
+ homepage_uri: https://github.com/ask-rb/ask-honeybadger
158
+ source_code_uri: https://github.com/ask-rb/ask-honeybadger
159
+ changelog_uri: https://github.com/ask-rb/ask-honeybadger/blob/main/CHANGELOG.md
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '3.2'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubygems_version: 4.0.3
175
+ specification_version: 4
176
+ summary: Honeybadger — error tracking via the Honeybadger API
177
+ test_files: []