Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kathgironpe/random_user
Random user generator is an Elixir client for randomuser.me API
https://github.com/kathgironpe/random_user
Last synced: about 2 months ago
JSON representation
Random user generator is an Elixir client for randomuser.me API
- Host: GitHub
- URL: https://github.com/kathgironpe/random_user
- Owner: kathgironpe
- Created: 2016-07-21T04:45:14.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2022-08-29T01:58:18.000Z (almost 2 years ago)
- Last Synced: 2024-01-07T10:16:19.922Z (5 months ago)
- Language: Elixir
- Homepage: https://hexdocs.pm/random_user/0.3.5
- Size: 76.2 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Lists
- awesome-elixir - random_user - An Elixir client for randomuser.me API. (Third Party APIs)
README
# RandomUser
![Build Status](https://github.com/kathgironpe/random_user/actions/workflows/main.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/kathgironpe/random_user/badge.svg?branch=main)](https://coveralls.io/github/kathgironpe/random_user?branch=main)## Features
- [x] Return one random user
- [x] Return multiple random users
- [x] Seeds (always returns Becky Sims)
- [x] Choose gender, nationality and other options
- [x] Format results## Installation
This package is [available in Hex](https://hexdocs.pm/random_user/0.3.5) and can be installed as follows:
1. Add `random_user` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:random_user, "~> 0.3.5"}]
end
```2. Ensure `random_user` is started before your application:
```elixir
def application do
[applications: [:random_user]]
end
```## Usage
### One Random User
```elixir
# Returns one random user
RandomUser.Random.one# Returns a random female user
RandomUser.Random.one(%{ gender: "female" })# Returns a random British female user
RandomUser.Random.one(%{ gender: "female", nat: "gb" })
```### Multiple Random Users
```elixir
# Returns 50 users
RandomUser.Random.multiple(50)# Returns 50 female users
RandomUser.Random.multiple(50, %{ gender: "female" })# Returns 50 female users from AU and NZ
RandomUser.Random.multiple(50, %{ gender: "female", nat: "au,nz" })
```### Get results easily with Parser
For one random user:
```elixir
res = RandomUser.Random.one |> RandomUser.Parser.results |> RandomUser.Parser.parse
res.gender
res.picture["large"]
```For multiple random users:
```elixir
users = RandomUser.Random.multiple(2) |> RandomUser.Parser.results
Enum.map(users, fn u ->
user = RandomUser.Parser.parse(u)
large_pic = user.picture["large"]
end)
```