Class: PlanMyStuff::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/plan_my_stuff/client.rb

Overview

Infrastructure wrapper around Octokit. Handles auth, error normalization, and repo resolution. Domain modules (Issues, Projects, etc.) use this internally via PlanMyStuff.client.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(importing: false) ⇒ Client

Raises:



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/plan_my_stuff/client.rb', line 54

def initialize(importing: false)
  PlanMyStuff.configuration.validate!

  access_token = importing ? PlanMyStuff.configuration.import_access_token : PlanMyStuff.configuration.access_token

  if importing && access_token.blank?
    raise(PlanMyStuff::ConfigurationError, 'Import access token is required for import client but not configured')
  end

  @octokit = Octokit::Client.new(access_token: access_token)
end

Instance Attribute Details

#octokitOctokit::Client (readonly)

Returns:

  • (Octokit::Client)


11
12
13
# File 'lib/plan_my_stuff/client.rb', line 11

def octokit
  @octokit
end

Class Method Details

.exit_trace_mode!void

This method returns an undefined value.

Disables trace mode and clears any recorded requests.



34
35
36
37
# File 'lib/plan_my_stuff/client.rb', line 34

def exit_trace_mode!
  @trace_mode = false
  @traced_requests = []
end

.trace_mode!void

This method returns an undefined value.

Activates trace mode: every rest and graphql call is recorded into traced_requests until exit_trace_mode! is called. Useful for debugging which GitHub calls a code path makes.



25
26
27
28
# File 'lib/plan_my_stuff/client.rb', line 25

def trace_mode!
  @trace_mode = true
  @traced_requests = []
end

.trace_mode?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/plan_my_stuff/client.rb', line 40

def trace_mode?
  @trace_mode == true
end

.traced_requestsArray<Hash>

Returns:

  • (Array<Hash>)


45
46
47
# File 'lib/plan_my_stuff/client.rb', line 45

def traced_requests
  @traced_requests ||= []
end

Instance Method Details

#graphql(query, variables: {}) ⇒ Hash

Executes a GraphQL query against GitHub’s /graphql endpoint.

Parameters:

  • query (String)

    GraphQL query string

  • variables (Hash) (defaults to: {})

    GraphQL variables

Returns:

  • (Hash)

    parsed response data



87
88
89
90
91
# File 'lib/plan_my_stuff/client.rb', line 87

def graphql(query, variables: {})
  trace!(:graphql, query: query, variables: variables) do
    execute_graphql!(query, variables)
  end
end

#last_responseFaraday::Response?

Returns the Faraday response from the most recent Octokit call. Useful for reading headers (e.g. ‘ETag`, `X-RateLimit-Remaining`) that aren’t included in the parsed response body.

Returns:

  • (Faraday::Response, nil)


17
# File 'lib/plan_my_stuff/client.rb', line 17

delegate :last_response, to: :octokit

#resolve_repo!(repo = nil) ⇒ String

Resolves a repo param to a full “Org/Repo” string.

Parameters:

  • repo (Symbol, String, PlanMyStuff::Repo, nil) (defaults to: nil)

    repo key, full string, Repo instance, or nil for default

Returns:

  • (String)

    full repo path (e.g. “BrandsInsurance/Element”)



99
100
101
# File 'lib/plan_my_stuff/client.rb', line 99

def resolve_repo!(repo = nil)
  PlanMyStuff::Repo.resolve!(repo).full_name
end

#rest(method, *args, **kwargs, &block) ⇒ Object

Delegates a REST API call to Octokit, normalizing errors.

Parameters:

  • method (Symbol)

    Octokit method name (e.g. :create_issue)

  • args (Array)

    positional arguments

  • kwargs (Hash)

    keyword arguments

Returns:

  • (Object)

    Octokit response



74
75
76
77
78
# File 'lib/plan_my_stuff/client.rb', line 74

def rest(method, *args, **kwargs, &block)
  trace!(:rest, method: method, args: args, kwargs: kwargs) do
    execute_rest!(method, *args, **kwargs, &block)
  end
end