Class: SoracomCli::EventHandler

Inherits:
Thor
  • Object
show all
Defined in:
lib/soracom/cli.rb

Overview

EventHandler related commands

Instance Method Summary collapse

Instance Method Details

#createObject



218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/soracom/cli.rb', line 218

def create
  if options.req=~/^[a-z]+:\/\/(.+)/
    begin
      content = open(options.req.sub(/^file:\/\//,'')).read
      options['req'] = content
    rescue Errno::ENOENT
    rescue SocketError
      abort "ERROR: Cannot access #{options.req}."
    end
  end
  client = Soracom::Client.new(profile:options.profile)
  puts JSON.pretty_generate(client.create_event_handler(options.req))
end

#deleteObject



234
235
236
237
# File 'lib/soracom/cli.rb', line 234

def delete
  client = Soracom::Client.new(profile:options.profile)
  puts JSON.pretty_generate(client.delete_event_handler(options.handler_id))
end

#listObject



210
211
212
213
214
# File 'lib/soracom/cli.rb', line 210

def list
  client = Soracom::Client.new(profile:options.profile)
  options.delete('profile')
  puts JSON.pretty_generate(client.list_event_handlers(Hash[options.map { |k, v| [k.to_sym, v] }]))
end

#updateObject



242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/soracom/cli.rb', line 242

def update
  if options.req=~/^[a-z]+:\/\/(.+)/
    begin
      content = open(options.req.sub(/^file:\/\//,'')).read
      options['req'] = content
    rescue Errno::ENOENT
    rescue SocketError
      abort "ERROR: Cannot access #{options.req}."
    end
  end
  client = Soracom::Client.new(profile:options.profile)
  puts JSON.pretty_generate(client.update_event_handler(options.handler_id, options.req))
end