Sha256: ed8df888f96f4bd83095c28e7f30ae56966096e7619bf96e324d7ce08798521a

Contents?: true

Size: 719 Bytes

Versions: 13

Compression:

Stored size: 719 Bytes

Contents

# Module to allow mixing in the ability to retrieve JSON via http.
# Uses curb if available; otherwise falls back on Net::HTTP
module Djatoka::Net
  # Used to get the JSON response from Djatoka for Djatoka::Metadata and ping requests.
  # Uses curb if the gem is installed; otherwise it falls back on Net::HTTP.
  def get_json(url)
    if Djatoka.use_curb?
      c = Curl::Easy.new(url)
      data = nil
      c.on_success{|curl| data = JSON.parse(curl.body_str) }
      c.perform
    else
      uri = URI.parse(url)
      response = Net::HTTP.get_response(uri)
      case response
      when Net::HTTPSuccess
        data = JSON.parse(response.body)
      else
        data = nil
      end
    end
    data
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
djatoka-0.2.0 lib/djatoka/net.rb
djatoka-0.1.0 lib/djatoka/net.rb
djatoka-0.0.12 lib/djatoka/net.rb
djatoka-0.0.11 lib/djatoka/net.rb
djatoka-0.0.10 lib/djatoka/net.rb
djatoka-0.0.9 lib/djatoka/net.rb
djatoka-0.0.8 lib/djatoka/net.rb
djatoka-0.0.7 lib/djatoka/net.rb
djatoka-0.0.6 lib/djatoka/net.rb
djatoka-0.0.5 lib/djatoka/net.rb
djatoka-0.0.4 lib/djatoka/net.rb
djatoka-0.0.3 lib/djatoka/net.rb
djatoka-0.0.2 lib/djatoka/net.rb