Class: TvMaze::Api

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/tv_maze/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApi

Returns a new instance of Api.



9
10
11
# File 'lib/tv_maze/api.rb', line 9

def initialize
  self.base_url = "http://api.tvmaze.com/".freeze
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



7
8
9
# File 'lib/tv_maze/api.rb', line 7

def base_url
  @base_url
end

Instance Method Details

#url_for(action, params = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/tv_maze/api.rb', line 13

def url_for(action, params={})
  url = URI.join(base_url, action)

  if params[:embed]
    params['embed[]'] = params.delete(:embed)
  end

  url.query = URI.encode_www_form(params) if params
  url.to_s
end