lib/nzbmatrix/client.rb in nzbmatrix-0.0.1 vs lib/nzbmatrix/client.rb in nzbmatrix-0.0.2
- old
+ new
@@ -1,15 +1,20 @@
module Nzbmatrix
require 'rest_client'
class Client
+
+ require "nzbmatrix/api_response_parser"
+ require "nzbmatrix/search_result"
+
BASE_URL = "https://api.nzbmatrix.com/v1.1"
def initialize(username, api_key)
@username = username
@api_key = api_key
@creds = { :username => @username, :apikey => @api_key }
+ @parser = ApiResponseParser.new
end
def download(nzb_id)
RestClient.get "#{BASE_URL}/download.php", :params => { :id => nzb_id }.merge(@creds)
end
@@ -30,10 +35,14 @@
# :maxhits => MAX HITS
# :maxage => {MAX AGE} same as :age
# :englishonly => 1 if added the search will only return ENGLISH and UNKNOWN matches
# :searchin => SEARCH FIELD default name. possible options: name, subject, weblink
def search(search_term, opts = {})
- RestClient.get "#{BASE_URL}/search.php", :params => { :search => search_term }.merge(opts).merge(@creds)
+ params = { :search => search_term }.merge(opts).merge(@creds)
+ response = RestClient.get("#{BASE_URL}/search.php", :params => params)
+ @parser.parse(response).map do |parsed|
+ SearchResult.new(parsed)
+ end
end
def account
RestClient.get "#{BASE_URL}/account.php", :params => @creds
end