Ejemplo n.º 1
0
    def __init__(self, account_id, token_or_username, password=None):
        """
        Create a Basecamp service.

        :var account_id: Your Basecamp account id.
        :vartype account_id: int

        :var token_or_username: Either an OAuth 2.0 token, or the username if
          you want to use Basic authentication.
        :vartype token_or_username: str

        :var password: Only used with the Basic authentication, leave this as
            `None` when using OAuth.
        :vartype password: str

        """
        self.apiroot = 'https://basecamp.com/{0}/api/v1'

        self.add_filter(self.use_json)

        if password is None:
            self.access_token = token_or_username
            self.add_filter(self.add_authorization)
        else:
            self.add_filter(auth.BasicAuth(token_or_username, password))

        self.account_id = account_id
Ejemplo n.º 2
0
    def __init__(self,
                 host,
                 token_or_username,
                 oauth_token=None,
                 password=None):
        """
        Create a GitLab serivce.

        :var host: Url of GitLab server
        :vartype host: str

        :var token_or_username: Either an token, or the username if
          you want to use Basic authentication.
        :vartype token_or_username: str

        :var oauth_token: OAuth 2.0 token
        :vartype oauth_token: str

        :var password: Only used with the Basic authentication, leave this as
            `None` when using OAuth.
        :vartype password: str
        """
        self.apiroot = host + "/api/v3"

        if password is None:
            if oauth_token:
                self.oauth_token = oauth_token
                self.add_filter(self.add_authorization)
            else:
                self.token = token_or_username
                self.add_filter(self.add_privatetoken_authorization)
        else:
            self.add_filter(auth.BasicAuth(token_or_username, password))
Ejemplo n.º 3
0
    def __init__(self,
                 token_or_username,
                 password=None,
                 apiroot='https://api.github.com'):
        """
        Create a GitHub service.

        :var token_or_username: Either an OAuth 2.0 token, or the username if
          you want to use Basic authentication.
        :vartype token_or_username: str

        :var password: Only used with the Basic authentication, leave this as
            `None` when using OAuth.
        :vartype password: str

        :var apiroot: Only used for GitHub Enterprise, defaults to GitHub api url
        :vartype apiroot: str
        """
        self.apiroot = apiroot

        self.add_filter(self.use_json)

        if password is None:
            self.oauth_token = token_or_username
            self.add_filter(self.add_authorization)
        else:
            self.add_filter(auth.BasicAuth(token_or_username, password))
Ejemplo n.º 4
0
    def __init__(self, api_key):
        """
        Create a Stripe service.

        :var api_key: The API key.
        :vartype api_key: str
        """
        self.apiroot = 'https://api.stripe.com/v1'

        self.add_filter(auth.BasicAuth(api_key, ''))
Ejemplo n.º 5
0
    def __init__(self, api_key):
        """
        Create a Recurly service.

        :var api_key: The API key including.
        :vartype api_key: str
        """
        self.apiroot = 'https://api.recurly.com/v2'

        self.add_filter(auth.BasicAuth(api_key, ''))
        self.add_filter(self.use_xml)
Ejemplo n.º 6
0
    def test_unicode(self):
        # try both a unicode and a bytes parameter
        _lambda = b'\xce\xbb'
        _ulambda = _lambda.decode('utf-8')

        auth_bytes = auth.BasicAuth('user', _lambda)
        auth_unicode = auth.BasicAuth('user', _ulambda)
        auth_mixed = auth.BasicAuth(_lambda, _ulambda)

        expected_bytes = 'Basic dXNlcjrOuw=='
        expected_unicode = expected_bytes
        expected_mixed = 'Basic zrs6zrs='

        for auth_filter, expected in ((auth_bytes, expected_bytes),
                                      (auth_unicode, expected_unicode),
                                      (auth_mixed, expected_mixed)):

            req = http.Request('GET', 'http://example.net/')
            auth_filter(req)

            self.assertEqual(req.headers['Authorization'], expected)
Ejemplo n.º 7
0
    def __init__(self, app_id, api_key):
        """
        Create a Intercom service.

        :var app_id: The APP identifier.
        :vartype app_id: str
        :var api_key: The API key.
        :vartype api_key: str
        """
        self.apiroot = 'https://api.intercom.io/v1'

        self.add_filter(auth.BasicAuth(app_id, api_key))
        self.add_filter(self.use_json)
Ejemplo n.º 8
0
    def __init__(self, account_sid, auth_token):
        """
        Create a Twilio service.

        :var account_sid: The users's account SID
        :vartype account_sid: str

        :var auth_token: THe account's API token
        :vartype auth_token: str
        """
        self.apiroot = 'https://api.twilio.com/2010-04-01'
        self.add_filter(auth.BasicAuth(account_sid, auth_token))
        self.add_filter(use_json)
Ejemplo n.º 9
0
    def __init__(self, apikey, label):
        """
        Get a datasource resource.

        :var apikey: Your API key.
        :vartype apikey: str

        :var label: data source label
        :vartype label: str
        """
        self.url_tmpl = port.to_u('https://{0}.ducksboard.com/values/{1}')
        self.label = label

        self.add_filter(auth.BasicAuth(apikey, 'x'))
        self.add_filter(self.use_json)
Ejemplo n.º 10
0
    def __init__(self, username, password=None):
        """
        Create a BitBucket service.

        :var username: The username for the authenticated user.
        :vartype username: str

        :var password: The password for the authenticated user.
        :vartype password: str
        """
        self.apiroot = 'https://api.bitbucket.org/1.0'

        self.add_filter(auth.BasicAuth(username, password))
        # although not consistent throughout the documentation, BitBucket
        # resources seem to end with a trailing slash, regardless of whether
        # they represent a single object or a collection
        self.add_filter(self.add_trailing_slash)
Ejemplo n.º 11
0
    def __init__(self, apikey_or_username, password=None):
        """
        Create a Ducksboard service.

        :var apikey_or_username: Your apikey or your username if you
            want to get or reset your API key.
        :vartype apikey_or_username: str

        :var password: Only used with your username to get or reset your
            API key.
        :vartype password: str
        """
        self.apiroot = 'https://app.ducksboard.com/api'
        self.apikey_or_username = apikey_or_username

        self.add_filter(auth.BasicAuth(apikey_or_username, password))
        self.add_filter(self.use_json)
Ejemplo n.º 12
0
    def __init__(self, username, password, app_key):
        """
        Create a Pingdom service.

        :var username: The username for the authenticated user.
        :vartype username: str

        :var password: The password for the authenticated user.
        :vartype password: str

        :var app_key: The app_key for the application.
        :vartype app_key: str
        """
        self.apiroot = 'https://api.pingdom.com/api/2.0'
        self.app_key = app_key

        self.add_filter(auth.BasicAuth(username, password))
        self.add_filter(self.add_app_header)
Ejemplo n.º 13
0
    def __init__(self, subdomain, username, password):
        """
        Create a Zendesk service.

        :var subdomain: The account-specific part of the Zendesk domain, for
            instance use `mycompany` if your Zendesk domain is
            `mycompany.zendesk.com`.
        :vartype subdomain: str

        :var username: The email of the authenticated agent.
        :vartype username: str

        :var password: The password of the authenticated agent.
        :vartype password: str
        """
        tmpl = '{0}.zendesk.com/api/v2'
        self.apiroot = http.quote_any(tmpl.format(port.to_u(subdomain)))
        self.apiroot = 'https://' + self.apiroot

        self.add_filter(auth.BasicAuth(username, password))
        self.add_filter(self.use_json)
Ejemplo n.º 14
0
    def __init__(self, token, version='v1', test=False):
        """
        Initializes the EffiPeople service.

        You must pass the ``token`` for this service.

        >>> from effipy import EffiPeople
        >>> ef = EffiPeople(token='34234fasdfas2343fsdfa')
        >>> ef.apiroot
        >>> 'https://api.effipeople.com/v1'
        >>> ef = EffiPeople(token='34234fasdfas2343fsdfa', version='v2')
        >>> ef.apiroot
        >>> 'https://api.effipeople.com/v2'
        """
        self.token = token
        if test:
            endpoint = "https://effipeople-api-staging.azurewebsites.net"
        else:
            endpoint = "https://api.effipeople.com"
        self.apiroot = '%s/%s' % (endpoint, version)
        self.add_filter(self.use_json)
        self.add_filter(auth.BasicAuth(token, ''))
Ejemplo n.º 15
0
    def __init__(self,
                 subdomain,
                 username=None,
                 password=None,
                 access_token=None):
        """
        Create a Zendesk service.

        :var subdomain: The account-specific part of the Zendesk domain, for
            instance use `mycompany` if your Zendesk domain is
            `mycompany.zendesk.com`.
        :vartype subdomain: str

        :var username: The email of the authenticated agent. Use
            `[email protected]/token` for token-based authentication.
        :vartype username: str

        :var password: The password of the authenticated agent, or an API token
            if using token-based authentication.
        :vartype password: str

        :var access_token: An OAuth Access token. Username and password are not
            required if the OAuth Access token is provided.
        :vartype access_token: str
        """
        tmpl = '{0}.zendesk.com/api/v2'
        self.apiroot = http.quote_any(tmpl.format(port.to_u(subdomain)))
        self.apiroot = 'https://' + self.apiroot

        if access_token:
            self.access_token = access_token
            self.add_filter(self.add_authorization)
        else:
            self.add_filter(auth.BasicAuth(username, password))

        self.add_filter(self.use_json)
Ejemplo n.º 16
0
    def test_simple(self):
        auth_filter = auth.BasicAuth('user', 'pass')
        req = http.Request('GET', 'http://example.net/')
        auth_filter(req)

        self.assertEqual(req.headers['Authorization'], 'Basic dXNlcjpwYXNz')