module Onering module CLI module Call def self.configure(global={}) @api = Onering::CLI.connect(global) @opts = ::Trollop::options do banner <<-EOS Call an arbitrary Onering API endpoint and return the output Usage: onering call [options] [endpoint] Examples: # Returns the API status page at path /api/ $ onering call / # Returns details about the authenticated user $ onering call users/current # Delete the device called '0bf29c' $ onering call devices/0bf29c -m delete Options: EOS opt :method, "The HTTP method to use when performing the request", :default => 'get', :short => "-m", :type => :string opt :query, "A query string attribute to add to the request in the form of NAME=VALUE", :short => '-a', :type => :string, :multi => true end end def self.run(args) data = STDIN.read() unless STDIN.tty? rv = @api.request(@opts[:method], args.first, { :body => data, :query => Hash[@opts[:query].collect{|i| i.split('=',2) }] }.compact) return (rv.parsed_response rescue rv.response.body) end end end end