Sha256: 19da1c0514cbcd32c1c3798f19bb5670a9dddd661d2eedca3c03f4e84e54b4fd

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

begin
  require 'yaml'
  require 'json'
  require 'open-uri'

  namespace :oembed do
    desc "Update the embedly_urls.yml file using the services api."
    task :update_embedly do
      # Details at http://api.embed.ly/docs/service
      json_uri = URI.parse("http://api.embed.ly/1/services")
      yaml_path = File.join(File.dirname(__FILE__), "../oembed/providers/embedly_urls.yml")
    
      services = JSON.parse(json_uri.read)
    
      url_regexps = []
      services.each do |service|
        url_regexps += service['regex']
      end
      url_regexps.sort!
    
      YAML.dump(url_regexps, File.open(yaml_path, 'w'))
    end
  
    # Note: At the moment the list of enpoints in the oohembed-provided JSON file
    # do NOT match the full listing on their website. Until we sort that out, we'll
    # continue to use the manually entered list of oohembed URLs
    desc "Update the list of URLs supported by oohembed via their API"
    task :update_oohembed do
      # Details in the Q & A section of http://oohembed.com/
      json_uri = URI.parse("http://oohembed.com/static/endpoints.json")
      yaml_path = File.join(File.dirname(__FILE__), "../oembed/providers/oohembed_urls.yml")
    
      services = JSON.parse(json_uri.read)
    
      url_regexps = []
      services.each do |service|
        url_regexps << service['url']
      end
      url_regexps.sort!
    
      YAML.dump(url_regexps, File.open(yaml_path, 'w'))
    end
  end  
rescue LoadError
  puts "The oembed rake tasks require JSON. Install it with: gem install json"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-oembed-0.8.7 lib/tasks/oembed.rake