Class: Proc::Client
- Inherits:
- BasicObject
- Includes:
- Is::Async, Is::Global
- Defined in:
- lib/proc/client.rb
Overview
- public
-
Connection to proc, configured with an authorization.
Constant Summary collapse
- DEFAULT_HEADERS =
{ "accept" => "application/vnd.proc+msgpack", "content-type" => "application/vnd.proc+msgpack" }.freeze
Instance Attribute Summary collapse
-
#authorization ⇒ Object
readonly
- public
-
The configured authorization.
-
#host ⇒ Object
readonly
- public
-
The configured host.
-
#request_count ⇒ Object
readonly
- public
-
The number of requests this client has performed.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#scheme ⇒ Object
readonly
- public
-
The configured scheme.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](proc) ⇒ Object
- public
-
Returns a callable context for
proc.
-
#argument(name, **options) ⇒ Object
(also: #arg)
- public
-
Builds a named argument with options.
-
#call(proc = nil, input = ::Proc::Composer.undefined, **arguments, &block) ⇒ Object
- public
-
Calls a proc with the given input and arguments.
-
#initialize(authorization = ::Proc::Client.authorization, scheme: "https", host: "api.proc.dev") ⇒ Client
constructor
A new instance of Client.
-
#method_missing(name, input = input_omitted = true, **arguments) ⇒ Object
- public
-
Allows callable contexts to be built through method lookups.
-
#rate_limit ⇒ Object
- public
-
Returns the current rate limit.
-
#rate_limit_reset ⇒ Object
- public
-
Returns the time at which the current rate limit will reset.
-
#rate_limit_window ⇒ Object
- public
-
Returns the current rate limit window.
- #respond_to_missing?(name) ⇒ Boolean
Constructor Details
#initialize(authorization = ::Proc::Client.authorization, scheme: "https", host: "api.proc.dev") ⇒ Client
Returns a new instance of Client.
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/proc/client.rb', line 103 def initialize( = ::Proc::Client., scheme: "https", host: "api.proc.dev") @authorization = @scheme = scheme @host = host @request_count = 0 @__base_url = "#{@scheme}://#{host}" @__headers = { "authorization" => "bearer #{@authorization}" }.merge(DEFAULT_HEADERS) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, input = input_omitted = true, **arguments) ⇒ Object
- public
-
Allows callable contexts to be built through method lookups.
222 223 224 225 226 227 228 |
# File 'lib/proc/client.rb', line 222 def method_missing(name, input = input_omitted = true, *, **arguments) if input_omitted ::Proc::Callable.new(name, client: self, arguments: arguments) else ::Proc::Callable.new(name, client: self, input: input, arguments: arguments) end end |
Instance Attribute Details
#authorization ⇒ Object (readonly)
- public
-
The configured authorization.
82 83 84 |
# File 'lib/proc/client.rb', line 82 def @authorization end |
#host ⇒ Object (readonly)
- public
-
The configured host.
90 91 92 |
# File 'lib/proc/client.rb', line 90 def host @host end |
#request_count ⇒ Object (readonly)
- public
-
The number of requests this client has performed.
94 95 96 |
# File 'lib/proc/client.rb', line 94 def request_count @request_count end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
96 97 98 |
# File 'lib/proc/client.rb', line 96 def response @response end |
#scheme ⇒ Object (readonly)
- public
-
The configured scheme.
86 87 88 |
# File 'lib/proc/client.rb', line 86 def scheme @scheme end |
Class Method Details
.authorization ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/proc/client.rb', line 64 def ::ENV.fetch("PROC_AUTH") { auth_file_path = ::Pathname.new("~/.proc/auth"). if auth_file_path.exist? auth_file_path.read else "" end }.strip end |
Instance Method Details
#[](proc) ⇒ Object
- public
-
Returns a callable context for
proc.
117 118 119 120 121 122 123 |
# File 'lib/proc/client.rb', line 117 def [](proc) if ::Kernel.block_given? ::Proc::Callable.new(proc, client: self, arguments: {proc: yield}) else ::Proc::Callable.new(proc, client: self) end end |
#argument(name, **options) ⇒ Object Also known as: arg
- public
-
Builds a named argument with options.
236 237 238 |
# File 'lib/proc/client.rb', line 236 def argument(name, **) ::Proc::Composer::Argument.new(name, **) end |
#call(proc = nil, input = ::Proc::Composer.undefined, **arguments, &block) ⇒ Object
- public
-
Calls a proc with the given input and arguments.
If a block is passed and the proc returns an enumerable, the block will be called with each value.
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/proc/client.rb', line 156 def call(proc = nil, input = ::Proc::Composer.undefined, **arguments, &block) body = [] unless ::Proc::Composer.undefined?(input) body << [">>", serialize_value(input)] end arguments.each_pair do |key, value| body << ["$$", key.to_s, serialize_value(value)] end process(proc: proc, body: body, input: input, arguments: arguments, &block) end |
#rate_limit ⇒ Object
- public
-
Returns the current rate limit.
127 128 129 130 |
# File 'lib/proc/client.rb', line 127 def rate_limit refresh_rate_limit @rate_limit end |
#rate_limit_reset ⇒ Object
- public
-
Returns the time at which the current rate limit will reset.
141 142 143 144 |
# File 'lib/proc/client.rb', line 141 def rate_limit_reset refresh_rate_limit @rate_limit_reset end |
#rate_limit_window ⇒ Object
- public
-
Returns the current rate limit window.
134 135 136 137 |
# File 'lib/proc/client.rb', line 134 def rate_limit_window refresh_rate_limit @rate_limit_window end |
#respond_to_missing?(name) ⇒ Boolean
230 231 232 |
# File 'lib/proc/client.rb', line 230 def respond_to_missing?(name, *) true end |