Class: CleoQualityReview::GitHubClient

Inherits:
Object
  • Object
show all
Defined in:
lib/cleo_quality_review/github_client.rb

Overview

Thin authenticated HTTP client for the GitHub REST API

Defined Under Namespace

Classes: Response

Constant Summary collapse

API_VERSION =
"2022-11-28"
DEFAULT_API_URL =
"https://api.github.com"

Instance Method Summary collapse

Constructor Details

#initialize(token:, api_url: DEFAULT_API_URL) ⇒ GitHubClient

Returns a new instance of GitHubClient.

Parameters:

  • token (String)

    GitHub API token

  • api_url (String) (defaults to: DEFAULT_API_URL)

    base GitHub API URL



32
33
34
35
# File 'lib/cleo_quality_review/github_client.rb', line 32

def initialize(token:, api_url: DEFAULT_API_URL)
  @token = token
  @api_url = api_url.to_s.strip.empty? ? DEFAULT_API_URL : api_url
end

Instance Method Details

#get(path) ⇒ Response

Perform an authenticated GET request

Parameters:

  • path (String)

    API path beginning with "/"

Returns:



41
42
43
# File 'lib/cleo_quality_review/github_client.rb', line 41

def get(path)
  request_json(:get, uri_for(path))
end

#post(path, body) ⇒ Response

Perform an authenticated POST request

Parameters:

  • path (String)

    API path beginning with "/"

  • body (Hash)

    request body serialised as JSON

Returns:



50
51
52
# File 'lib/cleo_quality_review/github_client.rb', line 50

def post(path, body)
  request_json(:post, uri_for(path), body)
end