Class: GitlabApi::ApiClient
- Inherits:
-
Object
- Object
- GitlabApi::ApiClient
- Defined in:
- lib/git/gitlab/api/issue.rb,
lib/git/gitlab/apiclient.rb,
lib/git/gitlab/api/authorize.rb,
lib/git/gitlab/api/mergerequest.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Authorize, Issue, Mergerequest
Constant Summary collapse
- API_VERSION =
"v3"
- USER_AGENT =
"nyonyonyonyonyo! Gitlab nyo!!"
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
-
#initialize ⇒ ApiClient
constructor
A new instance of ApiClient.
- #project_id ⇒ Object
- #remote ⇒ Object
Constructor Details
#initialize ⇒ ApiClient
Returns a new instance of ApiClient.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/git/gitlab/apiclient.rb', line 13 def initialize @repository = Grit::Repo.new(`git rev-parse --show-toplevel`.chomp) config = @repository.config url = config["gitlab.url"] if url == nil raise "Plase set 'git config gitlab.url ${Gitlab URL}'" end token = config["gitlab.token"] if token == nil raise "Please set 'git config gitlab.token ${Gitlab Token}'" end Gitlab.configure do |config| config.endpoint = "#{url}/api/#{API_VERSION}" config.private_token = token config.user_agent = USER_AGENT end @client = Gitlab.client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/git/gitlab/apiclient.rb', line 11 def client @client end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
11 12 13 |
# File 'lib/git/gitlab/apiclient.rb', line 11 def repository @repository end |
Instance Method Details
#project_id ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/git/gitlab/apiclient.rb', line 44 def project_id pid = if @repository.config.keys.include? "gitlab.projectid" @repository.config["gitlab.projectid"].to_i else @repository.config["gitlab.project"] end if pid == nil raise "Please set 'git config gitlab.projectid ${Gitlab Project id}' of git config gitlab.project ${NAMESPACE/PROJECT}" end begin @client.project( URI.encode_www_form_component(pid.to_s)).id rescue Gitlab::Error::NotFound => e raise GitlabApi::Error::ProjectIdNotFound, "Can not find #{pid} Project." end end |
#remote ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/git/gitlab/apiclient.rb', line 36 def remote if @repository.config.keys.include? "gitlab.remote" @repository.config["gitlab.remote"] else "origin" end end |