ruser 2.0.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ab812ef94b94d2bb1ed0fe509a7dc8bbd159e9b
4
- data.tar.gz: 2240ea986ae78949f2db71bad85c4b5a76425434
3
+ metadata.gz: a093290642c49a0499ceda520e1ccb099b5acd31
4
+ data.tar.gz: 9bda021d3d1811cfea8d9e70eed0e08616876e78
5
5
  SHA512:
6
- metadata.gz: d517ab1f1b5ea28236341b0f4de48a92f2d6c0b9b259db5abb25db452180fee1e512634188e5ba55a9da1eb61154a897c94909dc2d5a9946b5b75f94e5efa0af
7
- data.tar.gz: cead44f2201b54fd8aeaa7c2d9925cc89db1981a5ff89ffebaa545c0de597fdcd662ec0e205e4b2e487178bb852f7bdd42f5407c983f6468ba9cc6aa42c2643f
6
+ metadata.gz: 4045cc4241063f1f5b0e0624b2ab673818b5e6b66c7dc02ed1485e39e070c101fdc12bec2f3a3e2e8cb862ba60e5dbdd088eb329af3cda4bef2c8b44cb779650
7
+ data.tar.gz: 020d69b5f8de2377059da9848b6833b0de19f3f84db191b3128a467379674148e4e7f8622b0afbbc5a5b2d448747237307e9920bb95caa543dfff0fb4c5a71ec
data/LICENSE CHANGED
@@ -1,9 +1,9 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright © 2014 Simple App Group LLC <info@simpleappgroup.com>
3
+ Copyright © 2014 Joshua Kendall <me@joshuakendall.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
7
7
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
8
 
9
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  RUser is a simple Ruby Gem to communicate with the randomuser.me API.
4
4
 
5
- [![Build Status](https://travis-ci.org/simpleappgroup/ruser.png)](https://travis-ci.org/simpleappgroup/ruser) [![Coverage Status](https://coveralls.io/repos/simpleappgroup/ruser/badge.png?branch=master)](https://coveralls.io/r/simpleappgroup/ruser?branch=master) [![Code Climate](https://codeclimate.com/github/simpleappgroup/ruser.png)](https://codeclimate.com/github/simpleappgroup/ruser) [![Dependency Status](https://gemnasium.com/simpleappgroup/ruser.svg)](https://gemnasium.com/simpleappgroup/ruser)
6
-
5
+ [![Build Status](https://travis-ci.org/jtkendall/ruser.png)](https://travis-ci.org/jtkendall/ruser) [![Coverage Status](https://coveralls.io/repos/jtkendall/ruser/badge.png?branch=master)](https://coveralls.io/r/jtkendall/ruser?branch=master) [![Code Climate](https://codeclimate.com/github/jtkendall/ruser.png)](https://codeclimate.com/github/jtkendall/ruser)
7
6
 
8
7
  ## Installation
9
8
 
@@ -11,35 +10,49 @@ RUser is a simple Ruby Gem to communicate with the randomuser.me API.
11
10
 
12
11
  or in your Gemfile
13
12
 
14
- gem 'ruser'
13
+ gem 'ruser', '~> 3.0'
15
14
 
16
15
 
17
16
  ## Documentation
18
17
 
19
- [rdoc.info/github/simpleappgroup/ruser](http://rdoc.info/github/simpleappgroup/ruser)
18
+ [rdoc.info/github/jtkendall/ruser](http://rdoc.info/github/jtkendall/ruser)
19
+
20
+ ## Changes from 2.x
21
+
22
+ 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.
23
+
24
+ Also new in version 3.0.0:
25
+
26
+ - Removed `name` object. Name parts (Title, First Name, Last Name) are now available as object.first_name instead of object.name.first_name
27
+ - Removed `location` object. Address parts (Street, City, State, Zip Code) are now available as object.street instead of object.location.street
28
+ - Changed `zip_code` to `postal` since not everyone calls them zip codes and not every country uses them.
29
+ - Removed `picture`. Picture has been replaced with `profile_large_url`, `profile_medium_url`, and `profile_thumbnail_url`.
30
+ - Added `nationality`. With the RandomUser API now supporting different nationalities this variable was added.
31
+ - Updated to support API version `0.7`
32
+ - Removed the dependency of `multi_json`
33
+ - Removed the dependency of `hashie`
34
+ - Removed the dependency of `rest-client`
20
35
 
21
36
  ## Quickstart
22
37
 
23
38
  Using RUser in it's simplest form is as easy as calling:
24
39
 
25
40
  require 'ruser'
26
-
27
- user = RUser.new.first
28
41
 
29
- puts "This user is a #{user.gender} named #{user.name.first_name}!"
42
+ user = RUser.new
43
+
44
+ puts "This user is a #{user.gender} named #{user.first_name}!"
30
45
 
31
46
  Then you can access any of the following user attributes:
32
47
 
33
48
  - gender
34
- - name
35
- - first\_name
36
- - last\_name
37
- - title
38
- - location
39
- - street
40
- - city
41
- - state
42
- - zipcode
49
+ - first\_name
50
+ - last\_name
51
+ - title
52
+ - street
53
+ - city
54
+ - state
55
+ - postal
43
56
  - email
44
57
  - username
45
58
  - password
@@ -51,38 +64,42 @@ Then you can access any of the following user attributes:
51
64
  - dob
52
65
  - phone
53
66
  - cell
54
- - ssn
55
- - picture
67
+ - nidn
68
+ - nidt
69
+ - profile_large_url
70
+ - profile_medium_url
71
+ - profile_thumbnail_url
72
+ - nationality
56
73
  - seed
57
74
 
58
- If you want to request a female or male user specifically, specify the `:gender` key in the options hash passed to `new`:
75
+ If you want to request a female or male user specifically, specify the `gender:` key in the options hash passed to `new`:
59
76
 
60
77
  require 'ruser'
61
-
62
- woman = RUser.new({:gender => 'female'})
63
78
 
64
- man = RUser.new({:gender => 'male'})
79
+ woman = RUser.new({ gender: 'female' })
80
+
81
+ man = RUser.new({ gender: 'male' })
65
82
 
66
- If you want to request a specific user by their seed, specify the `:seed` key in the options hash passed to `new`:
83
+ If you want to request a specific user by their seed, specify the `seed:` key in the options hash passed to `new`:
67
84
 
68
85
  require 'ruser'
69
-
70
- lazyWolf = RUser.new({:seed => 'lazyWolf'})
71
86
 
72
- If you would like more than one user supply the `:results` key in the options hash passed to `new`:
87
+ lazyWolf = RUser.new({ seed: 'lazyWolf' })
88
+
89
+ If you would like more than one user supply the `results:` key in the options hash passed to `new`:
73
90
 
74
91
  require 'ruser'
75
-
76
- results = RUser.new({:results => 3})
77
92
 
78
- The maximum number of results is 40, any number larger than that will default to 40. You can pass the `:gender` key along with results to return x number of male or female users:
93
+ results = RUser.new( results: => 3 })
94
+
95
+ The maximum number of results is 2000. Any number larger than that will return only 2000, unless you have a [RandomAPI](http://randomapi.com) 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:
79
96
 
80
97
  results = RUser.new({ :results => 3, :gender => 'female' })
81
98
 
82
99
 
83
100
  ## Contributing & Development
84
101
 
85
- $ git clone https://github.com/simpleappgroup/ruser && cd ruser
102
+ $ git clone https://github.com/jtkendall/ruser && cd ruser
86
103
  $ bundle install
87
104
 
88
105
  * Fork the project.
@@ -93,4 +110,4 @@ The maximum number of results is 40, any number larger than that will default to
93
110
 
94
111
  ## License & Copyright
95
112
 
96
- See LICENSE for details.
113
+ See LICENSE for details.
data/lib/ruser.rb CHANGED
@@ -1,4 +1,8 @@
1
+ # RUser is a simple Ruby Gem to communicate with the randomuser.me API.
1
2
  module RUser
3
+ require 'json'
4
+ require 'net/http'
5
+ require 'uri'
2
6
  require 'ruser/version'
3
7
  require 'ruser/api'
4
8
  require 'ruser/person'
@@ -9,7 +13,8 @@ module RUser
9
13
  #
10
14
  # @option options [String] :gender (nil) the user's gender
11
15
  # @option options [String] :seed (nil) the user's unique seed value
12
- # @option options [String] :limit (1) the number of results to return
16
+ # @option options [Integer] :results (1) the number of results to return
17
+ # @option options [String] :nat (nil) the user's nationality
13
18
  #
14
19
  # @example Create a random user
15
20
  # Person.new()
@@ -17,35 +22,40 @@ module RUser
17
22
  # Person.new({:gender => 'male'})
18
23
  # @example Create a female user
19
24
  # Person.new({:gender => 'female'})
25
+ # @example Create a random user with a specific nationality
26
+ # Person.new({:nat => 'US'})
20
27
  # @example Create a specific user from a seed
21
28
  # Person.new({:seed => 'lazyWolf'})
22
29
  # @example Create three users
23
- # Person.new({:results=> 3})
30
+ # Person.new({:results => 3})
24
31
  # @example Create three male users
25
- # Person.new({:results=> 3. :gender => 'male'})
32
+ # Person.new({:results => 3. :gender => 'male'})
26
33
  # @return [Person]
27
34
  def self.new(options = {})
28
- if options.has_key?('results')
29
- if options[:results] > 40
30
- options[:results] = 40
31
- end
32
- end
35
+ params = options.map { |k, v| "#{k}=#{v}" } || ''
33
36
 
34
- params = options.map { |k,v| "#{k}=#{v}" }
37
+ json = JSON.parse(Net::HTTP.get(URI([
38
+ RUser::Api::URL,
39
+ RUser::Api::VERSION,
40
+ '',
41
+ '?' + params.join('&')
42
+ ].join('/'))))
35
43
 
36
- data = MultiJson.load(RestClient.get [
37
- RUser::Api::Url,
38
- RUser::Api::Version,
39
- "?" + params.join('&')
40
- ].join('/'))['results']
44
+ results(json)
45
+ end
41
46
 
47
+ # Handles results
48
+ #
49
+ # @param [Hash] data the data to be processed.
50
+ def self.results(data)
42
51
  results = []
43
-
44
- data.each do |user|
45
- results << RUser::Person.new(Hashie::Mash.new(user))
52
+ if data['results'].size > 1
53
+ data['results'].each do |user|
54
+ results << RUser::Person.new(user, data['nationality'], data['seed'])
55
+ end
56
+ results
57
+ else
58
+ RUser::Person.new(data['results'][0], data['nationality'], data['seed'])
46
59
  end
47
-
48
- results
49
60
  end
50
-
51
- end
61
+ end
data/lib/ruser/api.rb CHANGED
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
1
2
  module RUser
2
3
  # This module defines the RandomUser.me API constants used by classes.
3
- # @author Simple App Group, LLC.
4
+ # @author Joshua Kendall
4
5
  module Api
5
6
  # The URL for the API.
6
- Url = 'http://api.randomuser.me'
7
+ URL = 'http://api.randomuser.me'.freeze
7
8
 
8
9
  # The version of the API that is used.
9
- Version = '0.4.1'
10
+ VERSION = '0.7'.freeze
10
11
  end
11
- end
12
+ end
data/lib/ruser/person.rb CHANGED
@@ -1,24 +1,43 @@
1
- require 'rest_client'
2
- require 'multi_json'
3
- require 'hashie'
4
-
5
1
  module RUser
6
2
  # This class allows the creation of new users from the RandomUser.me API.
7
- # @author Simple App Group, LLC.
3
+ # @author Joshua Kendall
8
4
  class Person
5
+ KEYS = {
6
+ 'zip' => 'postal',
7
+ 'first' => 'first_name',
8
+ 'last' => 'last_name',
9
+ 'large' => 'profile_large_url',
10
+ 'medium' => 'profile_medium_url',
11
+ 'thumbnail' => 'profile_thumbnail_url'
12
+ }.freeze
13
+
14
+ NIDT = %w(TFN DNI HETU INSEE PPS BSN SSN NINO).freeze
9
15
 
10
16
  # @return [String] the user's gender, either male or female.
11
17
  attr_reader :gender
12
18
 
13
- # As of version 1.1.0 the location hash now uses the key :zipcode instead of :zip, so that dot
14
- # notation users don't end up using the Ruby Array zip method by calling user.location.zip.
15
- # @return [Hash] the user's location including containing the :street, :city, :state, and :zipcode.
16
- attr_reader :location
19
+ # @return [String] the user's title (Mr, Mrs, etc.).
20
+ attr_reader :title
21
+
22
+ # @return [String] the user's first name.
23
+ attr_reader :first_name
24
+
25
+ # @return [String] the user's last name.
26
+ attr_reader :last_name
17
27
 
18
- # @return [Hash] the user's name including :title (Mr, Mrs, etc.), :first_name, and :last_name.
19
- attr_reader :name
28
+ # @return [String] the user's street address.
29
+ attr_reader :street
20
30
 
21
- # @return [String] the user's email address.
31
+ # @return [String] the user's city.
32
+ attr_reader :city
33
+
34
+ # @return [String] the user's state.
35
+ attr_reader :state
36
+
37
+ # @return [String] the user's zip code or postal code.
38
+ attr_reader :postal
39
+
40
+ # @return [String] the user's email.
22
41
  attr_reader :email
23
42
 
24
43
  # @return [String] the user's username.
@@ -30,19 +49,19 @@ module RUser
30
49
  # @return [String] the user's password salt.
31
50
  attr_reader :salt
32
51
 
33
- # @return [String] the md5 hash of the user's salted password.
52
+ # @return [String] the user's md5 hash of the user's salted password.
34
53
  attr_reader :md5
35
54
 
36
- # @return [String] the sha1 hash of the user's salted password.
55
+ # @return [String] the user's sha1 hash of the user's salted password.
37
56
  attr_reader :sha1
38
57
 
39
- # @return [String] the sha256 hash of the user's salted password.
58
+ # @return [String] the user's sha256 hash of the user's salted password.
40
59
  attr_reader :sha256
41
60
 
42
- # @return [String] the date of the user's registration.
61
+ # @return [String] the user's registration date.
43
62
  attr_reader :registered
44
63
 
45
- # @return [String] the user's date of birth.
64
+ # @return [String] the user's birth date.
46
65
  attr_reader :dob
47
66
 
48
67
  # @return [String] the user's phone number.
@@ -51,47 +70,65 @@ module RUser
51
70
  # @return [String] the user's cell phone number.
52
71
  attr_reader :cell
53
72
 
54
- # @return [String] the user's social security number.
55
- attr_reader :ssn
73
+ # @return [String] the user's national Id number (SSN, PPS, HETU,, etc.).
74
+ attr_reader :nidn
75
+
76
+ # @return [String] the user's national Id type (SSN, PPS, HETU, NINO, etc.).
77
+ attr_reader :nidt
56
78
 
57
- # @return [String] the user's profile picture url.
58
- attr_reader :picture
79
+ # @return [String] the user's large profile photo url
80
+ attr_reader :profile_large_url
59
81
 
60
- # @return [String] the user's unique seed which allows future calls for the same user.
82
+ # @return [String] the user's medium profile photo url
83
+ attr_reader :profile_medium_url
84
+
85
+ # @return [String] the user's thumbnail profile photo url
86
+ attr_reader :profile_thumbnail_url
87
+
88
+ # @return [String] the user's nationality
89
+ attr_reader :nationality
90
+
91
+ # @return [String] the user's unique seed which allows future calls.
61
92
  attr_reader :seed
62
93
 
63
94
  # Creates a new person object
64
95
  #
65
96
  # @param [Hash] data the data used to create the user
66
97
  # @return [Person]
67
- def initialize(data)
68
- @gender = data.user.gender
69
- @location = Hashie::Mash.new({
70
- "street" => data.user.location.street,
71
- "city" => data.user.location.city,
72
- "state" => data.user.location.state,
73
- "zipcode" => data.user.location['zip']
74
- })
75
- @name = Hashie::Mash.new({
76
- "title" => data.user.name.title,
77
- "first_name" => data.user.name['first'],
78
- "last_name" => data.user.name['last']
79
- })
80
- @email = data.user.email
81
- @username = data.user.username
82
- @password = data.user.password
83
- @salt = data.user.salt
84
- @md5 = data.user.md5
85
- @sha1 = data.user.sha1
86
- @sha256 = data.user.sha256
87
- @registered = data.user.registered
88
- @dob = data.user.dob
89
- @phone = data.user.phone
90
- @cell = data.user.cell
91
- @ssn = data.user.SSN
92
- @picture = data.user.picture
93
- @seed = data.seed
98
+ def initialize(data, nationality, seed)
99
+ @nationality = nationality
100
+ @seed = seed
101
+ convert(data)
102
+ end
103
+
104
+ # Converts a hash to instance variables
105
+ #
106
+ # @param [Hash] data the data used to create the instance variables
107
+ def convert(data)
108
+ data.each do |k, v|
109
+ k = KEYS[k] if KEYS.include?(k)
110
+ v = v.to_s if k.eql? 'zip'
111
+
112
+ if NIDT.include?(k)
113
+ instance_variable_set('@nidt', k)
114
+ k = 'nidn'
115
+ v = v.to_s
116
+ end
117
+
118
+ var_set(k, v)
119
+ end
94
120
  end
95
121
 
122
+ # Sets all instance variables
123
+ #
124
+ # @param [String] k the key used to create the instance variables
125
+ # @param [String] v the value used to create the instance variables
126
+ def var_set(k, v)
127
+ varget = proc { instance_variable_get("@#{k}") }
128
+ varset = proc { |y| instance_variable_set("@#{k}", y) }
129
+ v.is_a?(Hash) ? convert(v) : instance_variable_set("@#{k}", v)
130
+ self.class.send(:define_method, k, varget)
131
+ self.class.send(:define_method, "#{k}=", varset)
132
+ end
96
133
  end
97
- end
134
+ end
data/lib/ruser/version.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module RUser
2
- Version = '2.0.1'
3
- end
3
+ VERSION = '3.0.0'.freeze
4
+ end
@@ -0,0 +1,16 @@
1
+ require 'ruser'
2
+ require 'spec_helper'
3
+
4
+ # API Health Test
5
+ # Verifies that the API has not changed.
6
+ describe 'API' do
7
+ # URL
8
+ it 'should have the proper url' do
9
+ expect(RUser::Api::URL).to eq('http://api.randomuser.me')
10
+ end
11
+
12
+ # Version
13
+ it 'should have the proper version' do
14
+ expect(RUser::Api::VERSION).to eq('0.7')
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ require 'ruser'
2
+ require 'spec_helper'
3
+
4
+ # Gender Health Test
5
+ # Verifies that we can receive a valid person with a gender field,
6
+ # and that the schema has not changed.
7
+ describe 'Gender' do
8
+ it 'should be a male user' do
9
+ user = RUser.new(gender: 'male')
10
+ expect(user.gender).to eq('male')
11
+ end
12
+
13
+ it 'should be a female user' do
14
+ user = RUser.new(gender: 'female')
15
+ expect(user.gender).to eq('female')
16
+ end
17
+
18
+ it 'should be a gendered user' do
19
+ user = RUser.new
20
+ expect(user.gender).to be_instance_of(String)
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ require 'ruser'
2
+ require 'spec_helper'
3
+
4
+ # Seed Health Test
5
+ # Verifies that we can receive a valid user with a specific seed and that the
6
+ # schema has not changed.
7
+ describe 'Seed' do
8
+ before do
9
+ @user = RUser.new(seed: '73ee20ff00e034b404')
10
+ end
11
+
12
+ it 'should have a reusable seed' do
13
+ expect(@user.seed).to be_instance_of(String)
14
+ end
15
+
16
+ it 'should have the first name carol' do
17
+ expect(@user.first_name).to eql('carol')
18
+ end
19
+
20
+ it 'should have the last name williamson' do
21
+ expect(@user.last_name).to eql('williamson')
22
+ end
23
+
24
+ it 'should be a female user' do
25
+ expect(@user.gender).to eql('female')
26
+ end
27
+
28
+ it 'should have the seed 73ee20ff00e034b404' do
29
+ expect(@user.seed).to eql('73ee20ff00e034b404')
30
+ end
31
+ end
@@ -0,0 +1,114 @@
1
+ require 'ruser'
2
+ require 'spec_helper'
3
+
4
+ # User Health Test
5
+ # Verifies that we can receive a valid user and that the schema has not changed.
6
+ describe 'User' do
7
+ before do
8
+ @user = RUser.new
9
+ end
10
+
11
+ it 'should have a gender' do
12
+ expect(@user.gender).to be_instance_of(String)
13
+ end
14
+
15
+ it 'should have a title' do
16
+ expect(@user.title).to be_instance_of(String)
17
+ end
18
+
19
+ it 'should have a first name' do
20
+ expect(@user.first_name).to be_instance_of(String)
21
+ end
22
+
23
+ it 'should have a last name' do
24
+ expect(@user.last_name).to be_instance_of(String)
25
+ end
26
+
27
+ it 'should have a street address' do
28
+ expect(@user.street).to be_instance_of(String)
29
+ end
30
+
31
+ it 'should have a city' do
32
+ expect(@user.city).to be_instance_of(String)
33
+ end
34
+
35
+ it 'should have a state' do
36
+ expect(@user.state).to be_instance_of(String)
37
+ end
38
+
39
+ it 'should have a zip or postal code' do
40
+ expect(@user.postal).to be_instance_of(String)
41
+ end
42
+
43
+ it 'should have an email' do
44
+ expect(@user.email).to be_instance_of(String)
45
+ end
46
+
47
+ it 'should have a username' do
48
+ expect(@user.username).to be_instance_of(String)
49
+ end
50
+
51
+ it 'should have a password' do
52
+ expect(@user.password).to be_instance_of(String)
53
+ end
54
+
55
+ it 'should have a password salt' do
56
+ expect(@user.salt).to be_instance_of(String)
57
+ end
58
+
59
+ it 'should have a md5 hash of the password' do
60
+ expect(@user.md5).to be_instance_of(String)
61
+ end
62
+
63
+ it 'should have a sha1 hash of the password' do
64
+ expect(@user.sha1).to be_instance_of(String)
65
+ end
66
+
67
+ it 'should have a sha256 hash of the password' do
68
+ expect(@user.sha256).to be_instance_of(String)
69
+ end
70
+
71
+ it 'should have a registration date' do
72
+ expect(@user.registered).to be_instance_of(Fixnum)
73
+ end
74
+
75
+ it 'should have a date of birth' do
76
+ expect(@user.dob).to be_instance_of(Fixnum)
77
+ end
78
+
79
+ it 'should have a phone number' do
80
+ expect(@user.phone).to be_instance_of(String)
81
+ end
82
+
83
+ it 'should have a cell phone number' do
84
+ expect(@user.cell).to be_instance_of(String)
85
+ end
86
+
87
+ it 'should have a national Id number' do
88
+ expect(@user.nidn).to be_instance_of(String)
89
+ end
90
+
91
+ it 'should have a national Id type' do
92
+ expect(@user.nidt).to be_instance_of(String)
93
+ end
94
+
95
+ it 'should have a large profile photo url' do
96
+ expect(@user.profile_large_url).to be_instance_of(String)
97
+ end
98
+
99
+ it 'should have a medium profile photo url' do
100
+ expect(@user.profile_medium_url).to be_instance_of(String)
101
+ end
102
+
103
+ it 'should have a thumbnail profile photo url' do
104
+ expect(@user.profile_thumbnail_url).to be_instance_of(String)
105
+ end
106
+
107
+ it 'should have a nationality' do
108
+ expect(@user.nationality).to be_instance_of(String)
109
+ end
110
+
111
+ it 'should have a reusable seed' do
112
+ expect(@user.seed).to be_instance_of(String)
113
+ end
114
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,20 @@
1
1
  require 'rubygems'
2
2
  require 'simplecov'
3
3
  require 'coveralls'
4
+ require 'codeclimate-test-reporter'
5
+ require 'webmock/rspec'
6
+ require 'support/fakerandomuser'
4
7
 
5
8
  SimpleCov.start
6
9
  Coveralls.wear!
7
10
 
11
+ WebMock.disable_net_connect!(allow: 'codeclimate.com')
12
+
13
+ CodeClimate::TestReporter.start
14
+
8
15
  RSpec.configure do |config|
9
- config.order = "random"
10
- end
16
+ config.order = 'random'
17
+ config.before(:each) do
18
+ stub_request(:get, /api.randomuser.me/).to_rack(FakeRandomUser)
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ require 'sinatra/base'
2
+
3
+ class FakeRandomUser < Sinatra::Base
4
+ get '/0.7/' do
5
+ if params[:gender] && params[:gender].eql?('male')
6
+ json_response 200, 'male.json'
7
+ else
8
+ json_response 200, 'female.json'
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def json_response(response_code, file_name)
15
+ content_type :json
16
+ status response_code
17
+ File.open(File.dirname(__FILE__) + '/fixtures/' + file_name, 'rb').read
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ {
2
+ "results": [
3
+ {
4
+ "user": {
5
+ "gender": "female",
6
+ "name": {
7
+ "title": "ms",
8
+ "first": "carol",
9
+ "last": "williamson"
10
+ },
11
+ "location": {
12
+ "street": "3953 grove road",
13
+ "city": "york",
14
+ "state": "clwyd",
15
+ "zip": "AK4 7JW"
16
+ },
17
+ "email": "carol.williamson@example.com",
18
+ "username": "redgorilla103",
19
+ "password": "lucky13",
20
+ "salt": "EF8KWSja",
21
+ "md5": "cd36642a91f62188d7561ce35fce7011",
22
+ "sha1": "6d0b0e0c4fd58bdf11f7fdb6586188b40a70dd1c",
23
+ "sha256": "40bac4c83318ed54fe6556f5b2eef3980e7cc733308e85bf5f24603cd037ee01",
24
+ "registered": 1284008234,
25
+ "dob": 1087588856,
26
+ "phone": "015395 78637",
27
+ "cell": "0745-845-025",
28
+ "NINO": "SE 18 99 09 K",
29
+ "picture": {
30
+ "large": "https://randomuser.me/api/portraits/women/24.jpg",
31
+ "medium": "https://randomuser.me/api/portraits/med/women/24.jpg",
32
+ "thumbnail": "https://randomuser.me/api/portraits/thumb/women/24.jpg"
33
+ }
34
+ }
35
+ }
36
+ ],
37
+ "nationality": "GB",
38
+ "seed": "73ee20ff00e034b404",
39
+ "version": "0.7"
40
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "results": [
3
+ {
4
+ "user": {
5
+ "gender": "male",
6
+ "name": {
7
+ "title": "mr",
8
+ "first": "adolfo",
9
+ "last": "peña"
10
+ },
11
+ "location": {
12
+ "street": "3157 paseo de extremadura",
13
+ "city": "gandía",
14
+ "state": "la rioja",
15
+ "zip": 82066
16
+ },
17
+ "email": "adolfo.peña@example.com",
18
+ "username": "beautifulduck210",
19
+ "password": "magelan",
20
+ "salt": "q1QQAlu3",
21
+ "md5": "046dbdd1995e141afdef4f1245b4cf84",
22
+ "sha1": "df43fb4a7f088c97b9ba9265e072326824b4a490",
23
+ "sha256": "fc5bef9fdbc9559ef56bcc01ad7cb6a968847494bc86589a4f5d7f6dda4a44bf",
24
+ "registered": 1061858115,
25
+ "dob": 1142231427,
26
+ "phone": "988-432-692",
27
+ "cell": "697-947-659",
28
+ "DNI": "82222742-B",
29
+ "picture": {
30
+ "large": "https://randomuser.me/api/portraits/men/57.jpg",
31
+ "medium": "https://randomuser.me/api/portraits/med/men/57.jpg",
32
+ "thumbnail": "https://randomuser.me/api/portraits/thumb/men/57.jpg"
33
+ }
34
+ }
35
+ }
36
+ ],
37
+ "nationality": "ES",
38
+ "seed": "88e0778bf400620201",
39
+ "version": "0.7"
40
+ }
metadata CHANGED
@@ -1,59 +1,87 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Kendall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-17 00:00:00.000000000 Z
11
+ date: 2016-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: multi_json
14
+ name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
20
- type: :runtime
19
+ version: '3.4'
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '3.4'
27
27
  - !ruby/object:Gem::Dependency
28
- name: hashie
28
+ name: sinatra
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.3'
34
- type: :runtime
33
+ version: '1.4'
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.3'
40
+ version: '1.4'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rest-client
42
+ name: codeclimate-test-reporter
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.7'
48
- type: :runtime
47
+ version: '0.4'
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.7'
54
+ version: '0.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.22'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.22'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.36'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.36'
55
83
  description: A gem to interact with the randomuser.me API.
56
- email: josh@simpleappgroup.com
84
+ email: me@joshuakendall.com
57
85
  executables: []
58
86
  extensions: []
59
87
  extra_rdoc_files: []
@@ -64,10 +92,15 @@ files:
64
92
  - lib/ruser/api.rb
65
93
  - lib/ruser/person.rb
66
94
  - lib/ruser/version.rb
67
- - spec/functional/api_spec.rb
68
- - spec/functional/ruser_spec.rb
95
+ - spec/features/api_spec.rb
96
+ - spec/features/gender_spec.rb
97
+ - spec/features/seed_spec.rb
98
+ - spec/features/user_spec.rb
69
99
  - spec/spec_helper.rb
70
- homepage: http://github.com/simpleappgroup/ruser
100
+ - spec/support/fakerandomuser.rb
101
+ - spec/support/fixtures/female.json
102
+ - spec/support/fixtures/male.json
103
+ homepage: http://github.com/jtkendall/ruser
71
104
  licenses:
72
105
  - MIT
73
106
  metadata: {}
@@ -87,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
120
  version: '0'
88
121
  requirements: []
89
122
  rubyforge_project:
90
- rubygems_version: 2.2.2
123
+ rubygems_version: 2.5.1
91
124
  signing_key:
92
125
  specification_version: 4
93
126
  summary: Random User Generator API
@@ -1,127 +0,0 @@
1
- require 'ruser'
2
- require 'spec_helper'
3
-
4
- # API Health Test
5
- # Verifies that the API has not changed.
6
- describe 'API' do
7
-
8
- describe '.health' do
9
- before do
10
- @user = RUser.new().first
11
- end
12
-
13
- # Gender
14
- it 'should have a gender string' do
15
- expect(@user.gender).to be_instance_of(String)
16
- end
17
-
18
- # Location Hash
19
- it 'should have a location hash' do
20
- expect(@user.location).to be_instance_of(Hashie::Mash)
21
- end
22
-
23
- it 'should have a street address in the location hash' do
24
- expect(@user.location.street).to be_instance_of(String)
25
- end
26
-
27
- it 'should have a city in the location hash' do
28
- expect(@user.location.city).to be_instance_of(String)
29
- end
30
-
31
- it 'should have a state in the location hash' do
32
- expect(@user.location.state).to be_instance_of(String)
33
- end
34
-
35
- it 'should have a zipcode in the location hash' do
36
- expect(@user.location.zipcode).to be_instance_of(String)
37
- end
38
-
39
- # Name Hash
40
- it 'should have a name hash' do
41
- expect(@user.name).to be_instance_of(Hashie::Mash)
42
- end
43
-
44
- it 'should have a title in the name hash' do
45
- expect(@user.name.title).to be_instance_of(String)
46
- end
47
-
48
- it 'should have a first name in the name hash' do
49
- expect(@user.name.first_name).to be_instance_of(String)
50
- end
51
-
52
- it 'should have a last name in the name hash' do
53
- expect(@user.name.last_name).to be_instance_of(String)
54
- end
55
-
56
- # Email Address
57
- it 'should have a email address string' do
58
- expect(@user.email).to be_instance_of(String)
59
- end
60
-
61
- # Username
62
- it 'should have a username string' do
63
- expect(@user.username).to be_instance_of(String)
64
- end
65
-
66
- # Password
67
- it 'should have a password string' do
68
- expect(@user.password).to be_instance_of(String)
69
- end
70
-
71
- # Salt
72
- it 'should have a salt string' do
73
- expect(@user.salt).to be_instance_of(String)
74
- end
75
-
76
- # MD5
77
- it 'should have a md5 string' do
78
- expect(@user.sha1).to be_instance_of(String)
79
- end
80
-
81
- # SHA1
82
- it 'should have a sha1 string' do
83
- expect(@user.sha1).to be_instance_of(String)
84
- end
85
-
86
- # SHA256
87
- it 'should have a sha56 string' do
88
- expect(@user.sha256).to be_instance_of(String)
89
- end
90
-
91
- # Registered
92
- it 'should have a registered string' do
93
- expect(@user.registered).to be_instance_of(String)
94
- end
95
-
96
- # DOB
97
- it 'should have a date of birth string' do
98
- expect(@user.dob).to be_instance_of(String)
99
- end
100
-
101
- # Phone
102
- it 'should have a phone string' do
103
- expect(@user.phone).to be_instance_of(String)
104
- end
105
-
106
- # Cell
107
- it 'should have a cell phone string' do
108
- expect(@user.cell).to be_instance_of(String)
109
- end
110
-
111
- # SSN
112
- it 'should have a ssn string' do
113
- expect(@user.ssn).to be_instance_of(String)
114
- end
115
-
116
- # Picture
117
- it 'should have a picture string' do
118
- expect(@user.picture).to be_instance_of(String)
119
- end
120
-
121
- # Seed
122
- it 'should have a seed string' do
123
- expect(@user.seed).to be_instance_of(String)
124
- end
125
- end
126
-
127
- end
@@ -1,54 +0,0 @@
1
- require 'ruser'
2
- require 'spec_helper'
3
-
4
- describe 'RUser' do
5
-
6
- describe '.man' do
7
- before do
8
- @man = RUser.new({ :gender => 'male' }).first
9
- end
10
-
11
- it 'should return a male user' do
12
- expect(@man.gender).to eql('male')
13
- end
14
- end
15
-
16
- describe '.woman' do
17
- before do
18
- @woman = RUser.new({ :gender => 'female' }).first
19
- end
20
-
21
- it 'should return a female user' do
22
- expect(@woman.gender).to eql('female')
23
- end
24
- end
25
-
26
- describe '.random' do
27
- before do
28
- @user = RUser.new().first
29
- end
30
-
31
- it 'should return a gendered user' do
32
- expect(@user.gender).to be_instance_of(String)
33
- end
34
- end
35
-
36
- describe '.seed' do
37
- before do
38
- @user = RUser.new({ :seed => 'lazyWolf' }).first
39
- end
40
-
41
- it 'should have the first name alberto' do
42
- expect(@user.name.first_name).to eql('alberto')
43
- end
44
-
45
- it 'should have the last name holland' do
46
- expect(@user.name.last_name).to eql('holland')
47
- end
48
-
49
- it 'should return a male user' do
50
- expect(@user.gender).to eql('male')
51
- end
52
- end
53
-
54
- end