Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
fc34c956
Commit
fc34c956
authored
Aug 22, 2016
by
Douglas Barbosa Alexandre
Committed by
Stan Hu
Nov 21, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a Bitbucket client for the OAuth2 API
parent
a2ef52b3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
lib/bitbucket/client.rb
lib/bitbucket/client.rb
+11
-0
lib/bitbucket/connection.rb
lib/bitbucket/connection.rb
+69
-0
No files found.
lib/bitbucket/client.rb
0 → 100644
View file @
fc34c956
module
Bitbucket
class
Client
def
initialize
(
options
=
{})
@connection
=
options
.
fetch
(
:connection
,
Connection
.
new
(
options
))
end
private
attr_reader
:connection
end
end
lib/bitbucket/connection.rb
0 → 100644
View file @
fc34c956
module
Bitbucket
class
Connection
DEFAULT_API_VERSION
=
'2.0'
DEFAULT_BASE_URI
=
'https://api.bitbucket.org/'
DEFAULT_QUERY
=
{}
def
initialize
(
options
=
{})
@api_version
=
options
.
fetch
(
:api_version
,
DEFAULT_API_VERSION
)
@base_uri
=
options
.
fetch
(
:base_uri
,
DEFAULT_BASE_URI
)
@query
=
options
.
fetch
(
:query
,
DEFAULT_QUERY
)
@token
=
options
.
fetch
(
:token
)
@expires_at
=
options
.
fetch
(
:expires_at
)
@expires_in
=
options
.
fetch
(
:expires_in
)
@refresh_token
=
options
.
fetch
(
:refresh_token
)
@client
=
OAuth2
::
Client
.
new
(
provider
.
app_id
,
provider
.
app_secret
,
options
)
@connection
=
OAuth2
::
AccessToken
.
new
(
@client
,
@token
,
refresh_token:
@refresh_token
,
expires_at:
@expires_at
,
expires_in:
@expires_in
)
end
def
query
(
params
=
{})
@query
.
update
(
params
)
end
def
get
(
path
,
query
=
{})
refresh!
if
expired?
response
=
connection
.
get
(
build_url
(
path
),
params:
@query
.
merge
(
query
))
response
.
parsed
end
def
expired?
connection
.
expired?
end
def
refresh!
response
=
connection
.
refresh!
@token
=
response
.
token
@expires_at
=
response
.
expires_at
@expires_in
=
response
.
expires_in
@refresh_token
=
response
.
refresh_token
@connection
=
OAuth2
::
AccessToken
.
new
(
@client
,
@token
,
refresh_token:
@refresh_token
,
expires_at:
@expires_at
,
expires_in:
@expires_in
)
end
private
attr_reader
:connection
,
:expires_at
,
:expires_in
,
:refresh_token
,
:token
def
build_url
(
path
)
return
path
if
path
.
starts_with?
(
root_url
)
"
#{
root_url
}#{
path
}
"
end
def
root_url
@root_url
||=
"
#{
@base_uri
}#{
@api_version
}
"
end
def
provider
Gitlab
.
config
.
omniauth
.
providers
.
find
{
|
provider
|
provider
.
name
==
'bitbucket'
}
end
def
options
OmniAuth
::
Strategies
::
Bitbucket
.
default_options
[
:client_options
].
deep_symbolize_keys
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment