numverify 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 95a8e6ad4810a2cc64032f65558d0f47fe98c3f8
4
+ data.tar.gz: a093132bcc6db581d0ab39d90359e1b4c57afc80
5
+ SHA512:
6
+ metadata.gz: 96e19ffdb17c71d866b6203ca3f7e02fea5ec81c3e9ec734a15a48eca66648d88e0efcdb61cb9849c0f954d4ade67697eaa406fbf00ecadc380d61ac965c1416
7
+ data.tar.gz: 7c2dc61c55487c1373f008a586fb5f8165bf77366d3fd403afcdcb6e9428b660220af76c288378c941f8faacc73e06996d88bd9b27e1a9994496a2b201cd3696
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,15 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+
4
+ Metrics/MethodLength:
5
+ Max: 20
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - 'spec/**/*'
10
+
11
+ Style/Documentation:
12
+ Exclude:
13
+ - 'spec/**/*'
14
+ - 'test/**/*'
15
+ - 'lib/**/*'
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in numverify.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Olivier Buffon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Numverify
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/numverify`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'numverify'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install numverify
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/numverify.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'numverify'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/numverify.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'excon'
2
+ require 'json'
3
+ require 'numverify/version'
4
+ require 'numverify/request'
5
+
6
+ module NumverifyClient
7
+ class << self
8
+ def validate(number:, country_code: nil, access_key: ENV['NUMVERIFY_ACCESS_KEY'])
9
+ request(build_query(number, country_code, access_key)).perform(method: :get)
10
+ end
11
+
12
+ private
13
+
14
+ def build_query(number, country_code, access_key)
15
+ {
16
+ number: number,
17
+ country_code: country_code,
18
+ access_key: access_key
19
+ }
20
+ end
21
+
22
+ def request(query)
23
+ NumverifyClient::Request.new(query)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ module NumverifyClient
2
+ class APIError < NumverifyClientError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module NumverifyClient
2
+ class HttpsAccessRestrictionError < NumverifyClientError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module NumverifyClient
2
+ class InactiveUserError < NumverifyClientError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module NumverifyClient
2
+ class InvalidAccessKeyError < NumverifyClientError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module NumverifyClient
2
+ class InvalidApiFunctionError < NumverifyClientError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module NumverifyClient
2
+ class InvalidCountryCodeError < NumverifyClientError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module NumverifyClient
2
+ class NoPhoneNumberError < NumverifyClientError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module NumverifyClient
2
+ class NonNumericPhoneNumberError < NumverifyClientError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module NumverifyClient
2
+ class NotFoundError < NumverifyClientError
3
+ end
4
+ end
@@ -0,0 +1,13 @@
1
+ module NumverifyClient
2
+ class NumverifyClientError < StandardError
3
+ attr_reader :message
4
+
5
+ def initialize(message)
6
+ @message = message
7
+ end
8
+
9
+ def to_s
10
+ message
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module NumverifyClient
2
+ class UsageLimitError < NumverifyClientError
3
+ end
4
+ end
@@ -0,0 +1,63 @@
1
+ require 'numverify/errors/numverify_client_error'
2
+ require 'numverify/errors/api_error'
3
+ require 'numverify/errors/https_access_restriction_error'
4
+ require 'numverify/errors/inactive_user_error'
5
+ require 'numverify/errors/invalid_access_key_error'
6
+ require 'numverify/errors/invalid_api_function_error'
7
+ require 'numverify/errors/invalid_country_code_error'
8
+ require 'numverify/errors/no_phone_number_error'
9
+ require 'numverify/errors/non_numeric_phone_number_error'
10
+ require 'numverify/errors/not_found_error'
11
+ require 'numverify/errors/usage_limit_error'
12
+ require 'numverify/result'
13
+ require 'uri'
14
+
15
+ module NumverifyClient
16
+ class Request
17
+ def initialize(query = {})
18
+ @base_uri = 'http://apilayer.net'
19
+ @query = query
20
+ @path = '/api/validate'
21
+ @connection = Excon.new(@base_uri)
22
+ end
23
+
24
+ attr_reader :connection, :path, :query
25
+
26
+ def perform(**args)
27
+ response = connection.request(args.merge(path: path, query: query))
28
+ parsed_response = JSON.parse(response.body)
29
+ if parsed_response.key?('error')
30
+ handle_error(parsed_response['error'])
31
+ else
32
+ NumverifyClient::Result.new(parsed_response)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def handle_error(error)
39
+ case error['code']
40
+ when 404
41
+ raise NotFoundError, error['info']
42
+ when 101
43
+ raise InvalidAccessKeyError, error['info']
44
+ when 103
45
+ raise InvalidApiFunctionError, error['info']
46
+ when 210
47
+ raise NoPhoneNumberError, error['info']
48
+ when 211
49
+ raise NonNumericPhoneNumberError, error['info']
50
+ when 310
51
+ raise InvalidCountryCodeError, error['info']
52
+ when 104
53
+ raise UsageLimitError, error['info']
54
+ when 105
55
+ raise HttpsAccessRestrictionError, error['info']
56
+ when 102
57
+ raise InactiveUserError, error['info']
58
+ else
59
+ raise APIError, error['info']
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,27 @@
1
+ module NumverifyClient
2
+ class Result
3
+ def initialize(data = {})
4
+ convert_to_obj(data)
5
+ end
6
+
7
+ def attributes
8
+ instance_variables.each_with_object({}) do |instance_variable, h|
9
+ h[instance_variable[1..instance_variable.length]] = instance_variable_get(instance_variable)
10
+ end
11
+ end
12
+
13
+ def to_json
14
+ attributes.to_json
15
+ end
16
+
17
+ private
18
+
19
+ def convert_to_obj(h)
20
+ h.each do |key, value|
21
+ self.class.send(:attr_accessor, key)
22
+ instance_variable_set("@#{key}", value)
23
+ convert_to_obj(value) if value.is_a? Hash
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module NumverifyClient
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/numverify.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'numverify/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'numverify'
9
+ spec.version = NumverifyClient::VERSION
10
+ spec.authors = ['Olivier Buffon']
11
+ spec.email = ['olivier@chronogolf.ca']
12
+
13
+ spec.summary = 'API Client for Numverify services'
14
+ spec.description = 'Numverify: Global Phone Number Validation & Lookup JSON API'
15
+ spec.homepage = 'https://github.com/chronogolf/numverify'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency('excon', '~> 0.45.4')
26
+ spec.add_dependency('json', '~> 1.8.3')
27
+
28
+ spec.add_development_dependency('rake')
29
+ spec.add_development_dependency('rspec')
30
+ spec.add_development_dependency('pry')
31
+ spec.add_development_dependency('rubocop')
32
+ spec.add_development_dependency('bundler-audit')
33
+ spec.add_development_dependency('rspec_junit_formatter')
34
+ spec.add_development_dependency('webmock')
35
+ spec.add_development_dependency('vcr')
36
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: numverify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Olivier Buffon
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: excon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.45.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.45.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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: rspec
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: pry
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: rubocop
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: bundler-audit
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: rspec_junit_formatter
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
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
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
+ description: 'Numverify: Global Phone Number Validation & Lookup JSON API'
154
+ email:
155
+ - olivier@chronogolf.ca
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".rubocop.yml"
163
+ - ".travis.yml"
164
+ - Gemfile
165
+ - LICENSE.txt
166
+ - README.md
167
+ - Rakefile
168
+ - bin/console
169
+ - bin/setup
170
+ - lib/numverify.rb
171
+ - lib/numverify/errors/api_error.rb
172
+ - lib/numverify/errors/https_access_restriction_error.rb
173
+ - lib/numverify/errors/inactive_user_error.rb
174
+ - lib/numverify/errors/invalid_access_key_error.rb
175
+ - lib/numverify/errors/invalid_api_function_error.rb
176
+ - lib/numverify/errors/invalid_country_code_error.rb
177
+ - lib/numverify/errors/no_phone_number_error.rb
178
+ - lib/numverify/errors/non_numeric_phone_number_error.rb
179
+ - lib/numverify/errors/not_found_error.rb
180
+ - lib/numverify/errors/numverify_client_error.rb
181
+ - lib/numverify/errors/usage_limit_error.rb
182
+ - lib/numverify/request.rb
183
+ - lib/numverify/result.rb
184
+ - lib/numverify/version.rb
185
+ - numverify.gemspec
186
+ homepage: https://github.com/chronogolf/numverify
187
+ licenses:
188
+ - MIT
189
+ metadata: {}
190
+ post_install_message:
191
+ rdoc_options: []
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ requirements: []
205
+ rubyforge_project:
206
+ rubygems_version: 2.4.6
207
+ signing_key:
208
+ specification_version: 4
209
+ summary: API Client for Numverify services
210
+ test_files: []