Class: BitBucket::API

Inherits:
Object
  • Object
show all
Includes:
Authorization, Connection, Normalizer, ParameterFilter, Request, Validations
Defined in:
lib/bitbucket_rest_api/api.rb,
lib/bitbucket_rest_api/api/actions.rb

Constant Summary

Constants included from Validations

Validations::VALID_API_KEYS

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

Connection::ALLOWED_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Normalizer

#normalize!

Methods included from ParameterFilter

#filter!

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

#validates_token_for

Methods included from Validations::Format

#assert_valid_values

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(options = {}, &block)
  super()
  setup options
  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., self.password = auth.split(':', 2)
  when Hash
    self.    = auth[:login]
    self.password = auth[:password]
  end
end

#set_api_clientObject

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(options = {})
  options = BitBucket.options.merge(options)
  Configuration::VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key])
  end
  process_basic_auth(options[: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