From 763564633a945d894e9c5da9fe8a3d1d2b331b60 Mon Sep 17 00:00:00 2001 From: Manisha Singh Date: Mon, 9 Dec 2024 13:12:54 +0530 Subject: [PATCH] feat: auth ruby (#734) --- .../auth_strategy/token_auth_strategy.rb | 3 +- lib/twilio-ruby/framework/rest/page.rb | 1 + .../rest/preview_iam/versionless.rb | 49 -- .../preview_iam/versionless/organization.rb | 273 ---------- .../versionless/organization/account.rb | 302 ----------- .../organization/role_assignment.rb | 364 ------------- .../versionless/organization/user.rb | 511 ------------------ 7 files changed, 3 insertions(+), 1500 deletions(-) delete mode 100644 lib/twilio-ruby/rest/preview_iam/versionless.rb delete mode 100644 lib/twilio-ruby/rest/preview_iam/versionless/organization.rb delete mode 100644 lib/twilio-ruby/rest/preview_iam/versionless/organization/account.rb delete mode 100644 lib/twilio-ruby/rest/preview_iam/versionless/organization/role_assignment.rb delete mode 100644 lib/twilio-ruby/rest/preview_iam/versionless/organization/user.rb diff --git a/lib/twilio-ruby/auth_strategy/token_auth_strategy.rb b/lib/twilio-ruby/auth_strategy/token_auth_strategy.rb index ff9071b66..8de4a5147 100644 --- a/lib/twilio-ruby/auth_strategy/token_auth_strategy.rb +++ b/lib/twilio-ruby/auth_strategy/token_auth_strategy.rb @@ -1,5 +1,6 @@ require_relative 'auth_strategy' require_relative './../credential/auth_type' +require 'jwt' module Twilio module REST class TokenAuthStrategy < AuthStrategy @@ -25,7 +26,7 @@ def fetch_token end def token_expired? - decoded_token = JWT.decode(@token, nil, false) + decoded_token = ::JWT.decode(@token, nil, false) exp = decoded_token[0]['exp'] Time.at(exp) < Time.now end diff --git a/lib/twilio-ruby/framework/rest/page.rb b/lib/twilio-ruby/framework/rest/page.rb index e3212314a..d027e5b6f 100644 --- a/lib/twilio-ruby/framework/rest/page.rb +++ b/lib/twilio-ruby/framework/rest/page.rb @@ -38,6 +38,7 @@ def process_response(response) end def load_page(payload) + return payload['Resources'] if payload['Resources'] if payload['meta'] && payload['meta']['key'] return payload[payload['meta']['key']] else diff --git a/lib/twilio-ruby/rest/preview_iam/versionless.rb b/lib/twilio-ruby/rest/preview_iam/versionless.rb deleted file mode 100644 index 17c1ed12a..000000000 --- a/lib/twilio-ruby/rest/preview_iam/versionless.rb +++ /dev/null @@ -1,49 +0,0 @@ -## -# This code was generated by -# ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ -# | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ -# | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ -# -# Organization Public API -# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) -# -# NOTE: This class is auto generated by OpenAPI Generator. -# https://openapi-generator.tech -# Do not edit the class manually. -# - -module Twilio - module REST - class PreviewIam - class Versionless < Version - ## - # Initialize the Versionless version of PreviewIam - def initialize(domain) - super - @version = 'Organizations' - @organization = nil - end - - ## - # @param [String] organization_sid - # @return [Twilio::REST::PreviewIam::Versionless::OrganizationContext] if organizationSid was passed. - # @return [Twilio::REST::PreviewIam::Versionless::OrganizationList] - def organization(organization_sid=:unset) - if organization_sid.nil? - raise ArgumentError, 'organization_sid cannot be nil' - end - if organization_sid == :unset - @organization ||= OrganizationList.new self - else - OrganizationContext.new(self, organization_sid) - end - end - ## - # Provide a user friendly representation - def to_s - ''; - end - end - end - end -end diff --git a/lib/twilio-ruby/rest/preview_iam/versionless/organization.rb b/lib/twilio-ruby/rest/preview_iam/versionless/organization.rb deleted file mode 100644 index 3a06eec6e..000000000 --- a/lib/twilio-ruby/rest/preview_iam/versionless/organization.rb +++ /dev/null @@ -1,273 +0,0 @@ -## -# This code was generated by -# ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ -# | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ -# | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ -# -# Organization Public API -# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) -# -# NOTE: This class is auto generated by OpenAPI Generator. -# https://openapi-generator.tech -# Do not edit the class manually. -# - - -module Twilio - module REST - class PreviewIam < PreviewIamBase - class Versionless < Version - class OrganizationList < ListResource - - ## - # Initialize the OrganizationList - # @param [Version] version Version that contains the resource - # @return [OrganizationList] OrganizationList - def initialize(version) - super(version) - # Path Solution - @solution = { } - - - end - - - - # Provide a user friendly representation - def to_s - '#' - end - end - - - class OrganizationContext < InstanceContext - ## - # Initialize the OrganizationContext - # @param [Version] version Version that contains the resource - # @param [String] organization_sid - # @return [OrganizationContext] OrganizationContext - def initialize(version, organization_sid) - super(version) - - # Path Solution - @solution = { organization_sid: organization_sid, } - @uri = "/#{@solution[:organization_sid]}" - - # Dependents - @resource_types = nil - @role_assignments = nil - @accounts = nil - @users = nil - end - ## - # Fetch the OrganizationInstance - # @return [OrganizationInstance] Fetched OrganizationInstance - def fetch - - headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', }) - - payload = @version.fetch('GET', @uri, headers: headers) - OrganizationInstance.new( - @version, - payload, - organization_sid: @solution[:organization_sid], - ) - end - - ## - # Access the resource_types - # @return [ResourceTypeList] - # @return [ResourceTypeContext] - def resource_types - unless @resource_types - @resource_types = ResourceTypeList.new( - @version, ) - end - @resource_types - end - ## - # Access the role_assignments - # @return [RoleAssignmentList] - # @return [RoleAssignmentContext] if sid was passed. - def role_assignments(role_assignment_sid=:unset) - - raise ArgumentError, 'role_assignment_sid cannot be nil' if role_assignment_sid.nil? - - if role_assignment_sid != :unset - return RoleAssignmentContext.new(@version, @solution[:organization_sid],role_assignment_sid ) - end - - unless @role_assignments - @role_assignments = RoleAssignmentList.new( - @version, ) - end - - @role_assignments - end - ## - # Access the accounts - # @return [AccountList] - # @return [AccountContext] if sid was passed. - def accounts(account_sid=:unset) - - raise ArgumentError, 'account_sid cannot be nil' if account_sid.nil? - - if account_sid != :unset - return AccountContext.new(@version, @solution[:organization_sid],account_sid ) - end - - unless @accounts - @accounts = AccountList.new( - @version, organization_sid: @solution[:organization_sid], ) - end - - @accounts - end - ## - # Access the users - # @return [UserList] - # @return [UserContext] if sid was passed. - def users(user_sid=:unset) - - raise ArgumentError, 'user_sid cannot be nil' if user_sid.nil? - - if user_sid != :unset - return UserContext.new(@version, @solution[:organization_sid],user_sid ) - end - - unless @users - @users = UserList.new( - @version, organization_sid: @solution[:organization_sid], ) - end - - @users - end - - ## - # Provide a user friendly representation - def to_s - context = @solution.map{|k, v| "#{k}: #{v}"}.join(',') - "#" - end - - ## - # Provide a detailed, user friendly representation - def inspect - context = @solution.map{|k, v| "#{k}: #{v}"}.join(',') - "#" - end - end - - class OrganizationPage < Page - ## - # Initialize the OrganizationPage - # @param [Version] version Version that contains the resource - # @param [Response] response Response from the API - # @param [Hash] solution Path solution for the resource - # @return [OrganizationPage] OrganizationPage - def initialize(version, response, solution) - super(version, response) - - # Path Solution - @solution = solution - end - - ## - # Build an instance of OrganizationInstance - # @param [Hash] payload Payload response from the API - # @return [OrganizationInstance] OrganizationInstance - def get_instance(payload) - OrganizationInstance.new(@version, payload) - end - - ## - # Provide a user friendly representation - def to_s - '' - end - end - class OrganizationInstance < InstanceResource - ## - # Initialize the OrganizationInstance - # @param [Version] version Version that contains the resource - # @param [Hash] payload payload that contains response from Twilio - # @param [String] account_sid The SID of the - # {Account}[https://www.twilio.com/docs/iam/api/account] that created this Organization - # resource. - # @param [String] sid The SID of the Call resource to fetch. - # @return [OrganizationInstance] OrganizationInstance - def initialize(version , organization_sid: nil) - super(version) - - - # Context - @instance_context = nil - @params = { 'organization_sid' => organization_sid || @properties['organization_sid'] , } - end - - ## - # Generate an instance context for the instance, the context is capable of - # performing various actions. All instance actions are proxied to the context - # @return [OrganizationContext] CallContext for this CallInstance - def context - unless @instance_context - @instance_context = OrganizationContext.new(@version , @params['organization_sid']) - end - @instance_context - end - - ## - # Fetch the OrganizationInstance - # @return [OrganizationInstance] Fetched OrganizationInstance - def fetch - - context.fetch - end - - ## - # Access the resource_types - # @return [resource_types] resource_types - def resource_types - context.resource_types - end - - ## - # Access the role_assignments - # @return [role_assignments] role_assignments - def role_assignments - context.role_assignments - end - - ## - # Access the accounts - # @return [accounts] accounts - def accounts - context.accounts - end - - ## - # Access the users - # @return [users] users - def users - context.users - end - - ## - # Provide a user friendly representation - def to_s - values = @params.map{|k, v| "#{k}: #{v}"}.join(" ") - "" - end - - ## - # Provide a detailed, user friendly representation - def inspect - values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ") - "" - end - end - - end - end - end -end diff --git a/lib/twilio-ruby/rest/preview_iam/versionless/organization/account.rb b/lib/twilio-ruby/rest/preview_iam/versionless/organization/account.rb deleted file mode 100644 index da2144194..000000000 --- a/lib/twilio-ruby/rest/preview_iam/versionless/organization/account.rb +++ /dev/null @@ -1,302 +0,0 @@ -## -# This code was generated by -# ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ -# | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ -# | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ -# -# Organization Public API -# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) -# -# NOTE: This class is auto generated by OpenAPI Generator. -# https://openapi-generator.tech -# Do not edit the class manually. -# - - -module Twilio - module REST - class PreviewIam < PreviewIamBase - class Versionless < Version - class OrganizationContext < InstanceContext - - class AccountList < ListResource - - ## - # Initialize the AccountList - # @param [Version] version Version that contains the resource - # @return [AccountList] AccountList - def initialize(version, organization_sid: nil) - super(version) - # Path Solution - @solution = { organization_sid: organization_sid } - @uri = "/#{@solution[:organization_sid]}/Accounts" - - 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 [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(limit: nil, page_size: nil) - self.stream( - 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 [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(limit: nil, page_size: nil) - limits = @version.read_limits(limit, page_size) - - page = self.page( - 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] 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(page_token: :unset, page_number: :unset, page_size: :unset) - params = Twilio::Values.of({ - '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 - '#' - end - end - - - class AccountContext < InstanceContext - ## - # Initialize the AccountContext - # @param [Version] version Version that contains the resource - # @param [String] organization_sid - # @param [String] account_sid - # @return [AccountContext] AccountContext - def initialize(version, organization_sid, account_sid) - super(version) - - # Path Solution - @solution = { organization_sid: organization_sid, account_sid: account_sid, } - @uri = "/#{@solution[:organization_sid]}/Accounts/#{@solution[:account_sid]}" - - - end - ## - # Fetch the AccountInstance - # @return [AccountInstance] Fetched AccountInstance - def fetch - - headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', }) - - payload = @version.fetch('GET', @uri, headers: headers) - AccountInstance.new( - @version, - payload, - organization_sid: @solution[:organization_sid], - account_sid: @solution[:account_sid], - ) - end - - - ## - # Provide a user friendly representation - def to_s - context = @solution.map{|k, v| "#{k}: #{v}"}.join(',') - "#" - end - - ## - # Provide a detailed, user friendly representation - def inspect - context = @solution.map{|k, v| "#{k}: #{v}"}.join(',') - "#" - end - end - - class AccountPage < Page - ## - # Initialize the AccountPage - # @param [Version] version Version that contains the resource - # @param [Response] response Response from the API - # @param [Hash] solution Path solution for the resource - # @return [AccountPage] AccountPage - def initialize(version, response, solution) - super(version, response) - - # Path Solution - @solution = solution - end - - ## - # Build an instance of AccountInstance - # @param [Hash] payload Payload response from the API - # @return [AccountInstance] AccountInstance - def get_instance(payload) - AccountInstance.new(@version, payload, organization_sid: @solution[:organization_sid]) - end - - ## - # Provide a user friendly representation - def to_s - '' - end - end - class AccountInstance < InstanceResource - ## - # Initialize the AccountInstance - # @param [Version] version Version that contains the resource - # @param [Hash] payload payload that contains response from Twilio - # @param [String] account_sid The SID of the - # {Account}[https://www.twilio.com/docs/iam/api/account] that created this Account - # resource. - # @param [String] sid The SID of the Call resource to fetch. - # @return [AccountInstance] AccountInstance - def initialize(version, payload , organization_sid: nil, account_sid: nil) - super(version) - - # Marshaled Properties - @properties = { - 'account_sid' => payload['account_sid'], - 'friendly_name' => payload['friendly_name'], - 'status' => payload['status'], - 'owner_sid' => payload['owner_sid'], - 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']), - } - - # Context - @instance_context = nil - @params = { 'organization_sid' => organization_sid || @properties['organization_sid'] ,'account_sid' => account_sid , } - end - - ## - # Generate an instance context for the instance, the context is capable of - # performing various actions. All instance actions are proxied to the context - # @return [AccountContext] CallContext for this CallInstance - def context - unless @instance_context - @instance_context = AccountContext.new(@version , @params['organization_sid'], @params['account_sid']) - end - @instance_context - end - - ## - # @return [String] Twilio account sid - def account_sid - @properties['account_sid'] - end - - ## - # @return [String] Account friendly name - def friendly_name - @properties['friendly_name'] - end - - ## - # @return [String] Account status - def status - @properties['status'] - end - - ## - # @return [String] Twilio account sid - def owner_sid - @properties['owner_sid'] - end - - ## - # @return [Time] The date and time when the account was created in the system - def date_created - @properties['date_created'] - end - - ## - # Fetch the AccountInstance - # @return [AccountInstance] Fetched AccountInstance - def fetch - - context.fetch - end - - ## - # Provide a user friendly representation - def to_s - values = @params.map{|k, v| "#{k}: #{v}"}.join(" ") - "" - end - - ## - # Provide a detailed, user friendly representation - def inspect - values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ") - "" - end - end - - end - end - end - end -end - - diff --git a/lib/twilio-ruby/rest/preview_iam/versionless/organization/role_assignment.rb b/lib/twilio-ruby/rest/preview_iam/versionless/organization/role_assignment.rb deleted file mode 100644 index 4448331c5..000000000 --- a/lib/twilio-ruby/rest/preview_iam/versionless/organization/role_assignment.rb +++ /dev/null @@ -1,364 +0,0 @@ -## -# This code was generated by -# ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ -# | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ -# | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ -# -# Organization Public API -# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) -# -# NOTE: This class is auto generated by OpenAPI Generator. -# https://openapi-generator.tech -# Do not edit the class manually. -# - - -module Twilio - module REST - class PreviewIam < PreviewIamBase - class Versionless < Version - class OrganizationContext < InstanceContext - - class RoleAssignmentList < ListResource - - class PublicApiCreateRoleAssignmentRequest - # @param [role_sid]: [String] Twilio Role Sid representing assigned role - # @param [scope]: [String] Twilio Sid representing scope of this assignment - # @param [identity]: [String] Twilio Sid representing identity of this assignment - attr_accessor :role_sid, :scope, :identity - def initialize(payload) - @role_sid = payload["role_sid"] - @scope = payload["scope"] - @identity = payload["identity"] - end - def to_json(options = {}) - { - role_sid: @role_sid, - scope: @scope, - identity: @identity, - }.to_json(options) - end - end - - ## - # Initialize the RoleAssignmentList - # @param [Version] version Version that contains the resource - # @return [RoleAssignmentList] RoleAssignmentList - def initialize(version, organization_sid: nil) - super(version) - # Path Solution - @solution = { organization_sid: organization_sid } - @uri = "/#{@solution[:organization_sid]}/RoleAssignments" - - end - ## - # Create the RoleAssignmentInstance - # @param [PublicApiCreateRoleAssignmentRequest] public_api_create_role_assignment_request - # @return [RoleAssignmentInstance] Created RoleAssignmentInstance - def create(public_api_create_role_assignment_request: nil) - - headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', }) - headers['Content-Type'] = 'application/json' - payload = @version.create('POST', @uri, headers: headers, data: public_api_create_role_assignment_request.to_json) - RoleAssignmentInstance.new( - @version, - payload, - organization_sid: @solution[:organization_sid], - ) - end - - - ## - # Lists RoleAssignmentInstance records from the API as a list. - # Unlike stream(), this operation is eager and will load `limit` records into - # memory before returning. - # @param [String] identity - # @param [String] scope - # @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(identity: :unset, scope: :unset , limit: nil, page_size: nil) - self.stream( - identity: identity, - scope: scope, - 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] identity - # @param [String] scope - # @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(identity: :unset, scope: :unset , limit: nil, page_size: nil) - limits = @version.read_limits(limit, page_size) - - page = self.page( - identity: identity, - scope: scope, - page_size: limits[:page_size], ) - - @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) - end - - ## - # When passed a block, yields RoleAssignmentInstance 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 RoleAssignmentInstance records from the API. - # Request is executed immediately. - # @param [String] identity - # @param [String] scope - # @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 RoleAssignmentInstance - def page(identity: :unset, scope: :unset , page_token: :unset, page_number: :unset, page_size: :unset) - params = Twilio::Values.of({ - 'Identity' => identity, - 'Scope' => scope, - 'PageToken' => page_token, - 'Page' => page_number, - 'PageSize' => page_size, - }) - - response = @version.page('GET', @uri, params: params) - - RoleAssignmentPage.new(@version, response, @solution) - end - - ## - # Retrieve a single page of RoleAssignmentInstance records from the API. - # Request is executed immediately. - # @param [String] target_url API-generated URL for the requested results page - # @return [Page] Page of RoleAssignmentInstance - def get_page(target_url) - response = @version.domain.request( - 'GET', - target_url - ) - RoleAssignmentPage.new(@version, response, @solution) - end - - - - # Provide a user friendly representation - def to_s - '#' - end - end - - - class RoleAssignmentContext < InstanceContext - ## - # Initialize the RoleAssignmentContext - # @param [Version] version Version that contains the resource - # @param [String] organization_sid - # @param [String] role_assignment_sid - # @return [RoleAssignmentContext] RoleAssignmentContext - def initialize(version, organization_sid, role_assignment_sid) - super(version) - - # Path Solution - @solution = { organization_sid: organization_sid, role_assignment_sid: role_assignment_sid, } - @uri = "/#{@solution[:organization_sid]}/RoleAssignments/#{@solution[:role_assignment_sid]}" - - - end - ## - # Delete the RoleAssignmentInstance - # @return [Boolean] True if delete succeeds, false otherwise - def delete - - headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', }) - - @version.delete('DELETE', @uri, headers: headers) - end - - - ## - # Provide a user friendly representation - def to_s - context = @solution.map{|k, v| "#{k}: #{v}"}.join(',') - "#" - end - - ## - # Provide a detailed, user friendly representation - def inspect - context = @solution.map{|k, v| "#{k}: #{v}"}.join(',') - "#" - end - end - - class RoleAssignmentPage < Page - ## - # Initialize the RoleAssignmentPage - # @param [Version] version Version that contains the resource - # @param [Response] response Response from the API - # @param [Hash] solution Path solution for the resource - # @return [RoleAssignmentPage] RoleAssignmentPage - def initialize(version, response, solution) - super(version, response) - - # Path Solution - @solution = solution - end - - ## - # Build an instance of RoleAssignmentInstance - # @param [Hash] payload Payload response from the API - # @return [RoleAssignmentInstance] RoleAssignmentInstance - def get_instance(payload) - RoleAssignmentInstance.new(@version, payload, organization_sid: @solution[:organization_sid]) - end - - ## - # Provide a user friendly representation - def to_s - '' - end - end - class RoleAssignmentInstance < InstanceResource - ## - # Initialize the RoleAssignmentInstance - # @param [Version] version Version that contains the resource - # @param [Hash] payload payload that contains response from Twilio - # @param [String] account_sid The SID of the - # {Account}[https://www.twilio.com/docs/iam/api/account] that created this RoleAssignment - # resource. - # @param [String] sid The SID of the Call resource to fetch. - # @return [RoleAssignmentInstance] RoleAssignmentInstance - def initialize(version, payload , organization_sid: nil, role_assignment_sid: nil) - super(version) - - # Marshaled Properties - @properties = { - 'sid' => payload['sid'], - 'role_sid' => payload['role_sid'], - 'scope' => payload['scope'], - 'identity' => payload['identity'], - 'code' => payload['code'], - 'message' => payload['message'], - 'more_info' => payload['more_info'], - 'status' => payload['status'], - } - - # Context - @instance_context = nil - @params = { 'organization_sid' => organization_sid || @properties['organization_sid'] ,'role_assignment_sid' => role_assignment_sid || @properties['role_assignment_sid'] , } - end - - ## - # Generate an instance context for the instance, the context is capable of - # performing various actions. All instance actions are proxied to the context - # @return [RoleAssignmentContext] CallContext for this CallInstance - def context - unless @instance_context - @instance_context = RoleAssignmentContext.new(@version , @params['organization_sid'], @params['role_assignment_sid']) - end - @instance_context - end - - ## - # @return [String] Twilio Role Assignment Sid representing this role assignment - def sid - @properties['sid'] - end - - ## - # @return [String] Twilio Role Sid representing assigned role - def role_sid - @properties['role_sid'] - end - - ## - # @return [String] Twilio Sid representing identity of this assignment - def scope - @properties['scope'] - end - - ## - # @return [String] Twilio Sid representing scope of this assignment - def identity - @properties['identity'] - end - - ## - # @return [String] Twilio-specific error code - def code - @properties['code'] - end - - ## - # @return [String] Error message - def message - @properties['message'] - end - - ## - # @return [String] Link to Error Code References - def more_info - @properties['more_info'] - end - - ## - # @return [String] HTTP response status code - def status - @properties['status'] - end - - ## - # Delete the RoleAssignmentInstance - # @return [Boolean] True if delete succeeds, false otherwise - def delete - - context.delete - end - - ## - # Provide a user friendly representation - def to_s - values = @params.map{|k, v| "#{k}: #{v}"}.join(" ") - "" - end - - ## - # Provide a detailed, user friendly representation - def inspect - values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ") - "" - end - end - - end - end - end - end -end - - diff --git a/lib/twilio-ruby/rest/preview_iam/versionless/organization/user.rb b/lib/twilio-ruby/rest/preview_iam/versionless/organization/user.rb deleted file mode 100644 index cac277b0a..000000000 --- a/lib/twilio-ruby/rest/preview_iam/versionless/organization/user.rb +++ /dev/null @@ -1,511 +0,0 @@ -## -# This code was generated by -# ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ -# | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ -# | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ -# -# Organization Public API -# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) -# -# NOTE: This class is auto generated by OpenAPI Generator. -# https://openapi-generator.tech -# Do not edit the class manually. -# - - -module Twilio - module REST - class PreviewIam < PreviewIamBase - class Versionless < Version - class OrganizationContext < InstanceContext - - class UserList < ListResource - - class ScimUser - # @param [id]: [String] Unique Twilio user sid - # @param [external_id]: [String] External unique resource id defined by provisioning client - # @param [user_name]: [String] Unique username, MUST be same as primary email address - # @param [display_name]: [String] User friendly display name - # @param [name]: [UserList.ScimName] - # @param [emails]: [Array] Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username. - # @param [active]: [Boolean] Indicates whether the user is active - # @param [locale]: [String] User's locale - # @param [timezone]: [String] User's time zone - # @param [schemas]: [Array] An array of URIs that indicate the schemas supported for this user resource - # @param [meta]: [UserList.ScimMeta] - # @param [detail]: [String] A human-readable description of the error - # @param [scim_type]: [String] A scimType error code as defined in RFC7644 - # @param [status]: [String] Http status code - # @param [code]: [String] Twilio-specific error code - # @param [more_info]: [String] Link to Error Code References - attr_accessor :id, :external_id, :user_name, :display_name, :name, :emails, :active, :locale, :timezone, :schemas, :meta, :detail, :scim_type, :status, :code, :more_info - def initialize(payload) - @id = payload["id"] - @external_id = payload["external_id"] - @user_name = payload["user_name"] - @display_name = payload["display_name"] - @name = payload["name"] - @emails = payload["emails"] - @active = payload["active"] - @locale = payload["locale"] - @timezone = payload["timezone"] - @schemas = payload["schemas"] - @meta = payload["meta"] - @detail = payload["detail"] - @scim_type = payload["scim_type"] - @status = payload["status"] - @code = payload["code"] - @more_info = payload["more_info"] - end - def to_json(options = {}) - { - id: @id, - external_id: @external_id, - user_name: @user_name, - display_name: @display_name, - name: @name, - emails: @emails, - active: @active, - locale: @locale, - timezone: @timezone, - schemas: @schemas, - meta: @meta, - detail: @detail, - scim_type: @scim_type, - status: @status, - code: @code, - more_info: @more_info, - }.to_json(options) - end - end - - ## - # Initialize the UserList - # @param [Version] version Version that contains the resource - # @return [UserList] UserList - def initialize(version, organization_sid: nil) - super(version) - # Path Solution - @solution = { organization_sid: organization_sid } - @uri = "/#{@solution[:organization_sid]}/scim/Users" - - end - ## - # Create the UserInstance - # @param [ScimUser] scim_user - # @return [UserInstance] Created UserInstance - def create(scim_user: nil) - - headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', }) - headers['Content-Type'] = 'application/json' - payload = @version.create('POST', @uri, headers: headers, data: scim_user.to_json) - UserInstance.new( - @version, - payload, - organization_sid: @solution[:organization_sid], - ) - end - - - ## - # Lists UserInstance records from the API as a list. - # Unlike stream(), this operation is eager and will load `limit` records into - # memory before returning. - # @param [String] filter - # @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(filter: :unset , limit: nil, page_size: nil) - self.stream( - filter: filter, - 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] filter - # @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(filter: :unset , limit: nil, page_size: nil) - limits = @version.read_limits(limit, page_size) - - page = self.page( - filter: filter, - page_size: limits[:page_size], ) - - @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit]) - end - - ## - # When passed a block, yields UserInstance 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 UserInstance records from the API. - # Request is executed immediately. - # @param [String] filter - # @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 UserInstance - def page(filter: :unset , page_token: :unset, page_number: :unset, page_size: :unset) - params = Twilio::Values.of({ - 'filter' => filter, - 'PageToken' => page_token, - 'Page' => page_number, - 'PageSize' => page_size, - }) - - response = @version.page('GET', @uri, params: params) - - UserPage.new(@version, response, @solution) - end - - ## - # Retrieve a single page of UserInstance records from the API. - # Request is executed immediately. - # @param [String] target_url API-generated URL for the requested results page - # @return [Page] Page of UserInstance - def get_page(target_url) - response = @version.domain.request( - 'GET', - target_url - ) - UserPage.new(@version, response, @solution) - end - - - - # Provide a user friendly representation - def to_s - '#' - end - end - - - class UserContext < InstanceContext - ## - # Initialize the UserContext - # @param [Version] version Version that contains the resource - # @param [String] organization_sid - # @param [String] user_sid - # @return [UserContext] UserContext - def initialize(version, organization_sid, user_sid) - super(version) - - # Path Solution - @solution = { organization_sid: organization_sid, user_sid: user_sid, } - @uri = "/#{@solution[:organization_sid]}/scim/Users/#{@solution[:user_sid]}" - - - end - ## - # Delete the UserInstance - # @return [Boolean] True if delete succeeds, false otherwise - def delete - - headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', }) - - @version.delete('DELETE', @uri, headers: headers) - end - - ## - # Fetch the UserInstance - # @return [UserInstance] Fetched UserInstance - def fetch - - headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', }) - - payload = @version.fetch('GET', @uri, headers: headers) - UserInstance.new( - @version, - payload, - organization_sid: @solution[:organization_sid], - user_sid: @solution[:user_sid], - ) - end - - ## - # Update the UserInstance - # @param [String] if_match - # @param [ScimUser] scim_user - # @return [UserInstance] Updated UserInstance - def update( - if_match: :unset, scim_user: nil - ) - - headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'If-Match' => if_match, }) - headers['Content-Type'] = 'application/json' - payload = @version.update('PUT', @uri, headers: headers, data: scim_user.to_json) - UserInstance.new( - @version, - payload, - organization_sid: @solution[:organization_sid], - user_sid: @solution[:user_sid], - ) - end - - - ## - # Provide a user friendly representation - def to_s - context = @solution.map{|k, v| "#{k}: #{v}"}.join(',') - "#" - end - - ## - # Provide a detailed, user friendly representation - def inspect - context = @solution.map{|k, v| "#{k}: #{v}"}.join(',') - "#" - end - end - - class UserPage < Page - ## - # Initialize the UserPage - # @param [Version] version Version that contains the resource - # @param [Response] response Response from the API - # @param [Hash] solution Path solution for the resource - # @return [UserPage] UserPage - def initialize(version, response, solution) - super(version, response) - - # Path Solution - @solution = solution - end - - ## - # Build an instance of UserInstance - # @param [Hash] payload Payload response from the API - # @return [UserInstance] UserInstance - def get_instance(payload) - UserInstance.new(@version, payload, organization_sid: @solution[:organization_sid]) - end - - ## - # Provide a user friendly representation - def to_s - '' - end - end - class UserInstance < InstanceResource - ## - # Initialize the UserInstance - # @param [Version] version Version that contains the resource - # @param [Hash] payload payload that contains response from Twilio - # @param [String] account_sid The SID of the - # {Account}[https://www.twilio.com/docs/iam/api/account] that created this User - # resource. - # @param [String] sid The SID of the Call resource to fetch. - # @return [UserInstance] UserInstance - def initialize(version, payload , organization_sid: nil, user_sid: nil) - super(version) - - # Marshaled Properties - @properties = { - 'id' => payload['id'], - 'external_id' => payload['external_id'], - 'user_name' => payload['user_name'], - 'display_name' => payload['display_name'], - 'name' => payload['name'], - 'emails' => payload['emails'], - 'active' => payload['active'], - 'locale' => payload['locale'], - 'timezone' => payload['timezone'], - 'schemas' => payload['schemas'], - 'meta' => payload['meta'], - 'detail' => payload['detail'], - 'scim_type' => payload['scim_type'], - 'status' => payload['status'], - 'code' => payload['code'], - 'more_info' => payload['more_info'], - } - - # Context - @instance_context = nil - @params = { 'organization_sid' => organization_sid || @properties['organization_sid'] ,'user_sid' => user_sid || @properties['user_sid'] , } - end - - ## - # Generate an instance context for the instance, the context is capable of - # performing various actions. All instance actions are proxied to the context - # @return [UserContext] CallContext for this CallInstance - def context - unless @instance_context - @instance_context = UserContext.new(@version , @params['organization_sid'], @params['user_sid']) - end - @instance_context - end - - ## - # @return [String] Unique Twilio user sid - def id - @properties['id'] - end - - ## - # @return [String] External unique resource id defined by provisioning client - def external_id - @properties['external_id'] - end - - ## - # @return [String] Unique username, MUST be same as primary email address - def user_name - @properties['user_name'] - end - - ## - # @return [String] User friendly display name - def display_name - @properties['display_name'] - end - - ## - # @return [UserList.ScimName] - def name - @properties['name'] - end - - ## - # @return [Array] Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username. - def emails - @properties['emails'] - end - - ## - # @return [Boolean] Indicates whether the user is active - def active - @properties['active'] - end - - ## - # @return [String] User's locale - def locale - @properties['locale'] - end - - ## - # @return [String] User's time zone - def timezone - @properties['timezone'] - end - - ## - # @return [Array] An array of URIs that indicate the schemas supported for this user resource - def schemas - @properties['schemas'] - end - - ## - # @return [UserList.ScimMeta] - def meta - @properties['meta'] - end - - ## - # @return [String] A human-readable description of the error - def detail - @properties['detail'] - end - - ## - # @return [String] A scimType error code as defined in RFC7644 - def scim_type - @properties['scim_type'] - end - - ## - # @return [String] Http status code - def status - @properties['status'] - end - - ## - # @return [String] Twilio-specific error code - def code - @properties['code'] - end - - ## - # @return [String] Link to Error Code References - def more_info - @properties['more_info'] - end - - ## - # Delete the UserInstance - # @return [Boolean] True if delete succeeds, false otherwise - def delete - - context.delete - end - - ## - # Fetch the UserInstance - # @return [UserInstance] Fetched UserInstance - def fetch - - context.fetch - end - - ## - # Update the UserInstance - # @param [String] if_match - # @param [ScimUser] scim_user - # @return [UserInstance] Updated UserInstance - def update( - if_match: :unset, scim_user: nil - ) - - context.update( - if_match: if_match, - ) - end - - ## - # Provide a user friendly representation - def to_s - values = @params.map{|k, v| "#{k}: #{v}"}.join(" ") - "" - end - - ## - # Provide a detailed, user friendly representation - def inspect - values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ") - "" - end - end - - end - end - end - end -end - -