def __init__(self, session, object_factory): """Init a new OrganizationsAPI object with the provided RestSession. Args: session(RestSession): The RESTful session object to be used for API calls to the Webex Teams service. Raises: TypeError: If the parameter types are incorrect. """ check_type(session, RestSession, may_be_none=False) super(OrganizationsAPI, self).__init__() self._session = session self._object_factory = object_factory
def __init__(self, session, object_factory): """Init a new OrganizationsAPI object with the provided RestSession. Args: session(RestSession): The RESTful session object to be used for API calls to the Webex Teams service. Raises: TypeError: If the parameter types are incorrect. """ check_type(session, RestSession, may_be_none=False) super(OrganizationsAPI, self).__init__() self._session = session self._object_factory = object_factory
def get(self, orgId): """Get the details of an Organization, by ID. Args: orgId(basestring): The ID of the Organization to be retrieved. Returns: Organization: An Organization object with the details of the requested organization. Raises: TypeError: If the parameter types are incorrect. ApiError: If the Webex Teams cloud returns an error. """ check_type(orgId, basestring, may_be_none=False) # API request json_data = self._session.get(API_ENDPOINT + '/' + orgId) # Return a organization object created from the returned JSON object return self._object_factory(OBJECT_TYPE, json_data)
def get(self, orgId): """Get the details of an Organization, by ID. Args: orgId(basestring): The ID of the Organization to be retrieved. Returns: Organization: An Organization object with the details of the requested organization. Raises: TypeError: If the parameter types are incorrect. ApiError: If the Webex Teams cloud returns an error. """ check_type(orgId, basestring, may_be_none=False) # API request json_data = self._session.get(API_ENDPOINT + '/' + orgId) # Return a organization object created from the returned JSON object return self._object_factory(OBJECT_TYPE, json_data)
def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL, single_request_timeout=DEFAULT_SINGLE_REQUEST_TIMEOUT, wait_on_rate_limit=DEFAULT_WAIT_ON_RATE_LIMIT, object_factory=immutable_data_factory): """Create a new WebexTeamsAPI object. An access token must be used when interacting with the Webex Teams API. This package supports two methods for you to provide that access token: 1. You may manually specify the access token via the `access_token` argument, when creating a new WebexTeamsAPI object. 2. If an access_token argument is not supplied, the package checks for a WEBEX_TEAMS_ACCESS_TOKEN environment variable. An AccessTokenError is raised if an access token is not provided via one of these two methods. Args: access_token(basestring): The access token to be used for API calls to the Webex Teams service. Defaults to checking for a WEBEX_TEAMS_ACCESS_TOKEN environment variable. base_url(basestring): The base URL to be prefixed to the individual API endpoint suffixes. Defaults to webexteamssdk.DEFAULT_BASE_URL. single_request_timeout(int): Timeout (in seconds) for RESTful HTTP requests. Defaults to webexteamssdk.config.DEFAULT_SINGLE_REQUEST_TIMEOUT. wait_on_rate_limit(bool): Enables or disables automatic rate-limit handling. Defaults to webexteamssdk.config.DEFAULT_WAIT_ON_RATE_LIMIT. object_factory(callable): The factory function to use to create Python objects from the returned Webex Teams JSON data objects. Returns: WebexTeamsAPI: A new WebexTeamsAPI object. Raises: TypeError: If the parameter types are incorrect. AccessTokenError: If an access token is not provided via the access_token argument or an environment variable. """ check_type(access_token, basestring) check_type(base_url, basestring) check_type(single_request_timeout, int) check_type(wait_on_rate_limit, bool) access_token = access_token or WEBEX_TEAMS_ACCESS_TOKEN if not access_token: raise AccessTokenError( "You must provide a Webex Teams access token to interact with " "the Webex Teams APIs, either via a WEBEX_TEAMS_ACCESS_TOKEN " "environment variable or via the access_token argument.") # Create the API session # All of the API calls associated with a WebexTeamsAPI object will # leverage a single RESTful 'session' connecting to the Webex Teams # cloud. self._session = RestSession( access_token=access_token, base_url=base_url, single_request_timeout=single_request_timeout, wait_on_rate_limit=wait_on_rate_limit) # API wrappers self.people = PeopleAPI(self._session, object_factory) self.rooms = RoomsAPI(self._session, object_factory) self.memberships = MembershipsAPI(self._session, object_factory) self.messages = MessagesAPI(self._session, object_factory) self.teams = TeamsAPI(self._session, object_factory) self.team_memberships = TeamMembershipsAPI(self._session, object_factory) self.webhooks = WebhooksAPI(self._session, object_factory) self.organizations = OrganizationsAPI(self._session, object_factory) self.licenses = LicensesAPI(self._session, object_factory) self.roles = RolesAPI(self._session, object_factory) self.access_tokens = AccessTokensAPI( self.base_url, object_factory, single_request_timeout=single_request_timeout) self.events = EventsAPI(self._session, object_factory)
def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL, single_request_timeout=DEFAULT_SINGLE_REQUEST_TIMEOUT, wait_on_rate_limit=DEFAULT_WAIT_ON_RATE_LIMIT, object_factory=immutable_data_factory, client_id=None, client_secret=None, oauth_code=None, redirect_uri=None, proxies=None): """Create a new WebexTeamsAPI object. An access token must be used when interacting with the Webex Teams API. This package supports three methods for you to provide that access token: 1. You may manually specify the access token via the `access_token` argument, when creating a new WebexTeamsAPI object. 2. If an access_token argument is not supplied, the package checks for a WEBEX_TEAMS_ACCESS_TOKEN environment variable. 3. Provide the parameters (client_id, client_secret, oauth_code and oauth_redirect_uri) from your oauth flow. An AccessTokenError is raised if an access token is not provided via one of these two methods. Args: access_token(basestring): The access token to be used for API calls to the Webex Teams service. Defaults to checking for a WEBEX_TEAMS_ACCESS_TOKEN environment variable. base_url(basestring): The base URL to be prefixed to the individual API endpoint suffixes. Defaults to webexteamssdk.DEFAULT_BASE_URL. single_request_timeout(int): Timeout (in seconds) for RESTful HTTP requests. Defaults to webexteamssdk.config.DEFAULT_SINGLE_REQUEST_TIMEOUT. wait_on_rate_limit(bool): Enables or disables automatic rate-limit handling. Defaults to webexteamssdk.config.DEFAULT_WAIT_ON_RATE_LIMIT. object_factory(callable): The factory function to use to create Python objects from the returned Webex Teams JSON data objects. client_id(basestring): The client id of your integration. Provided upon creation in the portal. client_secret(basestring): The client secret of your integration. Provided upon creation in the portal. oauth_code(basestring): The oauth authorization code provided by the user oauth process. oauth_redirect_uri(basestring): The redirect URI used in the user OAuth process. proxies(dict): Dictionary of proxies passed on to the requests session. Returns: WebexTeamsAPI: A new WebexTeamsAPI object. Raises: TypeError: If the parameter types are incorrect. AccessTokenError: If an access token is not provided via the access_token argument or an environment variable. """ check_type(access_token, basestring, optional=True) check_type(base_url, basestring, optional=True) check_type(single_request_timeout, int, optional=True) check_type(wait_on_rate_limit, bool, optional=True) check_type(client_id, basestring, optional=True) check_type(client_secret, basestring, optional=True) check_type(oauth_code, basestring, optional=True) check_type(redirect_uri, basestring, optional=True) check_type(proxies, dict, optional=True) access_token = access_token or WEBEX_TEAMS_ACCESS_TOKEN # Init AccessTokensAPI wrapper early to use for oauth requests self.access_tokens = AccessTokensAPI( base_url, object_factory, single_request_timeout=single_request_timeout, ) # Check if the user has provided the required oauth parameters oauth_param_list = [client_id, client_secret, oauth_code, redirect_uri] if not access_token and all(oauth_param_list): access_token = self.access_tokens.get( client_id=client_id, client_secret=client_secret, code=oauth_code, redirect_uri=redirect_uri).access_token # If an access token hasn't been provided as a parameter, environment # variable, or obtained via an OAuth exchange raise an error. if not access_token: raise AccessTokenError( "You must provide a Webex Teams access token to interact with " "the Webex Teams APIs, either via a WEBEX_TEAMS_ACCESS_TOKEN " "environment variable or via the access_token argument.") # Create the API session # All of the API calls associated with a WebexTeamsAPI object will # leverage a single RESTful 'session' connecting to the Webex Teams # cloud. self._session = RestSession( access_token=access_token, base_url=base_url, single_request_timeout=single_request_timeout, wait_on_rate_limit=wait_on_rate_limit, proxies=proxies) # API wrappers self.admin_audit_events = AdminAuditEventsAPI( self._session, object_factory, ) self.attachment_actions = AttachmentActionsAPI( self._session, object_factory, ) self.events = EventsAPI(self._session, object_factory) self.guest_issuer = GuestIssuerAPI(self._session, object_factory) self.licenses = LicensesAPI(self._session, object_factory) self.memberships = MembershipsAPI(self._session, object_factory) self.messages = MessagesAPI(self._session, object_factory) self.organizations = OrganizationsAPI(self._session, object_factory) self.people = PeopleAPI(self._session, object_factory) self.roles = RolesAPI(self._session, object_factory) self.rooms = RoomsAPI(self._session, object_factory) self.teams = TeamsAPI(self._session, object_factory) self.team_memberships = TeamMembershipsAPI( self._session, object_factory, ) self.webhooks = WebhooksAPI(self._session, object_factory)
def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL, single_request_timeout=DEFAULT_SINGLE_REQUEST_TIMEOUT, wait_on_rate_limit=DEFAULT_WAIT_ON_RATE_LIMIT, object_factory=immutable_data_factory, client_id=None, client_secret=None, oauth_code=None, redirect_uri=None): """Create a new WebexTeamsAPI object. An access token must be used when interacting with the Webex Teams API. This package supports three methods for you to provide that access token: 1. You may manually specify the access token via the `access_token` argument, when creating a new WebexTeamsAPI object. 2. If an access_token argument is not supplied, the package checks for a WEBEX_TEAMS_ACCESS_TOKEN environment variable. 3. Provide the parameters (client_id, client_secret, oauth_code and oauth_redirect_uri) from your oauth flow. An AccessTokenError is raised if an access token is not provided via one of these two methods. Args: access_token(basestring): The access token to be used for API calls to the Webex Teams service. Defaults to checking for a WEBEX_TEAMS_ACCESS_TOKEN environment variable. base_url(basestring): The base URL to be prefixed to the individual API endpoint suffixes. Defaults to webexteamssdk.DEFAULT_BASE_URL. single_request_timeout(int): Timeout (in seconds) for RESTful HTTP requests. Defaults to webexteamssdk.config.DEFAULT_SINGLE_REQUEST_TIMEOUT. wait_on_rate_limit(bool): Enables or disables automatic rate-limit handling. Defaults to webexteamssdk.config.DEFAULT_WAIT_ON_RATE_LIMIT. object_factory(callable): The factory function to use to create Python objects from the returned Webex Teams JSON data objects. client_id(basestring): The client id of your integration. Provided upon creation in the portal. client_secret(basestring): The client secret of your integration. Provided upon creation in the portal. oauth_code(basestring): The oauth authorization code provided by the user oauth process. oauth_redirect_uri(basestring): The redirect URI used in the user OAuth process. Returns: WebexTeamsAPI: A new WebexTeamsAPI object. Raises: TypeError: If the parameter types are incorrect. AccessTokenError: If an access token is not provided via the access_token argument or an environment variable. """ check_type(access_token, basestring) check_type(base_url, basestring) check_type(single_request_timeout, int) check_type(wait_on_rate_limit, bool) check_type(client_id, basestring, may_be_none=True) check_type(client_secret, basestring, may_be_none=True) check_type(oauth_code, basestring, may_be_none=True) check_type(redirect_uri, basestring, may_be_none=True) access_token = access_token or WEBEX_TEAMS_ACCESS_TOKEN # Init AccessTokensAPI wrapper early to use for oauth requests self.access_tokens = AccessTokensAPI( base_url, object_factory, single_request_timeout=single_request_timeout, ) # Check if the user has provided the required oauth parameters oauth_param_list = [client_id, client_secret, oauth_code, redirect_uri] if not access_token and all(oauth_param_list): access_token = self.access_tokens.get( client_id=client_id, client_secret=client_secret, code=oauth_code, redirect_uri=redirect_uri ).access_token # If an access token hasn't been provided as a parameter, environment # variable, or obtained via an OAuth exchange raise an error. if not access_token: raise AccessTokenError( "You must provide a Webex Teams access token to interact with " "the Webex Teams APIs, either via a WEBEX_TEAMS_ACCESS_TOKEN " "environment variable or via the access_token argument." ) # Create the API session # All of the API calls associated with a WebexTeamsAPI object will # leverage a single RESTful 'session' connecting to the Webex Teams # cloud. self._session = RestSession( access_token=access_token, base_url=base_url, single_request_timeout=single_request_timeout, wait_on_rate_limit=wait_on_rate_limit ) # API wrappers self.people = PeopleAPI(self._session, object_factory) self.rooms = RoomsAPI(self._session, object_factory) self.memberships = MembershipsAPI(self._session, object_factory) self.messages = MessagesAPI(self._session, object_factory) self.teams = TeamsAPI(self._session, object_factory) self.team_memberships = TeamMembershipsAPI( self._session, object_factory ) self.webhooks = WebhooksAPI(self._session, object_factory) self.organizations = OrganizationsAPI(self._session, object_factory) self.licenses = LicensesAPI(self._session, object_factory) self.roles = RolesAPI(self._session, object_factory) self.events = EventsAPI(self._session, object_factory) self.guest_issuer = GuestIssuerAPI(self._session, object_factory)
def list(self, orgId, _from, to, actorId=None, max=100, offset=0, **request_parameters): """List Organizations. This method supports Webex Teams's implementation of RFC5988 Web Linking to provide pagination support. It returns a generator container that incrementally yields all audit events returned by the query. The generator will automatically request additional 'pages' of responses from Webex as needed until all responses have been returned. The container makes the generator safe for reuse. A new API call will be made, using the same parameters that were specified when the generator was created, every time a new iterator is requested from the container. Args: orgId(basestring): List events in this organization, by ID. _from(basestring): List events which occurred after a specific date and time. to(basestring): List events which occurred before a specific date and time. actorId(basestring): List events performed by this person, by ID. max(int): Limit the maximum number of events in the response. The maximum value is 200. offset(int): Offset from the first result that you want to fetch. **request_parameters: Additional request parameters (provides support for parameters that may be added in the future). Returns: GeneratorContainer: A GeneratorContainer which, when iterated, yields the organizations returned by the Webex Teams query. Raises: TypeError: If the parameter types are incorrect. ApiError: If the Webex Teams cloud returns an error. """ check_type(orgId, basestring) check_type(_from, basestring) check_type(to, basestring) check_type(actorId, basestring, optional=True) check_type(max, int) check_type(offset, int) params = dict_from_items_with_values( request_parameters, orgId=orgId, _from=_from, to=to, actorId=actorId, max=max, offset=offset, ) if _from: params["from"] = params.pop("_from") # API request - get items items = self._session.get_items(API_ENDPOINT, params=params) # Yield AdminAuditEvent objects created from the returned JSON objects for item in items: yield self._object_factory(OBJECT_TYPE, item)