class Tmdb::Connection
Constants
- CONNECTIONS_PER_MINUTE
- CONNECTION_SPACING
- TMDB_URL
Attributes
api_key[RW]
debug_output $stdout
rate_limit_time[RW]
debug_output $stdout
request[RW]
debug_output $stdout
response[RW]
debug_output $stdout
Public Class Methods
new(api_key = ENV["TMDB_API_KEY"])
click to toggle source
# File lib/tmdb/connection.rb, line 37 def initialize(api_key = ENV["TMDB_API_KEY"]) @api_key = api_key Tmdb.connection = self end
Public Instance Methods
rate_limit()
click to toggle source
# File lib/tmdb/connection.rb, line 43 def rate_limit while(Time.now.to_f<@rate_limit_time.to_f+CONNECTION_SPACING) sleep 0.1 end @rate_limit_time = Time.now end
Private Instance Methods
get(url, params={})
click to toggle source
# File lib/tmdb/connection.rb, line 52 def get(url, params={}) params.merge!({api_key: @api_key, language: params[:language]||"en"}) rate_limit @response = self.class.get(TMDB_URL + url, query: params) @request = @response.request return @response end
post(url, params={})
click to toggle source
# File lib/tmdb/connection.rb, line 60 def post(url, params={}) params.merge!({api_key: @api_key, language: params[:language]||"en"}) rate_limit @response = self.class.post(TMDB_URL + url, query: params) @request = @response.request return @response end