Module: Legion::Extensions::Github::Runners::Gists
- Includes:
- Helpers::Cache, Helpers::Client, Helpers::Lex
- Included in:
- Client
- Defined in:
- lib/legion/extensions/github/runners/gists.rb
Constant Summary
Constants included from Helpers::Cache
Helpers::Cache::DEFAULT_TTL, Helpers::Cache::DEFAULT_TTLS
Constants included from Helpers::Client
Helpers::Client::CREDENTIAL_RESOLVERS
Constants included from Helpers::TokenCache
Helpers::TokenCache::TOKEN_BUFFER_SECONDS
Instance Method Summary collapse
- #create_gist(files:, description: nil, public: false) ⇒ Object
- #delete_gist(gist_id:) ⇒ Object
- #get_gist(gist_id:) ⇒ Object
- #list_gists(per_page: 30, page: 1) ⇒ Object
- #update_gist(gist_id:, files: nil, description: nil) ⇒ Object
Methods included from Helpers::Cache
#cache_connected?, #cache_invalidate, #cache_write, #cached_get, #github_ttl_for, #local_cache_connected?, #local_cache_delete, #local_cache_get, #local_cache_set
Methods included from Helpers::Client
#connection, #gh_cli_token_output, #max_fallback_retries, #on_rate_limit, #on_scope_authorized, #on_scope_denied, #resolve_broker_app, #resolve_credential, #resolve_env, #resolve_gh_cli, #resolve_next_credential, #resolve_settings_app, #resolve_settings_delegated, #resolve_settings_pat, #resolve_vault_app, #resolve_vault_delegated, #resolve_vault_pat
Methods included from Helpers::ScopeRegistry
#credential_fingerprint, #invalidate_scope, #mark_rate_limited, #rate_limited?, #register_scope, #scope_status
Methods included from Helpers::TokenCache
#fetch_token, #mark_rate_limited, #rate_limited?, #store_token
Instance Method Details
#create_gist(files:, description: nil, public: false) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/legion/extensions/github/runners/gists.rb', line 24 def create_gist(files:, description: nil, public: false, **) payload = { files: files, description: description, public: public } response = connection(**).post('/gists', payload) cache_write("github:gist:#{response.body['id']}", response.body) if response.body['id'] { result: response.body } end |
#delete_gist(gist_id:) ⇒ Object
38 39 40 41 42 |
# File 'lib/legion/extensions/github/runners/gists.rb', line 38 def delete_gist(gist_id:, **) response = connection(**).delete("/gists/#{gist_id}") cache_invalidate("github:gist:#{gist_id}") if response.status == 204 { result: response.status == 204 } end |
#get_gist(gist_id:) ⇒ Object
20 21 22 |
# File 'lib/legion/extensions/github/runners/gists.rb', line 20 def get_gist(gist_id:, **) { result: cached_get("github:gist:#{gist_id}") { connection(**).get("/gists/#{gist_id}").body } } end |
#list_gists(per_page: 30, page: 1) ⇒ Object
14 15 16 17 18 |
# File 'lib/legion/extensions/github/runners/gists.rb', line 14 def list_gists(per_page: 30, page: 1, **) cred = resolve_credential fp = cred&.dig(:metadata, :credential_fingerprint) || 'anonymous' { result: cached_get("github:user:gists:#{fp}:#{page}:#{per_page}") { connection(**).get('/gists', per_page: per_page, page: page).body } } end |
#update_gist(gist_id:, files: nil, description: nil) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/legion/extensions/github/runners/gists.rb', line 31 def update_gist(gist_id:, files: nil, description: nil, **) payload = { files: files, description: description }.compact response = connection(**).patch("/gists/#{gist_id}", payload) cache_write("github:gist:#{gist_id}", response.body) if response.body['id'] { result: response.body } end |