Class: CliNasaAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/services/cli_nasa_API.rb

Class Method Summary collapse

Class Method Details

.basic_search(terms) ⇒ Object

Returns results of all types based on the terms provided



5
6
7
# File 'lib/services/cli_nasa_API.rb', line 5

def self.basic_search(terms)
  results = HTTParty.get(@baseline + "/search?q=#{terms}")
end

.media_search(type, terms) ⇒ Object

Returns results of the specified media type (first value passed) based on the provided search terms (second value passed), parsed as a hash



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/services/cli_nasa_API.rb', line 11

def self.media_search(type, terms)
  case type
  when "image"
    results = HTTParty.get(@baseline + "/search?q=#{terms}&media_type=image", format: :plain)
    parsed_results = JSON.parse(results.body)
    puts parsed_results.class
    parsed_results
  when "audio"
    results = HTTParty.get(@baseline + "/search?q=#{terms}&media_type=audio", format: :plain)
    parsed_results = JSON.parse(results.body)
    parsed_results
  when "video"
    results = HTTParty.get(@baseline + "/search?q=#{terms}&media_type=video")
    parsed_results = JSON.parse(results.body)
    parsed_results
  end
end