fake_name_generator 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/README.rdoc +1 -0
- data/lib/fake_name_generator.rb +38 -90
- data/spec/fake_name_generator_spec.rb +60 -46
- data/spec/spec_helper.rb +11 -3
- metadata +3 -3
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fake_name_generator (0.0.
|
4
|
+
fake_name_generator (0.0.2)
|
5
5
|
json (>= 1.5.1)
|
6
6
|
|
7
7
|
GEM
|
@@ -9,7 +9,7 @@ GEM
|
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.1.2)
|
11
11
|
fakeweb (1.3.0)
|
12
|
-
json (1.5.
|
12
|
+
json (1.5.3)
|
13
13
|
rspec (2.5.0)
|
14
14
|
rspec-core (~> 2.5.0)
|
15
15
|
rspec-expectations (~> 2.5.0)
|
data/README.rdoc
CHANGED
data/lib/fake_name_generator.rb
CHANGED
@@ -50,7 +50,7 @@ class FakeNameGenerator
|
|
50
50
|
|
51
51
|
##
|
52
52
|
# The current version of the gem
|
53
|
-
VERSION = '0.0.
|
53
|
+
VERSION = '0.0.3'
|
54
54
|
|
55
55
|
##
|
56
56
|
# The current FakeNameGenerator.com API endpoint
|
@@ -76,42 +76,7 @@ class FakeNameGenerator
|
|
76
76
|
class APIConnectionError < StandardError; end
|
77
77
|
class APIKeyInvalidError < StandardError; end
|
78
78
|
|
79
|
-
attr_reader :country,
|
80
|
-
:nameset,
|
81
|
-
:gender,
|
82
|
-
:data,
|
83
|
-
:full_name,
|
84
|
-
:first_name,
|
85
|
-
:middle_name,
|
86
|
-
:last_name,
|
87
|
-
:maiden_name,
|
88
|
-
:email_address,
|
89
|
-
:gender_name,
|
90
|
-
:street1,
|
91
|
-
:street2,
|
92
|
-
:street3,
|
93
|
-
:city,
|
94
|
-
:state,
|
95
|
-
:zip,
|
96
|
-
:country_code,
|
97
|
-
:phone_number,
|
98
|
-
:birthday,
|
99
|
-
:occupation,
|
100
|
-
:password,
|
101
|
-
:domain,
|
102
|
-
:cc_type,
|
103
|
-
:cc_number,
|
104
|
-
:cc_exp_month,
|
105
|
-
:cc_exp_year,
|
106
|
-
:cc_cvv,
|
107
|
-
:national_id,
|
108
|
-
:national_id_type,
|
109
|
-
:blood_type,
|
110
|
-
:weight_kilograms,
|
111
|
-
:weight_pounds,
|
112
|
-
:height_centimeters,
|
113
|
-
:height_inches,
|
114
|
-
:ups_tracking_number
|
79
|
+
attr_reader :country, :data, :gender, :nameset
|
115
80
|
|
116
81
|
# === Parameters
|
117
82
|
# * _api_key_ = API key for accessing the FakeNameGenerator.com API (required)
|
@@ -119,7 +84,8 @@ class FakeNameGenerator
|
|
119
84
|
# * _nameset_ = language-related names returned (default: 'us')
|
120
85
|
# * _gender_ = specify whether random, male, or female values returned (default: random)
|
121
86
|
def initialize(options={})
|
122
|
-
|
87
|
+
options[:api_key] || options[:json_data] or raise ArgumentError, "No API key or JSON data provided"
|
88
|
+
@api_key = options[:api_key]
|
123
89
|
@country = options[:country] || DEFAULT_COUNTRY
|
124
90
|
@nameset = options[:nameset] || DEFAULT_NAMESET
|
125
91
|
@gender = options[:gender] || DEFAULT_GENDER
|
@@ -128,21 +94,29 @@ class FakeNameGenerator
|
|
128
94
|
raise ArgumentError, "Specified nameset parameter is not valid. Please see FakeNameGenerator::VALID_NAMESET_CODES" unless VALID_NAMESET_CODES.include?(@nameset)
|
129
95
|
raise ArgumentError, "Specified gender parameter is not valid. Please see FakeNameGenerator::VALID_GENDER_CODES" unless VALID_GENDER_CODES.include?(@gender)
|
130
96
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
case response.code
|
135
|
-
when '500' || 500
|
136
|
-
raise APIConnectionError, "FakeNameGenerator API not working (500 Error)"
|
137
|
-
when '403' || 403
|
138
|
-
raise APIKeyInvalidError, "Provided API key is not valid (403 Error)"
|
139
|
-
when '200' || 200
|
140
|
-
@data = JSON.parse(response.body)
|
141
|
-
build_name
|
97
|
+
if options[:json_data]
|
98
|
+
@data = JSON.parse(options[:json_data])
|
142
99
|
else
|
143
|
-
|
100
|
+
url = [API_URL, build_params].join('?')
|
101
|
+
response = Net::HTTP.get_response(URI.parse(url))
|
102
|
+
|
103
|
+
case response.code
|
104
|
+
when '500' || 500
|
105
|
+
raise APIConnectionError, "FakeNameGenerator API not working (500 Error)"
|
106
|
+
when '403' || 403
|
107
|
+
raise APIKeyInvalidError, "Provided API key is not valid (403 Error)"
|
108
|
+
when '200' || 200
|
109
|
+
@data = JSON.parse(response.body)
|
110
|
+
else
|
111
|
+
raise StandardError, "Unexpected response from FakeNameGenerator.com API"
|
112
|
+
end
|
144
113
|
end
|
114
|
+
end
|
145
115
|
|
116
|
+
##
|
117
|
+
# Return the current fake name attributes as JSON
|
118
|
+
def to_json
|
119
|
+
@data.to_json
|
146
120
|
end
|
147
121
|
|
148
122
|
private
|
@@ -151,46 +125,20 @@ class FakeNameGenerator
|
|
151
125
|
"wsvKey=#{@api_key}&output=#{DEFAULT_OUTPUT}&c=#{@country}&n=#{@nameset}&gen=#{@gender}"
|
152
126
|
end
|
153
127
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
@state = data['identity']['state']['value']
|
169
|
-
@zip = data['identity']['zip']['value']
|
170
|
-
@country_code = data['identity']['country_code']['value']
|
171
|
-
@phone_number = data['identity']['phone_number']['value']
|
172
|
-
# misc personal info
|
173
|
-
@birthday = data['identity']['birthday']['value']
|
174
|
-
@occupation = data['identity']['occupation']['value']
|
175
|
-
@password = data['identity']['password']['value']
|
176
|
-
@domain = data['identity']['domain']['value']
|
177
|
-
# credit card info
|
178
|
-
@cc_type = data['identity']['cc_type']['value']
|
179
|
-
@cc_number = data['identity']['cc_number']['value']
|
180
|
-
@cc_exp_month = data['identity']['cc_exp_month']['value']
|
181
|
-
@cc_exp_year = data['identity']['cc_exp_year']['value']
|
182
|
-
@cc_cvv = data['identity']['cc_cvv']['value']
|
183
|
-
# identifying information
|
184
|
-
@national_id = data['identity']['national_id']['value']
|
185
|
-
@national_id_type = data['identity']['national_id_type']['value']
|
186
|
-
@blood_type = data['identity']['blood_type']['value']
|
187
|
-
@weight_kilograms = data['identity']['weight_kilograms']['value']
|
188
|
-
@weight_pounds = data['identity']['weight_pounds']['value']
|
189
|
-
@height_centimeters = data['identity']['height_centimeters']['value']
|
190
|
-
@height_inches = data['identity']['height_inches']['value']
|
191
|
-
@ups_tracking_number = data['identity']['ups_tracking_number']['value']
|
192
|
-
|
128
|
+
METHOD_ALIASES = {
|
129
|
+
:gender_name => :gender,
|
130
|
+
:first_name => :given_name,
|
131
|
+
:last_name => :surname
|
132
|
+
}
|
133
|
+
|
134
|
+
def method_missing(sym)
|
135
|
+
if data['identity'][sym.to_s]
|
136
|
+
data['identity'][sym.to_s]['value']
|
137
|
+
elsif METHOD_ALIASES[sym]
|
138
|
+
data['identity'][METHOD_ALIASES[sym].to_s]['value']
|
139
|
+
else
|
140
|
+
raise NoMethodError, "undefined method \`#{sym}' for #{self}"
|
141
|
+
end
|
193
142
|
end
|
194
|
-
|
195
143
|
end
|
196
144
|
|
@@ -69,52 +69,66 @@ describe FakeNameGenerator do
|
|
69
69
|
|
70
70
|
#end
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
72
|
+
describe "validly initialized" do
|
73
|
+
|
74
|
+
shared_examples_for "a valid instance" do
|
75
|
+
it "should fill in the name fields" do
|
76
|
+
fake.full_name.should_not be_empty
|
77
|
+
fake.first_name.should_not be_empty
|
78
|
+
fake.middle_name.should_not be_empty
|
79
|
+
fake.last_name.should_not be_empty
|
80
|
+
fake.maiden_name.should_not be_empty
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should fill in the address fields" do
|
84
|
+
fake.street1.should_not be_empty
|
85
|
+
fake.street2.should_not be_empty
|
86
|
+
fake.city.should_not be_empty
|
87
|
+
fake.state.should_not be_empty
|
88
|
+
fake.zip.should_not be_empty
|
89
|
+
fake.country_code.should_not be_empty
|
90
|
+
fake.phone_number.should_not be_empty
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should fill in the credit card fields" do
|
94
|
+
fake.cc_type.should_not be_empty
|
95
|
+
fake.cc_number.should_not be_empty
|
96
|
+
fake.cc_exp_month.should_not be_nil
|
97
|
+
fake.cc_exp_year.should_not be_nil
|
98
|
+
fake.cc_cvv.should_not be_empty
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should fill in the other random values" do
|
102
|
+
fake.gender_name.should_not be_empty
|
103
|
+
fake.birthday.should_not be_empty
|
104
|
+
fake.occupation.should_not be_empty
|
105
|
+
fake.password.should_not be_empty
|
106
|
+
fake.domain.should_not be_empty
|
107
|
+
fake.national_id.should_not be_empty
|
108
|
+
fake.national_id_type.should_not be_empty
|
109
|
+
fake.blood_type.should_not be_empty
|
110
|
+
fake.weight_kilograms.should_not be_nil
|
111
|
+
fake.weight_pounds.should_not be_nil
|
112
|
+
fake.height_centimeters.should_not be_nil
|
113
|
+
fake.height_inches.should_not be_nil
|
114
|
+
fake.ups_tracking_number.should_not be_empty
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should provide its data in JSON form when converted to_json" do
|
118
|
+
fake.to_json.should == fake.data.to_json
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "from the web" do
|
123
|
+
it_should_behave_like "a valid instance" do
|
124
|
+
let(:fake) { FakeNameGenerator.new(:api_key => 'VALID_API_KEY') }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "using JSON data" do
|
129
|
+
it_should_behave_like "a valid instance" do
|
130
|
+
let(:fake) { FakeNameGenerator.new(:json_data => valid_api_body) }
|
131
|
+
end
|
118
132
|
end
|
119
133
|
|
120
134
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,12 +7,20 @@ require 'fakeweb'
|
|
7
7
|
|
8
8
|
require 'fake_name_generator'
|
9
9
|
|
10
|
-
|
10
|
+
FIXTURES = File.dirname(File.expand_path(__FILE__)) + "/fixtures"
|
11
|
+
|
12
|
+
def valid_api_body
|
13
|
+
File.read("#{FIXTURES}/VALID_API_KEY.json")
|
14
|
+
end
|
15
|
+
|
16
|
+
def invalid_api_body
|
17
|
+
File.read("#{FIXTURES}/INVALID_API_KEY.xml")
|
18
|
+
end
|
11
19
|
|
12
20
|
FakeWeb.allow_net_connect = false
|
13
21
|
|
14
|
-
FakeWeb.register_uri(:get, %r[http://svc\.webservius\.com/v1/CorbanWork/fakename\?(.*&|)wsvKey=VALID_API_KEY]i, :body =>
|
15
|
-
FakeWeb.register_uri(:get, %r[http://svc\.webservius\.com/v1/CorbanWork/fakename\?(.*&|)wsvKey=INVALID_API_KEY]i, :body =>
|
22
|
+
FakeWeb.register_uri(:get, %r[http://svc\.webservius\.com/v1/CorbanWork/fakename\?(.*&|)wsvKey=VALID_API_KEY]i, :body => valid_api_body, :content_type => 'text/json', :status => ['200', 'OK'])
|
23
|
+
FakeWeb.register_uri(:get, %r[http://svc\.webservius\.com/v1/CorbanWork/fakename\?(.*&|)wsvKey=INVALID_API_KEY]i, :body => invalid_api_body, :content_type => 'application/xml', :status => ["403", "Forbidden"])
|
16
24
|
|
17
25
|
RSpec.configure do |config|
|
18
26
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: fake_name_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Bill Turner
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-06-22 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
requirements: []
|
105
105
|
|
106
106
|
rubyforge_project: fake_name_generator
|
107
|
-
rubygems_version: 1.
|
107
|
+
rubygems_version: 1.6.2
|
108
108
|
signing_key:
|
109
109
|
specification_version: 3
|
110
110
|
summary: A simple Ruby wrapper to the FakeNameGenerator.com API
|