Skip to content

Instantly share code, notes, and snippets.

@shrutiburman
Created January 29, 2023 17:46
Show Gist options
  • Save shrutiburman/5f1c644ec67589de964eb9fb45f9b137 to your computer and use it in GitHub Desktop.
Save shrutiburman/5f1c644ec67589de964eb9fb45f9b137 to your computer and use it in GitHub Desktop.
##
# This code was generated by
# ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
# | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
# | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
#
# Twilio - Api
# This is the public Twilio REST API.
#
# NOTE: This class is auto generated by OpenAPI Generator.
# https://openapi-generator.tech
# Do not edit the class manually.
#
module Twilio
module REST
class Api < Domain
class V2010 < Version
class AccountList < ListResource
##
# Initialize the AccountList
# @param [Version] version Version that contains the resource
# @return [AccountList] AccountList
def initialize(version)
super(version)
# Path Solution
@solution = { }
@uri = "/Accounts.json"
end
##
# Create the AccountInstance
# @param [String] friendly_name A human readable description of the account to create, defaults to &#x60;SubAccount Created at {YYYY-MM-DD HH:MM meridian}&#x60;
# @return [AccountInstance] Created AccountInstance
def create(friendly_name: :unset
)
data = Twilio::Values.of(
'FriendlyName' => friendly_name,
})
payload = @version.create('POST', @uri, data: data)
AccountInstance.new(@version, payload, )
end
##
# Lists AccountInstance records from the API as a list.
# Unlike stream(), this operation is eager and will load `limit` records into
# memory before returning.
# @param [String] friendly_name Only return the Account resources with friendly names that exactly match this name.
# @param [AccountStatus] status Only return Account resources with the given status. Can be &#x60;closed&#x60;, &#x60;suspended&#x60; or &#x60;active&#x60;.
# @param [Integer] limit Upper limit for the number of records to return. stream()
# guarantees to never return more than limit. Default is no limit
# @param [Integer] page_size Number of records to fetch per request, when
# not set will use the default value of 50 records. If no page_size is defined
# but a limit is defined, stream() will attempt to read the limit with the most
# efficient page size, i.e. min(limit, 1000)
# @return [Array] Array of up to limit results
def list(friendly_name: :unset,status: :unset, limit: nil, page_size: nil)
self.stream(
friendly_name: friendly_name,
status: status,
limit: limit,
page_size: page_size
).entries
end
##
# Streams Instance records from the API as an Enumerable.
# This operation lazily loads records as efficiently as possible until the limit
# is reached.
# @param [String] friendly_name Only return the Account resources with friendly names that exactly match this name.
# @param [AccountStatus] status Only return Account resources with the given status. Can be &#x60;closed&#x60;, &#x60;suspended&#x60; or &#x60;active&#x60;.
# @param [Integer] limit Upper limit for the number of records to return. stream()
# guarantees to never return more than limit. Default is no limit
# @param [Integer] page_size Number of records to fetch per request, when
# not set will use the default value of 50 records. If no page_size is defined
# but a limit is defined, stream() will attempt to read the limit with the most
# efficient page size, i.e. min(limit, 1000)
# @return [Enumerable] Enumerable that will yield up to limit results
def stream(friendly_name: :unset,status: :unset, limit: nil, page_size: nil)
limits = @version.read_limits(limit, page_size)
page = self.page(
friendly_name: friendly_name,
status: status,
page_size: limits[:page_size], )
@version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
end
##
# When passed a block, yields AccountInstance records from the API.
# This operation lazily loads records as efficiently as possible until the limit
# is reached.
def each
limits = @version.read_limits
page = self.page(page_size: limits[:page_size], )
@version.stream(page,
limit: limits[:limit],
page_limit: limits[:page_limit]).each {|x| yield x}
end
##
# Retrieve a single page of AccountInstance records from the API.
# Request is executed immediately.
# @param [String] friendly_name Only return the Account resources with friendly names that exactly match this name.
# @param [AccountStatus] status Only return Account resources with the given status. Can be &#x60;closed&#x60;, &#x60;suspended&#x60; or &#x60;active&#x60;.
# @param [String] page_token PageToken provided by the API
# @param [Integer] page_number Page Number, this value is simply for client state
# @param [Integer] page_size Number of records to return, defaults to 50
# @return [Page] Page of AccountInstance
def page(friendly_name: :unset,status: :unset, page_token: :unset, page_number: :unset, page_size: :unset)
params = Twilio::Values.of({
'FriendlyName' => friendly_name,
'Status' => status,
'PageToken' => page_token,
'Page' => page_number,
'PageSize' => page_size,
})
response = @version.page('GET', @uri, params: params)
AccountPage.new(@version, response, @solution)
end
##
# Retrieve a single page of AccountInstance records from the API.
# Request is executed immediately.
# @param [String] target_url API-generated URL for the requested results page
# @return [Page] Page of AccountInstance
def get_page(target_url)
response = @version.domain.request(
'GET',
target_url
)
AccountPage.new(@version, response, @solution)
end
##
# Provide a user friendly representation
def to_s
'#<Twilio.Api.V2010.AccountList>'
end
end
##
# PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact help@twilio.com.
class AccountContext < InstanceContext
##
# Initialize the AccountContext
# @param [Version] version Version that contains the resource
# @param [String] sid The Account Sid that uniquely identifies the account to update
# @return [AccountContext] AccountContext
def initialize(version, sid)
super(version)
# Path Solution
@solution = { sid: sid, }
@uri = "/Accounts/#{@solution[:sid]}.json"
# Dependents
@recordings = nil
@usage = nil
@messages = nil
@keys = nil
@new_keys = nil
@applications = nil
@incoming_phone_numbers = nil
@conferences = nil
@calls = nil
@outgoing_caller_ids = nil
@validation_requests = nil
@transcriptions = nil
@connect_apps = nil
@authorized_connect_apps = nil
@tokens = nil
@balance = nil
@sip = nil
@notifications = nil
@available_phone_numbers = nil
@addresses = nil
@queues = nil
@short_codes = nil
@signing_keys = nil
@new_signing_keys = nil
end
##
#
# Fetch the AccountInstance
# @return [AccountInstance] Fetched AccountInstance
def fetch
payload = @version.fetch('GET',@uri )
AccountInstance.new(@version, payload, )
end
##
#
# Update the AccountInstance
# @param [String] friendly_name Update the human-readable description of this Account
# @param [AccountStatus] status
# @return [AccountInstance] Updated AccountInstance
def update(friendly_name: :unset , status: :unset )
data = Twilio::Values.of({
'FriendlyName' => friendly_name,
'Status' => status,
})
payload = @version.update('POST',@uri, data: data )
AccountInstance.new(@version, payload, )
end
##
# Access the applications
# @return [ApplicationsList]
# @return [ApplicationContext] if sid was passed.
def applications(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return ApplicationsContext.new(@version,sid )
end
unless @applications
@applications = ApplicationList.new(
@version
)
end
@applications
end
##
# Access the recordings
# @return [RecordingsList]
# @return [RecordingContext] if sid was passed.
def recordings(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return RecordingsContext.new(@version,sid )
end
unless @recordings
@recordings = RecordingList.new(
@version
)
end
@recordings
end
##
# Access the connect_apps
# @return [Connect_appsList]
# @return [Connect_appContext] if sid was passed.
def connect_apps(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return Connect_appsContext.new(@version,sid )
end
unless @connect_apps
@connect_apps = Connect_appList.new(
@version
)
end
@connect_apps
end
##
# Access the calls
# @return [CallsList]
# @return [CallContext] if sid was passed.
def calls(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return CallsContext.new(@version,sid )
end
unless @calls
@calls = CallList.new(
@version
)
end
@calls
end
##
# Access the signing_keys
# @return [Signing_keysList]
# @return [Signing_keyContext] if sid was passed.
def signing_keys(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return Signing_keysContext.new(@version,sid )
end
unless @signing_keys
@signing_keys = Signing_keyList.new(
@version
)
end
@signing_keys
end
##
# Access the outgoing_caller_ids
# @return [Outgoing_caller_idsList]
# @return [Outgoing_caller_idContext] if sid was passed.
def outgoing_caller_ids(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return Outgoing_caller_idsContext.new(@version,sid )
end
unless @outgoing_caller_ids
@outgoing_caller_ids = Outgoing_caller_idList.new(
@version
)
end
@outgoing_caller_ids
end
##
# Access the short_codes
# @return [Short_codesList]
# @return [Short_codeContext] if sid was passed.
def short_codes(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return Short_codesContext.new(@version,sid )
end
unless @short_codes
@short_codes = Short_codeList.new(
@version
)
end
@short_codes
end
##
# Access the incoming_phone_numbers
# @return [Incoming_phone_numbersList]
# @return [Incoming_phone_numberContext] if sid was passed.
def incoming_phone_numbers(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return Incoming_phone_numbersContext.new(@version,sid )
end
unless @incoming_phone_numbers
@incoming_phone_numbers = Incoming_phone_numberList.new(
@version
)
end
@incoming_phone_numbers
end
##
# Access the queues
# @return [QueuesList]
# @return [QueueContext] if sid was passed.
def queues(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return QueuesContext.new(@version,sid )
end
unless @queues
@queues = QueueList.new(
@version
)
end
@queues
end
##
# Access the authorized_connect_apps
# @return [Authorized_connect_appsList]
# @return [Authorized_connect_appContext] if sid was passed.
def authorized_connect_apps(connect_app_sid=:unset)
raise ArgumentError, 'connect_app_sid cannot be nil' if connect_app_sid.nil?
if connect_app_sid != :unset
return Authorized_connect_appsContext.new(@version,connect_app_sid )
end
unless @authorized_connect_apps
@authorized_connect_apps = Authorized_connect_appList.new(
@version
)
end
@authorized_connect_apps
end
##
# Access the available_phone_numbers
# @return [Available_phone_numbersList]
# @return [Available_phone_number_countryContext] if sid was passed.
def available_phone_numbers(country_code=:unset)
raise ArgumentError, 'country_code cannot be nil' if country_code.nil?
if country_code != :unset
return Available_phone_numbersContext.new(@version,country_code )
end
unless @available_phone_numbers
@available_phone_numbers = Available_phone_number_countryList.new(
@version
)
end
@available_phone_numbers
end
##
# Access the addresses
# @return [AddressesList]
# @return [AddressContext] if sid was passed.
def addresses(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return AddressesContext.new(@version,sid )
end
unless @addresses
@addresses = AddressList.new(
@version
)
end
@addresses
end
##
# Access the transcriptions
# @return [TranscriptionsList]
# @return [TranscriptionContext] if sid was passed.
def transcriptions(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return TranscriptionsContext.new(@version,sid )
end
unless @transcriptions
@transcriptions = TranscriptionList.new(
@version
)
end
@transcriptions
end
##
# Access the conferences
# @return [ConferencesList]
# @return [ConferenceContext] if sid was passed.
def conferences(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return ConferencesContext.new(@version,sid )
end
unless @conferences
@conferences = ConferenceList.new(
@version
)
end
@conferences
end
##
# Access the keys
# @return [KeysList]
# @return [KeyContext] if sid was passed.
def keys(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return KeysContext.new(@version,sid )
end
unless @keys
@keys = KeyList.new(
@version
)
end
@keys
end
##
# Access the notifications
# @return [NotificationsList]
# @return [NotificationContext] if sid was passed.
def notifications(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return NotificationsContext.new(@version,sid )
end
unless @notifications
@notifications = NotificationList.new(
@version
)
end
@notifications
end
##
# Access the messages
# @return [MessagesList]
# @return [MessageContext] if sid was passed.
def messages(sid=:unset)
raise ArgumentError, 'sid cannot be nil' if sid.nil?
if sid != :unset
return MessagesContext.new(@version,sid )
end
unless @messages
@messages = MessageList.new(
@version
)
end
@messages
end
##
# Provide a user friendly representation
def to_s
context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
"#<Twilio.Api.V2010.AccountContext #{context}>"
end
##
# Provide a detailed, user friendly representation
def inspect
context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
"#<Twilio.Api.V2010.AccountContext #{context}>"
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment