<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def request(self, method, url_parts, headers=None, data=None):
 """ Method for making requests to the Optimizely API """

        if method in self.ALLOWED_REQUESTS:
            # add request token header
            headers = headers or {}

            # test if Oauth token
            if self.token_type == 'legacy':
                headers.update(
                    {'Token': self.api_key,
                     'User-Agent': 'optimizely-client-python/0.1.1'})
            elif self.token_type == 'oauth':
                headers.update(
                    {'Authorization': 'Bearer ' + self.api_key,
                     'User-Agent': 'optimizely-client-python/0.1.1'})
            else:
                raise ValueError(
                    '{} is not a valid token type.'.format(self.token_type))
            # make request and return parsed response
            url = urlparse.urljoin(
                self.api_base,
                '/'.join([str(url_part) for url_part in url_parts])
            )
            return self.parse_response(
                getattr(requests, method)(url, headers=headers, data=data)
            )
        else:
            raise error.BadRequestError(
                '%s is not a valid request type.' % method)