Class: Gitlab::GitlabImport::Client

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

Constant Summary collapse

PER_PAGE =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ Client

Returns a new instance of Client.


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gitlab/gitlab_import/client.rb', line 10

def initialize(access_token)
  @client = ::OAuth2::Client.new(
    config.app_id,
    config.app_secret,
    gitlab_options
  )

  if access_token
    @api = OAuth2::AccessToken.from_hash(@client, access_token: access_token)
  end
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api


6
7
8
# File 'lib/gitlab/gitlab_import/client.rb', line 6

def api
  @api
end

#clientObject (readonly)

Returns the value of attribute client


6
7
8
# File 'lib/gitlab/gitlab_import/client.rb', line 6

def client
  @client
end

Instance Method Details

#authorize_url(redirect_uri) ⇒ Object


22
23
24
25
26
27
# File 'lib/gitlab/gitlab_import/client.rb', line 22

def authorize_url(redirect_uri)
  client.auth_code.authorize_url({
    redirect_uri: redirect_uri,
    scope: "api"
  })
end

#get_token(code, redirect_uri) ⇒ Object


29
30
31
# File 'lib/gitlab/gitlab_import/client.rb', line 29

def get_token(code, redirect_uri)
  client.auth_code.get_token(code, redirect_uri: redirect_uri).token
end

#issue_comments(project_identifier, issue_id, **kwargs) ⇒ Object


43
44
45
46
47
# File 'lib/gitlab/gitlab_import/client.rb', line 43

def issue_comments(project_identifier, issue_id, **kwargs)
  lazy_page_iterator(**kwargs) do |page, per_page|
    api.get("/api/v4/projects/#{project_identifier}/issues/#{issue_id}/notes?per_page=#{per_page}&page=#{page}").parsed
  end
end

#issues(project_identifier, **kwargs) ⇒ Object


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

def issues(project_identifier, **kwargs)
  lazy_page_iterator(**kwargs) do |page, per_page|
    api.get("/api/v4/projects/#{project_identifier}/issues?per_page=#{per_page}&page=#{page}").parsed
  end
end

#project(id) ⇒ Object


49
50
51
# File 'lib/gitlab/gitlab_import/client.rb', line 49

def project(id)
  api.get("/api/v4/projects/#{id}").parsed
end

#projects(**kwargs) ⇒ Object


53
54
55
56
57
# File 'lib/gitlab/gitlab_import/client.rb', line 53

def projects(**kwargs)
  lazy_page_iterator(**kwargs) do |page, per_page|
    api.get("/api/v4/projects?per_page=#{per_page}&page=#{page}&simple=true&membership=true").parsed
  end
end

#userObject


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

def user
  api.get("/api/v4/user").parsed
end