Sha256: 088996db6a6a0d912074737137f0366c0434e9e749234c093af51e35ab30dac0

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

#!/usr/bin/env ruby
require 'firebase-ruby/trollop'
require 'firebase-ruby'


opts = Trollop::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 :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

Trollop::die :path, "is missing" if path.nil?

db = Firebase::Database.new()
db.set_auth_with_keyfile(opts[:key])

method = opts[:request].downcase.to_sym

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
    Trollop::die :data, "is missing"
  end
end

puts data if data

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
firebase-ruby-0.0.2 bin/fbrb