Class: Bitbucket::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/bitbucket/connection.rb

Constant Summary collapse

DEFAULT_API_VERSION =
'2.0'
DEFAULT_BASE_URI =
'https://api.bitbucket.org/'
DEFAULT_QUERY =
{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connection

Returns a new instance of Connection.


11
12
13
14
15
16
17
18
19
20
# File 'lib/bitbucket/connection.rb', line 11

def initialize(options = {})
  @api_version   = options.fetch(:api_version, DEFAULT_API_VERSION)
  @base_uri      = options.fetch(:base_uri, DEFAULT_BASE_URI)
  @default_query = options.fetch(:query, DEFAULT_QUERY)

  @token         = options[:token]
  @expires_at    = options[:expires_at]
  @expires_in    = options[:expires_in]
  @refresh_token = options[:refresh_token]
end

Instance Attribute Details

#expires_atObject (readonly)

Returns the value of attribute expires_at


9
10
11
# File 'lib/bitbucket/connection.rb', line 9

def expires_at
  @expires_at
end

#expires_inObject (readonly)

Returns the value of attribute expires_in


9
10
11
# File 'lib/bitbucket/connection.rb', line 9

def expires_in
  @expires_in
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token


9
10
11
# File 'lib/bitbucket/connection.rb', line 9

def refresh_token
  @refresh_token
end

#tokenObject (readonly)

Returns the value of attribute token


9
10
11
# File 'lib/bitbucket/connection.rb', line 9

def token
  @token
end

Instance Method Details

#get(path, extra_query = {}) ⇒ Object


22
23
24
25
26
27
# File 'lib/bitbucket/connection.rb', line 22

def get(path, extra_query = {})
  refresh! if expired?

  response = connection.get(build_url(path), params: @default_query.merge(extra_query))
  response.parsed
end

#refresh!Object


31
32
33
34
35
36
37
38
39
# File 'lib/bitbucket/connection.rb', line 31

def refresh!
  response = connection.refresh!

  @token         = response.token
  @expires_at    = response.expires_at
  @expires_in    = response.expires_in
  @refresh_token = response.refresh_token
  @connection    = nil
end