Class: PlanMyStuff::Client
- Inherits:
-
Object
- Object
- PlanMyStuff::Client
- 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
- #octokit ⇒ Octokit::Client readonly
Class Method Summary collapse
-
.exit_trace_mode! ⇒ void
Disables trace mode and clears any recorded requests.
-
.trace_mode! ⇒ void
Activates trace mode: every
restandgraphqlcall is recorded intotraced_requestsuntilexit_trace_mode!is called. - .trace_mode? ⇒ Boolean
- .traced_requests ⇒ Array<Hash>
Instance Method Summary collapse
-
#graphql(query, variables: {}) ⇒ Hash
Executes a GraphQL query against GitHub’s /graphql endpoint.
- #initialize(importing: false) ⇒ Client constructor
-
#last_response ⇒ Faraday::Response?
Returns the Faraday response from the most recent Octokit call.
-
#resolve_repo!(repo = nil) ⇒ String
Resolves a repo param to a full “Org/Repo” string.
-
#rest(method, *args, **kwargs, &block) ⇒ Object
Delegates a REST API call to Octokit, normalizing errors.
Constructor Details
#initialize(importing: false) ⇒ Client
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
#octokit ⇒ Octokit::Client (readonly)
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
40 41 42 |
# File 'lib/plan_my_stuff/client.rb', line 40 def trace_mode? @trace_mode == true end |
.traced_requests ⇒ 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.
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_response ⇒ Faraday::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.
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.
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.
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 |