Skip to content
A Ruby interface for http://swapi.co/ - the Star Wars API
Ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
.rubocop.yml
.travis.yml
Gemfile
Guardfile
LICENSE.txt
README.md
Rakefile
starwars.gemspec

README.md

Starwars

Coverage Status Build Status Inline docs Code Climate

A Ruby interface for http://swapi.co/ - the Star Wars API Starwars

API Support

  • Films API
  • People API
  • Planet API
  • Species API
  • Vehicles API
  • Starship API

Installation

Add this line to your application's Gemfile:

gem 'starwars'

And then execute:

$ bundle

Or install it yourself as:

$ gem install starwars

Available Resources

Usage

All the resources defined above have 2 functions, #fetch and #fetch_all

#Fetch

#fetch is used to fetch a single resource via ID or Resource URL

Starwars::Person.fetch(1).name
Starwars::Person.fetch('http://swapi.co/api/people/3/').name

#fetch_all

#fetch_all is used to fetch all resources via pagination

planets = Starwars::Planet.fetch_all

# to access the items use #items
planets.items.map(&:name)
planets.items.each{|item| p item.inspect}

# you can also use #results instead of iteams
planets.results.map(&:name)

Pagination

using #fetch_all will yield a pagination response:

starships = Starwars::Starship.fetch_all
p starships.number_of_pages
p starships.last_page?
p starships.next_page?

To iterate pages you can use the following interface:

Starwars::Starship.fetch_all.each{|page|
  p page.next
  p page.previous
  p page.results.size
}

Documentation

the gem is fairly documented. Browse the YARD documentaion for more information.

Contributing

  1. Fork it ( https://github.com/moski/starwars/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
You can’t perform that action at this time.