helpjuice.client
Client
This module provides a Client object to interface with the Helpjuice API.
Module Contents
Classes
Attaches API Key Authentication to the given Request object. |
|
Helpjuice Client. |
|
The built-in HTTP Adapter for urllib3. |
Attributes
- helpjuice.client.logger
- class helpjuice.client.HelpjuiceAuth(api_key)
Bases:
requests.auth.HTTPBasicAuthAttaches API Key Authentication to the given Request object.
- class helpjuice.client.Client(account, api_key, v='v3', timeout=5, total=5, backoff_factor=30)
Bases:
requests.SessionHelpjuice Client.
Constructs a
requests.Sessionfor Helpjuice API requests with authorization, base URL, request timeouts, and request retries.- Parameters
account (str) – Helpjuice base address subdomain.
api_key (str) – Helpjuice API key.
version (str, optional) – Helpjuice API version. Defaults to “v3”.
timeout (int, optional) –
TimeoutHTTPAdaptertimeout value. Defaults to 5.total (int, optional) –
Retrytotal value. Defaults to 5.backoff_factor (int, optional) –
Retrybackoff_factor value. Defaults to 30.
Usage:
from helpjuice import Client helpjuice = Client(account="your-account", api_key="ffb722a62e8**********************") # Get a single article article = helpjuice.Article(id=1).get() # Search for articles with pagination for question in helpjuice.Search().get(query="foo", limit=1000, paginate=True): print(question)
- request(method, path, *args, **kwargs)
Override
Sessionrequest method to add retries and output JSON.- Parameters
method (str) – Method for the new Request object.
path (str) – Path from host for the new Request object.
- Returns
Response JSON
- Return type
dict
- class helpjuice.client.TimeoutHTTPAdapter(timeout, *args, **kwargs)
Bases:
requests.adapters.HTTPAdapterThe built-in HTTP Adapter for urllib3.
Provides a general-case interface for Requests sessions to contact HTTP and HTTPS urls by implementing the Transport Adapter interface. This class will usually be created by the
Sessionclass under the covers.- Parameters
pool_connections – The number of urllib3 connection pools to cache.
pool_maxsize – The maximum number of connections to save in the pool.
max_retries – The maximum number of retries each connection should attempt. Note, this applies only to failed DNS lookups, socket connections and connection timeouts, never to requests where data has made it to the server. By default, Requests does not retry failed connections. If you need granular control over the conditions under which we retry a request, import urllib3’s
Retryclass and pass that instead.pool_block – Whether the connection pool should block for connections.
Usage:
>>> import requests >>> s = requests.Session() >>> a = requests.adapters.HTTPAdapter(max_retries=3) >>> s.mount('http://', a)
- send(request, **kwargs)
Override
HTTPAdaptersend method to add a default timeout.