Sha256: fdfb7b5f8bf5b398004ef6e9496d53b82f559dd408cf8f3fc09290c8690eb813
Contents?: true
Size: 1.48 KB
Versions: 2
Compression:
Stored size: 1.48 KB
Contents
#!/usr/bin/env ruby require 'firebase-ruby/optimist' require 'firebase-ruby' require 'json' opts = Optimist::options do banner "fbrb [options] <URL>" opt :data, 'HTTP POST data', type: :string opt :id, 'Project ID', type: :string opt :key, 'JSON file with private key', type: :string opt :log, 'Log file', type: :string opt :path, 'Path', type: :string opt :request, 'Specify request command to use', type: :string, short: 'X', default: 'get' opt :ruby, 'Output Ruby format' opt :verbose, 'Verbose mode' end if opts[:log_given] Firebase.logger = Logger.new(opts[:log]) Firebase.logger.level = Logger::WARN end if opts[:verbose] Firebase.logger = Logger.new(STDOUT) unless opts[:log_given] Firebase.logger.level = Logger::DEBUG end log = Firebase.logger log.debug("Command line arguments: #{opts}") path = opts[:path] path ||= ARGV.shift Optimist::die :path, "is missing" if path.nil? db = Firebase::Database.new() db.set_auth_with_key(path: opts[:key]) method = opts[:request].downcase.to_sym begin case method when :get, :delete data = db.public_send(method, path) when :put, :patch, :post if opts[:data_given] data = db.public_send(method, path, opts[:data]) else Optimist::die :data, "is missing" end end if data if opts[:ruby] puts data else json_opts = {indent: ' ', space: ' ', object_nl: "\n", array_nl: "\n"} puts JSON.fast_generate(data, json_opts) end end rescue => e puts e.message exit 1 end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
firebase-ruby-0.3.1 | bin/fbrb |
firebase-ruby-0.3.0 | bin/fbrb |