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
35 36 37 38 39 40 |
# File 'lib/u_torrent/http.rb', line 35 def @cookie ||= begin generate! @cookie end end |
.generate! ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/u_torrent/http.rb', line 42 def generate! uri = UTorrent.base_uri uri.path = '/gui/token.html' response = get(uri) @token = Nokogiri::HTML(response.body).at_xpath('//div').content @cookie = response['set-cookie'] end |
.get(uri, query = {}) {|request| ... } ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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? UTorrent.log.debug "UTorrent::Http.get #{request.path}" 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
28 29 30 31 32 33 |
# File 'lib/u_torrent/http.rb', line 28 def token @token ||= begin generate! @token end end |
.urify_query(query_hash) ⇒ Object
52 53 54 |
# File 'lib/u_torrent/http.rb', line 52 def urify_query(query_hash) URI.encode_www_form(query_hash.to_a) end |