Class: Bitbucket::Connection
- Inherits:
-
Object
- Object
- Bitbucket::Connection
- 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
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #get(path, extra_query = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #refresh! ⇒ Object
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( = {}) @api_version = .fetch(:api_version, DEFAULT_API_VERSION) @base_uri = .fetch(:base_uri, DEFAULT_BASE_URI) @default_query = .fetch(:query, DEFAULT_QUERY) @token = [:token] @expires_at = [:expires_at] @expires_in = [:expires_in] @refresh_token = [:refresh_token] end |
Instance Attribute Details
#expires_at ⇒ Object (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_in ⇒ Object (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_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
9 10 11 |
# File 'lib/bitbucket/connection.rb', line 9 def refresh_token @refresh_token end |
#token ⇒ Object (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 |