Class: ThePirateBayClient
- Inherits:
-
Object
- Object
- ThePirateBayClient
- Defined in:
- lib/my_shows/the_pirate_bay_client.rb
Instance Method Summary collapse
Instance Method Details
#connection ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/my_shows/the_pirate_bay_client.rb', line 6 def connection @connection ||= Faraday.new url: 'http://thepiratebay.org' do |conn| conn.headers[:user_agent] = 'libcurl-agent/1.0' conn.request :url_encoded conn.response :follow_redirects conn.response :logger, MyShows.logger conn.adapter Faraday.default_adapter end end |
#search(query) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/my_shows/the_pirate_bay_client.rb', line 16 def search(query) response = connection.get URI.escape("/search/#{query}/0/99/200") html = Nokogiri::HTML(response.body) html.css('#searchResult > tr').map do |row| Hashie::Mash.new(name: row.at_css('.detName a').content, magnet_link: row.at_css('a[href^=magnet]')['href'], seeders: row.css('td')[-2].content.to_i) end end |