Class: Gitlab::GithubImport::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/github_import/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ Client

Returns a new instance of Client


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/github_import/client.rb', line 6

def initialize(access_token)
  @client = ::OAuth2::Client.new(
    config.app_id,
    config.app_secret,
    github_options.merge(ssl: { verify: config['verify_ssl'] })
  )

  if access_token
    ::Octokit.auto_paginate = true

    @api = ::Octokit::Client.new(
      access_token: access_token,
      api_endpoint: github_options[:site],
      connection_options: {
        ssl: { verify: config['verify_ssl'] }
      }
    )
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object


37
38
39
40
41
42
43
# File 'lib/gitlab/github_import/client.rb', line 37

def method_missing(method, *args, &block)
  if api.respond_to?(method)
    api.send(method, *args, &block)
  else
    super(method, *args, &block)
  end
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api


4
5
6
# File 'lib/gitlab/github_import/client.rb', line 4

def api
  @api
end

#clientObject (readonly)

Returns the value of attribute client


4
5
6
# File 'lib/gitlab/github_import/client.rb', line 4

def client
  @client
end

Instance Method Details

#authorize_url(redirect_uri) ⇒ Object


26
27
28
29
30
31
# File 'lib/gitlab/github_import/client.rb', line 26

def authorize_url(redirect_uri)
  client.auth_code.authorize_url({
    redirect_uri: redirect_uri,
    scope: "repo, user, user:email"
  })
end

#get_token(code) ⇒ Object


33
34
35
# File 'lib/gitlab/github_import/client.rb', line 33

def get_token(code)
  client.auth_code.get_token(code).token
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)

45
46
47
# File 'lib/gitlab/github_import/client.rb', line 45

def respond_to?(method)
  api.respond_to?(method) || super
end