Class: Geet::Github::Milestone

Inherits:
Object
  • Object
show all
Extended by:
Helpers::JsonHelper, T::Sig
Defined in:
lib/geet/github/milestone.rb

Constant Summary collapse

STATE_CLOSED =
"closed"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::JsonHelper

parse_iso_8601_timestamp

Constructor Details

#initialize(number, title, due_on, api_interface) ⇒ Milestone

Returns a new instance of Milestone.



36
37
38
39
40
41
42
# File 'lib/geet/github/milestone.rb', line 36

def initialize(number, title, due_on, api_interface)
  @number = number
  @title = title
  @due_on = due_on

  @api_interface = api_interface
end

Instance Attribute Details

#due_onObject (readonly)

Returns the value of attribute due_on.



16
17
18
# File 'lib/geet/github/milestone.rb', line 16

def due_on
  @due_on
end

#numberObject (readonly)

Returns the value of attribute number.



10
11
12
# File 'lib/geet/github/milestone.rb', line 10

def number
  @number
end

#titleObject (readonly)

Returns the value of attribute title.



13
14
15
# File 'lib/geet/github/milestone.rb', line 13

def title
  @title
end

Class Method Details

.close(number, api_interface) ⇒ Object



103
104
105
106
107
108
# File 'lib/geet/github/milestone.rb', line 103

def self.close(number, api_interface)
  api_path = "milestones/#{number}"
  request_data = {state: STATE_CLOSED}

  api_interface.send_request(api_path, data: request_data)
end

.create(title, api_interface) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/geet/github/milestone.rb', line 51

def self.create(title, api_interface)
  api_path = "milestones"
  request_data = {title: title}

  response = T.cast(
    api_interface.send_request(api_path, data: request_data),
    T::Hash[String, T.untyped]
  )

  number = T.cast(response.fetch("number"), Integer)
  title = T.cast(response.fetch("title"), String)
  due_on = nil

  new(number, title, due_on, api_interface)
end

.list(api_interface) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/geet/github/milestone.rb', line 74

def self.list(api_interface)
  api_path = "milestones"

  response = T.cast(
    api_interface.send_request(api_path, multipage: true),
    T::Array[T::Hash[String, T.untyped]]
  )

  response.map do |milestone_data|
    number = T.cast(milestone_data.fetch("number"), Integer)
    title = T.cast(milestone_data.fetch("title"), String)
    due_on = parse_iso_8601_timestamp(
      T.cast(milestone_data.fetch("due_on"), T.nilable(String))
    )

    new(number, title, due_on, api_interface)
  end
end