Sha256: 27bb90d8649c8b7a6532926779306c38b72571727e92e64156fcb4a737b4f4e0

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

#!/usr/bin/env ruby
$:.unshift(File.expand_path('../../lib', __FILE__))
%w{embedly json optparse ostruct}.each {|l| require l}

options = OpenStruct.new({
  :endpoint => nil,
  :key => nil,
  :verbose => false,
  :args => {}
})

action = File.basename(__FILE__)[/embedly_(\w+)/, 1]

opts = OptionParser.new do |opts|
  opts.banner = <<-DOC
Fetch JSON from the embedly #{action} service.
Usage #{action} [OPTIONS] <url> [url] ..
  DOC

  opts.separator ""
  opts.separator "Options:"

  opts.on("-e", "--endpoint ENDPOINT",
          "Embedly host.  If key is present, default is pro.embed.ly, else " +
          "it is api.embed.ly.") do |e|
    options.endpoint = e
  end

  opts.on("-k", "--key KEY", "Embedly PRO key") do |k|
    options.key = k
  end

  opts.on("-o", "--option NAME=VALUE", "Set option to be passed as query param.") do |o|
    k,v = o.split('=')
    options.args[k] = v
  end

  opts.separator ""
  opts.separator "Common Options:"

  opts.on("-v", "--verbose", "Run verbosely") do
    options.verbose = true
  end

  opts.on("-h", "--help", "Display this message") do
    puts opts
    exit
  end

  opts.separator ""
  opts.separator "Bob Corsaro <bob@embed.ly>"
end

opts.parse!

if ARGV.size < 1
  $stderr.puts "ERROR: url required"
  $stderr.puts opts
  exit 1
end

Embedly::Config.logging = true if options.verbose

options.args[:urls] = ARGV
api = Embedly::API.new options.marshal_dump
objs = [api.send(action, options.args)].flatten.collect{|o| o.marshal_dump}
puts JSON.pretty_generate(objs)

Version data entries

6 entries across 2 versions & 1 rubygems

Version Path
embedly-0.2.0 bin/embedly_objectify
embedly-0.2.0 bin/embedly_oembed
embedly-0.2.0 bin/embedly_preview
embedly-0.1.0 bin/embedly_objectify
embedly-0.1.0 bin/embedly_oembed
embedly-0.1.0 bin/embedly_preview