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


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

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


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

def api
  @api
end

#clientObject (readonly)

Returns the value of attribute client


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

def client
  @client
end

Instance Method Details

#authorize_url(redirect_uri) ⇒ Object


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

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

#get_token(code, redirect_uri) ⇒ Object


27
28
29
# File 'lib/gitlab/gitlab_import/client.rb', line 27

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

#issue_comments(project_identifier, issue_id) ⇒ Object


41
42
43
44
45
# File 'lib/gitlab/gitlab_import/client.rb', line 41

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

#issues(project_identifier) ⇒ Object


35
36
37
38
39
# File 'lib/gitlab/gitlab_import/client.rb', line 35

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

#project(id) ⇒ Object


47
48
49
# File 'lib/gitlab/gitlab_import/client.rb', line 47

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

#projectsObject


51
52
53
54
55
# File 'lib/gitlab/gitlab_import/client.rb', line 51

def projects
  lazy_page_iterator(PER_PAGE) do |page|
    api.get("/api/v3/projects?per_page=#{PER_PAGE}&page=#{page}").parsed
  end
end

#userObject


31
32
33
# File 'lib/gitlab/gitlab_import/client.rb', line 31

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