twilio-api-sdk-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +28 -0
- data/README.md +155 -0
- data/bin/console +15 -0
- data/lib/twilio_accounts/api_helper.rb +10 -0
- data/lib/twilio_accounts/apis/accounts_v1_auth_token_promotion_api.rb +27 -0
- data/lib/twilio_accounts/apis/accounts_v1_aws_api.rb +137 -0
- data/lib/twilio_accounts/apis/accounts_v1_bulk_consents_api.rb +41 -0
- data/lib/twilio_accounts/apis/accounts_v1_bulk_contacts_api.rb +36 -0
- data/lib/twilio_accounts/apis/accounts_v1_messaging_geopermissions_api.rb +54 -0
- data/lib/twilio_accounts/apis/accounts_v1_public_key_api.rb +136 -0
- data/lib/twilio_accounts/apis/accounts_v1_safelist_api.rb +69 -0
- data/lib/twilio_accounts/apis/accounts_v1_secondary_auth_token_api.rb +39 -0
- data/lib/twilio_accounts/apis/base_api.rb +67 -0
- data/lib/twilio_accounts/client.rb +117 -0
- data/lib/twilio_accounts/configuration.rb +165 -0
- data/lib/twilio_accounts/exceptions/api_exception.rb +21 -0
- data/lib/twilio_accounts/http/api_response.rb +19 -0
- data/lib/twilio_accounts/http/auth/basic_auth.rb +62 -0
- data/lib/twilio_accounts/http/http_call_back.rb +10 -0
- data/lib/twilio_accounts/http/http_method_enum.rb +10 -0
- data/lib/twilio_accounts/http/http_request.rb +10 -0
- data/lib/twilio_accounts/http/http_response.rb +10 -0
- data/lib/twilio_accounts/http/proxy_settings.rb +22 -0
- data/lib/twilio_accounts/logging/configuration/api_logging_configuration.rb +186 -0
- data/lib/twilio_accounts/logging/sdk_logger.rb +17 -0
- data/lib/twilio_accounts/models/accounts_v1_auth_token_promotion.rb +142 -0
- data/lib/twilio_accounts/models/accounts_v1_bulk_consents.rb +83 -0
- data/lib/twilio_accounts/models/accounts_v1_bulk_contacts.rb +83 -0
- data/lib/twilio_accounts/models/accounts_v1_credential_credential_aws.rb +153 -0
- data/lib/twilio_accounts/models/accounts_v1_credential_credential_public_key.rb +153 -0
- data/lib/twilio_accounts/models/accounts_v1_messaging_geopermissions.rb +86 -0
- data/lib/twilio_accounts/models/accounts_v1_safelist.rb +88 -0
- data/lib/twilio_accounts/models/accounts_v1_secondary_auth_token.rb +145 -0
- data/lib/twilio_accounts/models/base_model.rb +110 -0
- data/lib/twilio_accounts/models/list_credential_aws_response.rb +94 -0
- data/lib/twilio_accounts/models/list_credential_public_key_response.rb +94 -0
- data/lib/twilio_accounts/models/meta.rb +140 -0
- data/lib/twilio_accounts/utilities/date_time_helper.rb +11 -0
- data/lib/twilio_accounts/utilities/file_wrapper.rb +28 -0
- data/lib/twilio_accounts.rb +64 -0
- metadata +125 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# twilio_accounts
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0 (
|
|
4
|
+
# https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TwilioAccounts
|
|
7
|
+
# AccountsV1SafelistApi
|
|
8
|
+
class AccountsV1SafelistApi < BaseApi
|
|
9
|
+
# Add a new phone number or phone number 1k prefix to SafeList.
|
|
10
|
+
# @param [String] phone_number Required parameter: The phone number or phone
|
|
11
|
+
# number 1k prefix to be added in SafeList. Phone numbers must be in [E.164
|
|
12
|
+
# format](https://www.twilio.com/docs/glossary/what-e164).
|
|
13
|
+
# @return [ApiResponse] Complete http response with raw body and status code.
|
|
14
|
+
def create_safelist(phone_number)
|
|
15
|
+
@api_call
|
|
16
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
|
17
|
+
'/v1/SafeList/Numbers',
|
|
18
|
+
Server::DEFAULT)
|
|
19
|
+
.form_param(new_parameter(phone_number, key: 'PhoneNumber')
|
|
20
|
+
.is_required(true))
|
|
21
|
+
.header_param(new_parameter('application/x-www-form-urlencoded', key: 'content-type'))
|
|
22
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
|
23
|
+
.auth(Single.new('accountSid_authToken')))
|
|
24
|
+
.response(new_response_handler
|
|
25
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
|
26
|
+
.deserialize_into(AccountsV1Safelist.method(:from_hash))
|
|
27
|
+
.is_api_response(true))
|
|
28
|
+
.execute
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Check if a phone number or phone number 1k prefix exists in SafeList.
|
|
32
|
+
# @param [String] phone_number Optional parameter: The phone number or phone
|
|
33
|
+
# number 1k prefix to be fetched from SafeList. Phone numbers must be in
|
|
34
|
+
# [E.164 format](https://www.twilio.com/docs/glossary/what-e164).
|
|
35
|
+
# @return [ApiResponse] Complete http response with raw body and status code.
|
|
36
|
+
def fetch_safelist(phone_number: nil)
|
|
37
|
+
@api_call
|
|
38
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
|
39
|
+
'/v1/SafeList/Numbers',
|
|
40
|
+
Server::DEFAULT)
|
|
41
|
+
.query_param(new_parameter(phone_number, key: 'PhoneNumber'))
|
|
42
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
|
43
|
+
.auth(Single.new('accountSid_authToken')))
|
|
44
|
+
.response(new_response_handler
|
|
45
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
|
46
|
+
.deserialize_into(AccountsV1Safelist.method(:from_hash))
|
|
47
|
+
.is_api_response(true))
|
|
48
|
+
.execute
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Remove a phone number or phone number 1k prefix from SafeList.
|
|
52
|
+
# @param [String] phone_number Optional parameter: The phone number or phone
|
|
53
|
+
# number 1k prefix to be removed from SafeList. Phone numbers must be in
|
|
54
|
+
# [E.164 format](https://www.twilio.com/docs/glossary/what-e164).
|
|
55
|
+
# @return [ApiResponse] Complete http response with raw body and status code.
|
|
56
|
+
def delete_safelist(phone_number: nil)
|
|
57
|
+
@api_call
|
|
58
|
+
.request(new_request_builder(HttpMethodEnum::DELETE,
|
|
59
|
+
'/v1/SafeList/Numbers',
|
|
60
|
+
Server::DEFAULT)
|
|
61
|
+
.query_param(new_parameter(phone_number, key: 'PhoneNumber'))
|
|
62
|
+
.auth(Single.new('accountSid_authToken')))
|
|
63
|
+
.response(new_response_handler
|
|
64
|
+
.is_response_void(true)
|
|
65
|
+
.is_api_response(true))
|
|
66
|
+
.execute
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# twilio_accounts
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0 (
|
|
4
|
+
# https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TwilioAccounts
|
|
7
|
+
# AccountsV1SecondaryAuthTokenApi
|
|
8
|
+
class AccountsV1SecondaryAuthTokenApi < BaseApi
|
|
9
|
+
# Create a new secondary Auth Token
|
|
10
|
+
# @return [ApiResponse] Complete http response with raw body and status code.
|
|
11
|
+
def create_secondary_auth_token
|
|
12
|
+
@api_call
|
|
13
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
|
14
|
+
'/v1/AuthTokens/Secondary',
|
|
15
|
+
Server::DEFAULT)
|
|
16
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
|
17
|
+
.auth(Single.new('accountSid_authToken')))
|
|
18
|
+
.response(new_response_handler
|
|
19
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
|
20
|
+
.deserialize_into(AccountsV1SecondaryAuthToken.method(:from_hash))
|
|
21
|
+
.is_api_response(true))
|
|
22
|
+
.execute
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Delete the secondary Auth Token from your account
|
|
26
|
+
# @return [ApiResponse] Complete http response with raw body and status code.
|
|
27
|
+
def delete_secondary_auth_token
|
|
28
|
+
@api_call
|
|
29
|
+
.request(new_request_builder(HttpMethodEnum::DELETE,
|
|
30
|
+
'/v1/AuthTokens/Secondary',
|
|
31
|
+
Server::DEFAULT)
|
|
32
|
+
.auth(Single.new('accountSid_authToken')))
|
|
33
|
+
.response(new_response_handler
|
|
34
|
+
.is_response_void(true)
|
|
35
|
+
.is_api_response(true))
|
|
36
|
+
.execute
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# twilio_accounts
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0 (
|
|
4
|
+
# https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TwilioAccounts
|
|
7
|
+
# BaseApi.
|
|
8
|
+
class BaseApi
|
|
9
|
+
include CoreLibrary
|
|
10
|
+
attr_accessor :config, :http_call_back
|
|
11
|
+
|
|
12
|
+
def self.user_agent
|
|
13
|
+
'Ruby-SDK/1.0.0 (OS: {os-info}, Engine: {engine}/{engine-version})'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.user_agent_parameters
|
|
17
|
+
{
|
|
18
|
+
'{engine}' => { 'value' => RUBY_ENGINE, 'encode' => false },
|
|
19
|
+
'{engine-version}' => { 'value' => RUBY_ENGINE_VERSION, 'encode' => false },
|
|
20
|
+
'{os-info}' => { 'value' => RUBY_PLATFORM, 'encode' => false }
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
GLOBAL_ERRORS = {
|
|
25
|
+
'default' => ErrorCase.new
|
|
26
|
+
.error_message('HTTP response not OK.')
|
|
27
|
+
.exception_type(APIException)
|
|
28
|
+
}.freeze
|
|
29
|
+
|
|
30
|
+
# Initialization constructor.
|
|
31
|
+
# @param [GlobalConfiguration] global_configuration The instance of GlobalConfiguration.
|
|
32
|
+
def initialize(global_configuration)
|
|
33
|
+
@global_configuration = global_configuration
|
|
34
|
+
@config = @global_configuration.client_configuration
|
|
35
|
+
@http_call_back = @config.http_callback
|
|
36
|
+
@api_call = ApiCall.new(@global_configuration)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Creates a new instance of the request builder.
|
|
40
|
+
# @param [String] http_method The HTTP method to use in the request.
|
|
41
|
+
# @param [String] path The endpoint path to use in the request.
|
|
42
|
+
# @param [String] server The server to extract the base uri for the request.
|
|
43
|
+
# @return [RequestBuilder] The instance of RequestBuilder.
|
|
44
|
+
def new_request_builder(http_method, path, server)
|
|
45
|
+
RequestBuilder.new
|
|
46
|
+
.http_method(http_method)
|
|
47
|
+
.path(path)
|
|
48
|
+
.server(server)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Creates a new instance of the response handler.
|
|
52
|
+
# @return [ResponseHandler] The instance of ResponseHandler.
|
|
53
|
+
def new_response_handler
|
|
54
|
+
ResponseHandler.new
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Creates a new instance of the parameter.
|
|
58
|
+
# @param [String|optional] key The key of the parameter.
|
|
59
|
+
# @param [Object] value The value of the parameter.
|
|
60
|
+
# @return [Parameter] The instance of Parameter.
|
|
61
|
+
def new_parameter(value, key: nil)
|
|
62
|
+
Parameter.new
|
|
63
|
+
.key(key)
|
|
64
|
+
.value(value)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# twilio_accounts
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0 (
|
|
4
|
+
# https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TwilioAccounts
|
|
7
|
+
# twilio_accounts client class.
|
|
8
|
+
class Client
|
|
9
|
+
include CoreLibrary
|
|
10
|
+
attr_reader :config, :auth_managers
|
|
11
|
+
|
|
12
|
+
def user_agent_detail
|
|
13
|
+
config.user_agent_detail
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Access to accounts_v1_auth_token_promotion controller.
|
|
17
|
+
# @return [AccountsV1AuthTokenPromotionApi] Returns the controller instance.
|
|
18
|
+
def accounts_v1_auth_token_promotion
|
|
19
|
+
@accounts_v1_auth_token_promotion ||= AccountsV1AuthTokenPromotionApi.new @global_configuration
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Access to accounts_v1_aws controller.
|
|
23
|
+
# @return [AccountsV1AwsApi] Returns the controller instance.
|
|
24
|
+
def accounts_v1_aws
|
|
25
|
+
@accounts_v1_aws ||= AccountsV1AwsApi.new @global_configuration
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Access to accounts_v1_bulk_consents controller.
|
|
29
|
+
# @return [AccountsV1BulkConsentsApi] Returns the controller instance.
|
|
30
|
+
def accounts_v1_bulk_consents
|
|
31
|
+
@accounts_v1_bulk_consents ||= AccountsV1BulkConsentsApi.new @global_configuration
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Access to accounts_v1_bulk_contacts controller.
|
|
35
|
+
# @return [AccountsV1BulkContactsApi] Returns the controller instance.
|
|
36
|
+
def accounts_v1_bulk_contacts
|
|
37
|
+
@accounts_v1_bulk_contacts ||= AccountsV1BulkContactsApi.new @global_configuration
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Access to accounts_v1_messaging_geopermissions controller.
|
|
41
|
+
# @return [AccountsV1MessagingGeopermissionsApi] Returns the controller instance.
|
|
42
|
+
def accounts_v1_messaging_geopermissions
|
|
43
|
+
@accounts_v1_messaging_geopermissions ||= AccountsV1MessagingGeopermissionsApi.new @global_configuration
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Access to accounts_v1_public_key controller.
|
|
47
|
+
# @return [AccountsV1PublicKeyApi] Returns the controller instance.
|
|
48
|
+
def accounts_v1_public_key
|
|
49
|
+
@accounts_v1_public_key ||= AccountsV1PublicKeyApi.new @global_configuration
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Access to accounts_v1_safelist controller.
|
|
53
|
+
# @return [AccountsV1SafelistApi] Returns the controller instance.
|
|
54
|
+
def accounts_v1_safelist
|
|
55
|
+
@accounts_v1_safelist ||= AccountsV1SafelistApi.new @global_configuration
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Access to accounts_v1_secondary_auth_token controller.
|
|
59
|
+
# @return [AccountsV1SecondaryAuthTokenApi] Returns the controller instance.
|
|
60
|
+
def accounts_v1_secondary_auth_token
|
|
61
|
+
@accounts_v1_secondary_auth_token ||= AccountsV1SecondaryAuthTokenApi.new @global_configuration
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def initialize(
|
|
65
|
+
connection: nil, adapter: :net_http_persistent, timeout: 30,
|
|
66
|
+
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
|
67
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
|
68
|
+
retry_methods: %i[get put], http_callback: nil, proxy_settings: nil,
|
|
69
|
+
logging_configuration: nil, environment: Environment::PRODUCTION,
|
|
70
|
+
basic_auth_credentials: nil, config: nil
|
|
71
|
+
)
|
|
72
|
+
@config = if config.nil?
|
|
73
|
+
Configuration.new(
|
|
74
|
+
connection: connection, adapter: adapter, timeout: timeout,
|
|
75
|
+
max_retries: max_retries, retry_interval: retry_interval,
|
|
76
|
+
backoff_factor: backoff_factor,
|
|
77
|
+
retry_statuses: retry_statuses,
|
|
78
|
+
retry_methods: retry_methods, http_callback: http_callback,
|
|
79
|
+
proxy_settings: proxy_settings,
|
|
80
|
+
logging_configuration: logging_configuration,
|
|
81
|
+
environment: environment,
|
|
82
|
+
basic_auth_credentials: basic_auth_credentials
|
|
83
|
+
)
|
|
84
|
+
else
|
|
85
|
+
config
|
|
86
|
+
end
|
|
87
|
+
user_agent_params = BaseApi.user_agent_parameters
|
|
88
|
+
|
|
89
|
+
@global_configuration = GlobalConfiguration.new(client_configuration: @config)
|
|
90
|
+
.base_uri_executor(@config.method(:get_base_uri))
|
|
91
|
+
.global_errors(BaseApi::GLOBAL_ERRORS)
|
|
92
|
+
.user_agent(BaseApi.user_agent,
|
|
93
|
+
agent_parameters: user_agent_params)
|
|
94
|
+
|
|
95
|
+
initialize_auth_managers(@global_configuration)
|
|
96
|
+
@global_configuration = @global_configuration.auth_managers(@auth_managers)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Initializes the auth managers hash used for authenticating API calls.
|
|
100
|
+
# @param [GlobalConfiguration] global_config The global configuration of the SDK)
|
|
101
|
+
def initialize_auth_managers(global_config)
|
|
102
|
+
@auth_managers = {}
|
|
103
|
+
http_client_config = global_config.client_configuration
|
|
104
|
+
%w[accountSid_authToken].each { |auth| @auth_managers[auth] = nil }
|
|
105
|
+
@auth_managers['accountSid_authToken'] = BasicAuth.new(
|
|
106
|
+
http_client_config.basic_auth_credentials
|
|
107
|
+
)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Creates a client directly from environment variables.
|
|
111
|
+
def self.from_env(**overrides)
|
|
112
|
+
default_config = Configuration.build_default_config_from_env
|
|
113
|
+
new_config = default_config.clone_with(**overrides)
|
|
114
|
+
new(config: new_config)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# twilio_accounts
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0 (
|
|
4
|
+
# https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TwilioAccounts
|
|
7
|
+
# An enum for SDK environments.
|
|
8
|
+
class Environment
|
|
9
|
+
ENVIRONMENT = [
|
|
10
|
+
PRODUCTION = 'production'.freeze
|
|
11
|
+
].freeze
|
|
12
|
+
|
|
13
|
+
# Converts a string or symbol into a valid Environment constant.
|
|
14
|
+
def self.from_value(value, default_value = PRODUCTION)
|
|
15
|
+
return default_value if value.nil?
|
|
16
|
+
|
|
17
|
+
default_value
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# An enum for API servers.
|
|
22
|
+
class Server
|
|
23
|
+
SERVER = [
|
|
24
|
+
DEFAULT = 'default'.freeze
|
|
25
|
+
].freeze
|
|
26
|
+
|
|
27
|
+
# Converts a string or symbol into a valid Server constant.
|
|
28
|
+
def self.from_value(value, default_value = DEFAULT)
|
|
29
|
+
return default_value if value.nil?
|
|
30
|
+
|
|
31
|
+
default_value
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# All configuration including auth info and base URI for the API access
|
|
36
|
+
# are configured in this class.
|
|
37
|
+
class Configuration < CoreLibrary::HttpClientConfiguration
|
|
38
|
+
# The attribute readers for properties.
|
|
39
|
+
attr_reader :environment, :basic_auth_credentials
|
|
40
|
+
|
|
41
|
+
class << self
|
|
42
|
+
attr_reader :environments
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def initialize(
|
|
46
|
+
connection: nil, adapter: :net_http_persistent, timeout: 30,
|
|
47
|
+
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
|
48
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
|
49
|
+
retry_methods: %i[get put], http_callback: nil, proxy_settings: nil,
|
|
50
|
+
logging_configuration: nil, environment: Environment::PRODUCTION,
|
|
51
|
+
basic_auth_credentials: nil
|
|
52
|
+
)
|
|
53
|
+
super connection: connection, adapter: adapter, timeout: timeout,
|
|
54
|
+
max_retries: max_retries, retry_interval: retry_interval,
|
|
55
|
+
backoff_factor: backoff_factor, retry_statuses: retry_statuses,
|
|
56
|
+
retry_methods: retry_methods, http_callback: http_callback,
|
|
57
|
+
proxy_settings: proxy_settings,
|
|
58
|
+
logging_configuration: logging_configuration
|
|
59
|
+
|
|
60
|
+
# Current API environment
|
|
61
|
+
@environment = String(environment)
|
|
62
|
+
|
|
63
|
+
# The object holding Basic Authentication credentials
|
|
64
|
+
@basic_auth_credentials = basic_auth_credentials
|
|
65
|
+
|
|
66
|
+
# Initializing Basic Authentication credentials with the provided auth parameters
|
|
67
|
+
@basic_auth_credentials = basic_auth_credentials
|
|
68
|
+
|
|
69
|
+
# The Http Client to use for making requests.
|
|
70
|
+
set_http_client CoreLibrary::FaradayClient.new(self)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def clone_with(connection: nil, adapter: nil, timeout: nil,
|
|
74
|
+
max_retries: nil, retry_interval: nil, backoff_factor: nil,
|
|
75
|
+
retry_statuses: nil, retry_methods: nil, http_callback: nil,
|
|
76
|
+
proxy_settings: nil, logging_configuration: nil,
|
|
77
|
+
environment: nil, basic_auth_credentials: nil)
|
|
78
|
+
connection ||= self.connection
|
|
79
|
+
adapter ||= self.adapter
|
|
80
|
+
timeout ||= self.timeout
|
|
81
|
+
max_retries ||= self.max_retries
|
|
82
|
+
retry_interval ||= self.retry_interval
|
|
83
|
+
backoff_factor ||= self.backoff_factor
|
|
84
|
+
retry_statuses ||= self.retry_statuses
|
|
85
|
+
retry_methods ||= self.retry_methods
|
|
86
|
+
http_callback ||= self.http_callback
|
|
87
|
+
proxy_settings ||= self.proxy_settings
|
|
88
|
+
logging_configuration ||= self.logging_configuration
|
|
89
|
+
environment ||= self.environment
|
|
90
|
+
basic_auth_credentials ||= self.basic_auth_credentials
|
|
91
|
+
|
|
92
|
+
Configuration.new(connection: connection, adapter: adapter,
|
|
93
|
+
timeout: timeout, max_retries: max_retries,
|
|
94
|
+
retry_interval: retry_interval,
|
|
95
|
+
backoff_factor: backoff_factor,
|
|
96
|
+
retry_statuses: retry_statuses,
|
|
97
|
+
retry_methods: retry_methods,
|
|
98
|
+
http_callback: http_callback,
|
|
99
|
+
proxy_settings: proxy_settings,
|
|
100
|
+
logging_configuration: logging_configuration,
|
|
101
|
+
environment: environment,
|
|
102
|
+
basic_auth_credentials: basic_auth_credentials)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# All the environments the SDK can run in.
|
|
107
|
+
ENVIRONMENTS = {
|
|
108
|
+
Environment::PRODUCTION => {
|
|
109
|
+
Server::DEFAULT => 'https://accounts.twilio.com'
|
|
110
|
+
}
|
|
111
|
+
}.freeze
|
|
112
|
+
|
|
113
|
+
# Generates the appropriate base URI for the environment and the server.
|
|
114
|
+
# @param [Configuration::Server] server The server enum for which the base URI is
|
|
115
|
+
# required.
|
|
116
|
+
# @return [String] The base URI.
|
|
117
|
+
def get_base_uri(server = Server::DEFAULT)
|
|
118
|
+
ENVIRONMENTS[environment][server].clone
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Builds a Configuration instance using environment variables.
|
|
122
|
+
def self.build_default_config_from_env
|
|
123
|
+
# === Core environment ===
|
|
124
|
+
environment = Environment.from_value(ENV.fetch('ENVIRONMENT', 'production'))
|
|
125
|
+
timeout = (ENV['TIMEOUT'] || 30).to_f
|
|
126
|
+
max_retries = (ENV['MAX_RETRIES'] || 0).to_i
|
|
127
|
+
retry_interval = (ENV['RETRY_INTERVAL'] || 1).to_f
|
|
128
|
+
backoff_factor = (ENV['BACKOFF_FACTOR'] || 2).to_f
|
|
129
|
+
retry_statuses = ENV.fetch('RETRY_STATUSES',
|
|
130
|
+
'[408, 413, 429, 500, 502, 503, 504, 521, 522, 524]').gsub(/[\[\]]/, '')
|
|
131
|
+
.split(',')
|
|
132
|
+
.map(&:strip)
|
|
133
|
+
.map do |item|
|
|
134
|
+
item.match?(/\A\d+\z/) ? item.to_i : item.downcase
|
|
135
|
+
end
|
|
136
|
+
retry_methods = ENV.fetch('RETRY_METHODS', '%i[get put]').gsub(/[\[\]]/, '')
|
|
137
|
+
.split(',')
|
|
138
|
+
.map(&:strip)
|
|
139
|
+
.map do |item|
|
|
140
|
+
item.match?(/\A\d+\z/) ? item.to_i : item.downcase
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# === Authentication credentials ===
|
|
144
|
+
basic_auth_credentials = BasicAuthCredentials.from_env
|
|
145
|
+
|
|
146
|
+
# === Proxy settings ===
|
|
147
|
+
proxy_settings = ProxySettings.from_env
|
|
148
|
+
# === Logging Configuration ===
|
|
149
|
+
logging_configuration = LoggingConfiguration.from_env if LoggingConfiguration.any_logging_configured?
|
|
150
|
+
|
|
151
|
+
Configuration.new(
|
|
152
|
+
environment: environment,
|
|
153
|
+
timeout: timeout,
|
|
154
|
+
max_retries: max_retries,
|
|
155
|
+
retry_interval: retry_interval,
|
|
156
|
+
backoff_factor: backoff_factor,
|
|
157
|
+
retry_statuses: retry_statuses,
|
|
158
|
+
retry_methods: retry_methods,
|
|
159
|
+
basic_auth_credentials: basic_auth_credentials,
|
|
160
|
+
proxy_settings: proxy_settings,
|
|
161
|
+
logging_configuration: logging_configuration
|
|
162
|
+
)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# twilio_accounts
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0 (
|
|
4
|
+
# https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TwilioAccounts
|
|
7
|
+
# Class for exceptions when there is a network error, status code error, etc.
|
|
8
|
+
class APIException < CoreLibrary::ApiException
|
|
9
|
+
# Provides a human-readable string representation of the object.
|
|
10
|
+
def to_s
|
|
11
|
+
class_name = self.class.name.split('::').last
|
|
12
|
+
"<#{class_name} status_code: #{@response_code}, reason: #{@reason}>"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Provides a debugging-friendly string with detailed object information.
|
|
16
|
+
def inspect
|
|
17
|
+
class_name = self.class.name.split('::').last
|
|
18
|
+
"<#{class_name} status_code: #{@response_code.inspect}, reason: #{@reason.inspect}>"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# twilio_accounts
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0 (
|
|
4
|
+
# https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TwilioAccounts
|
|
7
|
+
# Http response received.
|
|
8
|
+
class ApiResponse < CoreLibrary::ApiResponse
|
|
9
|
+
# The constructor
|
|
10
|
+
# @param [HttpResponse] http_response The original, raw response from the api.
|
|
11
|
+
# @param [Object] data The data field specified for the response.
|
|
12
|
+
# @param [Array<String>] errors Any errors returned by the server.
|
|
13
|
+
def initialize(http_response,
|
|
14
|
+
data: nil,
|
|
15
|
+
errors: nil)
|
|
16
|
+
super
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# twilio_accounts
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0 (
|
|
4
|
+
# https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TwilioAccounts
|
|
7
|
+
# Utility class for basic authorization.
|
|
8
|
+
class BasicAuth < CoreLibrary::HeaderAuth
|
|
9
|
+
include CoreLibrary
|
|
10
|
+
# Display error message on occurrence of authentication failure.
|
|
11
|
+
# @returns [String] The oAuth error message.
|
|
12
|
+
def error_message
|
|
13
|
+
'BasicAuth: basic_auth_user_name or basic_auth_password is undefined.'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Initialization constructor.
|
|
17
|
+
def initialize(basic_auth_credentials)
|
|
18
|
+
auth_params = {}
|
|
19
|
+
unless basic_auth_credentials.nil? ||
|
|
20
|
+
basic_auth_credentials.username.nil? ||
|
|
21
|
+
basic_auth_credentials.password.nil?
|
|
22
|
+
auth_params['Authorization'] =
|
|
23
|
+
"Basic #{AuthHelper.get_base64_encoded_value(basic_auth_credentials.username,
|
|
24
|
+
basic_auth_credentials.password)}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
super auth_params
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Data class for BasicAuthCredentials.
|
|
32
|
+
class BasicAuthCredentials
|
|
33
|
+
attr_reader :username, :password
|
|
34
|
+
|
|
35
|
+
def initialize(username:, password:)
|
|
36
|
+
raise ArgumentError, 'username cannot be nil' if username.nil?
|
|
37
|
+
raise ArgumentError, 'password cannot be nil' if password.nil?
|
|
38
|
+
|
|
39
|
+
@username = username
|
|
40
|
+
@password = password
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.from_env
|
|
44
|
+
username = ENV['USERNAME']
|
|
45
|
+
password = ENV['PASSWORD']
|
|
46
|
+
all_nil = [
|
|
47
|
+
username,
|
|
48
|
+
password
|
|
49
|
+
].all?(&:nil?)
|
|
50
|
+
return nil if all_nil
|
|
51
|
+
|
|
52
|
+
new(username: username, password: password)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def clone_with(username: nil, password: nil)
|
|
56
|
+
username ||= self.username
|
|
57
|
+
password ||= self.password
|
|
58
|
+
|
|
59
|
+
BasicAuthCredentials.new(username: username, password: password)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# twilio_accounts
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0 (
|
|
4
|
+
# https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TwilioAccounts
|
|
7
|
+
# HttpCallBack allows defining callables for pre and post API calls.
|
|
8
|
+
class HttpCallBack < CoreLibrary::HttpCallback
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# twilio_accounts
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0 (
|
|
4
|
+
# https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TwilioAccounts
|
|
7
|
+
##
|
|
8
|
+
# ProxySettings encapsulates HTTP proxy configuration for Faraday,
|
|
9
|
+
# including optional basic authentication.
|
|
10
|
+
#
|
|
11
|
+
class ProxySettings < CoreLibrary::ProxySettings
|
|
12
|
+
def self.from_env
|
|
13
|
+
address = ENV['PROXY_ADDRESS']
|
|
14
|
+
port = ENV['PROXY_PORT']
|
|
15
|
+
username = ENV['PROXY_USERNAME']
|
|
16
|
+
password = ENV['PROXY_PASSWORD']
|
|
17
|
+
return nil if address.nil? || address.strip.empty?
|
|
18
|
+
|
|
19
|
+
new(address: address, port: port, username: username, password: password)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|