Skip to content

Instantly share code, notes, and snippets.

@CheezItMan
Created October 30, 2018 17:52
Show Gist options
  • Save CheezItMan/ab79abbbac83eacc004b4ccc65a912c4 to your computer and use it in GitHub Desktop.
Save CheezItMan/ab79abbbac83eacc004b4ccc65a912c4 to your computer and use it in GitHub Desktop.
My Example Ruby Code
require 'httparty' # If using Rails with a Gemfile, this require is not needed
require 'awesome_print'
# response = HTTParty.get('https://dog.ceo/api/breeds/image/random')
# puts response.code
# puts response.message
# puts response.body
# ap JSON.parse(response.body)
# puts response.headers["date"]
# ap JSON.parse(response.body)["message"]
# ap response["message"]
# response = HTTParty.get("https://dog.ceo/api/breeds/image/random")
# puts response
# ap JSON.parse(response.body)
# class Dog
# attr_accessor :breed
# def initialize(breed)
# @breed = breed
# end
# #Using HTTParty to get and parse a JSON request
# def random_picture
# # this will ensure that there are no weird characters in the URI (like a space in the breed name)
# encoded_uri = URI.encode("https://dog.ceo/api/breed/#{ @breed }/images/random")
# response = HTTParty.get(encoded_uri)
# if response.code != 200
# puts "Error #{response.code}"
# end
# picture = response.parsed_response['message']
# return picture
# end
# end
# myPug = Dog.new('pug')
# puts myPug.random_picture
# myBeagle = Dog.new('beale')
# puts myBeagle.random_picture
response = HTTParty.get('https://www.googleapis.com/books/v1/volumes?q=wheel%20of%20time&key=MYKEYGOESHERE')
parsed_response = response.parsed_response
# ap parsed_response["items"]
parsed_response["items"].each do |item|
puts "*******"
puts "Volume Info"
ap item['volumeInfo']['title']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment