Skip to content

Instantly share code, notes, and snippets.

@metade
Created March 23, 2012 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save metade/2169593 to your computer and use it in GitHub Desktop.
Save metade/2169593 to your computer and use it in GitHub Desktop.
require 'curb'
require 'openssl'
require 'nokogiri'
cert_path = "/Users/sinclp01/.certificates/dev.pem"
certificate = File.read(cert_path)
curb = Curl::Easy.new
curb.cert = cert_path
curb.cert_key = cert_path
curb.url = 'https://api.test.bbc.co.uk/nitro/api/v1/available/clips/?media_set=pc&page_size=200'
if curb.perform
doc = Nokogiri::XML(curb.body_str)
pids = doc.xpath('//nitro:clip_of', 'nitro' => 'http://www.bbc.co.uk/nitro/').map { |e| e['pid'] }.uniq
p pids.size
urls = pids.map { |pid| "https://api.test.bbc.co.uk/nitro/api/v1/available/clips/?media_set=pc&clip_of=#{pid}" }
responses = {}
easy_options = {:follow_location => true, :cert => cert_path, :cert_key => cert_path}
multi_options = {:pipeline => true}
Curl::Multi.get(urls, easy_options, multi_options) do |easy|
# do something interesting with the easy response
doc = Nokogiri::XML(easy.body_str)
updated_at = doc.xpath('//nitro:updated_time', 'nitro' => 'http://www.bbc.co.uk/nitro/')
p updated_at.first.to_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment