Class: Tmdb::Connection

Inherits:
Object
  • Object
show all
Includes:
HTTParty, GenreMethods, MovieMethods, PeopleMethods, SearchMethods
Defined in:
lib/tmdb/connection.rb

Constant Summary collapse

CONNECTIONS_PER_MINUTE =
150.0
CONNECTION_SPACING =
60.0/CONNECTIONS_PER_MINUTE
TMDB_URL =
"http://api.themoviedb.org/3"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GenreMethods

#genre_movie_list, #genre_movies, #genre_tv_list

Methods included from PeopleMethods

#person, #person_all_changes

Methods included from MovieMethods

#movie, #movie_all_changes

Constructor Details

#initialize(api_key = ENV["TMDB_API_KEY"]) ⇒ Connection

Returns a new instance of Connection.



37
38
39
40
# File 'lib/tmdb/connection.rb', line 37

def initialize(api_key = ENV["TMDB_API_KEY"])
  @api_key = api_key
  Tmdb.connection = self
end

Instance Attribute Details

#api_keyObject

debug_output $stdout



31
32
33
# File 'lib/tmdb/connection.rb', line 31

def api_key
  @api_key
end

#rate_limit_timeObject

debug_output $stdout



31
32
33
# File 'lib/tmdb/connection.rb', line 31

def rate_limit_time
  @rate_limit_time
end

#requestObject

debug_output $stdout



31
32
33
# File 'lib/tmdb/connection.rb', line 31

def request
  @request
end

#responseObject

debug_output $stdout



31
32
33
# File 'lib/tmdb/connection.rb', line 31

def response
  @response
end

Instance Method Details

#rate_limitObject



43
44
45
46
47
48
# 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