class Jekyll::Drivers::JsonDriver

Public Class Methods

new(options) click to toggle source
# File lib/jekyll/drivers/json_driver.rb, line 9
def initialize(options)
  @url = options['url']

  if !@url
    raise FatalException.new "'url' must be specified for json data source: #{options['name']}."
  end

  if @url !~ URI::regexp || URI(@url).scheme !~ /^http|https$/
    raise FatalException.new "incorrect json data source url: #{@url}"
  end
end

Public Instance Methods

load() click to toggle source
# File lib/jekyll/drivers/json_driver.rb, line 21
def load
  uri = URI(@url)

  if uri.scheme == 'https'
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE

    request = Net::HTTP::Get.new(uri.request_uri)
    response = http.request(request).body
  else
    response = Net::HTTP.get(uri)
  end

  JSON.parse(response)
end