genderize-io 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6be289a2888af4bf3942e5cd4a876343c45c0f8d23f9a9291e9d510cbcb24a8e
4
+ data.tar.gz: 64d7cc82232bfdcc6508f01f7810b0bd343e8cf3a88b4ce7f6b54d414ad081cd
5
+ SHA512:
6
+ metadata.gz: c2ae2db8659c0c856d235cf80a11f34defed927dfcf0a0aeea941244bc3125ed75033427aac005d66ba622245027d760fd64a358f8cdef38c77210a663e9c32a
7
+ data.tar.gz: 0b77aaa2ed9df12fb37efbefa30eacf12ba7a1264ae16789a4cda9cb08ae80ee66be726bff8e7b9c9b5b2c6328a887894b48e0c09e27b0d0337823e115f5e307
@@ -0,0 +1,19 @@
1
+ speedups:
2
+ rescue_vs_respond_to: true
3
+ module_eval: true
4
+ shuffle_first_vs_sample: true
5
+ for_loop_vs_each: true
6
+ each_with_index_vs_while: false
7
+ map_flatten_vs_flat_map: true
8
+ reverse_each_vs_reverse_each: true
9
+ select_first_vs_detect: true
10
+ sort_vs_sort_by: true
11
+ fetch_with_argument_vs_block: true
12
+ keys_each_vs_each_key: true
13
+ hash_merge_bang_vs_hash_brackets: true
14
+ block_vs_symbol_to_proc: true
15
+ proc_call_vs_yield: true
16
+ gsub_vs_tr: true
17
+ select_last_vs_reverse_detect: true
18
+ getter_vs_attr_reader: true
19
+ setter_vs_attr_writer: true
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.reek ADDED
@@ -0,0 +1,23 @@
1
+ ---
2
+ BooleanParameter:
3
+ enabled: false
4
+ DuplicateMethodCall:
5
+ enabled: false
6
+ InstanceVariableAssumption:
7
+ enabled: false
8
+ IrresponsibleModule:
9
+ enabled: false
10
+ LongParameterList:
11
+ enabled: false
12
+ NilCheck:
13
+ enabled: false
14
+ TooManyInstanceVariables:
15
+ enabled: false
16
+ TooManyStatements:
17
+ enabled: false
18
+ UnusedParameters:
19
+ enabled: false
20
+ UncommunicativeVariableName:
21
+ enabled: false
22
+ UtilityFunction:
23
+ enabled: false
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --backtrace
2
+ --color
3
+ --format progress
4
+ --order random
@@ -0,0 +1,24 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+ TargetRubyVersion: 2.4
5
+ Exclude:
6
+ - 'spec/**/**/*'
7
+ Gemspec/OrderedDependencies:
8
+ Enabled: false
9
+ Layout/EmptyLinesAroundClassBody:
10
+ Enabled: false
11
+ Layout/EmptyLinesAroundModuleBody:
12
+ Enabled: false
13
+ LineLength:
14
+ Max: 100
15
+ Lint/ScriptPermission:
16
+ Enabled: false
17
+ Style/Documentation:
18
+ Enabled: false
19
+ Style/MethodMissing:
20
+ Enabled: false
21
+ Style/PerlBackrefs:
22
+ Enabled: false
23
+ Style/RegexpLiteral:
24
+ Enabled: false
@@ -0,0 +1,13 @@
1
+ before_install:
2
+ - sudo apt-get install libxml2-dev
3
+ cache: bundler
4
+ language: ruby
5
+ notifications:
6
+ email:
7
+ recipients:
8
+ - j.gomez@drexed.com
9
+ on_failure: change
10
+ on_success: never
11
+ rvm:
12
+ - ruby-head
13
+ script: 'bundle exec rake'
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in trumail.gemspec
6
+ gemspec
@@ -0,0 +1,61 @@
1
+ # Genderize::Io
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/genderize-io.svg)](http://badge.fury.io/rb/genderize-io)
4
+ [![Build Status](https://travis-ci.org/drexed/genderize-io.svg?branch=master)](https://travis-ci.org/drexed/genderize-io)
5
+
6
+ API wrapper for the free [Genderize.io](https://genderize.io) gender determination system.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'genderize-io'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install genderize-io
23
+
24
+ ## Usage
25
+ ```ruby
26
+ # Basic Lookup
27
+ lookup = Genderize::Io::Lookup.new('kim').verify
28
+ lookup = Genderize::Io::Lookup.verify('kim')
29
+
30
+ # Custom Host
31
+ lookup = Genderize::Io::Lookup.new('kim', host: 'https://api.genderize.io?api_key=xxx').verify
32
+ lookup = Genderize::Io::Lookup.verify('kim', host: 'https://api.genderize.io?api_key=xxx')
33
+
34
+ # Custom IDs
35
+ lookup = Genderize::Io::Lookup.new('kim', country_id: 'dk').verify
36
+ lookup = Genderize::Io::Lookup.verify('kim', language_id: 'en')
37
+
38
+ # Public Methods
39
+ lookup.url => 'https://api.genderize.io?name=kim'
40
+ lookup.to_h => { 'name' => 'kim', 'gender' => 'female', ... }
41
+ lookup.name => 'kim'
42
+ lookup.gender => 'female'
43
+ lookup.probability => 0.94
44
+ lookup.count => 1098
45
+ lookup.country_id => 'dk'
46
+ lookup.language_id => 'en'
47
+ lookup.x_rate_limit_limit => 1000
48
+ lookup.x_rate_limit_remaining => 738
49
+ lookup.x_rate_reset => 13829
50
+ lookup.error => 'sorry, my bad!'
51
+ ```
52
+
53
+ ## Contributing
54
+
55
+ Your contribution is welcome.
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ task default: :spec
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-cayman
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'genderize/io'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require 'pry'
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
11
+
12
+ require 'rubygems'
13
+ require 'bundler/setup'
14
+
15
+ load Gem.bin_path('rake', 'rake')
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # coding: utf-8
4
+
5
+ lib = File.expand_path('../lib', __FILE__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ require 'genderize/io/version'
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = 'genderize-io'
11
+ spec.version = Genderize::Io::VERSION
12
+ spec.authors = ['Juan Gomez']
13
+ spec.email = ['j.gomez@drexed.com']
14
+
15
+ spec.summary = 'Genderize.io Ruby SDK.'
16
+ spec.description = 'Genderize.io Ruby SDK for interacting with the Genderize.io API.'
17
+ spec.homepage = 'http://drexed.github.io/genderize-io'
18
+ spec.license = 'MIT'
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = %w[lib support]
24
+
25
+ spec.add_runtime_dependency 'typhoeus'
26
+ spec.add_runtime_dependency 'user_agent_db'
27
+
28
+ spec.add_development_dependency 'bundler'
29
+ spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency 'rspec'
31
+ spec.add_development_dependency 'fasterer'
32
+ spec.add_development_dependency 'reek'
33
+ spec.add_development_dependency 'rubocop'
34
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w[json header].each do |file_name|
4
+ require "genderize/io/parser/#{file_name}"
5
+ end
6
+
7
+ %w[version lookup].each do |file_name|
8
+ require "genderize/io/#{file_name}"
9
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'typhoeus'
4
+ require 'user_agent_db'
5
+
6
+ module Genderize
7
+ module Io
8
+ class Lookup
9
+
10
+ DEFAULT_HOST ||= 'https://api.genderize.io'
11
+ RESPONSE_KEYS ||= %w[
12
+ count country_id error language_id gender probability x_rate_limit_limit
13
+ x_rate_limit_remaining x_rate_reset
14
+ ].freeze
15
+
16
+ attr_reader :country_id, :hash, :host, :language_id, :name, :response
17
+
18
+ def initialize(name, host: DEFAULT_HOST, country_id: nil, language_id: nil)
19
+ @name = name
20
+ @host = host
21
+ @country_id = country_id
22
+ @language_id = language_id
23
+ @response = nil
24
+ @hash = {}
25
+ end
26
+
27
+ def self.verify(name, host: DEFAULT_HOST, country_id: nil, language_id: nil)
28
+ klass = new(name, host: host, country_id: country_id, language_id: language_id)
29
+ klass.verify
30
+ klass
31
+ end
32
+
33
+ def verify
34
+ return @hash unless @response.nil?
35
+
36
+ Typhoeus::Config.user_agent = UserAgentDB.random
37
+ @response = Typhoeus.get(url, accept_encoding: 'gzip,deflate')
38
+
39
+ generate_hash
40
+ generate_rate_limits
41
+ end
42
+
43
+ def url
44
+ connector = @host.include?('?') ? '&' : '?'
45
+ "#{@host}#{connector}#{param_name}#{param_country_id}#{param_language_id}"
46
+ end
47
+
48
+ def to_h
49
+ @hash
50
+ end
51
+
52
+ RESPONSE_KEYS.each do |key|
53
+ define_method(key) { @hash[key] }
54
+ end
55
+
56
+ private
57
+
58
+ def generate_hash
59
+ return if @response.response_body.nil?
60
+ @hash = Genderize::Io::Parser::Json.parse(@response.response_body)
61
+ end
62
+
63
+ def generate_rate_limits
64
+ return if @response.response_headers.nil?
65
+ headers = Genderize::Io::Parser::Header.parse(@response.response_headers)
66
+ RESPONSE_KEYS.last(3).each { |key| @hash[key] = headers.send(key).to_i }
67
+ end
68
+
69
+ def param_name
70
+ return "name=#{@name}" unless @name.is_a?(Array)
71
+ @name.map.with_index { |name, i| "name[#{i}]=#{name}" }.join('&')
72
+ end
73
+
74
+ def param_country_id
75
+ "&country_id=#{@country_id}" unless @country_id.nil?
76
+ end
77
+
78
+ def param_language_id
79
+ "&language_id=#{@language_id}" unless @language_id.nil?
80
+ end
81
+
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genderize
4
+ module Io
5
+ module Parser
6
+ class Header
7
+
8
+ attr_reader :headers, :response, :strict
9
+
10
+ def initialize(response, strict: true)
11
+ @response = response
12
+ @strict = strict
13
+ @headers = []
14
+ end
15
+
16
+ def self.parse(response, strict: true)
17
+ klass = new(response, strict: strict)
18
+ klass.parse
19
+ klass
20
+ end
21
+
22
+ def parse
23
+ @headers = @response.split(/\\r\\n|\n|\r/)
24
+ end
25
+
26
+ def method_missing(sym, *_args)
27
+ detect_multi_value_keys(sym)
28
+ end
29
+
30
+ def response_code
31
+ @headers[0].match(/HTTP\/\d\.\d (\d{3}.*)/)[1]
32
+ end
33
+
34
+ def version
35
+ @headers[0].match(/HTTP\/\d\.\d/)[0]
36
+ end
37
+
38
+ private
39
+
40
+ def detect_multi_value_keys(tag)
41
+ tag = method_sym_to_http_pattern(tag)
42
+ results = @headers.select { |val| val =~ /^#{tag}:/i }.map { |val| value_from(val) }
43
+ results.size <= 1 ? results.first : results
44
+ end
45
+
46
+ def method_sym_to_http_pattern(sym)
47
+ replacement = @strict ? '-' : '[-_]'
48
+ sym.to_s.gsub('_', replacement)
49
+ end
50
+
51
+ def value_from(tag)
52
+ val = tag.split(/:\s+/)[1]
53
+ val =~ /^\"(.*)\"$/ ? $1 : val
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Genderize
6
+ module Io
7
+ module Parser
8
+ class Json
9
+
10
+ attr_reader :hash
11
+
12
+ def initialize(data)
13
+ @data = data
14
+ @hash = {}
15
+ end
16
+
17
+ def self.parse(data)
18
+ klass = new(data)
19
+ klass.parse
20
+ klass.hash
21
+ end
22
+
23
+ def parse
24
+ @hash = JSON.parse(@data)
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genderize
4
+ module Io
5
+ VERSION ||= '0.1.0'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: genderize-io
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan Gomez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: user_agent_db
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: fasterer
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: reek
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Genderize.io Ruby SDK for interacting with the Genderize.io API.
126
+ email:
127
+ - j.gomez@drexed.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".fasterer.yml"
133
+ - ".gitignore"
134
+ - ".reek"
135
+ - ".rspec"
136
+ - ".rubocop.yml"
137
+ - ".travis.yml"
138
+ - CODE_OF_CONDUCT.md
139
+ - Gemfile
140
+ - README.md
141
+ - Rakefile
142
+ - _config.yml
143
+ - bin/console
144
+ - bin/rake
145
+ - bin/setup
146
+ - genderize-io.gemspec
147
+ - lib/genderize/io.rb
148
+ - lib/genderize/io/lookup.rb
149
+ - lib/genderize/io/parser/header.rb
150
+ - lib/genderize/io/parser/json.rb
151
+ - lib/genderize/io/version.rb
152
+ homepage: http://drexed.github.io/genderize-io
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ - support
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.7.2
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: Genderize.io Ruby SDK.
177
+ test_files: []