Class: GHI::API

Inherits:
Object
  • Object
show all
Defined in:
lib/ghi/api.rb

Defined Under Namespace

Classes: InvalidConnection, InvalidRequest, ResponseError

Constant Summary collapse

API_HOST =
"github.com"
API_PATH =
"/api/v2/yaml/issues/:action/:user/:repo"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, repo, use_ssl = false) ⇒ API

Returns a new instance of API.

Raises:



20
21
22
23
# File 'lib/ghi/api.rb', line 20

def initialize(user, repo, use_ssl = false)
  raise InvalidConnection if user.nil? || repo.nil?
  @user, @repo, @use_ssl = user, repo, use_ssl
end

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



18
19
20
# File 'lib/ghi/api.rb', line 18

def repo
  @repo
end

#userObject (readonly)

Returns the value of attribute user.



18
19
20
# File 'lib/ghi/api.rb', line 18

def user
  @user
end

Instance Method Details

#add_label(label, number) ⇒ Object



54
55
56
# File 'lib/ghi/api.rb', line 54

def add_label(label, number)
  post("label/add", label, number)["labels"]
end

#close(number) ⇒ Object



46
47
48
# File 'lib/ghi/api.rb', line 46

def close(number)
  GHI::Issue.new post(:close, number)["issue"]
end

#comment(number, comment) ⇒ Object



62
63
64
# File 'lib/ghi/api.rb', line 62

def comment(number, comment)
  post(:comment, number, "comment" => comment)["comment"]
end

#edit(number, title, body) ⇒ Object



41
42
43
44
# File 'lib/ghi/api.rb', line 41

def edit(number, title, body)
  res = post :edit, number, "title" => title, "body" => body
  GHI::Issue.new res["issue"]
end

#list(state = :open) ⇒ Object



29
30
31
# File 'lib/ghi/api.rb', line 29

def list(state = :open)
  get(:list, state)["issues"].map { |attrs| GHI::Issue.new(attrs) }
end

#open(title, body) ⇒ Object



37
38
39
# File 'lib/ghi/api.rb', line 37

def open(title, body)
  GHI::Issue.new post(:open, "title" => title, "body" => body)["issue"]
end

#remove_label(label, number) ⇒ Object



58
59
60
# File 'lib/ghi/api.rb', line 58

def remove_label(label, number)
  post("label/remove", label, number)["labels"]
end

#reopen(number) ⇒ Object



50
51
52
# File 'lib/ghi/api.rb', line 50

def reopen(number)
  GHI::Issue.new post(:reopen, number)["issue"]
end

#search(term, state = :open) ⇒ Object



25
26
27
# File 'lib/ghi/api.rb', line 25

def search(term, state = :open)
  get(:search, state, term)["issues"].map { |attrs| GHI::Issue.new(attrs) }
end

#show(number) ⇒ Object



33
34
35
# File 'lib/ghi/api.rb', line 33

def show(number)
  GHI::Issue.new get(:show, number)["issue"]
end