|
Mantid
|
GitHubApiHelper : A helper class for supporting access to the github api through HTTP and HTTPS, inherits from the InternetHelper. More...
#include <GitHubApiHelper.h>
Public Member Functions | |
| std::string | getRateLimitDescription () |
| String describing the rate limit status. More... | |
| GitHubApiHelper () | |
| Constructor. More... | |
| GitHubApiHelper (const Kernel::ProxyInfo &proxy) | |
| Constructor. More... | |
| bool | isAuthenticated () |
| void | reset () override |
| Resets properties to defaults (except the proxy) More... | |
| virtual | ~GitHubApiHelper ()=default |
Public Member Functions inherited from Mantid::Kernel::InternetHelper | |
| void | addHeader (const std::string &key, const std::string &value) |
| Adds a header. More... | |
| void | clearHeaders () |
| Clears all headers. More... | |
| void | clearProxy () |
| Clears cached proxy details. More... | |
| virtual HTTPStatus | downloadFile (const std::string &urlFile, const std::string &localFilePath="") |
| Download a url and fetch it inside the local path given. More... | |
| const std::string & | getBody () |
| Gets the body set for future requests. More... | |
| std::streamsize | getContentLength () |
| Gets the content length. More... | |
| const std::string & | getContentType () |
| Gets the Content Type. More... | |
| const std::string & | getHeader (const std::string &key) |
| Gets the value of a header. More... | |
| const std::string & | getMethod () |
| Gets the method. More... | |
| Kernel::ProxyInfo & | getProxy (const std::string &url) |
| Gets proxy details for a system and a url. More... | |
| const std::string & | getResponseReason () |
| Gets the body set for future requests. More... | |
| HTTPStatus | getResponseStatus () |
| Gets the body set for future requests. More... | |
| int | getTimeout () |
| Gets the timeout in seconds. More... | |
| StringToStringMap & | headers () |
| Returns a reference to the headers map. More... | |
| InternetHelper () | |
| Constructor. More... | |
| InternetHelper (const Kernel::ProxyInfo &proxy) | |
| Constructor. More... | |
| void | removeHeader (const std::string &key) |
| Removes a header. More... | |
| virtual void | reset () |
| Resets properties to defaults (except the proxy) More... | |
| virtual HTTPStatus | sendRequest (const std::string &url, std::ostream &responseStream) |
| Performs a request using http or https depending on the url. More... | |
| void | setBody (const std::ostringstream &body) |
| Sets the body & content length for future requests, this will also set the method to POST is the body is not empty and GET if it is. More... | |
| void | setBody (const std::string &body) |
| Sets the body & content length for future requests, this will also set the method to POST is the body is not empty and GET if it is. More... | |
| void | setBody (Poco::Net::HTMLForm &form) |
| Sets the body & content length for future requests, this will also set the method to POST is the body is not empty and GET if it is. More... | |
| void | setContentLength (std::streamsize length) |
| Sets the content length. More... | |
| void | setContentType (const std::string &contentType) |
| Sets the Content Type. More... | |
| void | setMethod (const std::string &method) |
| Sets the Method. More... | |
| void | setProxy (const Kernel::ProxyInfo &proxy) |
| sets the proxy details. More... | |
| void | setTimeout (int seconds) |
| Sets the timeout in seconds. More... | |
| virtual | ~InternetHelper () |
| Destructor. More... | |
Protected Member Functions | |
| virtual void | processResponseHeaders (const Poco::Net::HTTPResponse &res) override |
| Process any headers from the response stream Basic implementation does nothing. More... | |
| virtual InternetHelper::HTTPStatus | sendRequestAndProcess (Poco::Net::HTTPClientSession &session, Poco::URI &uri, std::ostream &responseStream) override |
Protected Member Functions inherited from Mantid::Kernel::InternetHelper | |
| void | createRequest (Poco::URI &uri) |
| bool | isRelocated (const HTTPStatus &response) |
| Checks the HTTP status to decide if this is a relocation. More... | |
| void | logDebugRequestSending (const std::string &schemeName, const std::string &url) const |
| Helper to log (debug level) the request being sent (careful not to print blatant passwords, etc.). More... | |
| virtual HTTPStatus | processErrorStates (const Poco::Net::HTTPResponse &res, std::istream &rs, const std::string &url) |
| Process any HTTP errors states. More... | |
| InternetHelper::HTTPStatus | processRelocation (const Poco::Net::HTTPResponse &response, std::ostream &responseStream) |
| virtual void | processResponseHeaders (const Poco::Net::HTTPResponse &res) |
| Process any headers from the response stream Basic implementation does nothing. More... | |
| virtual HTTPStatus | sendHTTPRequest (const std::string &url, std::ostream &responseStream) |
| Performs a request using http. More... | |
| virtual HTTPStatus | sendHTTPSRequest (const std::string &url, std::ostream &responseStream) |
| Performs a request using https. More... | |
| virtual HTTPStatus | sendRequestAndProcess (Poco::Net::HTTPClientSession &session, Poco::URI &uri, std::ostream &responseStream) |
| void | setupProxyOnSession (Poco::Net::HTTPClientSession &session, const std::string &proxyUrl) |
| void | throwNotConnected (const std::string &url, const Poco::Net::HostNotFoundException &ex) |
| Throw an exception occurs when the computer is not connected to the internet. More... | |
Private Member Functions | |
| void | addAuthenticationToken () |
| InternetHelper::HTTPStatus | processAnonymousRequest (Poco::URI &uri, std::ostream &responseStream) |
Private Attributes | |
| std::string | m_api_token |
| API token for github access. More... | |
GitHubApiHelper : A helper class for supporting access to the github api through HTTP and HTTPS, inherits from the InternetHelper.
This class automatically adds the authorization to a read only account.
Definition at line 22 of file GitHubApiHelper.h.
| Mantid::Kernel::GitHubApiHelper::GitHubApiHelper | ( | ) |
Constructor.
Definition at line 100 of file GitHubApiHelper.cpp.
References addAuthenticationToken().
| Mantid::Kernel::GitHubApiHelper::GitHubApiHelper | ( | const Kernel::ProxyInfo & | proxy | ) |
Constructor.
Definition at line 105 of file GitHubApiHelper.cpp.
References addAuthenticationToken().
|
virtualdefault |
|
private |
Definition at line 114 of file GitHubApiHelper.cpp.
References Mantid::Kernel::InternetHelper::addHeader(), and m_api_token.
Referenced by GitHubApiHelper(), and reset().
| std::string Mantid::Kernel::GitHubApiHelper::getRateLimitDescription | ( | ) |
String describing the rate limit status.
This uses a url that github claims will never count against your REST API limit. https://developer.github.com/v3/rate_limit/
Definition at line 140 of file GitHubApiHelper.cpp.
References Mantid::Kernel::InternetHelper::sendRequest().
Referenced by Mantid::DataHandling::DownloadInstrument::exec().
| bool Mantid::Kernel::GitHubApiHelper::isAuthenticated | ( | ) |
Definition at line 121 of file GitHubApiHelper.cpp.
References Mantid::Kernel::InternetHelper::m_headers.
Referenced by sendRequestAndProcess().
|
private |
Definition at line 161 of file GitHubApiHelper.cpp.
References Mantid::Kernel::Logger::debug(), Mantid::Kernel::DateAndTimeHelpers::g_log, m_api_token, Mantid::Kernel::InternetHelper::removeHeader(), and Mantid::Kernel::InternetHelper::sendRequest().
Referenced by sendRequestAndProcess().
|
overrideprotectedvirtual |
Process any headers from the response stream Basic implementation does nothing.
Reimplemented from Mantid::Kernel::InternetHelper.
Definition at line 123 of file GitHubApiHelper.cpp.
References Mantid::Kernel::Logger::debug(), and Mantid::Kernel::DateAndTimeHelpers::g_log.
Referenced by sendRequestAndProcess().
|
overridevirtual |
Resets properties to defaults (except the proxy)
Reimplemented from Mantid::Kernel::InternetHelper.
Definition at line 109 of file GitHubApiHelper.cpp.
References addAuthenticationToken(), and Mantid::Kernel::InternetHelper::reset().
|
overrideprotectedvirtual |
Reimplemented from Mantid::Kernel::InternetHelper.
Definition at line 169 of file GitHubApiHelper.cpp.
References Mantid::Kernel::InternetHelper::CREATED, Mantid::Kernel::InternetHelper::createRequest(), Mantid::Kernel::Logger::debug(), Mantid::Kernel::InternetHelper::FORBIDDEN, Mantid::Kernel::DateAndTimeHelpers::g_log, isAuthenticated(), Mantid::Kernel::InternetHelper::isRelocated(), Mantid::Kernel::InternetHelper::m_body, Mantid::Kernel::InternetHelper::m_method, Mantid::Kernel::InternetHelper::m_request, Mantid::Kernel::InternetHelper::m_response, Mantid::Kernel::InternetHelper::NOT_FOUND, Mantid::Kernel::InternetHelper::OK, processAnonymousRequest(), Mantid::Kernel::InternetHelper::processErrorStates(), Mantid::Kernel::InternetHelper::processRelocation(), processResponseHeaders(), Mantid::Kernel::InternetHelper::UNAUTHORIZED, and Mantid::Kernel::Logger::warning().
|
private |
API token for github access.
This is only created during construction.
Definition at line 49 of file GitHubApiHelper.h.
Referenced by addAuthenticationToken(), and processAnonymousRequest().