Class: Jekyll::Drivers::JsonDriver

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/drivers/json_driver.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ JsonDriver

Returns a new instance of JsonDriver.



9
10
11
12
13
14
15
16
17
18
19
# 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

Instance Method Details

#loadObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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