def _get(self, method, format, params=None, headers=None, raw=False): """Performs GET request""" from requests.models import urlencode url = self._build_url(method, format) if params: url = "{0}?{1}".format(url, urlencode(params, True)) return self._request(url, None, headers, format, raw)
def get_auth_request_url(self, scopes: Optional[List[str]] = None) -> str: """Returns the url that a client needs to request an oauth grant from the server. To get an oauth access token, send your user to this URL. The user will be prompted to log in to FreshBooks, after which they will be redirected to the `redirect_uri` set on the client with the access grant as a parameter. That grant can then be used to fetch an access token by calling `get_access_token`. Note: The `redirect_uri` must be one of the URLs your application is registered for. If scopes are not specified, then the access token will be given the default scopes your application is registered for. Args: scopes: List of scopes if your want an access token with only a subset of your registered scopes Returns: The URL for the authorization request Raises: FreshBooksClientConfigError: If redirect_uri is not set on the client instance. """ if not self.redirect_uri: raise FreshBooksClientConfigError("redirect_uri must be configured") params = { "client_id": self.client_id, "response_type": "code", "redirect_uri": self.redirect_uri, } if scopes: params["scope"] = " ".join(scopes) formatted_params = "".join(urlencode(params)) return f"{self.authorization_url}?{formatted_params}"
def _predict_url(self, bypass_setting_attrs=False): """Can be used before or after dictionaries have been cleaned of NoneTypes""" prediction = self.base_url + self._encoded_q + '&' + urlencode( self.params) if not bypass_setting_attrs: self.last_predicted_url = prediction return prediction
def test_data_argument_accepts_tuples(list_of_tuples): """ Ensure that the data argument will accept tuples of strings and properly encode them. """ for data in list_of_tuples: p = PreparedRequest() p.prepare(method="GET", url="http://www.example.com", data=data, hooks=default_hooks()) assert p.body == urlencode(data)
def test_data_argument_accepts_tuples(data): """Ensure that the data argument will accept tuples of strings and properly encode them. """ p = PreparedRequest() p.prepare(method='GET', url='http://www.example.com', data=data, hooks=default_hooks()) assert p.body == urlencode(data)
def test_data_argument_accepts_tuples(data): """Ensure that the data argument will accept tuples of strings and properly encode them. """ p = PreparedRequest() p.prepare( method='GET', url='http://www.example.com', data=data, hooks=default_hooks() ) assert p.body == urlencode(data)
def _init_constructor_funcs(self): self.base_url = local_static_constants.API_ENDPOINTS[ self.endpoint_type] # encode your query to be URL-rdy self._encoded_q = urlencode(dict(q=self.query_plaintext)) # clean out them' dictionary attrs. self.headers = _clear_null_vals(self.headers) self.params = _clear_null_vals(self.params) # inject key into header self.headers = self._inject_key_into_header(self.headers) self.last_predicted_url = self._predict_url(bypass_setting_attrs=True) if self._verbose: print 'The search-interface has been initialized w/ the following params:\n\nEndpoint-Type: {}\n\nQuery-URL: {}\n\nHeader-Dict: {}'.format( self.endpoint_type, self.last_predicted_url, self.headers)
def auth_request_url(self, client_id = None, redirect_uris = "urn:ietf:wg:oauth:2.0:oob", scopes = ['read', 'write', 'follow']): """Returns the url that a client needs to request the grant from the server. """ if client_id is None: client_id = self.client_id else: if os.path.isfile(client_id): with open(client_id, 'r') as secret_file: client_id = secret_file.readline().rstrip() params = {} params['client_id'] = client_id params['response_type'] = "code" params['redirect_uri'] = redirect_uris params['scope'] = " ".join(scopes) formatted_params = urlencode(params) return "".join([self.api_base_url, "/oauth/authorize?", formatted_params])
def _sign(self, headers, params): params['nonce'] = self.next_nonce headers.update({'Key': self._API_KEY}) headers.update({'Sign': self._sha512(urlencode(params))})
def reset_query_string_and_paging(self, unencoded_query_str): self.query_plaintext = unencoded_query_str self._encoded_q = urlencode(dict(q=self.query_plaintext)) self.current_offset = 0 self.total_estimated_matches = 0