Sha256: bf5f70529fe1a8a2402744f472a6f5584d22e9f840de95d42124196d1268eee6

Contents?: true

Size: 1001 Bytes

Versions: 2

Compression:

Stored size: 1001 Bytes

Contents

class CliNasaAPI
  @baseline = "https://images-api.nasa.gov"

  # Returns results of all types based on the terms provided
  def self.basic_search(terms)
    results = HTTParty.get(@baseline + "/search?q=#{terms}")
  end

  # Returns results of the specified media type (first value passed) based on the
  # provided search terms (second value passed), parsed as a hash
  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cli-nasa-0.1.1 lib/services/cli_nasa_API.rb
cli-nasa-0.1.0 lib/services/cli_nasa_API.rb