Class: Localhook::Command

Inherits:
CLAide::Command
  • Object
show all
Defined in:
lib/localhook/command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Command

Returns a new instance of Command.



14
15
16
17
18
19
# File 'lib/localhook/command.rb', line 14

def initialize(argv)
  @remote_server = argv.shift_argument
  @local_server  = argv.shift_argument
  @token         = argv.option('token')
  super
end

Instance Attribute Details

#local_serverObject (readonly)

Returns the value of attribute local_server.



9
10
11
# File 'lib/localhook/command.rb', line 9

def local_server
  @local_server
end

#remote_serverObject (readonly)

Returns the value of attribute remote_server.



9
10
11
# File 'lib/localhook/command.rb', line 9

def remote_server
  @remote_server
end

Class Method Details

.optionsObject



21
22
23
24
25
# File 'lib/localhook/command.rb', line 21

def self.options
  [
    ['--token=<token>', 'Authentication Token']
  ].concat(super)
end

Instance Method Details

#runObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/localhook/command.rb', line 39

def run
  EventMachine.run do
    puts "forward remote server (#{@remote_server}) webhooks to #{@local_server}"
    @forwarder  = WebhookForwarder.new(@local_server)
    @source     = EventSource.new(@remote_server, @forwarder, @token)
    @source.error do |error|
      puts "error connecting to eventsource: #{error}"
    end
    @source.start
  end
end

#validate!Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/localhook/command.rb', line 27

def validate!
  if @remote_server.nil?
    help! "missing remote-server parameter"
  end
  if @local_server.nil?
    help! "missing local-server parameter"
  end
  if @token.nil?
    help! "missing token"
  end
end