Mantid
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
Mantid::Kernel::GitHubApiHelper Class Reference

GitHubApiHelper : A helper class for supporting access to the github api through HTTP and HTTPS, inherits from the InternetHelper. More...

#include <GitHubApiHelper.h>

Inheritance diagram for Mantid::Kernel::GitHubApiHelper:
Mantid::Kernel::InternetHelper

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::ProxyInfogetProxy (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...
 
StringToStringMapheaders ()
 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...
 

Additional Inherited Members

- Public Types inherited from Mantid::Kernel::InternetHelper
enum class  HTTPStatus {
  CONTINUE = 100 , SWITCHING_PROTOCOLS = 101 , OK = 200 , CREATED = 201 ,
  ACCEPTED = 202 , NONAUTHORITATIVE = 203 , NO_CONTENT = 204 , RESET_CONTENT = 205 ,
  PARTIAL_CONTENT = 206 , MULTIPLE_CHOICES = 300 , MOVED_PERMANENTLY = 301 , FOUND = 302 ,
  SEE_OTHER = 303 , NOT_MODIFIED = 304 , USEPROXY = 305 , TEMPORARY_REDIRECT = 307 ,
  BAD_REQUEST = 400 , UNAUTHORIZED = 401 , PAYMENT_REQUIRED = 402 , FORBIDDEN = 403 ,
  NOT_FOUND = 404 , METHOD_NOT_ALLOWED = 405 , NOT_ACCEPTABLE = 406 , PROXY_AUTHENTICATION_REQUIRED = 407 ,
  REQUEST_TIMEOUT = 408 , CONFLICT = 409 , GONE = 410 , LENGTH_REQUIRED = 411 ,
  PRECONDITION_FAILED = 412 , REQUESTENTITYTOOLARGE = 413 , REQUESTURITOOLONG = 414 , UNSUPPORTEDMEDIATYPE = 415 ,
  REQUESTED_RANGE_NOT_SATISFIABLE = 416 , EXPECTATION_FAILED = 417 , I_AM_A_TEAPOT = 418 , INTERNAL_SERVER_ERROR = 500 ,
  NOT_IMPLEMENTED = 501 , BAD_GATEWAY = 502 , SERVICE_UNAVAILABLE = 503 , GATEWAY_TIMEOUT = 504 ,
  VERSION_NOT_SUPPORTED = 505
}
 
using StringToStringMap = std::map< std::string, std::string >
 
- Protected Attributes inherited from Mantid::Kernel::InternetHelper
std::string m_body
 
std::streamsize m_contentLength
 
std::string m_contentType
 
StringToStringMap m_headers
 
bool m_isProxySet
 
bool m_isTimeoutSet
 
std::string m_method
 
Kernel::ProxyInfo m_proxyInfo
 
std::unique_ptr< Poco::Net::HTTPRequest > m_request
 
std::unique_ptr< Poco::Net::HTTPResponse > m_response
 
int m_timeout
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ GitHubApiHelper() [1/2]

Mantid::Kernel::GitHubApiHelper::GitHubApiHelper ( )

Constructor.

Definition at line 100 of file GitHubApiHelper.cpp.

References addAuthenticationToken().

◆ GitHubApiHelper() [2/2]

Mantid::Kernel::GitHubApiHelper::GitHubApiHelper ( const Kernel::ProxyInfo proxy)

Constructor.

Definition at line 105 of file GitHubApiHelper.cpp.

References addAuthenticationToken().

◆ ~GitHubApiHelper()

virtual Mantid::Kernel::GitHubApiHelper::~GitHubApiHelper ( )
virtualdefault

Member Function Documentation

◆ addAuthenticationToken()

void Mantid::Kernel::GitHubApiHelper::addAuthenticationToken ( )
private

Definition at line 114 of file GitHubApiHelper.cpp.

References Mantid::Kernel::InternetHelper::addHeader(), and m_api_token.

Referenced by GitHubApiHelper(), and reset().

◆ getRateLimitDescription()

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/

Returns
description of the status or an empty string

Definition at line 140 of file GitHubApiHelper.cpp.

References Mantid::Kernel::InternetHelper::sendRequest().

Referenced by Mantid::DataHandling::DownloadInstrument::exec().

◆ isAuthenticated()

bool Mantid::Kernel::GitHubApiHelper::isAuthenticated ( )

Definition at line 121 of file GitHubApiHelper.cpp.

References Mantid::Kernel::InternetHelper::m_headers.

Referenced by sendRequestAndProcess().

◆ processAnonymousRequest()

Kernel::InternetHelper::HTTPStatus Mantid::Kernel::GitHubApiHelper::processAnonymousRequest ( Poco::URI &  uri,
std::ostream &  responseStream 
)
private

◆ processResponseHeaders()

void Mantid::Kernel::GitHubApiHelper::processResponseHeaders ( const Poco::Net::HTTPResponse &  res)
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().

◆ reset()

void Mantid::Kernel::GitHubApiHelper::reset ( )
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().

◆ sendRequestAndProcess()

InternetHelper::HTTPStatus Mantid::Kernel::GitHubApiHelper::sendRequestAndProcess ( Poco::Net::HTTPClientSession &  session,
Poco::URI &  uri,
std::ostream &  responseStream 
)
overrideprotectedvirtual

Member Data Documentation

◆ m_api_token

std::string Mantid::Kernel::GitHubApiHelper::m_api_token
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().


The documentation for this class was generated from the following files: