Class: Tvrage::Client
- Inherits:
-
Object
- Object
- Tvrage::Client
- Defined in:
- lib/tvrage/client.rb
Instance Method Summary collapse
- #base_url ⇒ Object
- #search(query) ⇒ Object
- #tvshow_by_id(tvshow_id, full_info = false) ⇒ Object
- #updates_since(time) ⇒ Object
Instance Method Details
#base_url ⇒ Object
45 46 47 48 |
# File 'lib/tvrage/client.rb', line 45 def base_url # "http://www.tvrage.com/feeds" "http://services.tvrage.com/feeds" end |
#search(query) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/tvrage/client.rb', line 5 def search(query) response = get("/search.php?show=#{URI.escape(query)}") response.xpath('//Results/show').collect { |r| { 'id' => r.xpath('showid').text.to_i, 'name' => r.xpath('name').text, 'country' => r.xpath('country').text, 'started' => r.xpath('started').text.to_i, 'ended' => r.xpath('ended').text.to_i, 'seasons' => r.xpath('seasons').text.to_i, 'status' => r.xpath('status').text, 'classification' => r.xpath('classification').text } } end |
#tvshow_by_id(tvshow_id, full_info = false) ⇒ Object
19 20 21 22 |
# File 'lib/tvrage/client.rb', line 19 def tvshow_by_id(tvshow_id, full_info = false) response = get("/full_show_info.php?sid=#{tvshow_id}") Tvshow.new(response.xpath('//Show').first) unless response.xpath('//Show/name').text.empty? end |
#updates_since(time) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tvrage/client.rb', line 24 def updates_since(time) if time.is_a?(Date) time = time.to_time.to_i elsif time.is_a?(Time) time = time.to_time.to_i elsif !time.is_a?(Integer) raise "Incorrect time supplied. This needs to be either a Date, Time or Integer" end url = "/last_updates.php?" url << ((time < 1000) ? "hours=#{time}" : "since=#{time}") response = get(url) output = {} output['time'] = response.xpath("//updates").attr("at").text.to_i output['showing'] = response.xpath("//updates").attr("showing").text output['tvshows'] = response.xpath("//show/id").collect { |s| s.text.to_i } output end |