Class: Keiyaku::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/keiyaku/runtime.rb,
sig/keiyaku.rbs

Overview

Base class for generated clients. The generated subclass contains one declaration per operation and nothing else.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: nil, auth: nil, adapter: nil, timeout: 15, retries: 0, logger: nil) ⇒ Client

auth: is credentials by scheme name — a bare value only where the document declares one scheme, since with two there is nothing to say which it is.

Raises:



211
# File 'sig/keiyaku.rbs', line 211

def initialize: (

Class Attribute Details

.operationsHash[Symbol, Hash[Symbol, untyped]] (readonly)

Returns:

  • (Hash[Symbol, Hash[Symbol, untyped]])


176
# File 'sig/keiyaku.rbs', line 176

def self.operations: () -> Hash[Symbol, Hash[Symbol, untyped]]

Instance Attribute Details

#base_urlString (readonly)

Returns the value of attribute base_url.

Returns:

  • (String)


206
207
208
# File 'sig/keiyaku.rbs', line 206

def base_url
  @base_url
end

Class Method Details

.default_securityArray[Array[Symbol]]

Returns:

  • (Array[Array[Symbol]])


182
# File 'sig/keiyaku.rbs', line 182

def self.default_security: () -> Array[Array[Symbol]]

.deletevoid

This method returns an undefined value.

Parameters:

  • name (Symbol)
  • template (String)
  • (Object)


192
# File 'sig/keiyaku.rbs', line 192

def self.delete: (Symbol name, String template, **untyped) -> void

.getvoid

This method returns an undefined value.

Parameters:

  • name (Symbol)
  • template (String)
  • (Object)


188
# File 'sig/keiyaku.rbs', line 188

def self.get: (Symbol name, String template, **untyped) -> void

.headvoid

This method returns an undefined value.

Parameters:

  • name (Symbol)
  • template (String)
  • (Object)


193
# File 'sig/keiyaku.rbs', line 193

def self.head: (Symbol name, String template, **untyped) -> void

.inherited(subclass) ⇒ Object



557
558
559
560
561
562
563
# File 'lib/keiyaku/runtime.rb', line 557

def inherited(subclass)
  super
  subclass.instance_variable_set(:@operations, operations&.dup || {})
  subclass.instance_variable_set(:@server, @server)
  subclass.instance_variable_set(:@security, @security)
  subclass.instance_variable_set(:@default_security, @default_security)
end

.operation(verb, name, template, query: [], deep_object: [], header: {}, explode: [], required: [], body: nil, form: nil, multipart: nil, content_type: nil, body_required: false, into: nil, errors: {}, security: :inherit) ⇒ Object

Declare one operation, and define a real method for it.

required: names the query and header parameters a caller has to pass, by the name the document gave them — which for a header is the name on the wire rather than the Ruby one it arrives under:

get :find, "/pets", query: %i[status limit], required: %i[status]

deep_object: names the query parameters the document gave style: deepObject, which go out spelled a key at a time:

get :list, "/widgets", query: %i[filter], deep_object: %w[filter]

explode: names the path and header parameters the document wrote explode on, which is the one thing that cannot be read off the value itself: an object goes out as role=admin,name=alex where it was said and as role,admin,name,alex where it was not.



620
# File 'lib/keiyaku/runtime.rb', line 620

def self.operation: (

.optionsvoid

This method returns an undefined value.

Parameters:

  • name (Symbol)
  • template (String)
  • (Object)


194
# File 'sig/keiyaku.rbs', line 194

def self.options: (Symbol name, String template, **untyped) -> void

.patchvoid

This method returns an undefined value.

Parameters:

  • name (Symbol)
  • template (String)
  • (Object)


191
# File 'sig/keiyaku.rbs', line 191

def self.patch: (Symbol name, String template, **untyped) -> void

.postvoid

This method returns an undefined value.

Parameters:

  • name (Symbol)
  • template (String)
  • (Object)


189
# File 'sig/keiyaku.rbs', line 189

def self.post: (Symbol name, String template, **untyped) -> void

.putvoid

This method returns an undefined value.

Parameters:

  • name (Symbol)
  • template (String)
  • (Object)


190
# File 'sig/keiyaku.rbs', line 190

def self.put: (Symbol name, String template, **untyped) -> void

.requirement(declared) ⇒ Object

A security requirement is a list of alternatives, each of which is a set of schemes that all have to be satisfied: OpenAPI's OR of ANDs. false and [] are the operation that takes no credentials at all, which is not the same as one that does not say.



186
# File 'sig/keiyaku.rbs', line 186

def self.requirement: (untyped) -> Array[Array[Symbol]]

.security(schemes = nil, default: nil) ⇒ Object

The document's security schemes, by the name it gave them, plus the requirement that holds for an operation which does not state its own.

security({ api_key: { header: "api_key" }, petstore_auth: :bearer },
       default: :api_key)

A scheme is :bearer, :basic, or one of { header: }, { query: }, { cookie: } naming where an API key goes. Credentials are then given by scheme name, because a document that declares two has no single "the" credential and picking one for the caller is how a client ends up sending the wrong header to every operation it has.



181
# File 'sig/keiyaku.rbs', line 181

def self.security: (?Hash[Symbol | String, untyped] schemes, ?default: untyped) -> untyped

.server(url = nil) ⇒ String?

Parameters:

  • (String, nil)

Returns:

  • (String, nil)


177
# File 'sig/keiyaku.rbs', line 177

def self.server: (?String?) -> String?

.unsupported(name, reason) ⇒ Object

An operation the generator could not build correctly. Declaring it keeps the omission visible instead of leaving a silent hole in the client.



681
# File 'lib/keiyaku/runtime.rb', line 681

def self.unsupported: (Symbol name, String reason) -> void