Module: UTorrent::Http
- Defined in:
- lib/u_torrent/http.rb
Class Method Summary collapse
- .cookie ⇒ Object
- .generate! ⇒ Object
- .get(uri, query = {}) {|request| ... } ⇒ Object
- .get_with_authentication(query = {}) ⇒ Object
- .token ⇒ Object
- .urify_query(query_hash) ⇒ Object
Class Method Details
.cookie ⇒ Object
33 34 35 36 37 38 |
# File 'lib/u_torrent/http.rb', line 33 def ||= begin generate! end end |
.generate! ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/u_torrent/http.rb', line 40 def generate! uri = UTorrent.base_uri uri.path = '/gui/token.html' response = get(uri) @token = Nokogiri::HTML(response.body).at_xpath('//div').content = response['set-cookie'] end |
.get(uri, query = {}) {|request| ... } ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/u_torrent/http.rb', line 12 def get(uri, query={}) uri.query = urify_query(query) request = Net::HTTP::Get.new(uri) request.basic_auth( UTorrent.configuration.username, UTorrent.configuration.password ) yield request if block_given? http = Net::HTTP.new(uri.host, uri.port) http.request(request) end |
.get_with_authentication(query = {}) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/u_torrent/http.rb', line 5 def get_with_authentication(query={}) query.merge!(token: token) get(UTorrent.base_uri, query) do |request| request['Cookie'] = end end |
.token ⇒ Object
26 27 28 29 30 31 |
# File 'lib/u_torrent/http.rb', line 26 def token @token ||= begin generate! @token end end |
.urify_query(query_hash) ⇒ Object
50 51 52 |
# File 'lib/u_torrent/http.rb', line 50 def urify_query(query_hash) URI.encode_www_form(query_hash.to_a) end |