genderize-io 0.1.0 → 1.2.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
  SHA256:
3
- metadata.gz: 6be289a2888af4bf3942e5cd4a876343c45c0f8d23f9a9291e9d510cbcb24a8e
4
- data.tar.gz: 64d7cc82232bfdcc6508f01f7810b0bd343e8cf3a88b4ce7f6b54d414ad081cd
3
+ metadata.gz: b0bfa131c7e48eac55e7da3fbf184540049514a3a9fc5970f26d2a9ab175f51c
4
+ data.tar.gz: 989d8c9470a4dfc4a8120b1d3f382228b10d0da50eaa7cbd03c9d9fb571920a2
5
5
  SHA512:
6
- metadata.gz: c2ae2db8659c0c856d235cf80a11f34defed927dfcf0a0aeea941244bc3125ed75033427aac005d66ba622245027d760fd64a358f8cdef38c77210a663e9c32a
7
- data.tar.gz: 0b77aaa2ed9df12fb37efbefa30eacf12ba7a1264ae16789a4cda9cb08ae80ee66be726bff8e7b9c9b5b2c6328a887894b48e0c09e27b0d0337823e115f5e307
6
+ metadata.gz: a671f5c4202a3cf3fc8f98f0ce8416f71b3998622bba16db0bff2b38666275163c39a46ff584a7c9485b3bbf6e0f3e7ab2e7c9b94cdd8758cc75bb20907dcdf8
7
+ data.tar.gz: '086e6e570cb4b80b6d3f64834faabaea63967a9c1d68f73c1debc70d862db896392dc4af815db463d3ec955250ff78a17944b2a2f9d934efcda99fe69869fd99'
@@ -1,19 +1,19 @@
1
1
  speedups:
2
- rescue_vs_respond_to: true
3
- module_eval: true
4
- shuffle_first_vs_sample: true
5
- for_loop_vs_each: true
2
+ block_vs_symbol_to_proc: true
6
3
  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
4
  fetch_with_argument_vs_block: true
12
- keys_each_vs_each_key: true
5
+ for_loop_vs_each: true
6
+ getter_vs_attr_reader: true
7
+ gsub_vs_tr: true
13
8
  hash_merge_bang_vs_hash_brackets: true
14
- block_vs_symbol_to_proc: true
9
+ keys_each_vs_each_key: true
10
+ map_flatten_vs_flat_map: true
11
+ module_eval: true
15
12
  proc_call_vs_yield: true
16
- gsub_vs_tr: true
13
+ rescue_vs_respond_to: true
14
+ reverse_each_vs_reverse_each: true
15
+ select_first_vs_detect: true
17
16
  select_last_vs_reverse_detect: true
18
- getter_vs_attr_reader: true
19
17
  setter_vs_attr_writer: true
18
+ shuffle_first_vs_sample: true
19
+ sort_vs_sort_by: true
data/.gitignore CHANGED
@@ -1,9 +1,11 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
7
6
  /pkg/
8
7
  /spec/reports/
9
8
  /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
@@ -1,24 +1,37 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
1
4
  AllCops:
5
+ TargetRubyVersion: 2.7
6
+ NewCops: enable
2
7
  DisplayCopNames: true
3
8
  DisplayStyleGuide: true
4
- TargetRubyVersion: 2.4
9
+ Layout/EmptyLinesAroundAttributeAccessor:
10
+ Enabled: true
11
+ Layout/EmptyLinesAroundBlockBody:
5
12
  Exclude:
6
13
  - 'spec/**/**/*'
7
- Gemspec/OrderedDependencies:
8
- Enabled: false
9
14
  Layout/EmptyLinesAroundClassBody:
10
- Enabled: false
15
+ EnforcedStyle: empty_lines_except_namespace
11
16
  Layout/EmptyLinesAroundModuleBody:
12
- Enabled: false
13
- LineLength:
17
+ EnforcedStyle: empty_lines_except_namespace
18
+ Layout/LineLength:
14
19
  Max: 100
15
- Lint/ScriptPermission:
16
- Enabled: false
17
- Style/Documentation:
20
+ Layout/SpaceAroundMethodCallOperator:
21
+ Enabled: true
22
+ Lint/RaiseException:
23
+ Enabled: true
24
+ Lint/StructNewOverride:
25
+ Enabled: true
26
+ Metrics/BlockLength:
27
+ Exclude:
28
+ - 'spec/**/**/*'
29
+ - '*.gemspec'
30
+ RSpec/ExampleLength:
18
31
  Enabled: false
19
- Style/MethodMissing:
32
+ RSpec/MultipleExpectations:
20
33
  Enabled: false
21
- Style/PerlBackrefs:
34
+ Style/Documentation:
22
35
  Enabled: false
23
- Style/RegexpLiteral:
36
+ Style/ExpandPathArguments:
24
37
  Enabled: false
@@ -1,13 +1,25 @@
1
- before_install:
2
- - sudo apt-get install libxml2-dev
3
- cache: bundler
1
+ sudo: false
4
2
  language: ruby
5
- notifications:
6
- email:
7
- recipients:
8
- - j.gomez@drexed.com
9
- on_failure: change
10
- on_success: never
3
+ cache: bundler
11
4
  rvm:
12
- - ruby-head
13
- script: 'bundle exec rake'
5
+ - 2.5
6
+ - 2.6
7
+ - 2.7
8
+ - ruby-head
9
+ matrix:
10
+ fast_finish: true
11
+ allow_failures:
12
+ - rvm: ruby-head
13
+ before_install:
14
+ - gem update --system
15
+ - gem install bundler
16
+ install:
17
+ - bundle install --jobs=3 --retry=3
18
+ script:
19
+ - bundle exec rspec
20
+ - bundle exec rubocop
21
+ - bundle exec fasterer
22
+ notifications:
23
+ email: false
24
+ slack:
25
+ secure: bhsBY6XgILtpi5jt/WI4c95BuBTcXindABygXhmPGWNxn/pmbM/kzssvA+P9p29PWW3sgOSPDh8Ofkxv//8Fft4prM2duh8WLxHzroBDeEgl6I9ZTOmE2cx8gjcoyHk0UpBO90xhoqaKFLQNJ5q0Ajd4UIE+tPQlArXlNIrMbNRNfBTc1UYBX9C644RXPWLXmdyHgpc7gAvVakH+tKUA1PH8Xi1+PBSKHL4DGiGLj0kjuH/ik7HP5U4XnKfxnmmwSMDf04yLMHp5C9EpAvvRAsaH53DDQuU6LUdcZnGhhqYOebWY1QhAWCwSf52dZpySCysYwGk8dvhsD/2TFVc/8QwPiBueO+i9/J55OUR9z+BPLZ1VJYQK49kJUretM9H2h21YmbyjeiDtPF8mULXKEelWIrARFKa6ywYzSSxXu2Td3afGVigh5dd1X9B5aF2o2Z9ZbMynAyuzUa5YcwyuHM2YDb//RnV2hZPSOi0KpehG497o8oRcECADAu9HYgYPQGv/kujYsSZtH6VScDFL27vXH/F5P3cs2XirNM4pTF/1eOs3lhRGxn42e2vpYt0ODw+KyztfsGi/cN00TZgsL2b/d9BWZK3FUgFBkoqTBaSs2xtjSZ2MzElQBzg/HCVFL8LAdqWL5MFhZ7s4R0E71onOCZEcojmlEKF1e5zCIrI=
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [1.2.1] - 2020-07-03
10
+ ### Added
11
+ - Added Ruby 2.7 support
12
+
13
+ ## [1.2.0] - 2019-11-17
14
+ ### Added
15
+ - Added CHANGELOG.md
16
+ ### Changed
17
+ - Swap `user_agent_db` for `agents` gem
18
+ - Refactor code to clean up lint errors
19
+
20
+ ## [1.1.0] - 2019-11-17
21
+ ### NOTE
22
+ - Previous version without CHANGELOG.md
@@ -1,13 +1,74 @@
1
- # Contributor Code of Conduct
1
+ # Contributor Covenant Code of Conduct
2
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.
3
+ ## Our Pledge
4
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.
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
6
11
 
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.
12
+ ## Our Standards
8
13
 
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.
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
10
16
 
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.
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
12
22
 
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/)
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at j.gomez@drexed.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- # Specify your gem's dependencies in trumail.gemspec
5
+ # Specify your gem's dependencies in genderize-io.gemspec
6
6
  gemspec
@@ -0,0 +1,92 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ genderize-io (1.2.1)
5
+ agents
6
+ typhoeus
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ agents (0.1.4)
14
+ ast (2.4.1)
15
+ colorize (0.8.1)
16
+ crack (0.4.3)
17
+ safe_yaml (~> 1.0.0)
18
+ diff-lcs (1.4.4)
19
+ ethon (0.12.0)
20
+ ffi (>= 1.3.0)
21
+ fasterer (0.8.3)
22
+ colorize (~> 0.7)
23
+ ruby_parser (>= 3.14.1)
24
+ ffi (1.13.1)
25
+ hashdiff (1.0.1)
26
+ parallel (1.19.2)
27
+ parser (2.7.1.4)
28
+ ast (~> 2.4.1)
29
+ public_suffix (4.0.5)
30
+ rainbow (3.0.0)
31
+ rake (13.0.1)
32
+ regexp_parser (1.7.1)
33
+ rexml (3.2.4)
34
+ rspec (3.9.0)
35
+ rspec-core (~> 3.9.0)
36
+ rspec-expectations (~> 3.9.0)
37
+ rspec-mocks (~> 3.9.0)
38
+ rspec-core (3.9.2)
39
+ rspec-support (~> 3.9.3)
40
+ rspec-expectations (3.9.2)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.9.0)
43
+ rspec-mocks (3.9.1)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.9.0)
46
+ rspec-support (3.9.3)
47
+ rubocop (0.86.0)
48
+ parallel (~> 1.10)
49
+ parser (>= 2.7.0.1)
50
+ rainbow (>= 2.2.2, < 4.0)
51
+ regexp_parser (>= 1.7)
52
+ rexml
53
+ rubocop-ast (>= 0.0.3, < 1.0)
54
+ ruby-progressbar (~> 1.7)
55
+ unicode-display_width (>= 1.4.0, < 2.0)
56
+ rubocop-ast (0.1.0)
57
+ parser (>= 2.7.0.1)
58
+ rubocop-performance (1.6.1)
59
+ rubocop (>= 0.71.0)
60
+ rubocop-rspec (1.41.0)
61
+ rubocop (>= 0.68.1)
62
+ ruby-progressbar (1.10.1)
63
+ ruby_parser (3.14.2)
64
+ sexp_processor (~> 4.9)
65
+ safe_yaml (1.0.5)
66
+ sexp_processor (4.15.0)
67
+ typhoeus (1.4.0)
68
+ ethon (>= 0.9.0)
69
+ unicode-display_width (1.7.0)
70
+ vcr (6.0.0)
71
+ webmock (3.8.3)
72
+ addressable (>= 2.3.6)
73
+ crack (>= 0.3.2)
74
+ hashdiff (>= 0.4.0, < 2.0.0)
75
+
76
+ PLATFORMS
77
+ ruby
78
+
79
+ DEPENDENCIES
80
+ bundler
81
+ fasterer
82
+ genderize-io!
83
+ rake
84
+ rspec
85
+ rubocop
86
+ rubocop-performance
87
+ rubocop-rspec
88
+ vcr
89
+ webmock
90
+
91
+ BUNDLED WITH
92
+ 2.1.4
data/README.md CHANGED
@@ -3,7 +3,8 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/genderize-io.svg)](http://badge.fury.io/rb/genderize-io)
4
4
  [![Build Status](https://travis-ci.org/drexed/genderize-io.svg?branch=master)](https://travis-ci.org/drexed/genderize-io)
5
5
 
6
- API wrapper for the free [Genderize.io](https://genderize.io) gender determination system.
6
+ API wrapper for the [Genderize.io](https://genderize.io) first name gender determination system.
7
+ *Be aware that the free API has a limit of 1000 determinations per day.*
7
8
 
8
9
  ## Installation
9
10
 
@@ -22,22 +23,30 @@ Or install it yourself as:
22
23
  $ gem install genderize-io
23
24
 
24
25
  ## Usage
26
+
27
+ ### Simple Lookup
28
+
25
29
  ```ruby
26
30
  # 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')
31
+ lookup = Genderize::Io::Lookup.new('kim').determine
32
+ lookup = Genderize::Io::Lookup.determine('kim')
33
+
34
+ # Custom Options
35
+ lookup = Genderize::Io::Lookup.determine(
36
+ 'kim',
37
+ host: 'https://api.genderize.io?api_key=xxx',
38
+ country_id: 'dk',
39
+ language_id: 'en'
40
+ )
41
+ ```
33
42
 
34
- # Custom IDs
35
- lookup = Genderize::Io::Lookup.new('kim', country_id: 'dk').verify
36
- lookup = Genderize::Io::Lookup.verify('kim', language_id: 'en')
43
+ ### Simple Response
37
44
 
38
- # Public Methods
45
+ ```ruby
39
46
  lookup.url => 'https://api.genderize.io?name=kim'
40
- lookup.to_h => { 'name' => 'kim', 'gender' => 'female', ... }
47
+ lookup.data => { 'name' => 'kim', 'gender' => 'female', ... }
48
+
49
+ # Data Methods
41
50
  lookup.name => 'kim'
42
51
  lookup.gender => 'female'
43
52
  lookup.probability => 0.94
@@ -50,12 +59,49 @@ lookup.x_rate_reset => 13829
50
59
  lookup.error => 'sorry, my bad!'
51
60
  ```
52
61
 
62
+ ### Batch Lookup
63
+
64
+ ```ruby
65
+ # Basic Lookup
66
+ lookup = Genderize::Io::Batch::Lookup.new(['kim', 'jim']).determine
67
+ lookup = Genderize::Io::Batch::Lookup.determine(['kim', 'jim'])
68
+
69
+ # Custom Options
70
+ lookup = Genderize::Io::Batch::Lookup.determine(
71
+ ['kim', 'jim'],
72
+ host: 'https://api.genderize.io?api_key=xxx',
73
+ country_id: 'dk',
74
+ language_id: 'en'
75
+ )
76
+ ```
77
+
78
+ ### Batch Response
79
+
80
+ ```ruby
81
+ lookup.url => 'https://api.genderize.io?name[0]=kim&name[1]=jim'
82
+ lookup.data => {
83
+ 'rate_limits' => { 'x_rate_limit_limit' => 1069, ... },
84
+ 'responses' => [
85
+ { 'name' => 'kim', 'gender' => 'female', ... },
86
+ { 'name' => 'jim', 'gender' => 'male', ... }
87
+ ]
88
+ }
89
+ ```
90
+
91
+ ## Development
92
+
93
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
94
+
95
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
96
+
53
97
  ## Contributing
54
98
 
55
- Your contribution is welcome.
99
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/genderize-io. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
100
+
101
+ ## License
102
+
103
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
104
+
105
+ ## Code of Conduct
56
106
 
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
107
+ Everyone interacting in the Genderize::Io project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/genderize-io/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
4
7
 
5
8
  task default: :spec
@@ -1 +1 @@
1
- theme: jekyll-theme-cayman
1
+ theme: jekyll-theme-leap-day
@@ -8,8 +8,8 @@ require 'genderize/io'
8
8
  # with your gem easier. You can also use a different console, if you like.
9
9
 
10
10
  # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require 'pry'
11
+ # require "pry"
12
12
  # Pry.start
13
13
 
14
14
  require 'irb'
15
- IRB.start
15
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,6 +1,7 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
  IFS=$'\n\t'
4
+ set -vx
4
5
 
5
6
  bundle install
6
7
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # coding: utf-8
4
-
5
3
  lib = File.expand_path('../lib', __FILE__)
6
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
5
  require 'genderize/io/version'
@@ -12,23 +10,43 @@ Gem::Specification.new do |spec|
12
10
  spec.authors = ['Juan Gomez']
13
11
  spec.email = ['j.gomez@drexed.com']
14
12
 
15
- spec.summary = 'Genderize.io Ruby SDK.'
16
- spec.description = 'Genderize.io Ruby SDK for interacting with the Genderize.io API.'
13
+ spec.summary = 'Genderize.io Ruby SDK for interacting with the Genderize.io API.'
17
14
  spec.homepage = 'http://drexed.github.io/genderize-io'
18
15
  spec.license = 'MIT'
19
16
 
20
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata.merge(
21
+ 'allowed_push_host' => 'https://rubygems.org',
22
+ 'changelog_uri' => 'https://github.com/drexed/genderize-io/blob/master/CHANGELOG.md',
23
+ 'homepage_uri' => spec.homepage,
24
+ 'source_code_uri' => 'https://github.com/drexed/genderize-io'
25
+ )
26
+ else
27
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
28
+ 'public gem pushes.'
29
+ end
30
+
31
+ # Specify which files should be added to the gem when it is released.
32
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
33
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
34
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
35
+ end
21
36
  spec.bindir = 'exe'
22
37
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
- spec.require_paths = %w[lib support]
38
+ spec.require_paths = %w[lib]
24
39
 
40
+ spec.add_runtime_dependency 'agents'
25
41
  spec.add_runtime_dependency 'typhoeus'
26
- spec.add_runtime_dependency 'user_agent_db'
27
42
 
28
43
  spec.add_development_dependency 'bundler'
44
+ spec.add_development_dependency 'fasterer'
29
45
  spec.add_development_dependency 'rake'
30
46
  spec.add_development_dependency 'rspec'
31
- spec.add_development_dependency 'fasterer'
32
- spec.add_development_dependency 'reek'
33
47
  spec.add_development_dependency 'rubocop'
48
+ spec.add_development_dependency 'rubocop-performance'
49
+ spec.add_development_dependency 'rubocop-rspec'
50
+ spec.add_development_dependency 'vcr'
51
+ spec.add_development_dependency 'webmock'
34
52
  end
@@ -4,6 +4,7 @@
4
4
  require "genderize/io/parser/#{file_name}"
5
5
  end
6
6
 
7
- %w[version lookup].each do |file_name|
7
+ %w[version base lookup].each do |file_name|
8
8
  require "genderize/io/#{file_name}"
9
+ require "genderize/io/batch/#{file_name}" if file_name == 'lookup'
9
10
  end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'agents'
4
+ require 'typhoeus'
5
+
6
+ module Genderize
7
+ module Io
8
+ class Base
9
+
10
+ DEFAULT_HOST ||= 'https://api.genderize.io'
11
+ HEADER_KEYS ||= %w[
12
+ x_rate_limit_limit x_rate_limit_remaining x_rate_reset
13
+ ].freeze
14
+
15
+ attr_reader :country_id, :data, :host, :language_id, :name, :request
16
+
17
+ def initialize(name, host: DEFAULT_HOST, country_id: nil, language_id: nil)
18
+ @name = name
19
+ @host = host
20
+ @country_id = country_id
21
+ @language_id = language_id
22
+ @request = nil
23
+ end
24
+
25
+ def self.determine(name, host: DEFAULT_HOST, country_id: nil, language_id: nil)
26
+ klass = new(name, host: host, country_id: country_id, language_id: language_id)
27
+ klass.determine
28
+ klass
29
+ end
30
+
31
+ def url
32
+ connector = @host.include?('?') ? '&' : '?'
33
+ "#{@host}#{connector}#{param_name}#{param_country_id}#{param_language_id}"
34
+ end
35
+
36
+ private
37
+
38
+ def generate_data
39
+ return if @request.nil?
40
+
41
+ Genderize::Io::Parser::Json.parse(@request.response_body)
42
+ end
43
+
44
+ def generate_headers
45
+ return if @request.nil?
46
+
47
+ Genderize::Io::Parser::Header.parse(@request.response_headers)
48
+ end
49
+
50
+ def generate_rate_limits
51
+ headers = generate_headers
52
+ return if headers.nil?
53
+
54
+ HEADER_KEYS.each_with_object({}) { |key, hash| hash[key] = headers.send(key).to_i }
55
+ end
56
+
57
+ def generate_request
58
+ return @request unless @request.nil?
59
+
60
+ Typhoeus::Config.user_agent = Agents.random_user_agent(:desktop)
61
+ Typhoeus.get(url, accept_encoding: 'gzip,deflate')
62
+ end
63
+
64
+ def param_country_id
65
+ "&country_id=#{@country_id}" unless @country_id.nil?
66
+ end
67
+
68
+ def param_language_id
69
+ "&language_id=#{@language_id}" unless @language_id.nil?
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Genderize
4
+ module Io
5
+ module Batch
6
+ class Lookup < Genderize::Io::Base
7
+
8
+ def initialize(name, host: DEFAULT_HOST, country_id: nil, language_id: nil)
9
+ super
10
+
11
+ @data = { 'rate_limits' => {}, 'responses' => [] }
12
+ end
13
+
14
+ def determine
15
+ return @data unless @request.nil?
16
+
17
+ @request = generate_request
18
+ @data['responses'] = generate_data
19
+ @data['rate_limits'] = generate_rate_limits
20
+ end
21
+
22
+ private
23
+
24
+ def param_name
25
+ @name.map.with_index { |name, i| "name[#{i}]=#{name}" }.join('&')
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,82 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'typhoeus'
4
- require 'user_agent_db'
5
-
6
3
  module Genderize
7
4
  module Io
8
- class Lookup
5
+ class Lookup < Genderize::Io::Base
9
6
 
10
- DEFAULT_HOST ||= 'https://api.genderize.io'
11
7
  RESPONSE_KEYS ||= %w[
12
- count country_id error language_id gender probability x_rate_limit_limit
13
- x_rate_limit_remaining x_rate_reset
8
+ count country_id error language_id gender probability
14
9
  ].freeze
15
10
 
16
- attr_reader :country_id, :hash, :host, :language_id, :name, :response
17
-
18
11
  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
12
+ super
26
13
 
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
14
+ @data = {}
31
15
  end
32
16
 
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')
17
+ def determine
18
+ return @data unless @request.nil?
38
19
 
39
- generate_hash
40
- generate_rate_limits
20
+ @request = generate_request
21
+ @data = generate_data.merge(generate_rate_limits)
41
22
  end
42
23
 
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
24
+ HEADER_KEYS.each do |key|
25
+ define_method(key) { @data[key] }
50
26
  end
51
27
 
52
28
  RESPONSE_KEYS.each do |key|
53
- define_method(key) { @hash[key] }
29
+ define_method(key) { @data[key] }
54
30
  end
55
31
 
56
32
  private
57
33
 
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
34
  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?
35
+ "name=#{@name}"
80
36
  end
81
37
 
82
38
  end
@@ -23,16 +23,20 @@ module Genderize
23
23
  @headers = @response.split(/\\r\\n|\n|\r/)
24
24
  end
25
25
 
26
- def method_missing(sym, *_args)
27
- detect_multi_value_keys(sym)
26
+ def method_missing(sym, *)
27
+ detect_multi_value_keys(sym) || super
28
+ end
29
+
30
+ def respond_to_missing?(sym, *)
31
+ detect_multi_value_keys(sym) || super
28
32
  end
29
33
 
30
34
  def response_code
31
- @headers[0].match(/HTTP\/\d\.\d (\d{3}.*)/)[1]
35
+ @headers[0].match(%r{HTTP/\d\.\d (\d{3}.*)})[1]
32
36
  end
33
37
 
34
38
  def version
35
- @headers[0].match(/HTTP\/\d\.\d/)[0]
39
+ @headers[0].match(%r{HTTP/\d\.\d})[0]
36
40
  end
37
41
 
38
42
  private
@@ -50,7 +54,7 @@ module Genderize
50
54
 
51
55
  def value_from(tag)
52
56
  val = tag.split(/:\s+/)[1]
53
- val =~ /^\"(.*)\"$/ ? $1 : val
57
+ val =~ /^"(.*)"$/ ? Regexp.last_match(1) : val
54
58
  end
55
59
 
56
60
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Genderize
4
4
  module Io
5
- VERSION ||= '0.1.0'
5
+
6
+ VERSION ||= '1.2.1'
7
+
6
8
  end
7
9
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genderize-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-28 00:00:00.000000000 Z
11
+ date: 2020-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: typhoeus
14
+ name: agents
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: user_agent_db
28
+ name: typhoeus
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fasterer
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'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +95,7 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: fasterer
98
+ name: rubocop
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -95,7 +109,7 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: reek
112
+ name: rubocop-performance
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
@@ -109,7 +123,35 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: rubocop
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: vcr
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: webmock
113
155
  requirement: !ruby/object:Gem::Requirement
114
156
  requirements:
115
157
  - - ">="
@@ -122,7 +164,7 @@ dependencies:
122
164
  - - ">="
123
165
  - !ruby/object:Gem::Version
124
166
  version: '0'
125
- description: Genderize.io Ruby SDK for interacting with the Genderize.io API.
167
+ description:
126
168
  email:
127
169
  - j.gomez@drexed.com
128
170
  executables: []
@@ -131,20 +173,22 @@ extra_rdoc_files: []
131
173
  files:
132
174
  - ".fasterer.yml"
133
175
  - ".gitignore"
134
- - ".reek"
135
176
  - ".rspec"
136
177
  - ".rubocop.yml"
137
178
  - ".travis.yml"
179
+ - CHANGELOG.md
138
180
  - CODE_OF_CONDUCT.md
139
181
  - Gemfile
182
+ - Gemfile.lock
140
183
  - README.md
141
184
  - Rakefile
142
185
  - _config.yml
143
186
  - bin/console
144
- - bin/rake
145
187
  - bin/setup
146
188
  - genderize-io.gemspec
147
189
  - lib/genderize/io.rb
190
+ - lib/genderize/io/base.rb
191
+ - lib/genderize/io/batch/lookup.rb
148
192
  - lib/genderize/io/lookup.rb
149
193
  - lib/genderize/io/parser/header.rb
150
194
  - lib/genderize/io/parser/json.rb
@@ -153,11 +197,10 @@ homepage: http://drexed.github.io/genderize-io
153
197
  licenses:
154
198
  - MIT
155
199
  metadata: {}
156
- post_install_message:
200
+ post_install_message:
157
201
  rdoc_options: []
158
202
  require_paths:
159
203
  - lib
160
- - support
161
204
  required_ruby_version: !ruby/object:Gem::Requirement
162
205
  requirements:
163
206
  - - ">="
@@ -169,9 +212,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
212
  - !ruby/object:Gem::Version
170
213
  version: '0'
171
214
  requirements: []
172
- rubyforge_project:
173
- rubygems_version: 2.7.2
174
- signing_key:
215
+ rubygems_version: 3.1.4
216
+ signing_key:
175
217
  specification_version: 4
176
- summary: Genderize.io Ruby SDK.
218
+ summary: Genderize.io Ruby SDK for interacting with the Genderize.io API.
177
219
  test_files: []
data/.reek DELETED
@@ -1,23 +0,0 @@
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/bin/rake DELETED
@@ -1,15 +0,0 @@
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')