Class: Vectra::API
Defined Under Namespace
Classes: InvalidResponse
Class Method Summary collapse
Class Method Details
.pull(url) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vectra/api.rb', line 7 def self.pull(url) # Set the endpoint unless Vectra::Config.endpoint.include? "/api" Vectra::Config.endpoint = "#{Vectra::Config.endpoint}/api" end base_uri Vectra::Config.endpoint # Right now, they don't support signed Certs .update(verify: false) # Set basic auth .update(basic_auth: {username: Vectra::Config.username, password: Vectra::Config.password}) # Default the result set results = [] # Send the request response = get(url) # Check the response if !response.code.eql?(200) raise Vectra::API::InvalidResponse, "Invalid Response Received" end #response = response.response_parse if response.parsed_response.has_key? "next" unless response.parsed_response["next"].nil? results.concat(self.pull(response.parsed_response["next"])) end end # Merge the results into results if response.parsed_response.has_key? "results" results.concat(response.parsed_response["results"]) else return response.parsed_response end # Sort the results and spit them out results.sort!{|a,b| a['id']<=>b['id']} end |