Class: DocsKit::ApiClient
- Inherits:
-
Data
- Object
- Data
- DocsKit::ApiClient
- Defined in:
- lib/docs_kit/api_client.rb
Overview
One API-example language tab: a label, a Rouge lexer, a filename (a String or
a (request) -> String proc), and a template — a (DocsKit::ApiRequest) -> String callable that renders the snippet. DocsUI::RequestExample turns each
configured client into one DocsUI::Example tab.
DocsKit::ApiClient.new(
label: "cURL", lexer: :curl, filename: "request.sh",
template: ->(req) { "curl -X #{req.http_method} '#{req.url}'" }
)
The gem ships four generic-HTTP defaults (DEFAULTS); a site overrides or
extends them via DocsKit.configuration.api_clients (SDK-flavored snippets, a
cli tab, ...).
Constant Summary collapse
- DEFAULTS =
The four generic-HTTP clients every site starts from. Order is stable (curl → javascript → ruby → python) and preserved when a site merges its own.
{ curl: ApiClient.new( label: "cURL", lexer: :curl, filename: "request.sh", template: ApiTemplates.method(:curl) ), javascript: ApiClient.new( label: "JavaScript", lexer: :javascript, filename: "request.js", template: ApiTemplates.method(:javascript) ), ruby: ApiClient.new( label: "Ruby", lexer: :ruby, filename: "request.rb", template: ApiTemplates.method(:ruby) ), python: ApiClient.new( label: "Python", lexer: :python, filename: "request.py", template: ApiTemplates.method(:python) ) }.freeze
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#lexer ⇒ Object
readonly
Returns the value of attribute lexer.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#filename_for(request) ⇒ Object
The filename for this client's title bar: a static String, or the result of calling a proc filename with the request (so it can vary by verb/path).
-
#initialize(label:, lexer:, template:, filename: nil) ⇒ ApiClient
constructor
A new instance of ApiClient.
-
#render(request) ⇒ Object
Render the snippet for this client from the request struct.
Constructor Details
#initialize(label:, lexer:, template:, filename: nil) ⇒ ApiClient
Returns a new instance of ApiClient.
18 19 20 |
# File 'lib/docs_kit/api_client.rb', line 18 def initialize(label:, lexer:, template:, filename: nil) super end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename
17 18 19 |
# File 'lib/docs_kit/api_client.rb', line 17 def filename @filename end |
#label ⇒ Object (readonly)
Returns the value of attribute label
17 18 19 |
# File 'lib/docs_kit/api_client.rb', line 17 def label @label end |
#lexer ⇒ Object (readonly)
Returns the value of attribute lexer
17 18 19 |
# File 'lib/docs_kit/api_client.rb', line 17 def lexer @lexer end |
#template ⇒ Object (readonly)
Returns the value of attribute template
17 18 19 |
# File 'lib/docs_kit/api_client.rb', line 17 def template @template end |
Instance Method Details
#filename_for(request) ⇒ Object
The filename for this client's title bar: a static String, or the result of calling a proc filename with the request (so it can vary by verb/path).
24 25 26 |
# File 'lib/docs_kit/api_client.rb', line 24 def filename_for(request) filename.respond_to?(:call) ? filename.call(request) : filename end |
#render(request) ⇒ Object
Render the snippet for this client from the request struct.
29 |
# File 'lib/docs_kit/api_client.rb', line 29 def render(request) = template.call(request) |