module Tvdbjson::Requestable

Public Instance Methods

build_uri(uri, params) click to toggle source
# File lib/tvdbjson/requestable.rb, line 26
def build_uri(uri, params)
  query_string = "?"
  params.each do |key, value|
    query_string = "#{query_string}#{key}=#{value}&"
  end
  URI.escape(uri+query_string)
end
send_authenticated_request(hash, authentication) click to toggle source
# File lib/tvdbjson/requestable.rb, line 4
def send_authenticated_request(hash, authentication)
  options = {}
  options[:uri] = build_uri(hash[:uri],hash[:params])
  options[:body] = hash[:body]
  options[:header] = { "Authorization" => "Bearer #{authentication.token}" }

  request = Request.new(options)

  response = if hash[:method] == "GET"
    request.get
  elsif hash[:method] == "POST"
    request.post
  end

  if hash[:after_action]
    eval(hash[:after_action])
  else
    response
  end

end