genderize_io_rb 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +28 -0
- data/VERSION +1 -1
- data/genderize_io_rb.gemspec +77 -0
- data/include/database_schema.rb +17 -0
- data/lib/genderize_io_rb.rb +36 -6
- data/spec/genderize_io_rb_spec.rb +31 -0
- metadata +36 -2
data/Gemfile
CHANGED
@@ -6,6 +6,7 @@ source "http://rubygems.org"
|
|
6
6
|
gem "http2"
|
7
7
|
gem "json"
|
8
8
|
gem "string-cases"
|
9
|
+
gem "baza", "0.0.12"
|
9
10
|
|
10
11
|
# Add dependencies to develop your gem here.
|
11
12
|
# Include everything needed to run rake, tests, features, etc.
|
@@ -14,4 +15,5 @@ group :development do
|
|
14
15
|
gem "rdoc", "~> 3.12"
|
15
16
|
gem "bundler", ">= 1.0.0"
|
16
17
|
gem "jeweler", :git => "https://github.com/technicalpickles/jeweler.git"
|
18
|
+
gem "sqlite3"
|
17
19
|
end
|
data/Gemfile.lock
CHANGED
@@ -16,7 +16,15 @@ GEM
|
|
16
16
|
remote: http://rubygems.org/
|
17
17
|
specs:
|
18
18
|
addressable (2.3.5)
|
19
|
+
array_enumerator (0.0.3)
|
20
|
+
baza (0.0.12)
|
21
|
+
array_enumerator
|
22
|
+
datet
|
23
|
+
knjrbfw
|
24
|
+
string-cases
|
25
|
+
wref
|
19
26
|
builder (3.2.2)
|
27
|
+
datet (0.0.25)
|
20
28
|
diff-lcs (1.1.3)
|
21
29
|
faraday (0.8.8)
|
22
30
|
multipart-post (~> 1.2.0)
|
@@ -35,6 +43,13 @@ GEM
|
|
35
43
|
json (1.8.0)
|
36
44
|
jwt (0.1.8)
|
37
45
|
multi_json (>= 1.5)
|
46
|
+
knjrbfw (0.0.107)
|
47
|
+
datet
|
48
|
+
http2
|
49
|
+
php4r
|
50
|
+
ruby_process
|
51
|
+
tsafe
|
52
|
+
wref
|
38
53
|
multi_json (1.7.9)
|
39
54
|
multi_xml (0.5.5)
|
40
55
|
multipart-post (1.2.0)
|
@@ -46,6 +61,10 @@ GEM
|
|
46
61
|
multi_json (~> 1.0)
|
47
62
|
multi_xml (~> 0.5)
|
48
63
|
rack (~> 1.2)
|
64
|
+
php4r (0.0.4)
|
65
|
+
datet
|
66
|
+
http2
|
67
|
+
string-strtr
|
49
68
|
rack (1.5.2)
|
50
69
|
rake (10.1.0)
|
51
70
|
rdoc (3.12.2)
|
@@ -58,16 +77,25 @@ GEM
|
|
58
77
|
rspec-expectations (2.8.0)
|
59
78
|
diff-lcs (~> 1.1.2)
|
60
79
|
rspec-mocks (2.8.0)
|
80
|
+
ruby_process (0.0.8)
|
81
|
+
tsafe
|
82
|
+
wref
|
83
|
+
sqlite3 (1.3.8)
|
61
84
|
string-cases (0.0.0)
|
85
|
+
string-strtr (0.0.3)
|
86
|
+
tsafe (0.0.11)
|
87
|
+
wref (0.0.6)
|
62
88
|
|
63
89
|
PLATFORMS
|
64
90
|
ruby
|
65
91
|
|
66
92
|
DEPENDENCIES
|
93
|
+
baza (= 0.0.12)
|
67
94
|
bundler (>= 1.0.0)
|
68
95
|
http2
|
69
96
|
jeweler!
|
70
97
|
json
|
71
98
|
rdoc (~> 3.12)
|
72
99
|
rspec (~> 2.8.0)
|
100
|
+
sqlite3
|
73
101
|
string-cases
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "genderize_io_rb"
|
8
|
+
s.version = "0.0.5"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kasper Johansen"]
|
12
|
+
s.date = "2013-09-06"
|
13
|
+
s.description = "A small Gem that makes it possible to determine gender from a name via the Genderize.io service."
|
14
|
+
s.email = "kaspernj@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"genderize_io_rb.gemspec",
|
29
|
+
"include/database_schema.rb",
|
30
|
+
"include/result.rb",
|
31
|
+
"lib/genderize_io_rb.rb",
|
32
|
+
"spec/genderize_io_rb_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/kaspernj/genderize_io_rb"
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = "1.8.23"
|
39
|
+
s.summary = "A small Gem that makes it possible to determine gender from a name via the Genderize.io service."
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<http2>, [">= 0"])
|
46
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
47
|
+
s.add_runtime_dependency(%q<string-cases>, [">= 0"])
|
48
|
+
s.add_runtime_dependency(%q<baza>, ["= 0.0.12"])
|
49
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
50
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
51
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<http2>, [">= 0"])
|
56
|
+
s.add_dependency(%q<json>, [">= 0"])
|
57
|
+
s.add_dependency(%q<string-cases>, [">= 0"])
|
58
|
+
s.add_dependency(%q<baza>, ["= 0.0.12"])
|
59
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
60
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
61
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
63
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<http2>, [">= 0"])
|
67
|
+
s.add_dependency(%q<json>, [">= 0"])
|
68
|
+
s.add_dependency(%q<string-cases>, [">= 0"])
|
69
|
+
s.add_dependency(%q<baza>, ["= 0.0.12"])
|
70
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
71
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
72
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
73
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
74
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class GenderizeIoRb::DatabaseSchema
|
2
|
+
SCHEMA = {
|
3
|
+
:tables => {
|
4
|
+
:genderize_io_rb_cache => {
|
5
|
+
:columns => [
|
6
|
+
{:name => :id, :type => :int, :autoincr => true, :primarykey => true},
|
7
|
+
{:name => :name, :type => :varchar},
|
8
|
+
{:name => :result, :type => :text},
|
9
|
+
{:name => :created_at, :type => :datetime}
|
10
|
+
],
|
11
|
+
:indexes => [
|
12
|
+
{:name => :name, :columns => [:name], :unique => true}
|
13
|
+
]
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
data/lib/genderize_io_rb.rb
CHANGED
@@ -4,6 +4,8 @@ require "json" unless ::Kernel.const_defined?(:JSON)
|
|
4
4
|
require "string-cases" unless ::Kernel.const_defined?(:StringCases)
|
5
5
|
|
6
6
|
class GenderizeIoRb
|
7
|
+
attr_reader :cache_db
|
8
|
+
|
7
9
|
def self.const_missing(name)
|
8
10
|
require_relative "../include/#{::StringCases.camel_to_snake(name)}"
|
9
11
|
raise LoadError, "Still not defined: '#{name}'." unless ::GenderizeIoRb.const_defined?(name)
|
@@ -12,19 +14,47 @@ class GenderizeIoRb
|
|
12
14
|
|
13
15
|
def initialize(args = {})
|
14
16
|
@args = args
|
17
|
+
@http = Http2.new(:host => "api.genderize.io")
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
# Make sure the database-version is up-to-date.
|
20
|
+
@cache_db = args[:cache_db]
|
21
|
+
if @cache_db
|
22
|
+
Baza::Revision.new.init_db(:db => @cache_db, :schema => GenderizeIoRb::DatabaseSchema::SCHEMA)
|
23
|
+
end
|
19
24
|
end
|
20
25
|
|
21
26
|
def info_for_name(name)
|
22
|
-
|
27
|
+
name = name.to_s.strip
|
28
|
+
name_lc = name.downcase
|
29
|
+
|
30
|
+
# If a database-cache is enabled, try to look result up there first.
|
31
|
+
if @cache_db
|
32
|
+
res = @cache_db.single(:genderize_io_rb_cache, {:name => name_lc})
|
33
|
+
if res
|
34
|
+
return ::GenderizeIoRb::Result.new(
|
35
|
+
:data => JSON.parse(res[:result]),
|
36
|
+
:genderize_io_rb => self
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
23
40
|
|
24
|
-
|
25
|
-
|
41
|
+
http_res = @http.get("?name=#{CGI.escape(name)}")
|
42
|
+
|
43
|
+
res = ::GenderizeIoRb::Result.new(
|
44
|
+
:data => JSON.parse(http_res.body),
|
26
45
|
:genderize_io_rb => self
|
27
46
|
)
|
47
|
+
|
48
|
+
# Save result to the database cache.
|
49
|
+
if @cache_db
|
50
|
+
@cache_db.insert(:genderize_io_rb_cache, {
|
51
|
+
:name => name_lc,
|
52
|
+
:result => http_res.body,
|
53
|
+
:created_at => Time.now
|
54
|
+
}) unless @cache_db.single(:genderize_io_rb_cache, {:name => name_lc})
|
55
|
+
end
|
56
|
+
|
57
|
+
return res
|
28
58
|
end
|
29
59
|
|
30
60
|
def destroy
|
@@ -14,4 +14,35 @@ describe "GenderizeIoRb" do
|
|
14
14
|
|
15
15
|
gir.destroy
|
16
16
|
end
|
17
|
+
|
18
|
+
it "can use a db cache" do
|
19
|
+
require "baza"
|
20
|
+
require "tmpdir"
|
21
|
+
require "sqlite3"
|
22
|
+
|
23
|
+
db = Baza::Db.new(
|
24
|
+
:type => "sqlite3",
|
25
|
+
:path => "#{Dir.tmpdir}/genderize_io_rb_spec_#{Time.now.to_f.to_s}.sqlite3",
|
26
|
+
:debug => false
|
27
|
+
)
|
28
|
+
|
29
|
+
gir = GenderizeIoRb.new(:cache_db => db)
|
30
|
+
|
31
|
+
res = gir.info_for_name("kasper")
|
32
|
+
res.name.should eql("kasper")
|
33
|
+
|
34
|
+
res = gir.cache_db.select(:genderize_io_rb_cache, {"name" => "kasper"})
|
35
|
+
|
36
|
+
count = 0
|
37
|
+
res.each do |data|
|
38
|
+
data[:name].should eql("kasper")
|
39
|
+
count += 1
|
40
|
+
end
|
41
|
+
|
42
|
+
count.should > 0
|
43
|
+
|
44
|
+
expect {
|
45
|
+
gir.cache_db.insert(:genderize_io_rb_cache, :name => "kasper")
|
46
|
+
}.to raise_error
|
47
|
+
end
|
17
48
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: genderize_io_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kasper Johansen
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.12
|
69
|
+
name: baza
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - '='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.0.12
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
version_requirements: !ruby/object:Gem::Requirement
|
64
80
|
none: false
|
@@ -123,6 +139,22 @@ dependencies:
|
|
123
139
|
- - ! '>='
|
124
140
|
- !ruby/object:Gem::Version
|
125
141
|
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
version_requirements: !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ! '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
name: sqlite3
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
requirement: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
126
158
|
description: A small Gem that makes it possible to determine gender from a name via
|
127
159
|
the Genderize.io service.
|
128
160
|
email: kaspernj@gmail.com
|
@@ -140,6 +172,8 @@ files:
|
|
140
172
|
- README.rdoc
|
141
173
|
- Rakefile
|
142
174
|
- VERSION
|
175
|
+
- genderize_io_rb.gemspec
|
176
|
+
- include/database_schema.rb
|
143
177
|
- include/result.rb
|
144
178
|
- lib/genderize_io_rb.rb
|
145
179
|
- spec/genderize_io_rb_spec.rb
|
@@ -158,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
192
|
- !ruby/object:Gem::Version
|
159
193
|
segments:
|
160
194
|
- 0
|
161
|
-
hash:
|
195
|
+
hash: 2060623465687608994
|
162
196
|
version: '0'
|
163
197
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
198
|
none: false
|