Class: Github::API
- Inherits:
-
Object
- Object
- Github::API
- Includes:
- Authorization, Connection, Constants, MimeType, RateLimit, Request
- Defined in:
- lib/github_api/api.rb,
lib/github_api/api/actions.rb
Overview
Core class for api interface operations
Direct Known Subclasses
Activity, Github::Activity::Events, Github::Activity::Notifications, Github::Activity::Starring, Github::Activity::Watching, Authorizations, Client, Deployments, Emojis, Gists, Gists::Comments, GitData, GitData::Blobs, GitData::Commits, GitData::References, GitData::Tags, GitData::Trees, Gitignore, Issues, Issues::Assignees, Issues::Comments, Issues::Events, Issues::Labels, Issues::Milestones, Markdown, Meta, Orgs, Orgs::Members, Orgs::Teams, PullRequests, PullRequests::Comments, Repos, Repos::Collaborators, Repos::Comments, Repos::Commits, Repos::Contents, Repos::Downloads, Repos::Forks, Repos::Hooks, Repos::Keys, Repos::Merging, Repos::Pages, Repos::PubSubHubbub, Repos::Releases, Repos::Releases::Assets, Repos::Statistics, Repos::Statuses, Resource, Say, Scopes, Search, Search::Legacy, Users, Users::Emails, Users::Followers, Users::Keys
Constant Summary
Constants included from Request
Request::METHODS, Request::METHODS_WITH_BODIES
Constants included from Connection
Constants included from Constants
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::SERVER, Constants::USER_AGENT
Constants included from MimeType
Instance Attribute Summary collapse
-
#current_options ⇒ Object
Returns the value of attribute current_options.
Attributes included from Authorization
Class Method Summary collapse
-
.inherited(klass) ⇒ Object
Returns all API public methods for a given class.
Instance Method Summary collapse
- #api_methods_in(klass) ⇒ Object
- #append_arguments(method) ⇒ Object
-
#arguments(args = (not_set = true), options = {}, &block) ⇒ Object
Acts as setter and getter for api requests arguments parsing.
-
#initialize(options = {}, &block) ⇒ API
constructor
Create new API.
-
#method_missing(method, *args, &block) ⇒ Object
Responds to attribute query or attribute clear.
-
#process_basic_auth(auth) ⇒ Object
Extract login and password from basic_auth parameter.
-
#set(option, value = (not_set=true), ignore_setter = false, &block) ⇒ Object
Set an option to a given value.
-
#setup(options = {}) ⇒ Object
Configure options and process basic authorization.
-
#with(args) ⇒ Object
Scope for passing request required arguments.
- #yield_or_eval(&block) ⇒ Object
Methods included from RateLimit
#ratelimit, #ratelimit_remaining
Methods included from Request
#delete_request, #get_request, #patch_request, #post_request, #put_request, #request
Methods included from Connection
#caching?, #clear_cache, #connection, #default_middleware, #default_options, #stack
Methods included from MimeType
Methods included from Authorization
#auth_code, #authenticated?, #authentication, #authorize_url, #basic_authed?, #client, #get_token
Constructor Details
#initialize(options = {}, &block) ⇒ API
Create new API
43 44 45 46 |
# File 'lib/github_api/api.rb', line 43 def initialize(={}, &block) setup() yield_or_eval(&block) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Responds to attribute query or attribute clear
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/github_api/api.rb', line 77 def method_missing(method, *args, &block) # :nodoc: case method.to_s when /^(.*)\?$/ return !!self.send($1.to_s) when /^clear_(.*)$/ self.send("#{$1.to_s}=", nil) else super end end |
Instance Attribute Details
#current_options ⇒ Object
Returns the value of attribute current_options.
29 30 31 |
# File 'lib/github_api/api.rb', line 29 def @current_options end |
Class Method Details
.inherited(klass) ⇒ Object
Returns all API public methods for a given class.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/github_api/api/actions.rb', line 7 def self.inherited(klass) klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def self.actions self.new.api_methods_in(#{klass}) end def actions api_methods_in(#{klass}) end RUBY_EVAL super end |
Instance Method Details
#api_methods_in(klass) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/github_api/api/actions.rb', line 19 def api_methods_in(klass) puts "---" (klass.send(:instance_methods, false) - ['actions']).sort.each do |method| puts "|--> #{method}" end klass.included_modules.each do |mod| if mod.to_s =~ /#{klass}/ puts "| \\ #{mod.to_s}" mod.instance_methods(false).each do |met| puts "| |--> #{met}" end puts "| /" end end puts "---" nil end |
#append_arguments(method) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/github_api/api/actions.rb', line 37 def append_arguments(method) _method = self.method(method) if _method.arity == 0 args = "()" elsif _method.arity > 0 args = "(few)" else args = "(else)" end args end |
#arguments(args = (not_set = true), options = {}, &block) ⇒ Object
Acts as setter and getter for api requests arguments parsing.
Returns Arguments instance.
92 93 94 95 96 97 98 |
# File 'lib/github_api/api.rb', line 92 def arguments(args=(not_set = true), ={}, &block) if not_set @arguments else @arguments = Arguments.new(self, ).parse(*args, &block) end end |
#process_basic_auth(auth) ⇒ Object
Extract login and password from basic_auth parameter
66 67 68 69 70 71 72 73 74 |
# File 'lib/github_api/api.rb', line 66 def process_basic_auth(auth) case auth when String self.login, self.password = auth.split(':', 2) when Hash self.login = auth[:login] self.password = auth[:password] end end |
#set(option, value = (not_set=true), ignore_setter = false, &block) ⇒ Object
Set an option to a given value
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/github_api/api.rb', line 115 def set(option, value=(not_set=true), ignore_setter=false, &block) raise ArgumentError, 'value not set' if block and !not_set return self if !not_set and value.nil? if not_set option return self end if respond_to?("#{option}=") and not ignore_setter return __send__("#{option}=", value) end define_accessors option, value self end |
#setup(options = {}) ⇒ Object
Configure options and process basic authorization
55 56 57 58 59 60 61 62 |
# File 'lib/github_api/api.rb', line 55 def setup(={}) = Github..merge() self. = Configuration.keys.each do |key| send("#{key}=", [key]) end process_basic_auth([:basic_auth]) end |
#with(args) ⇒ Object
Scope for passing request required arguments.
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/github_api/api.rb', line 102 def with(args) case args when Hash set args when /.*\/.*/i user, repo = args.split('/') set :user => user, :repo => repo else ::Kernel.raise ArgumentError, 'This api does not support passed in arguments' end end |
#yield_or_eval(&block) ⇒ Object
48 49 50 51 |
# File 'lib/github_api/api.rb', line 48 def yield_or_eval(&block) return unless block block.arity > 0 ? yield(self) : self.instance_eval(&block) end |