genderize_io_rb 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "genderize_io_rb"
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
12
- s.date = "2013-09-06"
12
+ s.date = "2013-09-12"
13
13
  s.description = "A small Gem that makes it possible to determine gender from a name via the Genderize.io service."
14
14
  s.email = "kaspernj@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -12,7 +12,12 @@ class GenderizeIoRb
12
12
  return ::GenderizeIoRb.const_get(name)
13
13
  end
14
14
 
15
+ INITIALIZE_VALID_ARGS = [:cache_as, :cache_db]
15
16
  def initialize(args = {})
17
+ args.each do |key, val|
18
+ raise "Invalid key: '#{key}'." unless INITIALIZE_VALID_ARGS.include?(key)
19
+ end
20
+
16
21
  @args = args
17
22
  @http = Http2.new(:host => "api.genderize.io")
18
23
 
@@ -21,6 +26,8 @@ class GenderizeIoRb
21
26
  if @cache_db
22
27
  Baza::Revision.new.init_db(:db => @cache_db, :schema => GenderizeIoRb::DatabaseSchema::SCHEMA)
23
28
  end
29
+
30
+ @cache_as = args[:cache_as]
24
31
  end
25
32
 
26
33
  def info_for_name(name)
@@ -29,35 +36,54 @@ class GenderizeIoRb
29
36
 
30
37
  # If a database-cache is enabled, try to look result up there first.
31
38
  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]),
39
+ cache_db_res = @cache_db.single(:genderize_io_rb_cache, {:name => name_lc})
40
+ if cache_db_res
41
+ res = ::GenderizeIoRb::Result.new(
42
+ :data => JSON.parse(cache_db_res[:result]),
36
43
  :genderize_io_rb => self
37
44
  )
38
45
  end
39
46
  end
40
47
 
41
- http_res = @http.get("?name=#{CGI.escape(name)}")
42
- json_res = JSON.parse(http_res.body)
43
-
44
- raise GenderizeIoRb::Errors::NameNotFound, "Name was not found on Genderize.io: '#{name}'." unless json_res["gender"]
48
+ cache_as_key = "genderize_io_rb_#{name_lc}"
49
+ if @cache_as
50
+ cache_as_res = @cache_as.read(cache_as_key)
51
+ puts "CacheAsRes: #{cache_as_res}"
52
+
53
+ if cache_as_res
54
+ res = ::GenderizeIoRb::Result.new(
55
+ :data => JSON.parse(cache_as_res),
56
+ :genderize_io_rb => self
57
+ )
58
+ end
59
+ end
45
60
 
46
- res = ::GenderizeIoRb::Result.new(
47
- :data => json_res,
48
- :genderize_io_rb => self
49
- )
61
+ unless res
62
+ http_res = @http.get("?name=#{CGI.escape(name)}")
63
+ json_res = JSON.parse(http_res.body)
64
+
65
+ raise GenderizeIoRb::Errors::NameNotFound, "Name was not found on Genderize.io: '#{name}'." unless json_res["gender"]
66
+
67
+ res = ::GenderizeIoRb::Result.new(
68
+ :data => json_res,
69
+ :genderize_io_rb => self
70
+ )
71
+ end
50
72
 
51
73
  # Save result to the database cache.
52
- if @cache_db
74
+ if @cache_db && !cache_db_res
53
75
  @cache_db.insert(:genderize_io_rb_cache, {
54
76
  :name => name_lc,
55
77
  :result => http_res.body,
56
78
  :created_at => Time.now
57
- }) unless @cache_db.single(:genderize_io_rb_cache, {:name => name_lc})
79
+ })
80
+ end
81
+
82
+ if @cache_as && !cache_as_res
83
+ @cache_as.write(cache_as_key, http_res.body)
58
84
  end
59
85
 
60
- return res
86
+ return {:result => res, :cache_db => @cache_db_res, :cache_as => cache_as_res}
61
87
  end
62
88
 
63
89
  def destroy
metadata CHANGED
@@ -2,159 +2,159 @@
2
2
  name: genderize_io_rb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.7
5
+ version: 0.0.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-06 00:00:00.000000000 Z
12
+ date: 2013-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
+ prerelease: false
16
+ name: http2
17
+ type: :runtime
15
18
  version_requirements: !ruby/object:Gem::Requirement
16
- none: false
17
19
  requirements:
18
20
  - - ! '>='
19
21
  - !ruby/object:Gem::Version
20
22
  version: '0'
21
- name: http2
22
- type: :runtime
23
- prerelease: false
24
- requirement: !ruby/object:Gem::Requirement
25
23
  none: false
24
+ requirement: !ruby/object:Gem::Requirement
26
25
  requirements:
27
26
  - - ! '>='
28
27
  - !ruby/object:Gem::Version
29
28
  version: '0'
29
+ none: false
30
30
  - !ruby/object:Gem::Dependency
31
+ prerelease: false
32
+ name: json
33
+ type: :runtime
31
34
  version_requirements: !ruby/object:Gem::Requirement
32
- none: false
33
35
  requirements:
34
36
  - - ! '>='
35
37
  - !ruby/object:Gem::Version
36
38
  version: '0'
37
- name: json
38
- type: :runtime
39
- prerelease: false
40
- requirement: !ruby/object:Gem::Requirement
41
39
  none: false
40
+ requirement: !ruby/object:Gem::Requirement
42
41
  requirements:
43
42
  - - ! '>='
44
43
  - !ruby/object:Gem::Version
45
44
  version: '0'
45
+ none: false
46
46
  - !ruby/object:Gem::Dependency
47
+ prerelease: false
48
+ name: string-cases
49
+ type: :runtime
47
50
  version_requirements: !ruby/object:Gem::Requirement
48
- none: false
49
51
  requirements:
50
52
  - - ! '>='
51
53
  - !ruby/object:Gem::Version
52
54
  version: '0'
53
- name: string-cases
54
- type: :runtime
55
- prerelease: false
56
- requirement: !ruby/object:Gem::Requirement
57
55
  none: false
56
+ requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ! '>='
60
59
  - !ruby/object:Gem::Version
61
60
  version: '0'
61
+ none: false
62
62
  - !ruby/object:Gem::Dependency
63
+ prerelease: false
64
+ name: rspec
65
+ type: :development
63
66
  version_requirements: !ruby/object:Gem::Requirement
64
- none: false
65
67
  requirements:
66
68
  - - ~>
67
69
  - !ruby/object:Gem::Version
68
70
  version: 2.8.0
69
- name: rspec
70
- type: :development
71
- prerelease: false
72
- requirement: !ruby/object:Gem::Requirement
73
71
  none: false
72
+ requirement: !ruby/object:Gem::Requirement
74
73
  requirements:
75
74
  - - ~>
76
75
  - !ruby/object:Gem::Version
77
76
  version: 2.8.0
77
+ none: false
78
78
  - !ruby/object:Gem::Dependency
79
+ prerelease: false
80
+ name: rdoc
81
+ type: :development
79
82
  version_requirements: !ruby/object:Gem::Requirement
80
- none: false
81
83
  requirements:
82
84
  - - ~>
83
85
  - !ruby/object:Gem::Version
84
86
  version: '3.12'
85
- name: rdoc
86
- type: :development
87
- prerelease: false
88
- requirement: !ruby/object:Gem::Requirement
89
87
  none: false
88
+ requirement: !ruby/object:Gem::Requirement
90
89
  requirements:
91
90
  - - ~>
92
91
  - !ruby/object:Gem::Version
93
92
  version: '3.12'
93
+ none: false
94
94
  - !ruby/object:Gem::Dependency
95
+ prerelease: false
96
+ name: bundler
97
+ type: :development
95
98
  version_requirements: !ruby/object:Gem::Requirement
96
- none: false
97
99
  requirements:
98
100
  - - ! '>='
99
101
  - !ruby/object:Gem::Version
100
102
  version: 1.0.0
101
- name: bundler
102
- type: :development
103
- prerelease: false
104
- requirement: !ruby/object:Gem::Requirement
105
103
  none: false
104
+ requirement: !ruby/object:Gem::Requirement
106
105
  requirements:
107
106
  - - ! '>='
108
107
  - !ruby/object:Gem::Version
109
108
  version: 1.0.0
109
+ none: false
110
110
  - !ruby/object:Gem::Dependency
111
+ prerelease: false
112
+ name: jeweler
113
+ type: :development
111
114
  version_requirements: !ruby/object:Gem::Requirement
112
- none: false
113
115
  requirements:
114
116
  - - ! '>='
115
117
  - !ruby/object:Gem::Version
116
118
  version: '0'
117
- name: jeweler
118
- type: :development
119
- prerelease: false
120
- requirement: !ruby/object:Gem::Requirement
121
119
  none: false
120
+ requirement: !ruby/object:Gem::Requirement
122
121
  requirements:
123
122
  - - ! '>='
124
123
  - !ruby/object:Gem::Version
125
124
  version: '0'
125
+ none: false
126
126
  - !ruby/object:Gem::Dependency
127
+ prerelease: false
128
+ name: sqlite3
129
+ type: :development
127
130
  version_requirements: !ruby/object:Gem::Requirement
128
- none: false
129
131
  requirements:
130
132
  - - ! '>='
131
133
  - !ruby/object:Gem::Version
132
134
  version: '0'
133
- name: sqlite3
134
- type: :development
135
- prerelease: false
136
- requirement: !ruby/object:Gem::Requirement
137
135
  none: false
136
+ requirement: !ruby/object:Gem::Requirement
138
137
  requirements:
139
138
  - - ! '>='
140
139
  - !ruby/object:Gem::Version
141
140
  version: '0'
141
+ none: false
142
142
  - !ruby/object:Gem::Dependency
143
+ prerelease: false
144
+ name: baza
145
+ type: :development
143
146
  version_requirements: !ruby/object:Gem::Requirement
144
- none: false
145
147
  requirements:
146
148
  - - '='
147
149
  - !ruby/object:Gem::Version
148
150
  version: 0.0.12
149
- name: baza
150
- type: :development
151
- prerelease: false
152
- requirement: !ruby/object:Gem::Requirement
153
151
  none: false
152
+ requirement: !ruby/object:Gem::Requirement
154
153
  requirements:
155
154
  - - '='
156
155
  - !ruby/object:Gem::Version
157
156
  version: 0.0.12
157
+ none: false
158
158
  description: A small Gem that makes it possible to determine gender from a name via
159
159
  the Genderize.io service.
160
160
  email: kaspernj@gmail.com
@@ -187,20 +187,20 @@ rdoc_options: []
187
187
  require_paths:
188
188
  - lib
189
189
  required_ruby_version: !ruby/object:Gem::Requirement
190
- none: false
191
190
  requirements:
192
191
  - - ! '>='
193
192
  - !ruby/object:Gem::Version
194
193
  segments:
195
194
  - 0
196
- hash: -505520613497781920
195
+ hash: -1771412768099350443
197
196
  version: '0'
198
- required_rubygems_version: !ruby/object:Gem::Requirement
199
197
  none: false
198
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
199
  requirements:
201
200
  - - ! '>='
202
201
  - !ruby/object:Gem::Version
203
202
  version: '0'
203
+ none: false
204
204
  requirements: []
205
205
  rubyforge_project:
206
206
  rubygems_version: 1.8.23