gitlab-org--gitlab-foss/lib/gitlab/github_import/client.rb

54 lines
1.2 KiB
Ruby
Raw Normal View History

2014-12-31 13:07:48 +00:00
module Gitlab
2015-02-02 22:26:29 +00:00
module GithubImport
2014-12-31 13:07:48 +00:00
class Client
2015-02-06 00:57:27 +00:00
attr_reader :client, :api
2014-12-31 13:07:48 +00:00
2015-02-06 00:57:27 +00:00
def initialize(access_token)
2014-12-31 13:07:48 +00:00
@client = ::OAuth2::Client.new(
config.app_id,
config.app_secret,
github_options
)
2015-02-06 00:57:27 +00:00
if access_token
::Octokit.auto_paginate = true
@api = ::Octokit::Client.new(access_token: access_token)
end
end
def authorize_url(redirect_uri)
client.auth_code.authorize_url({
redirect_uri: redirect_uri,
scope: "repo, user, user:email"
})
end
def get_token(code)
client.auth_code.get_token(code).token
end
def method_missing(method, *args, &block)
if api.respond_to?(method)
api.send(method, *args, &block)
else
super(method, *args, &block)
end
end
def respond_to?(method)
api.respond_to?(method) || super
2014-12-31 13:07:48 +00:00
end
private
def config
2015-02-03 01:01:07 +00:00
Gitlab.config.omniauth.providers.find{|provider| provider.name == "github"}
2014-12-31 13:07:48 +00:00
end
def github_options
2015-11-30 14:12:31 +00:00
OmniAuth::Strategies::GitHub.default_options[:client_options].to_h.symbolize_keys
2014-12-31 13:07:48 +00:00
end
end
end
end