numverify 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -3
- data/lib/numverify.rb +14 -2
- data/lib/numverify/configuration.rb +10 -0
- data/lib/numverify/request.rb +6 -2
- data/lib/numverify/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c914ba8df5e118ce114d415cc8de3238d16f9740
|
4
|
+
data.tar.gz: d16fa6514e2eb8a6e8a6c25f3e11129cfd379f49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1aa0a4372c4954710a1b966c58a1b9d5977af267ee0d16bcdbf1508bf6d1b8fb5fdfcd2f5ece352d68f80041bfb3c8b85f496669cbb9301652ccda135c4a9a36
|
7
|
+
data.tar.gz: 4d721dcff846b8981d225f6d48b65fc5dd4de0765ee04317a47bf936d4d17936aca0d6df1701098c7d28ec478d492bd216bb5fb28dd6b1e88f91bbfcdcf0a9f1
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![CircleCI](https://circleci.com/gh/chronogolf/numverify/tree/master.svg?style=shield&circle-token=a035ff061b42aa7812b0db6e744f2168a2f6eb13)](https://circleci.com/gh/chronogolf/numverify/tree/master) [![Code Climate](https://codeclimate.com/github/chronogolf/numverify/badges/gpa.svg)](https://codeclimate.com/github/chronogolf/numverify) [![Gem Version](https://badge.fury.io/rb/numverify.svg)](https://badge.fury.io/rb/numverify)
|
2
|
+
|
1
3
|
# Numverify API Client
|
2
4
|
|
3
5
|
This gem is a non-official Ruby Client for Numverify API service.
|
@@ -20,18 +22,29 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
## Usage
|
22
24
|
|
23
|
-
####
|
25
|
+
#### Requirements
|
24
26
|
|
25
27
|
In order to use the client with your Numverify account I'll need to specify you `ACCESS_KEY`
|
26
|
-
This can be done
|
28
|
+
This can be done through an initializer like:
|
27
29
|
```ruby
|
28
|
-
NumverifyClient.
|
30
|
+
NumverifyClient.configure do |config|
|
31
|
+
config.access_key = NUMVERIFY_ACCESS_KEY
|
32
|
+
end
|
29
33
|
```
|
30
34
|
Or more permanently by using the environment variable
|
31
35
|
```ruby
|
32
36
|
ENV['NUMVERIFY_ACCESS_KEY']
|
33
37
|
```
|
34
38
|
|
39
|
+
_*Optional*_: You can also choose to use the service through `https`:
|
40
|
+
```ruby
|
41
|
+
NumverifyClient.configure do |config|
|
42
|
+
...
|
43
|
+
config.https = true
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
|
35
48
|
#### Number Validation:
|
36
49
|
|
37
50
|
To validate a phone number just use the `validate` method like:
|
data/lib/numverify.rb
CHANGED
@@ -1,16 +1,28 @@
|
|
1
1
|
require 'excon'
|
2
2
|
require 'json'
|
3
3
|
require 'numverify/version'
|
4
|
+
require 'numverify/configuration'
|
4
5
|
require 'numverify/request'
|
5
6
|
|
6
7
|
module NumverifyClient
|
7
8
|
class << self
|
8
|
-
|
9
|
+
attr_accessor :configuration
|
10
|
+
|
11
|
+
def configure
|
12
|
+
self.configuration ||= Configuration.new
|
13
|
+
yield configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate(number:, country_code: nil)
|
9
17
|
request(build_query(number, country_code, access_key)).perform(method: :get)
|
10
18
|
end
|
11
19
|
|
12
20
|
private
|
13
21
|
|
22
|
+
def access_key
|
23
|
+
configuration.access_key || ENV['NUMVERIFY_ACCESS_KEY']
|
24
|
+
end
|
25
|
+
|
14
26
|
def build_query(number, country_code, access_key)
|
15
27
|
{
|
16
28
|
number: number,
|
@@ -20,7 +32,7 @@ module NumverifyClient
|
|
20
32
|
end
|
21
33
|
|
22
34
|
def request(query)
|
23
|
-
NumverifyClient::Request.new(query)
|
35
|
+
NumverifyClient::Request.new(query: query, https: configuration.https)
|
24
36
|
end
|
25
37
|
end
|
26
38
|
end
|
data/lib/numverify/request.rb
CHANGED
@@ -14,8 +14,8 @@ require 'uri'
|
|
14
14
|
|
15
15
|
module NumverifyClient
|
16
16
|
class Request
|
17
|
-
def initialize(query
|
18
|
-
@base_uri =
|
17
|
+
def initialize(query: {}, https: false)
|
18
|
+
@base_uri = "#{protocol(https)}://apilayer.net"
|
19
19
|
@query = query
|
20
20
|
@path = '/api/validate'
|
21
21
|
@connection = Excon.new(@base_uri)
|
@@ -35,6 +35,10 @@ module NumverifyClient
|
|
35
35
|
|
36
36
|
private
|
37
37
|
|
38
|
+
def protocol(use_https)
|
39
|
+
use_https ? 'https' : 'http'
|
40
|
+
end
|
41
|
+
|
38
42
|
def handle_error(error)
|
39
43
|
case error['code']
|
40
44
|
when 404
|
data/lib/numverify/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numverify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olivier Buffon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- bin/console
|
169
169
|
- bin/setup
|
170
170
|
- lib/numverify.rb
|
171
|
+
- lib/numverify/configuration.rb
|
171
172
|
- lib/numverify/errors/api_error.rb
|
172
173
|
- lib/numverify/errors/https_access_restriction_error.rb
|
173
174
|
- lib/numverify/errors/inactive_user_error.rb
|