Class: Octokit::Client
- Inherits:
-
Object
- Object
- Octokit::Client
- Includes:
- Authentication, Authorizations, CommitComments, Commits, Contents, Downloads, Emojis, Events, Gists, Gitignore, Issues, Labels, LegacySearch, Markdown, Meta, Milestones, Notifications, Objects, Organizations, PubSubHubbub, PullRequests, RateLimit, Refs, Repositories, Say, Search, ServiceStatus, Stats, Statuses, Users, Configurable
- Defined in:
- lib/octokit/client.rb,
lib/octokit/client/say.rb,
lib/octokit/client/meta.rb,
lib/octokit/client/refs.rb,
lib/octokit/client/gists.rb,
lib/octokit/client/stats.rb,
lib/octokit/client/users.rb,
lib/octokit/client/emojis.rb,
lib/octokit/client/events.rb,
lib/octokit/client/issues.rb,
lib/octokit/client/labels.rb,
lib/octokit/client/search.rb,
lib/octokit/client/commits.rb,
lib/octokit/client/objects.rb,
lib/octokit/client/contents.rb,
lib/octokit/client/markdown.rb,
lib/octokit/client/statuses.rb,
lib/octokit/client/downloads.rb,
lib/octokit/client/gitignore.rb,
lib/octokit/client/milestones.rb,
lib/octokit/client/rate_limit.rb,
lib/octokit/client/repositories.rb,
lib/octokit/client/legacy_search.rb,
lib/octokit/client/notifications.rb,
lib/octokit/client/organizations.rb,
lib/octokit/client/pull_requests.rb,
lib/octokit/client/authorizations.rb,
lib/octokit/client/pub_sub_hubbub.rb,
lib/octokit/client/service_status.rb,
lib/octokit/client/commit_comments.rb
Overview
Client for the GitHub API
Defined Under Namespace
Modules: Authorizations, CommitComments, Commits, Contents, Downloads, Emojis, Events, Gists, Gitignore, Issues, Labels, LegacySearch, Markdown, Meta, Milestones, Notifications, Objects, Organizations, PubSubHubbub, PullRequests, RateLimit, Refs, Repositories, Say, Search, ServiceStatus, Stats, Statuses, Users
Constant Summary collapse
- CONVENIENCE_HEADERS =
Set.new [:accept]
Constants included from ServiceStatus
Instance Attribute Summary
Attributes included from Configurable
#access_token, #api_endpoint, #auto_paginate, #client_id, #client_secret, #connection_options, #default_media_type, #login, #middleware, #netrc, #netrc_file, #password, #per_page, #proxy, #user_agent, #web_endpoint
Instance Method Summary collapse
-
#agent ⇒ Sawyer::Agent
Hypermedia agent for the GitHub API.
-
#authorize_url(app_id, app_secret, options = {}) ⇒ String
Get the URL to authorize a user for an application via the web flow.
-
#delete(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP DELETE request.
-
#get(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP GET request.
-
#head(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP HEAD request.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#inspect ⇒ String
Text representation of the client, masking tokens and passwords.
-
#last_response ⇒ Sawyer::Response
Response for last HTTP request.
-
#paginate(url, options = {}) ⇒ Sawyer::Resource
Make one or more HTTP GET requests, optionally fetching the next page of results from URL in Link response header based on value in Octokit::Configurable#auto_paginate.
-
#patch(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP PATCH request.
-
#post(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP POST request.
-
#put(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP PUT request.
-
#root ⇒ Sawyer::Resource
Fetch the root resource for the API.
-
#same_options?(opts) ⇒ Boolean
Compares client options to a Hash of requested options.
Methods included from Users
#add_email, #add_key, #all_users, #emails, #exchange_code_for_token, #follow, #followers, #following, #follows?, #key, #keys, #remove_email, #remove_key, #starred, #starred?, #subscriptions, #unfollow, #update_key, #update_user, #user, #user_keys, #validate_credentials
Methods included from Statuses
Methods included from Stats
#code_frequency_stats, #commit_activity_stats, #contributors_stats, #participation_stats, #punch_card_stats
Methods included from ServiceStatus
#github_status, #github_status_last_message, #github_status_messages
Methods included from Search
#search_code, #search_issues, #search_repositories, #search_users
Methods included from Say
Methods included from Repositories
#add_collaborator, #add_deploy_key, #all_repositories, #branch, #branches, #check_assignee, #collaborators, #contributors, #create_hook, #create_repository, #delete_repository, #delete_subscription, #deploy_keys, #edit_hook, #edit_repository, #fork, #forks, #hook, #hooks, #languages, #remove_collaborator, #remove_deploy_key, #remove_hook, #repositories, #repository, #repository?, #repository_assignees, #repository_teams, #set_private, #set_public, #star, #stargazers, #subscribers, #subscription, #tags, #test_hook, #unstar, #unwatch, #update_subscription, #watch, #watchers
Methods included from Refs
#create_ref, #delete_ref, #ref, #refs, #update_ref
Methods included from RateLimit
#rate_limit, #rate_limit!, #rate_limit_remaining, #rate_limit_remaining!
Methods included from PullRequests
#close_pull_request, #create_pull_request, #create_pull_request_comment, #create_pull_request_comment_reply, #create_pull_request_for_issue, #delete_pull_request_comment, #merge_pull_request, #pull_merged?, #pull_request, #pull_request_comment, #pull_request_comments, #pull_request_commits, #pull_request_files, #pull_requests, #pull_requests_comments, #update_pull_request, #update_pull_request_comment
Methods included from PubSubHubbub
#subscribe, #subscribe_service_hook, #unsubscribe, #unsubscribe_service_hook
Methods included from Organizations
#add_team_member, #add_team_repository, #create_team, #delete_team, #organization, #organization_member?, #organization_members, #organization_public_member?, #organization_repositories, #organization_teams, #organizations, #publicize_membership, #remove_organization_member, #remove_team_member, #remove_team_repository, #team, #team_member?, #team_members, #team_repositories, #unpublicize_membership, #update_organization, #update_team
Methods included from Objects
#blob, #create_blob, #create_tag, #create_tree, #tag, #tree
Methods included from Notifications
#delete_thread_subscription, #mark_notifications_as_read, #mark_repository_notifications_as_read, #mark_thread_as_read, #notifications, #repository_notifications, #thread_notifications, #thread_subscription, #update_thread_subscription
Methods included from Milestones
#create_milestone, #delete_milestone, #list_milestones, #milestone, #update_milestone
Methods included from Markdown
Methods included from Meta
Methods included from LegacySearch
#legacy_search_issues, #legacy_search_repositories, #legacy_search_users
Methods included from Labels
#add_label, #add_labels_to_an_issue, #delete_label!, #label, #labels, #labels_for_issue, #labels_for_milestone, #remove_all_labels, #remove_label, #replace_all_labels, #update_label
Methods included from Issues
#add_comment, #close_issue, #create_issue, #delete_comment, #issue, #issue_comment, #issue_comments, #issues_comments, #list_issues, #org_issues, #reopen_issue, #update_comment, #update_issue, #user_issues
Methods included from Gitignore
#gitignore_template, #gitignore_templates
Methods included from Gists
#create_gist, #create_gist_comment, #delete_gist, #delete_gist_comment, #edit_gist, #fork_gist, #gist, #gist_comment, #gist_comments, #gist_starred?, #gists, #public_gists, #star_gist, #starred_gists, #unstar_gist, #update_gist_comment
Methods included from Events
#issue_event, #issue_events, #organization_events, #organization_public_events, #public_events, #received_events, #received_public_events, #repository_events, #repository_issue_events, #repository_network_events, #user_events, #user_public_events
Methods included from Emojis
Methods included from Downloads
#create_download, #delete_download, #download, #downloads
Methods included from Contents
#archive_link, #contents, #create_contents, #delete_contents, #readme, #update_contents
Methods included from CommitComments
#commit_comment, #commit_comments, #create_commit_comment, #delete_commit_comment, #list_commit_comments, #update_commit_comment
Methods included from Commits
#commit, #commit_comment, #commit_comments, #commits, #commits_before, #commits_between, #commits_on, #commits_since, #compare, #create_commit, #create_commit_comment, #delete_commit_comment, #list_commit_comments, #merge, #update_commit_comment
Methods included from Authorizations
#authorization, #authorizations, #create_authorization, #delete_authorization, #scopes, #update_authorization
Methods included from Configurable
#configure, keys, #netrc?, #reset!
Methods included from Authentication
#application_authenticated?, #basic_authenticated?, #token_authenticated?, #user_authenticated?
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
81 82 83 84 85 86 87 88 |
# File 'lib/octokit/client.rb', line 81 def initialize( = {}) # Use options passed in, but fall back to module defaults Octokit::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", [key] || Octokit.instance_variable_get(:"@#{key}")) end login_from_netrc unless user_authenticated? || application_authenticated? end |
Instance Method Details
#agent ⇒ Sawyer::Agent
Hypermedia agent for the GitHub API
200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/octokit/client.rb', line 200 def agent @agent ||= Sawyer::Agent.new(api_endpoint, ) do |http| http.headers[:accept] = default_media_type http.headers[:user_agent] = user_agent if basic_authenticated? http.basic_auth(@login, @password) elsif token_authenticated? http. 'token', @access_token end end end |
#authorize_url(app_id, app_secret, options = {}) ⇒ String
Get the URL to authorize a user for an application via the web flow
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/octokit/client/authorizations.rb', line 129 def (app_id, app_secret, = {}) = .delete(:endpoint) || Octokit.web_endpoint += "login/oauth/authorize?client_id=" + app_id + "&client_secret=" + app_secret .each do |key, value| += "&" + key.to_s + "=" + value end end |
#delete(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP DELETE request
158 159 160 |
# File 'lib/octokit/client.rb', line 158 def delete(url, = {}) request :delete, url, end |
#get(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP GET request
122 123 124 |
# File 'lib/octokit/client.rb', line 122 def get(url, = {}) request :get, url, parse_query_and_convenience_headers() end |
#head(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP HEAD request
167 168 169 |
# File 'lib/octokit/client.rb', line 167 def head(url, = {}) request :head, url, parse_query_and_convenience_headers() end |
#inspect ⇒ String
Text representation of the client, masking tokens and passwords
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/octokit/client.rb', line 101 def inspect inspected = super # mask password inspected = inspected.gsub! @password, "*******" if @password # Only show last 4 of token, secret if @access_token inspected = inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}" end if @client_secret inspected = inspected.gsub! @client_secret, "#{'*'*36}#{@client_secret[36..-1]}" end inspected end |
#last_response ⇒ Sawyer::Response
Response for last HTTP request
222 223 224 |
# File 'lib/octokit/client.rb', line 222 def last_response @last_response end |
#paginate(url, options = {}) ⇒ Sawyer::Resource
Make one or more HTTP GET requests, optionally fetching the next page of results from URL in Link response header based on value in Octokit::Configurable#auto_paginate.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/octokit/client.rb', line 178 def paginate(url, = {}) opts = parse_query_and_convenience_headers(.dup) if @auto_paginate || @per_page opts[:query][:per_page] ||= @per_page || (@auto_paginate ? 100 : nil) end data = request(:get, url, opts) if @auto_paginate && data.is_a?(Array) while @last_response.rels[:next] && rate_limit.remaining > 0 @last_response = @last_response.rels[:next].get data.concat(@last_response.data) if @last_response.data.is_a?(Array) end end data end |
#patch(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP PATCH request
149 150 151 |
# File 'lib/octokit/client.rb', line 149 def patch(url, = {}) request :patch, url, end |
#post(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP POST request
131 132 133 |
# File 'lib/octokit/client.rb', line 131 def post(url, = {}) request :post, url, end |
#put(url, options = {}) ⇒ Sawyer::Resource
Make a HTTP PUT request
140 141 142 |
# File 'lib/octokit/client.rb', line 140 def put(url, = {}) request :put, url, end |
#root ⇒ Sawyer::Resource
Fetch the root resource for the API
215 216 217 |
# File 'lib/octokit/client.rb', line 215 def root agent.start.data end |
#same_options?(opts) ⇒ Boolean
Compares client options to a Hash of requested options
94 95 96 |
# File 'lib/octokit/client.rb', line 94 def (opts) opts.hash == .hash end |