Class: SDLS::Client
- Inherits:
-
Object
- Object
- SDLS::Client
- Defined in:
- lib/sdls/client.rb
Instance Method Summary collapse
- #authenticate(otp: nil) ⇒ Object
- #create_download(magnet:, destination:) ⇒ Object
-
#initialize(host:, username:, password:, op_item_name: nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(host:, username:, password:, op_item_name: nil) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 |
# File 'lib/sdls/client.rb', line 8 def initialize(host:, username:, password:, op_item_name: nil) @host = host @username = username @password = password @op_item_name = op_item_name end |
Instance Method Details
#authenticate(otp: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/sdls/client.rb', line 15 def authenticate(otp: nil) uri = build_uri("/webapi/auth.cgi", auth_params(otp)) response_body = make_request(uri) handle_auth_response(response_body, otp) rescue => e warn "Authentication error: #{e.}" nil end |
#create_download(magnet:, destination:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sdls/client.rb', line 25 def create_download(magnet:, destination:) sid = authenticate return false unless sid uri = build_uri("/webapi/DownloadStation/task.cgi") data = download_params(magnet, destination, sid) response = Net::HTTP.post_form(uri, data) body = JSON.parse(response.body) if response.is_a?(Net::HTTPSuccess) && body["success"] puts "Download created successfully in #{destination}" true else warn "Download creation failed: #{body.inspect}" false end end |