Class: TelegramBot::GitHubConnector

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram-bot/github.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username:, repository:) ⇒ GitHubConnector

Returns a new instance of GitHubConnector.



8
9
10
11
12
13
# File 'lib/telegram-bot/github.rb', line 8

def initialize(username:, repository:)
  @github_object = Github.new
  @username      = username
  @repository    = repository
  @issues_list   = []
end

Instance Attribute Details

#github_objectObject (readonly)

Returns the value of attribute github_object.



6
7
8
# File 'lib/telegram-bot/github.rb', line 6

def github_object
  @github_object
end

#issues_listObject (readonly)

Returns the value of attribute issues_list.



6
7
8
# File 'lib/telegram-bot/github.rb', line 6

def issues_list
  @issues_list
end

#repositoryObject (readonly)

Returns the value of attribute repository.



6
7
8
# File 'lib/telegram-bot/github.rb', line 6

def repository
  @repository
end

#usernameObject (readonly)

Returns the value of attribute username.



6
7
8
# File 'lib/telegram-bot/github.rb', line 6

def username
  @username
end

Instance Method Details

#get_issues(state: 'open', order_mode: 'asc') ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/telegram-bot/github.rb', line 15

def get_issues(state: 'open', order_mode: 'asc')
  begin
    issues = @github_object.issues.list user:  @username, 
                                        repo:  @repository,
                                        state: state,
                                        sort:  'created', 
                                        direction: order_mode
    issues.each do |issue|
      @issues_list << Issue.new(id:     issue.id, 
                                number: issue.number,
                                title:  issue.title,
                                body:   issue.body,
                                state:  issue.state,
                                url:    issue.url)
    end
  rescue Github::Error::NotFound => exception
    @issues_list << "Usuario/Repositorio no encontrado"
  end
  @issues_list
end