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



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

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



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

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

#listObject



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

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



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

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