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, op_account: nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(host:, username:, password:, op_item_name: nil, op_account: nil) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 |
# File 'lib/sdls/client.rb', line 9 def initialize(host:, username:, password:, op_item_name: nil, op_account: nil) @host = host @username = username @password = password @op_item_name = op_item_name @op_account = op_account end |
Instance Method Details
#authenticate(otp: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/sdls/client.rb', line 17 def authenticate(otp: nil) uri = URI.join(@host, "/webapi/auth.cgi") response_body = make_post_request(uri, auth_params(otp)) handle_auth_response(response_body, otp) rescue => e warn "Authentication error: #{e.}" nil end |
#create_download(magnet:, destination:) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sdls/client.rb', line 27 def create_download(magnet:, destination:) sid = authenticate return false unless sid uri = URI.join(@host, "/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 |