RUser

RUser is a simple Ruby Gem to communicate with the randomuser.me API.

Build Status Code Climate Gem Version Dependency Status

Installation

gem install ruser

or in your Gemfile

gem 'ruser', '~> 3.0'

Documentation

rdoc.info/github/jtkendall/ruser

Changes from 2.x

From version 3.0.0 and forward we are now returning a nidt and nidn variable instead of a ssn variable. This is to allow users to properly associate national id numbers with their national id types. So a user in the US will have a standard SSN as the nidn value and "SSN" as the nidt value. This makes it easier to call user.nidt and user.nidn to get the proper information instead of calling user.ssn when the user might actually have a PPS instead of a SSN.

Also new in version 3.0.0:

  • Removed name object. Name parts (Title, First Name, Last Name) are now available as object.first_name instead of object.name.first_name
  • Removed location object. Address parts (Street, City, State, Zip Code) are now available as object.street instead of object.location.street
  • Changed zip_code to postal since not everyone calls them zip codes and not every country uses them.
  • Removed picture. Picture has been replaced with profile_large_url, profile_medium_url, and profile_thumbnail_url.
  • Added nationality. With the RandomUser API now supporting different nationalities this variable was added.
  • Updated to support API version 0.7
  • Removed the dependency of multi_json
  • Removed the dependency of hashie
  • Removed the dependency of rest-client

Quickstart

Using RUser in it's simplest form is as easy as calling:

require 'ruser'

user = RUser.new

puts "This user is a #{user.gender} named #{user.first_name}!"

Then you can access any of the following user attributes:

  • gender
  • first_name
  • last_name
  • title
  • street
  • city
  • state
  • postal
  • email
  • username
  • password
  • salt
  • md5
  • sha1
  • sha256
  • registered
  • dob
  • phone
  • cell
  • nidn
  • nidt
  • profile_large_url
  • profile_medium_url
  • profile_thumbnail_url
  • nationality
  • seed

If you want to request a female or male user specifically, specify the gender: key in the options hash passed to new:

require 'ruser'

woman = RUser.new({ gender: 'female' })

man = RUser.new({ gender: 'male' })

If you want to request a specific user by their seed, specify the seed: key in the options hash passed to new:

require 'ruser'

lazyWolf = RUser.new({ seed: 'lazyWolf' })

If you would like more than one user supply the results: key in the options hash passed to new:

require 'ruser'

results = RUser.new( results: 3 })

The maximum number of results is 2000. Any number larger than that will return only 2000, unless you have a RandomAPI API key. With an API key you can return up to 10000 results per request, just pass your key: with your optinos. You can pass the gender: key along with results to return x number of male or female users:

results = RUser.new({ results: 3, gender: 'female' })

Contributing & Development

$ git clone https://github.com/jtkendall/ruser && cd ruser
$ bundle install
  • Fork the project.
  • Make your feature addition or bug fix. All specs should pass.
  • Add specs for your changes. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with version, or history. If you want to have your own version, that is fine but bump version in a commit by itself in another branch so a maintainer ignore it when your pull request is merged.
  • Send a pull request. Bonus points for topic branches.

License & Copyright

See LICENSE for details.