Class: Knockapi::Client
Constant Summary
collapse
- DEFAULT_MAX_RETRIES =
Default max number of retries to attempt after a failed retryable request.
2
- DEFAULT_TIMEOUT_IN_SECONDS =
Default per-request timeout.
60.0
- DEFAULT_INITIAL_RETRY_DELAY =
Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.
0.5
- DEFAULT_MAX_RETRY_DELAY =
Default max retry delay in seconds.
8.0
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS
Instance Attribute Summary collapse
#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout
Instance Method Summary
collapse
follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!
#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type
Constructor Details
#initialize(api_key: ENV["KNOCK_API_KEY"], branch: ENV["KNOCK_BRANCH"], base_url: ENV["KNOCK_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY, idempotency_header: "Idempotency-Key") ⇒ Client
Creates and returns a new client for interacting with the API.
‘“api.example.com/v2/”`. Defaults to `ENV`
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/knockapi/client.rb', line 88
def initialize(
api_key: ENV["KNOCK_API_KEY"],
branch: ENV["KNOCK_BRANCH"],
base_url: ENV["KNOCK_BASE_URL"],
max_retries: self.class::DEFAULT_MAX_RETRIES,
timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY,
idempotency_header: "Idempotency-Key"
)
base_url ||= "https://api.knock.app"
if api_key.nil?
raise ArgumentError.new("api_key is required, and can be set via environ: \"KNOCK_API_KEY\"")
end
= {
"x-knock-branch" => (@branch = branch&.to_s)
}
@api_key = api_key.to_s
super(
base_url: base_url,
timeout: timeout,
max_retries: max_retries,
initial_retry_delay: initial_retry_delay,
max_retry_delay: max_retry_delay,
headers: ,
idempotency_header:
)
@recipients = Knockapi::Resources::Recipients.new(client: self)
@users = Knockapi::Resources::Users.new(client: self)
@objects = Knockapi::Resources::Objects.new(client: self)
@tenants = Knockapi::Resources::Tenants.new(client: self)
@bulk_operations = Knockapi::Resources::BulkOperations.new(client: self)
@messages = Knockapi::Resources::Messages.new(client: self)
@providers = Knockapi::Resources::Providers.new(client: self)
@integrations = Knockapi::Resources::Integrations.new(client: self)
@workflows = Knockapi::Resources::Workflows.new(client: self)
@schedules = Knockapi::Resources::Schedules.new(client: self)
@channels = Knockapi::Resources::Channels.new(client: self)
@audiences = Knockapi::Resources::Audiences.new(client: self)
end
|
Instance Attribute Details
#api_key ⇒ String
19
20
21
|
# File 'lib/knockapi/client.rb', line 19
def api_key
@api_key
end
|
59
60
61
|
# File 'lib/knockapi/client.rb', line 59
def audiences
@audiences
end
|
#branch ⇒ String?
The slug of an existing branch
23
24
25
|
# File 'lib/knockapi/client.rb', line 23
def branch
@branch
end
|
38
39
40
|
# File 'lib/knockapi/client.rb', line 38
def bulk_operations
@bulk_operations
end
|
56
57
58
|
# File 'lib/knockapi/client.rb', line 56
def channels
@channels
end
|
47
48
49
|
# File 'lib/knockapi/client.rb', line 47
def integrations
@integrations
end
|
41
42
43
|
# File 'lib/knockapi/client.rb', line 41
def messages
@messages
end
|
32
33
34
|
# File 'lib/knockapi/client.rb', line 32
def objects
@objects
end
|
44
45
46
|
# File 'lib/knockapi/client.rb', line 44
def providers
@providers
end
|
26
27
28
|
# File 'lib/knockapi/client.rb', line 26
def recipients
@recipients
end
|
53
54
55
|
# File 'lib/knockapi/client.rb', line 53
def schedules
@schedules
end
|
35
36
37
|
# File 'lib/knockapi/client.rb', line 35
def tenants
@tenants
end
|
29
30
31
|
# File 'lib/knockapi/client.rb', line 29
def users
@users
end
|
50
51
52
|
# File 'lib/knockapi/client.rb', line 50
def workflows
@workflows
end
|