Class: Clash::Web::Http
- Inherits:
-
RubyQt6::Bando::QObject
- Object
- RubyQt6::Bando::QObject
- Clash::Web::Http
- Defined in:
- lib/clash-systray/lib/clash/web/http.rb
Instance Method Summary collapse
- #get(path, options = {}) ⇒ Object
-
#initialize(client, options) ⇒ Http
constructor
A new instance of Http.
- #put(path, options = {}) ⇒ Object
Constructor Details
#initialize(client, options) ⇒ Http
Returns a new instance of Http.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/clash-systray/lib/clash/web/http.rb', line 8 def initialize(client, ) super($qApp) @client = client @host = .fetch(:host) @port = .fetch(:port) @on_reply_success = {} @manager = QNetworkAccessManager.new @manager.finished.connect(self, :_on_reply_finished) end |
Instance Method Details
#get(path, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/clash-systray/lib/clash/web/http.rb', line 20 def get(path, = {}) url = QUrl.new("http://#{@host}:#{@port}#{path}") set_url_query(url, [:params]) request = QNetworkRequest.new request.set_url(url) request.set_raw_header("Authorization", "Bearer #{@client.secret}") reply = @manager.get(request) @on_reply_success[reply._qobject_ptr] = [:on_success] end |
#put(path, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/clash-systray/lib/clash/web/http.rb', line 32 def put(path, = {}) url = QUrl.new("http://#{@host}:#{@port}#{path}") request = QNetworkRequest.new request.set_url(url) request.set_raw_header("Authorization", "Bearer #{@client.secret}") data = QByteArray.new([:json].to_json) reply = @manager.put(request, data) @on_reply_success[reply._qobject_ptr] = [:on_success] end |