randomuser 0.0.1 → 0.3.1

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: 2f629a1ae617982207be3f267b7b28676db37395
4
- data.tar.gz: dd1dc063fbfbfd0e6490c85fd3c7f04675c410f6
3
+ metadata.gz: 585ecd0aaefd548222f03514ba40642134be774f
4
+ data.tar.gz: c21db409a7bfa3c85e86c83a88181037220b9a0e
5
5
  SHA512:
6
- metadata.gz: 40f9509653a12a3daf989a64c85456e6f8815154e87636d62a004a712920938e07bd8e3204b5e61f2426ebda092fb630ecd2bebba20cd914d891e2c4b6eb5028
7
- data.tar.gz: ad8e5d44226d4f6c675858d00192949cb3322159416af3e61c5c03b7321ca7e88f6a0c90849968bcc0a5293537df3e4efa729231b61413ac75c432e9f0b7a8e1
6
+ metadata.gz: d6bd853433cad2ac3c5222828e5ca52e2abaa122d2be9a411a353f30ade08d84825ae595cda80da8eee0b7a87bb3c8a727d03672c9f4d08e62e0daa933ce236a
7
+ data.tar.gz: 06d1fb3049bf97636099ee7e729aed693246f01a548e81a265e6ed5cd16e2ce65a3fbf823add9629286bb1d4e938f06e03ce6cb1cc6cfccb00f55d4d7198e481
data/README.md CHANGED
@@ -6,49 +6,78 @@ This gem returns simple JSON/hash responses from the [Random User Generator](htt
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'randomuser'
9
+ ```ruby
10
+ gem 'randomuser'
11
+ ```
10
12
 
11
13
  And then execute:
12
14
 
13
- $ bundle
15
+ ```bash
16
+ $ bundle
17
+ ```
14
18
 
15
- Or install it yourself as:
19
+ Or install it as a standalone gem with:
16
20
 
17
- $ gem install randomuser
21
+ ```bash
22
+ $ gem install randomuser
23
+ ```
18
24
 
19
25
  ## Usage
20
26
 
21
27
  To request a single random user:
22
28
 
23
- ```
29
+ ```ruby
24
30
  Randomuser.generate
25
31
  ```
26
32
 
27
33
  To request multiple random users:
28
34
 
29
- ```
30
- Randomuser.generate('results=5')
35
+ ```ruby
36
+ Randomuser.generate(5)
31
37
  ```
32
38
 
33
- To request a specific gender:
39
+ To request a single female random user:
34
40
 
41
+ ```ruby
42
+ Randomuser.generate_female
35
43
  ```
36
- Randomuser.generate('gender=female')
44
+
45
+ To request multiple female random users:
46
+
47
+ ```ruby
48
+ Randomuser.generate_female(5)
37
49
  ```
38
50
 
39
- To request a specific gender with multiple results:
51
+ To request a single male random user:
40
52
 
53
+ ```ruby
54
+ Randomuser.generate_male
41
55
  ```
42
- Randomuser.generate('results=5&gender=female')
56
+
57
+ To request multiple male random users:
58
+
59
+ ```ruby
60
+ Randomuser.generate_male(5)
43
61
  ```
44
62
 
45
63
  To request a specific user:
46
64
 
65
+ ```ruby
66
+ Randomuser.generate_seed('foobar')
47
67
  ```
48
- Randomuser.generate('seed=smallPanda')
49
- ```
50
68
 
51
- For more information on how to customize requests, please see the [Random User Generator](http://randomuser.me) site.
69
+ For more information on this API, please see the [Random User Generator](http://randomuser.me) site.
70
+
71
+ ## Tests
72
+
73
+ Testing works as usual:
74
+
75
+ ```bash
76
+ git clone https://github.com/humanshell/randomuser.git
77
+ cd randomuser
78
+ bundle install
79
+ rake
80
+ ```
52
81
 
53
82
  ## Contributing
54
83
 
data/Rakefile CHANGED
@@ -4,15 +4,14 @@ require 'rake/testtask'
4
4
  desc 'Generate gem documentation'
5
5
  task :doc do
6
6
  system 'rm -rf doc/'
7
- system 'rdoc --exclude=/spec/'
7
+ system 'rdoc --exclude=/test/'
8
8
  end
9
9
 
10
10
  namespace :minitest do
11
11
  Rake::TestTask.new(:all) do |t|
12
- t.libs << 'spec'
13
- t.test_files = FileList['spec/*_spec.rb']
12
+ t.libs << 'test'
13
+ t.test_files = FileList['test/*_test.rb']
14
14
  end
15
15
  end
16
16
 
17
17
  task :default => 'minitest:all'
18
-
@@ -1,29 +1,41 @@
1
- # Randomuser Ruby Library
2
1
  require 'net/http'
3
2
  require 'uri'
4
3
  require 'json'
5
4
  require 'randomuser/version'
6
5
 
7
6
  module Randomuser
8
- @@api_base = 'http://randomuser.me/g/'
9
7
 
10
- def self.api_url(query='')
11
- "#{@@api_base}?#{query}"
8
+ def self.generate(number=1)
9
+ request("results=#{number}")
12
10
  end
13
11
 
14
- def self.generate(query='')
12
+ def self.generate_female(number=1)
13
+ request("results=#{number}&gender=female")
14
+ end
15
15
 
16
- # create the http connection object
17
- uri = URI.parse(self.api_url(query))
18
- http = Net::HTTP.new(uri.host, uri.port)
16
+ def self.generate_male(number=1)
17
+ request("results=#{number}&gender=male")
18
+ end
19
19
 
20
- # open our HTTP connection and send the appropriate request type
21
- # the block will automatically close our connection so we don't have to
22
- http.start do |connection|
23
- response = connection.send_request(:get, uri.request_uri)
24
- response = JSON.parse(response.body, symbolize_names: true)
25
- response[:results]
26
- end
27
-
20
+ def self.generate_seed(seed='')
21
+ request("seed=#{seed}")
28
22
  end
23
+
24
+ private
25
+
26
+ def self.api_url(query='')
27
+ "http://api.randomuser.me/#{Randomuser::VERSION}/?#{query}"
28
+ end
29
+
30
+ def self.request(query='')
31
+ uri = URI.parse(self.api_url(query))
32
+ http = Net::HTTP.new(uri.host, uri.port)
33
+
34
+ http.start do |connection|
35
+ response = connection.send_request(:get, uri.request_uri)
36
+ response = JSON.parse(response.body, symbolize_names: true)
37
+ response[:results]
38
+ end
39
+ end
40
+
29
41
  end
@@ -1,3 +1,3 @@
1
1
  module Randomuser
2
- VERSION = '0.0.1'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -0,0 +1,62 @@
1
+ # coding: utf-8
2
+ require 'test_helper'
3
+
4
+ # all tests for randomuser api gem
5
+
6
+ class TestRandomuser < Minitest::Test
7
+
8
+ def test_generate_returns_single_response
9
+ response = Randomuser.generate
10
+ assert_equal(response.class, Array)
11
+ assert_equal(response.length, 1)
12
+ end
13
+
14
+ def test_generate_returns_multiple_responses
15
+ response = Randomuser.generate(5)
16
+ assert_equal(response.class, Array)
17
+ assert_equal(response.length, 5)
18
+ end
19
+
20
+ def test_generate_female_returns_single_response
21
+ response = Randomuser.generate_female
22
+ assert_equal(response.class, Array)
23
+ assert_equal(response.length, 1)
24
+ assert_equal(response.first[:user][:gender], 'female')
25
+ assert_equal(response.first[:user][:name][:title], 'mrs')
26
+ assert_equal(response.first[:user][:picture], 'http://api.randomuser.me/0.3.1/portraits/women/0.jpg')
27
+ end
28
+
29
+ def test_generate_female_returns_multiple_responses
30
+ response = Randomuser.generate_female(5)
31
+ assert_equal(response.class, Array)
32
+ assert_equal(response.length, 5)
33
+ assert_equal(response.first[:user][:gender], 'female')
34
+ assert_equal(response.first[:user][:name][:title], 'mrs')
35
+ assert_equal(response.first[:user][:picture], 'http://api.randomuser.me/0.3.1/portraits/women/0.jpg')
36
+ end
37
+
38
+ def test_generate_male_returns_single_response
39
+ response = Randomuser.generate_male
40
+ assert_equal(response.class, Array)
41
+ assert_equal(response.length, 1)
42
+ assert_equal(response.first[:user][:gender], 'male')
43
+ assert_equal(response.first[:user][:name][:title], 'mr')
44
+ assert_equal(response.first[:user][:picture], 'http://api.randomuser.me/0.3.1/portraits/men/0.jpg')
45
+ end
46
+
47
+ def test_generate_male_returns_multiple_responses
48
+ response = Randomuser.generate_male(5)
49
+ assert_equal(response.class, Array)
50
+ assert_equal(response.length, 5)
51
+ assert_equal(response.first[:user][:gender], 'male')
52
+ assert_equal(response.first[:user][:name][:title], 'mr')
53
+ assert_equal(response.first[:user][:picture], 'http://api.randomuser.me/0.3.1/portraits/men/0.jpg')
54
+ end
55
+
56
+ def test_generate_seed_returns_single_response
57
+ response = Randomuser.generate_seed
58
+ assert_equal(response.class, Array)
59
+ assert_equal(response.length, 1)
60
+ end
61
+
62
+ end
@@ -0,0 +1,59 @@
1
+ # coding: utf-8
2
+ # use minitest gem, not the one from stdlib
3
+ gem 'minitest'
4
+
5
+ require 'minitest/autorun'
6
+ require 'randomuser'
7
+
8
+ # override the generate methods so they return mock responses during testing
9
+ module Randomuser
10
+ def self.generate(number=1)
11
+ Array.new(number, mock_response)
12
+ end
13
+
14
+ def self.generate_female(number=1)
15
+ Array.new(number, mock_response)
16
+ end
17
+
18
+ def self.generate_male(number=1)
19
+ Array.new(number, mock_response('male'))
20
+ end
21
+
22
+ def self.generate_seed(seed='')
23
+ Array.new(1, mock_response)
24
+ end
25
+ end
26
+
27
+ def mock_response(gender='female')
28
+ {
29
+ user: {
30
+ gender: "#{gender == 'female' ? 'female' : 'male'}",
31
+ name: {
32
+ title: "#{gender == 'female' ? 'mrs' : 'mr'}",
33
+ first: "first",
34
+ last: "last"
35
+ },
36
+ location: {
37
+ street: "6127 pine dr",
38
+ city: "raleigh",
39
+ state: "colorado",
40
+ zip: "34545"
41
+ },
42
+ email: "first.last@example.com",
43
+ username: "blueleopard186",
44
+ password: "password",
45
+ salt: "L",
46
+ md5: "003b0f6e9b1b40200ba0370a5f29208e",
47
+ sha1: "87b7b6b2a06238c0bb7174f03f74ae86211afc7d",
48
+ sha256: "49995e8aadf97fa0cca079be5bbf47b5fa0c5ffb0dd81831ee9b382c9772b46b",
49
+ registered: "1134630377",
50
+ dob: "326899532",
51
+ phone: "(164)-244-7352",
52
+ cell: "(485)-899-1991",
53
+ SSN: "525-20-3862",
54
+ picture: "http://api.randomuser.me/0.3.1/portraits/#{gender == 'female' ? 'women' : 'men'}/0.jpg"
55
+ },
56
+ seed: "beautifulLeopard",
57
+ version: "0.3.1"
58
+ }
59
+ end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: randomuser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominic Giglio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-03 00:00:00.000000000 Z
11
+ date: 2014-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
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
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
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
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
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
54
  version: '0'
55
55
  description: This gem returns simple JSON/hash responses from the Random User Generator
@@ -61,7 +61,7 @@ executables:
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - .gitignore
64
+ - ".gitignore"
65
65
  - Gemfile
66
66
  - LICENSE.txt
67
67
  - README.md
@@ -70,6 +70,8 @@ files:
70
70
  - lib/randomuser.rb
71
71
  - lib/randomuser/version.rb
72
72
  - randomuser.gemspec
73
+ - test/all_test.rb
74
+ - test/test_helper.rb
73
75
  homepage: http://developr.me
74
76
  licenses:
75
77
  - MIT
@@ -80,18 +82,21 @@ require_paths:
80
82
  - lib
81
83
  required_ruby_version: !ruby/object:Gem::Requirement
82
84
  requirements:
83
- - - '>='
85
+ - - ">="
84
86
  - !ruby/object:Gem::Version
85
87
  version: '0'
86
88
  required_rubygems_version: !ruby/object:Gem::Requirement
87
89
  requirements:
88
- - - '>='
90
+ - - ">="
89
91
  - !ruby/object:Gem::Version
90
92
  version: '0'
91
93
  requirements: []
92
94
  rubyforge_project:
93
- rubygems_version: 2.0.3
95
+ rubygems_version: 2.0.14
94
96
  signing_key:
95
97
  specification_version: 4
96
98
  summary: Access Random User Generator API
97
- test_files: []
99
+ test_files:
100
+ - test/all_test.rb
101
+ - test/test_helper.rb
102
+ has_rdoc: