Module: Tvdbjson::Requestable

Included in:
Episode, Image, Series
Defined in:
lib/tvdbjson/requestable.rb

Instance Method Summary collapse

Instance Method Details

#build_uri(uri, params) ⇒ Object



26
27
28
29
30
31
32
# 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) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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] = { "Accept-Language" => "en", "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