Class: Sink::Client

Inherits:
BaseClient
  • Object
show all
Defined in:
lib/sink/client.rb

Constant Summary collapse

DEFAULT_MAX_RETRIES =

Default max number of retries to attempt after a failed retryable request.

1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment: nil, base_url: nil, user_token: nil, api_key_header: nil, api_key_query: nil, username: nil, client_id: nil, client_secret: nil, some_boolean_arg: nil, some_integer_arg: nil, some_number_arg: nil, some_number_arg_required: nil, some_number_arg_required_no_default: nil, some_number_arg_required_no_default_no_env: nil, required_arg_no_env: nil, required_arg_no_env_with_default: nil, client_path_param: nil, camel_case_path: nil, client_query_param: nil, client_path_or_query_param: nil, max_retries: DEFAULT_MAX_RETRIES, timeout: 60) ⇒ Sink::Client

Creates and returns a new client for interacting with the API.

Parameters:

  • environment ("production", "sandbox", nil) (defaults to: nil)

    Specifies the environment to use for the API.

    Each environment maps to a different base URL:

  • base_url (String, nil) (defaults to: nil)

    Override the default base URL for the API, e.g., ‘“api.example.com/v2/”`

  • user_token (String, nil) (defaults to: nil)

    The API Key for the SINK API, sent as a bearer token Defaults to ‘ENV`

  • api_key_header (String, nil) (defaults to: nil)

    The API Key for the SINK API, sent as an api key header Defaults to ‘ENV`

  • api_key_query (String, nil) (defaults to: nil)

    The API Key for the SINK API, sent as an api key query Defaults to ‘ENV`

  • username (String, nil) (defaults to: nil)

    Defaults to ‘ENV`

  • client_id (String, nil) (defaults to: nil)

    Defaults to ‘ENV`

  • client_secret (String, nil) (defaults to: nil)

    Defaults to ‘ENV`

  • some_boolean_arg (Boolean, nil) (defaults to: nil)

    Defaults to ‘ENV`

  • some_integer_arg (Integer, nil) (defaults to: nil)

    Defaults to ‘ENV`

  • some_number_arg (Float, nil) (defaults to: nil)

    Defaults to ‘ENV`

  • some_number_arg_required (Float, nil) (defaults to: nil)

    Defaults to ‘ENV`

  • some_number_arg_required_no_default (Float, nil) (defaults to: nil)

    Defaults to ‘ENV`

  • some_number_arg_required_no_default_no_env (Float, nil) (defaults to: nil)
  • required_arg_no_env (String, nil) (defaults to: nil)
  • required_arg_no_env_with_default (String, nil) (defaults to: nil)
  • client_path_param (String, nil) (defaults to: nil)
  • camel_case_path (String, nil) (defaults to: nil)
  • client_query_param (String, nil) (defaults to: nil)
  • client_path_or_query_param (String, nil) (defaults to: nil)
  • max_retries (Integer) (defaults to: DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

[View source]

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/sink/client.rb', line 236

def initialize(
  environment: nil,
  base_url: nil,
  user_token: nil,
  api_key_header: nil,
  api_key_query: nil,
  username: nil,
  client_id: nil,
  client_secret: nil,
  some_boolean_arg: nil,
  some_integer_arg: nil,
  some_number_arg: nil,
  some_number_arg_required: nil,
  some_number_arg_required_no_default: nil,
  some_number_arg_required_no_default_no_env: nil,
  required_arg_no_env: nil,
  required_arg_no_env_with_default: nil,
  client_path_param: nil,
  camel_case_path: nil,
  client_query_param: nil,
  client_path_or_query_param: nil,
  max_retries: DEFAULT_MAX_RETRIES,
  timeout: 60
)
  environments = {"production" => "https://demo.stainlessapi.com/", "sandbox" => "https://demo-sanbox.stainlessapi.com/"}
  if environment && base_url
    raise ArgumentError, "both environment and base_url given, expected only one"
  elsif environment
    if !environments.key?(environment.to_s)
      raise ArgumentError, "environment must be one of #{environments.keys}, got #{environment}"
    end
    base_url = environments[environment.to_s]
  elsif !base_url
    base_url = "https://demo.stainlessapi.com/"
  end

  username_header = [username, ENV["SINK_USER"]].find { |v| !v.nil? }
  if username_header.nil?
    raise ArgumentError, "username is required"
  end
  client_secret_header = [client_secret, ENV["SINK_CLIENT_SECRET"], "hellosecret"].find { |v| !v.nil? }
  some_integer_arg_header = [some_integer_arg, ENV["SINK_SOME_INTEGER_ARG"], 123].find { |v| !v.nil? }
  headers = {
    "My-Api-Version" => "11",
    "X-Enable-Metrics" => "1",
    "X-Client-UserName" => username_header,
    "X-Client-Secret" => client_secret_header,
    "X-Integer" => some_integer_arg_header
  }

  idempotency_header = "Idempotency-Key"

  @user_token = [user_token, ENV["SINK_CUSTOM_API_KEY_ENV"]].find { |v| !v.nil? }
  @api_key_header = [api_key_header, ENV["SINK_CUSTOM_API_KEY_HEADER_ENV"]].find { |v| !v.nil? }
  @api_key_query = [api_key_query, ENV["SINK_CUSTOM_API_KEY_QUERY_ENV"]].find { |v| !v.nil? }
  @client_id = [client_id, ENV["SINK_CLIENT_ID"]].find { |v| !v.nil? }
  @some_boolean_arg = [some_boolean_arg, ENV["SINK_SOME_BOOLEAN_ARG"], true].find { |v| !v.nil? }
  @some_number_arg = [some_number_arg, ENV["SINK_SOME_NUMBER_ARG"], 1.2].find { |v| !v.nil? }
  @some_number_arg_required = [some_number_arg_required, ENV["SINK_SOME_NUMBER_ARG"], 1.2].find do |v|
    !v.nil?
  end
  @some_number_arg_required_no_default = [
    some_number_arg_required_no_default,
    ENV["SINK_SOME_NUMBER_ARG"]
  ].find do |v|
    !v.nil?
  end
  if @some_number_arg_required_no_default.nil?
    raise ArgumentError, "some_number_arg_required_no_default is required"
  end
  @some_number_arg_required_no_default_no_env = some_number_arg_required_no_default_no_env
  if @some_number_arg_required_no_default_no_env.nil?
    raise ArgumentError, "some_number_arg_required_no_default_no_env is required"
  end
  @required_arg_no_env = required_arg_no_env
  if @required_arg_no_env.nil?
    raise ArgumentError, "required_arg_no_env is required"
  end
  @required_arg_no_env_with_default = [required_arg_no_env_with_default, "hi!"].find { |v| !v.nil? }
  @client_query_param = client_query_param

  super(
    base_url: base_url,
    max_retries: max_retries,
    timeout: timeout,
    headers: headers,
    idempotency_header: idempotency_header
  )

  @testing = Sink::Resources::Testing.new(client: self)
  @complex_queries = Sink::Resources::ComplexQueries.new(client: self)
  @casing = Sink::Resources::Casing.new(client: self)
  @tools = Sink::Resources::Tools.new(client: self)
  @undocumented_resource = Sink::Resources::UndocumentedResource.new(client: self)
  @method_config = Sink::Resources::MethodConfig.new(client: self)
  @streaming = Sink::Resources::Streaming.new(client: self)
  @pagination_tests = Sink::Resources::PaginationTests.new(client: self)
  @docstrings = Sink::Resources::Docstrings.new(client: self)
  @invalid_schemas = Sink::Resources::InvalidSchemas.new(client: self)
  @resource_refs = Sink::Resources::ResourceRefs.new(client: self)
  @cards = Sink::Resources::Cards.new(client: self)
  @files = Sink::Resources::Files.new(client: self)
  @resources = Sink::Resources::Resources.new(client: self)
  @config_tools = Sink::Resources::ConfigTools.new(client: self)
  @company = Sink::Resources::Company.new(client: self)
  @openapi_formats = Sink::Resources::OpenAPIFormats.new(client: self)
  @parent = Sink::Resources::Parent.new(client: self)
  @envelopes = Sink::Resources::Envelopes.new(client: self)
  @types = Sink::Resources::Types.new(client: self)
  @clients = Sink::Resources::Clients.new(client: self)
  @names = Sink::Resources::Names.new(client: self)
  @widgets = Sink::Resources::Widgets.new(client: self)
  @responses = Sink::Resources::Responses.new(client: self)
  @path_params = Sink::Resources::PathParams.new(client: self)
  @positional_params = Sink::Resources::PositionalParams.new(client: self)
  @empty_body = Sink::Resources::EmptyBody.new(client: self)
  @query_params = Sink::Resources::QueryParams.new(client: self)
  @body_params = Sink::Resources::BodyParams.new(client: self)
  @header_params = Sink::Resources::HeaderParams.new(client: self)
  @mixed_params = Sink::Resources::MixedParams.new(client: self)
  @make_ambiguous_schemas_looser = Sink::Resources::MakeAmbiguousSchemasLooser.new(client: self)
  @make_ambiguous_schemas_explicit = Sink::Resources::MakeAmbiguousSchemasExplicit.new(client: self)
  @decorator_tests = Sink::Resources::DecoratorTests.new(client: self)
  @tests = Sink::Resources::Tests.new(client: self)
  @deeply_nested = Sink::Resources::DeeplyNested.new(client: self)
  @version_1_30_names = Sink::Resources::Version1_30Names.new(client: self)
  @recursion = Sink::Resources::Recursion.new(client: self)
  @shared_query_params = Sink::Resources::SharedQueryParams.new(client: self)
  @model_referenced_in_parent_and_child = Sink::Resources::ModelReferencedInParentAndChild.new(client: self)
end

Instance Attribute Details

#api_key_headerString (readonly)

Client option

Returns:

  • (String)

14
15
16
# File 'lib/sink/client.rb', line 14

def api_key_header
  @api_key_header
end

#api_key_queryString (readonly)

Client option

Returns:

  • (String)

18
19
20
# File 'lib/sink/client.rb', line 18

def api_key_query
  @api_key_query
end

#body_paramsSink::Resources::BodyParams (readonly)


168
169
170
# File 'lib/sink/client.rb', line 168

def body_params
  @body_params
end

#camel_case_pathString (readonly)

Client option

Returns:

  • (String)

70
71
72
# File 'lib/sink/client.rb', line 70

def camel_case_path
  @camel_case_path
end

#cardsSink::Resources::Cards (readonly)


114
115
116
# File 'lib/sink/client.rb', line 114

def cards
  @cards
end

#casingSink::Resources::Casing (readonly)


87
88
89
# File 'lib/sink/client.rb', line 87

def casing
  @casing
end

#client_idString (readonly)

Client option

Returns:

  • (String)

26
27
28
# File 'lib/sink/client.rb', line 26

def client_id
  @client_id
end

#client_path_or_query_paramString (readonly)

Client option

Returns:

  • (String)

78
79
80
# File 'lib/sink/client.rb', line 78

def client_path_or_query_param
  @client_path_or_query_param
end

#client_path_paramString (readonly)

Client option

Returns:

  • (String)

66
67
68
# File 'lib/sink/client.rb', line 66

def client_path_param
  @client_path_param
end

#client_query_paramString (readonly)

Client option

Returns:

  • (String)

74
75
76
# File 'lib/sink/client.rb', line 74

def client_query_param
  @client_query_param
end

#client_secretString (readonly)

Client option

Returns:

  • (String)

30
31
32
# File 'lib/sink/client.rb', line 30

def client_secret
  @client_secret
end

#clientsSink::Resources::Clients (readonly)


142
143
144
# File 'lib/sink/client.rb', line 142

def clients
  @clients
end

#companySink::Resources::Company (readonly)

Stainless API company


127
128
129
# File 'lib/sink/client.rb', line 127

def company
  @company
end

#complex_queriesSink::Resources::ComplexQueries (readonly)


84
85
86
# File 'lib/sink/client.rb', line 84

def complex_queries
  @complex_queries
end

#config_toolsSink::Resources::ConfigTools (readonly)


123
124
125
# File 'lib/sink/client.rb', line 123

def config_tools
  @config_tools
end

#decorator_testsSink::Resources::DecoratorTests (readonly)


183
184
185
# File 'lib/sink/client.rb', line 183

def decorator_tests
  @decorator_tests
end

#deeply_nestedSink::Resources::DeeplyNested (readonly)


189
190
191
# File 'lib/sink/client.rb', line 189

def deeply_nested
  @deeply_nested
end

#docstringsSink::Resources::Docstrings (readonly)


105
106
107
# File 'lib/sink/client.rb', line 105

def docstrings
  @docstrings
end

#empty_bodySink::Resources::EmptyBody (readonly)


162
163
164
# File 'lib/sink/client.rb', line 162

def empty_body
  @empty_body
end

#envelopesSink::Resources::Envelopes (readonly)


136
137
138
# File 'lib/sink/client.rb', line 136

def envelopes
  @envelopes
end

#filesSink::Resources::Files (readonly)


117
118
119
# File 'lib/sink/client.rb', line 117

def files
  @files
end

#header_paramsSink::Resources::HeaderParams (readonly)


171
172
173
# File 'lib/sink/client.rb', line 171

def header_params
  @header_params
end

#invalid_schemasSink::Resources::InvalidSchemas (readonly)


108
109
110
# File 'lib/sink/client.rb', line 108

def invalid_schemas
  @invalid_schemas
end

#make_ambiguous_schemas_explicitSink::Resources::MakeAmbiguousSchemasExplicit (readonly)


180
181
182
# File 'lib/sink/client.rb', line 180

def make_ambiguous_schemas_explicit
  @make_ambiguous_schemas_explicit
end

#make_ambiguous_schemas_looserSink::Resources::MakeAmbiguousSchemasLooser (readonly)


177
178
179
# File 'lib/sink/client.rb', line 177

def make_ambiguous_schemas_looser
  @make_ambiguous_schemas_looser
end

#method_configSink::Resources::MethodConfig (readonly)


96
97
98
# File 'lib/sink/client.rb', line 96

def method_config
  @method_config
end

#mixed_paramsSink::Resources::MixedParams (readonly)


174
175
176
# File 'lib/sink/client.rb', line 174

def mixed_params
  @mixed_params
end

#model_referenced_in_parent_and_childSink::Resources::ModelReferencedInParentAndChild (readonly)


201
202
203
# File 'lib/sink/client.rb', line 201

def model_referenced_in_parent_and_child
  @model_referenced_in_parent_and_child
end

#namesSink::Resources::Names (readonly)


145
146
147
# File 'lib/sink/client.rb', line 145

def names
  @names
end

#openapi_formatsSink::Resources::OpenAPIFormats (readonly)


130
131
132
# File 'lib/sink/client.rb', line 130

def openapi_formats
  @openapi_formats
end

#pagination_testsSink::Resources::PaginationTests (readonly)


102
103
104
# File 'lib/sink/client.rb', line 102

def pagination_tests
  @pagination_tests
end

#parentSink::Resources::Parent (readonly)


133
134
135
# File 'lib/sink/client.rb', line 133

def parent
  @parent
end

#path_paramsSink::Resources::PathParams (readonly)


156
157
158
# File 'lib/sink/client.rb', line 156

def path_params
  @path_params
end

#positional_paramsSink::Resources::PositionalParams (readonly)


159
160
161
# File 'lib/sink/client.rb', line 159

def positional_params
  @positional_params
end

#query_paramsSink::Resources::QueryParams (readonly)


165
166
167
# File 'lib/sink/client.rb', line 165

def query_params
  @query_params
end

#recursionSink::Resources::Recursion (readonly)


195
196
197
# File 'lib/sink/client.rb', line 195

def recursion
  @recursion
end

#required_arg_no_envString (readonly)

Client option

Returns:

  • (String)

58
59
60
# File 'lib/sink/client.rb', line 58

def required_arg_no_env
  @required_arg_no_env
end

#required_arg_no_env_with_defaultString (readonly)

Client option

Returns:

  • (String)

62
63
64
# File 'lib/sink/client.rb', line 62

def required_arg_no_env_with_default
  @required_arg_no_env_with_default
end

#resource_refsSink::Resources::ResourceRefs (readonly)


111
112
113
# File 'lib/sink/client.rb', line 111

def resource_refs
  @resource_refs
end

#resourcesSink::Resources::Resources (readonly)


120
121
122
# File 'lib/sink/client.rb', line 120

def resources
  @resources
end

#responsesSink::Resources::Responses (readonly)


153
154
155
# File 'lib/sink/client.rb', line 153

def responses
  @responses
end

#shared_query_paramsSink::Resources::SharedQueryParams (readonly)


198
199
200
# File 'lib/sink/client.rb', line 198

def shared_query_params
  @shared_query_params
end

#some_boolean_argBoolean (readonly)

Client option

Returns:

  • (Boolean)

34
35
36
# File 'lib/sink/client.rb', line 34

def some_boolean_arg
  @some_boolean_arg
end

#some_integer_argInteger (readonly)

Client option

Returns:

  • (Integer)

38
39
40
# File 'lib/sink/client.rb', line 38

def some_integer_arg
  @some_integer_arg
end

#some_number_argFloat (readonly)

Client option

Returns:

  • (Float)

42
43
44
# File 'lib/sink/client.rb', line 42

def some_number_arg
  @some_number_arg
end

#some_number_arg_requiredFloat (readonly)

Client option

Returns:

  • (Float)

46
47
48
# File 'lib/sink/client.rb', line 46

def some_number_arg_required
  @some_number_arg_required
end

#some_number_arg_required_no_defaultFloat (readonly)

Client option

Returns:

  • (Float)

50
51
52
# File 'lib/sink/client.rb', line 50

def some_number_arg_required_no_default
  @some_number_arg_required_no_default
end

#some_number_arg_required_no_default_no_envFloat (readonly)

Client option

Returns:

  • (Float)

54
55
56
# File 'lib/sink/client.rb', line 54

def some_number_arg_required_no_default_no_env
  @some_number_arg_required_no_default_no_env
end

#streamingSink::Resources::Streaming (readonly)


99
100
101
# File 'lib/sink/client.rb', line 99

def streaming
  @streaming
end

#testingSink::Resources::Testing (readonly)


81
82
83
# File 'lib/sink/client.rb', line 81

def testing
  @testing
end

#testsSink::Resources::Tests (readonly)


186
187
188
# File 'lib/sink/client.rb', line 186

def tests
  @tests
end

#toolsSink::Resources::Tools (readonly)


90
91
92
# File 'lib/sink/client.rb', line 90

def tools
  @tools
end

#typesSink::Resources::Types (readonly)


139
140
141
# File 'lib/sink/client.rb', line 139

def types
  @types
end

#undocumented_resourceSink::Resources::UndocumentedResource (readonly)


93
94
95
# File 'lib/sink/client.rb', line 93

def undocumented_resource
  @undocumented_resource
end

#user_tokenString (readonly)

Client option

Returns:

  • (String)

10
11
12
# File 'lib/sink/client.rb', line 10

def user_token
  @user_token
end

#usernameString (readonly)

Client option

Returns:

  • (String)

22
23
24
# File 'lib/sink/client.rb', line 22

def username
  @username
end

#version_1_30_namesSink::Resources::Version1_30Names (readonly)


192
193
194
# File 'lib/sink/client.rb', line 192

def version_1_30_names
  @version_1_30_names
end

#widgetsSink::Resources::Widgets (readonly)

Widget is love Widget is life


150
151
152
# File 'lib/sink/client.rb', line 150

def widgets
  @widgets
end