module RUser
RUser
is a simple Ruby Gem to communicate with the randomuser.me API.
Constants
- VERSION
Public Class Methods
new(options = {})
click to toggle source
Creates a new Ruser object
@param [Hash] options a set of options to pass to the template
@option options [String] :gender (nil) the user's gender @option options [String] :seed (nil) the user's unique seed value @option options [Integer] :results (1) the number of results to return @option options [String] :nat (nil) the user's nationality
@example Create a random user
Person.new()
@example Create a male user
Person.new({:gender => 'male'})
@example Create a female user
Person.new({:gender => 'female'})
@example Create a random user with a specific nationality
Person.new({:nat => 'US'})
@example Create a specific user from a seed
Person.new({:seed => 'lazyWolf'})
@example Create three users
Person.new({:results => 3})
@example Create three male users
Person.new({:results => 3. :gender => 'male'})
@return [Person]
# File lib/ruser.rb, line 34 def self.new(options = {}) params = options.map { |k, v| "#{k}=#{v}" } || '' json = JSON.parse(Net::HTTP.get(URI([ RUser::Api::URL, RUser::Api::VERSION, '', '?' + params.join('&') ].join('/')))) results(json) end
results(data)
click to toggle source
Handles results
@param [Hash] data the data to be processed.
# File lib/ruser.rb, line 50 def self.results(data) results = [] if data['results'].size > 1 data['results'].each do |user| results << RUser::Person.new(user, data['nationality'], data['seed']) end results else RUser::Person.new(data['results'][0], data['nationality'], data['seed']) end end