Skip to content

Commit

Permalink
initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
NARKOZ committed Sep 21, 2012
0 parents commit b47a324
Show file tree
Hide file tree
Showing 49 changed files with 1,560 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in gitlab.gemspec
gemspec
24 changes: 24 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2012 Nihad Abbasov / NARKOZ
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "bundler/gem_tasks"

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
spec.rspec_opts = ['--color', '--format d']
end

task :default => :spec
25 changes: 25 additions & 0 deletions gitlab.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'gitlab/version'

Gem::Specification.new do |gem|
gem.name = "gitlab"
gem.version = Gitlab::VERSION
gem.authors = ["Nihad Abbasov"]
gem.email = ["mail@narkoz.me"]
gem.description = %q{Ruby client for GitLab API}
gem.summary = %q{A Ruby wrapper for the GitLab API}
gem.homepage = "https://github.com/narkoz/gitlab"

gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]

gem.add_runtime_dependency 'httparty'

gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'webmock'
end
29 changes: 29 additions & 0 deletions lib/gitlab.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require File.expand_path('../gitlab/version', __FILE__)
require File.expand_path('../gitlab/objectified_hash', __FILE__)
require File.expand_path('../gitlab/configuration', __FILE__)
require File.expand_path('../gitlab/error', __FILE__)
require File.expand_path('../gitlab/request', __FILE__)
require File.expand_path('../gitlab/api', __FILE__)
require File.expand_path('../gitlab/client', __FILE__)

module Gitlab
extend Configuration

# Alias for Gitlab::Client.new
#
# @return [Gitlab::Client]
def self.client(options={})
Gitlab::Client.new(options)
end

# Delegate to Gitlab::Client
def self.method_missing(method, *args, &block)
return super unless client.respond_to?(method)
client.send(method, *args, &block)
end

# Delegate to Gitlab::Client
def self.respond_to?(method)
return client.respond_to?(method) || super
end
end
17 changes: 17 additions & 0 deletions lib/gitlab/api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Gitlab
# @private
class API < Request
# @private
attr_accessor *Configuration::VALID_OPTIONS_KEYS

# Creates a new API.
# @raise [Error:MissingCredentials]
def initialize(options={})
options = Gitlab.options.merge(options)
Configuration::VALID_OPTIONS_KEYS.each do |key|
send("#{key}=", options[key])
end
set_request_defaults @base_uri, @endpoint, @private_token
end
end
end
13 changes: 13 additions & 0 deletions lib/gitlab/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Gitlab
# Wrapper for the Gitlab REST API.
class Client < API
Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}

include Gitlab::Client::Users
include Gitlab::Client::Issues
include Gitlab::Client::Milestones
include Gitlab::Client::Snippets
include Gitlab::Client::Projects
include Gitlab::Client::Repositories
end
end
69 changes: 69 additions & 0 deletions lib/gitlab/client/issues.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class Gitlab::Client
# Defines methods related to issues.
module Issues
# Gets a list of user's issues.
# Will return a list of project's issues if project ID or code name passed.
#
# @example
# Gitlab.issues
# Gitlab.issues(5)
# Gitlab.issues('gitlab', :per_page => 40)
#
# @param [Integer, String] project The ID or code name of a project.
# @param [Hash] options A customizable set of options.
# @option options [Integer] :page The page number.
# @option options [Integer] :per_page The number of results per page.
# @return [Array<Gitlab::ObjectifiedHash>]
def issues(project=nil, options={})
if project.to_i.zero?
get("/issues", :query => options)
else
get("/projects/#{project}/issues", :query => options)
end
end

# Gets a single issue.
#
# @example
# Gitlab.issue(5, 36)
# Gitlab.issue('gitlab', 42)
#
# @param [Integer, String] project The ID or code name of a project.
# @param [Integer] id The ID of an issue.
# @return [Array<Gitlab::ObjectifiedHash>]
def issue(project, id)
get("/projects/#{project}/issues/#{id}")
end

# Creates a new issue.
#
# @param [Integer, String] project The ID or code name of a project.
# @param [String] title The title of an issue.
# @param [Hash] options A customizable set of options.
# @option options [String] :description The description of an issue.
# @option options [Integer] :assignee_id The ID of a user to assign issue.
# @option options [Integer] :milestone_id The ID of a milestone to assign issue.
# @option options [String] :labels Comma-separated label names for an issue.
# @return [Gitlab::ObjectifiedHash] Information about created issue.
def create_issue(project, title, options={})
body = {:title => title}.merge(options)
post("/projects/#{project}/issues", :body => body)
end

# Updates an issue.
#
# @param [Integer, String] project The ID or code name of a project.
# @param [Integer] id The ID of an issue.
# @param [Hash] options A customizable set of options.
# @option options [String] :title The title of an issue.
# @option options [String] :description The description of an issue.
# @option options [Integer] :assignee_id The ID of a user to assign issue.
# @option options [Integer] :milestone_id The ID of a milestone to assign issue.
# @option options [String] :labels Comma-separated label names for an issue.
# @option options [Boolean] :closed The state of an issue (0 = false, 1 = true).
# @return [Gitlab::ObjectifiedHash] Information about updated issue.
def edit_issue(project, id, options={})
put("/projects/#{project}/issues/#{id}", :body => options)
end
end
end
59 changes: 59 additions & 0 deletions lib/gitlab/client/milestones.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
class Gitlab::Client
# Defines methods related to milestones.
module Milestones
# Gets a list of project's milestones.
#
# @example
# Gitlab.milestones(5)
# Gitlab.milestones('gitlab')
#
# @param [Integer, String] project The ID or code name of a project.
# @param [Hash] options A customizable set of options.
# @option options [Integer] :page The page number.
# @option options [Integer] :per_page The number of results per page.
# @return [Array<Gitlab::ObjectifiedHash>]
def milestones(project, options={})
get("/projects/#{project}/milestones", :query => options)
end

# Gets a single milestone.
#
# @example
# Gitlab.milestone(5, 36)
# Gitlab.milestone('gitlab', 42)
#
# @param [Integer, String] project The ID or code name of a project.
# @param [Integer] id The ID of a milestone.
# @return [Array<Gitlab::ObjectifiedHash>]
def milestone(project, id)
get("/projects/#{project}/milestones/#{id}")
end

# Creates a new milestone.
#
# @param [Integer, String] project The ID or code name of a project.
# @param [String] title The title of a milestone.
# @param [Hash] options A customizable set of options.
# @option options [String] :description The description of a milestone.
# @option options [String] :due_date The due date of a milestone.
# @return [Gitlab::ObjectifiedHash] Information about created milestone.
def create_milestone(project, title, options={})
body = {:title => title}.merge(options)
post("/projects/#{project}/milestones", :body => body)
end

# Updates a milestone.
#
# @param [Integer, String] project The ID or code name of a project.
# @param [Integer] id The ID of a milestone.
# @param [Hash] options A customizable set of options.
# @option options [String] :title The title of a milestone.
# @option options [String] :description The description of a milestone.
# @option options [String] :due_date The due date of a milestone.
# @option options [Boolean] :closed The state of a milestone (0 = false, 1 = true).
# @return [Gitlab::ObjectifiedHash] Information about updated milestone.
def edit_milestone(project, id, options={})
put("/projects/#{project}/milestones/#{id}", :body => options)
end
end
end
Loading

0 comments on commit b47a324

Please sign in to comment.