Class: BitBucket::API
- Inherits:
-
Object
- Object
- BitBucket::API
- Includes:
- Authorization, Connection, Normalizer, ParameterFilter, Request, Validations
- Defined in:
- lib/bitbucket_rest_api/api.rb,
lib/bitbucket_rest_api/api/actions.rb
Direct Known Subclasses
Client, Invitations, Issues, Issues::Comments, Issues::Components, Issues::Milestones, Repos, Repos::Changesets, Repos::Commits, Repos::Components, Repos::DefaultReviewers, Repos::Download, Repos::Following, Repos::Forks, Repos::Keys, Repos::PullRequest, Repos::Services, Repos::Sources, Repos::Webhooks, Teams, User, Users, Users::Account
Constant Summary
Constants included from Validations
Constants included from Validations::Token
Validations::Token::TOKEN_REQUIRED, Validations::Token::TOKEN_REQUIRED_REGEXP
Constants included from Request
Request::METHODS, Request::METHODS_WITH_BODIES
Constants included from Connection
Class Method Summary collapse
-
.inherited(klass) ⇒ Object
Returns all API public methods for a given class.
Instance Method Summary collapse
-
#_merge_mime_type(resource, params) ⇒ Object
:nodoc:.
-
#_merge_user_into_params!(params) ⇒ Object
:nodoc:.
-
#_merge_user_repo_into_params!(params) ⇒ Object
:nodoc:.
-
#_update_user_repo_params(user_name, repo_name = nil) ⇒ Object
:nodoc:.
- #api_methods_in(klass) ⇒ Object
-
#initialize(options = {}, &block) ⇒ API
constructor
Creates 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_api_client ⇒ Object
Assigns current api class.
- #setup(options = {}) ⇒ Object
- #update_and_validate_user_repo_params(user_name, repo_name = nil) ⇒ Object
Methods included from Normalizer
Methods included from ParameterFilter
Methods included from AutoloadHelper
#autoload_all, #lookup_constant, #register_constant
Methods included from Validations::Required
#assert_required_keys, #assert_required_values_present, #parse_values
Methods included from Validations::Token
Methods included from Validations::Format
Methods included from Validations::Presence
#_validate_presence_of, #_validate_user_repo_params
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 Authorization
#authenticated?, #authentication, #basic_authed?
Constructor Details
#initialize(options = {}, &block) ⇒ API
Creates new API
37 38 39 40 41 42 43 |
# File 'lib/bitbucket_rest_api/api.rb', line 37 def initialize( = {}, &block) super() setup set_api_client instance_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
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/bitbucket_rest_api/api.rb', line 70 def method_missing(method, *args, &block) # :nodoc: case method.to_s when /^(.*)\?$/ !send(Regexp.last_match(1).to_s).nil? when /^clear_(.*)$/ send("#{Regexp.last_match(1)}=", nil) else super end end |
Class Method Details
.inherited(klass) ⇒ Object
Returns all API public methods for a given class.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/bitbucket_rest_api/api/actions.rb', line 5 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
#_merge_mime_type(resource, params) ⇒ Object
:nodoc:
99 100 101 102 |
# File 'lib/bitbucket_rest_api/api.rb', line 99 def _merge_mime_type(resource, params) # :nodoc: # params['resource'] = resource # params['mime_type'] = params['mime_type'] || :raw end |
#_merge_user_into_params!(params) ⇒ Object
:nodoc:
91 92 93 |
# File 'lib/bitbucket_rest_api/api.rb', line 91 def _merge_user_into_params!(params) # :nodoc: params.merge!('user' => user) if user? end |
#_merge_user_repo_into_params!(params) ⇒ Object
:nodoc:
95 96 97 |
# File 'lib/bitbucket_rest_api/api.rb', line 95 def _merge_user_repo_into_params!(params) # :nodoc: { 'user' => user, 'repo' => repo }.merge!(params) end |
#_update_user_repo_params(user_name, repo_name = nil) ⇒ Object
:nodoc:
86 87 88 89 |
# File 'lib/bitbucket_rest_api/api.rb', line 86 def _update_user_repo_params(user_name, repo_name = nil) # :nodoc: self.user = user_name || user self.repo = repo_name || repo end |
#api_methods_in(klass) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bitbucket_rest_api/api/actions.rb', line 17 def api_methods_in(klass) methods = [] (klass.send(:instance_methods, false) - ['actions']).sort.each do |method| methods << method end klass.included_modules.each do |mod| next unless mod.to_s =~ /#{klass}/ mod.instance_methods(false).each do |met| methods << met end end methods end |
#process_basic_auth(auth) ⇒ Object
Extract login and password from basic_auth parameter
54 55 56 57 58 59 60 61 62 |
# File 'lib/bitbucket_rest_api/api.rb', line 54 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_api_client ⇒ Object
Assigns current api class
65 66 67 |
# File 'lib/bitbucket_rest_api/api.rb', line 65 def set_api_client BitBucket.api_client = self end |
#setup(options = {}) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/bitbucket_rest_api/api.rb', line 45 def setup( = {}) = BitBucket..merge() Configuration::VALID_OPTIONS_KEYS.each do |key| send("#{key}=", [key]) end process_basic_auth([:basic_auth]) end |
#update_and_validate_user_repo_params(user_name, repo_name = nil) ⇒ Object
81 82 83 84 |
# File 'lib/bitbucket_rest_api/api.rb', line 81 def update_and_validate_user_repo_params(user_name, repo_name = nil) _update_user_repo_params(user_name, repo_name) _validate_user_repo_params(user, repo) unless user? && repo? end |