Movatterモバイル変換


[0]ホーム

URL:


Libraries »piotrmurach/github(master) »Index (A) »Github »API

Class: Github::API

Inherits:
Object
  • Object
  • Github::API
show all
Includes:
Authorization,Constants,MimeType,RateLimit,Request::Verbs
Defined in:
lib/github_api/api.rb,
lib/github_api/api/config.rb,
lib/github_api/api/actions.rb,
lib/github_api/api/factory.rb,
lib/github_api/api/arguments.rb,
lib/github_api/api/config/property.rb,
lib/github_api/api/config/property_set.rb

Overview

Responsible for providing inspection of api methods

Direct Known Subclasses

Client,Client::Activity,Client::Activity::Events,Client::Activity::Feeds,Client::Activity::Notifications,Client::Activity::Starring,Client::Activity::Watching,Client::Authorizations,Client::Emojis,Client::Gists,Client::Gists::Comments,Client::GitData,Client::GitData::Blobs,Client::GitData::Commits,Client::GitData::References,Client::GitData::Tags,Client::GitData::Trees,Client::Gitignore,Client::Issues,Client::Issues::Assignees,Client::Issues::Comments,Client::Issues::Events,Client::Issues::Labels,Client::Issues::Milestones,Client::Markdown,Client::Meta,Client::Orgs,Client::Orgs::Hooks,Client::Orgs::Members,Client::Orgs::Memberships,Client::Orgs::Projects,Client::Orgs::Teams,Client::Projects,Client::Projects::Cards,Client::Projects::Columns,Client::PullRequests,Client::PullRequests::Comments,Client::PullRequests::Reviews,Client::Repos,Client::Repos::Branches,Client::Repos::Branches::Protections,Client::Repos::Collaborators,Client::Repos::Comments,Client::Repos::Commits,Client::Repos::Contents,Client::Repos::Deployments,Client::Repos::Downloads,Client::Repos::Forks,Client::Repos::Hooks,Client::Repos::Invitations,Client::Repos::Keys,Client::Repos::Merging,Client::Repos::Pages,Client::Repos::Projects,Client::Repos::PubSubHubbub,Client::Repos::Releases,Client::Repos::Releases::Assets,Client::Repos::Releases::Tags,Client::Repos::Statistics,Client::Repos::Statuses,Client::Say,Client::Scopes,Client::Search,Client::Search::Legacy,Client::Users,Client::Users::Emails,Client::Users::Followers,Client::Users::Keys

Defined Under Namespace

Classes:Arguments,Config,Factory

Constant Summary

Constants included fromMimeType

MimeType::MEDIA_LOOKUP

Constants included fromConstants

Constants::ACCEPT,Constants::ACCEPTED_OAUTH_SCOPES,Constants::ACCEPT_CHARSET,Constants::CACHE_CONTROL,Constants::CONTENT_LENGTH,Constants::CONTENT_TYPE,Constants::DATE,Constants::ETAG,Constants::HEADER_LAST,Constants::HEADER_LINK,Constants::HEADER_NEXT,Constants::LOCATION,Constants::META_FIRST,Constants::META_LAST,Constants::META_NEXT,Constants::META_PREV,Constants::META_REL,Constants::OAUTH_SCOPES,Constants::PARAM_PAGE,Constants::PARAM_PER_PAGE,Constants::PARAM_START_PAGE,Constants::RATELIMIT_LIMIT,Constants::RATELIMIT_REMAINING,Constants::RATELIMIT_RESET,Constants::SERVER,Constants::USER_AGENT

Class Attribute Summarycollapse

Instance Attribute Summarycollapse

Class Method Summarycollapse

Instance Method Summarycollapse

Methods included fromRequest::Verbs

#delete_request,#get_request,#head_request,#options_request,#patch_request,#post_request,#put_request

Methods included fromRateLimit

#ratelimit,#ratelimit_remaining,#ratelimit_reset

Methods included fromMimeType

#lookup_media,#parse

Methods included fromAuthorization

#auth_code,#authenticated?,#authentication,#authorize_url,#basic_authed?,#client,#get_token

Constructor Details

#initialize(options = {}, &block) ⇒API

Create new API

596061626364656667686970717273
# File 'lib/github_api/api.rb', line 59definitialize(options={},&block)opts=Github.configuration.fetch.merge(options)@current_options=optsGithub.configuration.property_names.eachdo|key|send("#{key}=",opts[key])endifopts.key?(:login)&&!opts[:login].nil?@login,@password=opts[:login],opts[:password]elsifopts.key?(:basic_auth)&&!opts[:basic_auth].nil?@login,@password=extract_basic_auth(opts[:basic_auth])endyield_or_eval(&block)ifblock_given?end

Dynamic Method Handling

This class handles dynamic methods through themethod_missing method

#method_missing(method_name, *args, &block) ⇒Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Responds to attribute query or attribute clear

258259260261262263264265266267
# File 'lib/github_api/api.rb', line 258defmethod_missing(method_name,*args,&block)# :nodoc:casemethod_name.to_swhen/^(.*)\?$/return!!send($1.to_s)when/^clear_(.*)$/send("#{$1.to_s}=",nil)elsesuperendend

Class Attribute Details

.rootObject(readonly)Also known as:root?

Returns the value of attribute root.

134135136
# File 'lib/github_api/api.rb', line 134defroot@rootend

Instance Attribute Details

#current_optionsObject

Returns the value of attribute current_options.

282930
# File 'lib/github_api/api.rb', line 28defcurrent_options@current_optionsend

Class Method Details

.after_callbacksObject

List of after callbacks

115116117
# File 'lib/github_api/api.rb', line 115defself.after_callbacks@after_callbacks||=[]end

.after_request(callback, params = {}) ⇒Object

After request filter

129130131
# File 'lib/github_api/api.rb', line 129defself.after_request(callback,params={})after_callbacks<<params.merge(callback:callback)end

.before_callbacksObject

List of before callbacks

108109110
# File 'lib/github_api/api.rb', line 108defself.before_callbacks@before_callbacks||=[]end

.before_request(callback, params = {}) ⇒Object

Before request filter

122123124
# File 'lib/github_api/api.rb', line 122defself.before_request(callback,params={})before_callbacks<<params.merge(callback:callback)end

.clear_request_methods!Object

183184185
# File 'lib/github_api/api.rb', line 183defself.clear_request_methods!@request_methods=nilend

.extend_with_actions(child_class) ⇒nil

Returns all API public methods for a given class.

Returns:

  • (nil)
1112131415161718192021222324
# File 'lib/github_api/api/actions.rb', line 11defself.extend_with_actions(child_class)returnunlesschild_class.is_a?(Class)returnifchild_class.name.nil?# Skip anonymous classeschild_class.class_eval<<-RUBY_EVAL,__FILE__,__LINE__+1    def self.actions      self.new.actions    end    def actions      api_methods_in(#{child_class}) + module_methods_in(#{child_class})    end  RUBY_EVALend

.extra_methodsObject

164165166
# File 'lib/github_api/api.rb', line 164defself.extra_methods['actions']end

.extract_class_name(name, options) ⇒String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extracts class name from options

Examples:

extract_class_name(:stats,class_name::statistics)

Parameters:

Options Hash (options):

  • :full_name(String)

    the full name for the class

  • :root(Boolean)

    if the class is at the root or not

Returns:

  • (String)
353354355356357358359
# File 'lib/github_api/api.rb', line 353defself.extract_class_name(name,options)converted=options.fetch(:full_name,name).to_sconverted=converted.split('_').map(&:capitalize).joinclass_name=options.fetch(:root,false)?'':"#{self.name}::"class_name+=convertedclass_nameend

.inherited(child_class) ⇒Object

142143144145146147148149150151152153154
# File 'lib/github_api/api.rb', line 142defself.inherited(child_class)before_callbacks.reverse_each{|callback|child_class.before_callbacks.unshift(callback)}after_callbacks.reverse_each{|callback|child_class.after_callbacks.unshift(callback)}extend_with_actions(child_class)unlesschild_class.instance_variable_defined?(:@root)child_class.instance_variable_set(:@root,false)endsuperend

.internal_methodsObject

158159160161162
# File 'lib/github_api/api.rb', line 158defself.internal_methodsapi=selfapi=api.superclassuntilapi.root?api.public_instance_methods(true)end

.method_added(method_name) ⇒Object

187188189190191192193194195196197198199200201202203204205206207208209210211212213214
# File 'lib/github_api/api.rb', line 187defself.method_added(method_name)method_name=method_name.to_s.gsub(/_with(out)?_callback_.*$/,'')# Only subclasses matterreturnifself.root?returnifextra_methods.include?(method_name)# Only public methods are of interestreturnunlessrequest_methods.include?(method_name)# Do not redefinereturnif(@__methods_added||=[]).include?(method_name)class_name=self.name.to_s.split('::').last.downcasewith_method="#{method_name}_with_callback_#{class_name}"without_method="#{method_name}_without_callback_#{class_name}"returnifpublic_method_defined?(with_method)[method_name,with_method,without_method].eachdo|met|@__methods_added<<metendreturnifpublic_method_defined?(with_method)define_method(with_method)do|*args,&block|send(:execute,without_method,*args,&block)endalias_methodwithout_method,method_namealias_methodmethod_name,with_methodclear_request_methods!end

.namespace(*names) ⇒self

Defines a namespace

Examples:

namespace:scopes

Parameters:

  • names(Array[Symbol])

    the name for the scope

Returns:

  • (self)
322323324325326327328329330331332333334335336337
# File 'lib/github_api/api.rb', line 322defself.namespace(*names)options=names.last.is_a?(Hash)?names.pop:{}names=names.map(&:to_sym)name=names.popifpublic_method_defined?(name)raiseArgumentError,"namespace '#{name}' is already defined"endclass_name=extract_class_name(name,options)define_method(name)do|*args,&block|options=args.last.is_a?(Hash)?args.pop:{}API::Factory.new(class_name,current_options.merge(options),&block)endend

.request_methodsSet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Find all the api methods that should be considred by request callbacks.

Returns:

  • (Set)
174175176177178179180181
# File 'lib/github_api/api.rb', line 174defself.request_methods@request_methods||=beginmethods=(public_instance_methods(true)-internal_methods+public_instance_methods(false)).uniq.map(&:to_s)Set.new(methods-extra_methods)endend

.require_all(prefix, *libs) ⇒self

Requires internal libraries

Parameters:

  • prefix(String)

    the relative path prefix

  • libs(Array[String])

    the array of libraries to require

Returns:

  • (self)
5051525354
# File 'lib/github_api/api.rb', line 50defself.require_all(prefix,*libs)libs.eachdo|lib|require"#{File.join(prefix,lib)}"endend

.root!Object

138139140
# File 'lib/github_api/api.rb', line 138defself.root!@root=trueend

Instance Method Details

#api_methods_in(klass) ⇒Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finds api methods in a class

Parameters:

  • klass(Class)

    The klass to inspect for methods.

32333435363738394041
# File 'lib/github_api/api/actions.rb', line 32defapi_methods_in(klass)methods=klass.send(:instance_methods,false)-[:actions]methods.sort.each_with_object([])do|method_name,accumulator|unlessmethod_name.to_s.include?('with')||method_name.to_s.include?('without')accumulator<<method_nameendaccumulatorendend

#arguments(args = (not_set = true), options = {}, &block) ⇒Object

Acts as setter and getter for api requests arguments parsing.

Returns Arguments instance.

277278279280281282283
# File 'lib/github_api/api.rb', line 277defarguments(args=(not_set=true),options={},&block)ifnot_set@argumentselse@arguments=Arguments.new(options.merge!(api:self)).parse(*args,&block)endend

#disable_redirectsObject

Disable following redirects inside a block

9899100101102103
# File 'lib/github_api/api.rb', line 98defdisable_redirectsself.follow_redirects=falseyieldensureself.follow_redirects=trueend

#execute(action, *args, &block) ⇒Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Execute action

Parameters:

  • action(Symbol)
246247248249250251252253
# File 'lib/github_api/api.rb', line 246defexecute(action,*args,&block)action_name=action.to_s.gsub(/_with(out)?_callback_.*$/,'')result=nilrun_callbacks(action_name)doresult=send(action,*args,&block)endresultend

#extract_basic_auth(auth) ⇒Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract login and password from basic_auth parameter

8687888990919293
# File 'lib/github_api/api.rb', line 86defextract_basic_auth(auth)caseauthwhenStringauth.split(':',2)whenHash[auth[:login],auth[:password]]endend

#filter_callbacks(kind, action_name) ⇒Array[Hash]

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Filter callbacks based on kind

Parameters:

  • kind(Symbol)

    one of :before or :after

Returns:

224225226227228
# File 'lib/github_api/api.rb', line 224deffilter_callbacks(kind,action_name)self.class.send("#{kind}_callbacks").selectdo|callback|callback[:only].nil?||callback[:only].include?(action_name)endend

#module_methods_in(klass) ⇒Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finds methods included through class modules

Parameters:

  • klass(Class)

    The klass to inspect for methods.

49505152535455565758
# File 'lib/github_api/api/actions.rb', line 49defmodule_methods_in(klass)klass.included_modules.each_with_object([])do|mod,accumulator|ifmod.to_s=~/#{klass}/mod.instance_methods(false).eachdo|method|accumulator<<methodendendaccumulatorendend

#respond_to?(method_name, include_private = false) ⇒Boolean

Returns:

  • (Boolean)
269270271
# File 'lib/github_api/api.rb', line 269defrespond_to?(method_name,include_private=false)method_name.to_s.start_with?('clear_')||superend

#run_callbacks(action_name, &block) ⇒Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run all callbacks associated with this action

Parameters:

  • action_name(Symbol)
235236237238239
# File 'lib/github_api/api.rb', line 235defrun_callbacks(action_name,&block)filter_callbacks(:before,action_name).each{|hook|sendhook[:callback]}yieldifblock_given?filter_callbacks(:after,action_name).each{|hook|sendhook[:callback]}end

#set(option, value = (not_set=true), ignore_setter = false, &block) ⇒self

Set a configuration option for a given namespace

Parameters:

  • option(String)
  • value(Object)(defaults to:(not_set=true))
  • ignore_setter(Boolean)(defaults to:false)

Returns:

  • (self)

Raises:

  • (ArgumentError)
294295296297298299300301302303304305306307308309
# File 'lib/github_api/api.rb', line 294defset(option,value=(not_set=true),ignore_setter=false,&block)raiseArgumentError,'value not set'ifblockand!not_setreturnselfif!not_setandvalue.nil?ifnot_setset_optionsoptionreturnselfendifrespond_to?("#{option}=")andnotignore_setterreturn__send__("#{option}=",value)enddefine_accessorsoption,valueselfend

#yield_or_eval(&block) ⇒Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Call block with argument

78798081
# File 'lib/github_api/api.rb', line 78defyield_or_eval(&block)returnunlessblockblock.arity>0?yield(self):self.instance_eval(&block)end
Generated on Mon Nov 17 01:54:50 2025 byyard 0.9.37 (ruby-3.4.3).

[8]ページ先頭

©2009-2025 Movatter.jp