Package scapi :: Class ApiConnector
[hide private]
[frames] | no frames]

Class ApiConnector

source code

object --+
         |
        ApiConnector

The ApiConnector holds all the data necessary to authenticate against the soundcloud-api. You can instantiate several connectors if you like, but usually one should be sufficient.

Instance Methods [hide private]
 
__init__(self, host, user=None, password=None, authenticator=None, base='', collapse_scope=True)
Constructor for the API-Singleton.
source code
 
normalize_method(self, method)
This method will take a method that has been part of a redirect of some sort and see if it's valid, which means that it's located beneath our base.
source code
 
fetch_request_token(self, url=None, oauth_callback='oob', oauth_verifier=None)
Helper-function for a registered consumer to obtain a request token, as used by oauth.
source code
 
fetch_access_token(self, oauth_verifier)
Helper-function for a registered consumer to exchange an access token for a request token.
source code
 
get_request_token_authorization_url(self, token)
Simple helper function to generate the url needed to ask a user for request token authorization.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  LIST_LIMIT = 50
The query-parameter that is used to request results beginning from a certain offset.
  LIST_OFFSET_PARAMETER = 'offset'
The query-parameter that is used to request results being limited to a certain amount.
  LIST_LIMIT_PARAMETER = 'limit'
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, host, user=None, password=None, authenticator=None, base='', collapse_scope=True)
(Constructor)

source code 

Constructor for the API-Singleton. Use it once with parameters, and then the subsequent calls internal to the API will work.

Parameters:
  • host (str) - the host to connect to, e.g. "api.soundcloud.com". If a port is needed, use "api.soundcloud.com:1234"
  • user (str) - if given, the username for basic HTTP authentication
  • password (str) - if the user is given, you have to give a password as well
  • authenticator (OAuthAuthenticator | BasicAuthenticator) - the authenticator to use, see scapi.authentication
Overrides: object.__init__

normalize_method(self, method)

source code 

This method will take a method that has been part of a redirect of some sort and see if it's valid, which means that it's located beneath our base. If yes, we return it normalized without that very base.

fetch_request_token(self, url=None, oauth_callback='oob', oauth_verifier=None)

source code 

Helper-function for a registered consumer to obtain a request token, as used by oauth.

Use it like this:

>>> oauth_authenticator = scapi.authentication.OAuthAuthenticator(CONSUMER, 
                                                          CONSUMER_SECRET,
                                                          None, 
                                                          None)
>>> sca = scapi.ApiConnector(host=API_HOST, authenticator=oauth_authenticator)
>>> token, secret = sca.fetch_request_token()
>>> authorization_url = sca.get_request_token_authorization_url(token)

Please note the None passed as token & secret to the authenticator.

fetch_access_token(self, oauth_verifier)

source code 

Helper-function for a registered consumer to exchange an access token for a request token.

Use it like this:

>>> oauth_authenticator = scapi.authentication.OAuthAuthenticator(CONSUMER, 
                                                          CONSUMER_SECRET,
                                                          request_token, 
                                                          request_token_secret)
>>> sca = scapi.ApiConnector(host=API_HOST, authenticator=oauth_authenticator)
>>> token, secret = sca.fetch_access_token()

Please note the values passed as token & secret to the authenticator.

get_request_token_authorization_url(self, token)

source code 

Simple helper function to generate the url needed to ask a user for request token authorization.

See also fetch_request_token.

Possible usage:

>>> import webbrowser
>>> sca = scapi.ApiConnector()
>>> authorization_url = sca.get_request_token_authorization_url(token)
>>> webbrowser.open(authorization_url)

Class Variable Details [hide private]

LIST_OFFSET_PARAMETER

The query-parameter that is used to request results being limited to a certain amount.

Currently this is of no use and just for completeness sake.

Value:
'offset'