Created
September 14, 2015 19:48
-
-
Save cmar/2bc19fd1a31fd5e8a3de to your computer and use it in GitHub Desktop.
RubyLoCo Star Wars Hack Night Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
# RubyLoCo Star Wars Hack Night | |
# Documentation https://swapi.co/documentation | |
require 'bundler/inline' | |
# true to install gems | |
gemfile false do | |
source 'https://rubygems.org' | |
gem 'httparty' | |
end | |
class StarWars | |
include HTTParty | |
base_uri 'swapi.co/api' | |
def people(id) | |
response = self.class.get("/people/#{id}") | |
response.parsed_response | |
end | |
end | |
star_wars = StarWars.new | |
luke = star_wars.people(1) | |
p luke["name"] | |
p luke["films"] | |
p StarWars.get(luke["films"].first).parsed_response["title"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i tried my hand at porting this example & then fleshing it out into a client library in crystal, here's how far i got: https://gist.github.com/bjmllr/a366d137f0d52d95f405