trestle-data 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/trestle-data/api/reverse_phone.rb +20 -0
- data/lib/trestle-data/api/util.rb +43 -0
- data/lib/trestle-data/client.rb +16 -0
- data/lib/trestle-data/configurable.rb +25 -0
- data/lib/trestle-data.rb +10 -0
- data/spec/api/phone_intelligence_spec.rb +6 -0
- data/spec/api/reverse_phone_spec.rb +6 -0
- data/spec/api/util_spec.rb +6 -0
- data/spec/spec_helper.rb +26 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3099fc2b02b613024f9d089b1721e72d9c7e3e04a6448f8d6c5d594e81462636
|
4
|
+
data.tar.gz: bc5cc090f2b2c8b05af4a74bee0619769d670729b4f02ca3d57d1c6e37a6f5f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c48d0821da3e0f1c29c7e6a375ea34d3af16ba9ea7cce896a7ecfe72931dc36317959002d1508dd7092ccdf6d2992e06487a2e417ccd3923eb53d6fd3c70ba31
|
7
|
+
data.tar.gz: 9bb4ffafd68bc5540dd41b6d96bd4c40b891135b6aa4c798c43b4d4e7e941aa35ea2e24f854fa31846a131a1ab03a15d186e190d54be609d029e8ded538ab310
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'trestle-data/api/util'
|
2
|
+
|
3
|
+
module TrestleData
|
4
|
+
module API
|
5
|
+
module ReversePhone
|
6
|
+
include TrestleData::API::Util
|
7
|
+
|
8
|
+
API_VERSION = '3.0'
|
9
|
+
|
10
|
+
def reverse_lookup(phone_number, options = {})
|
11
|
+
call('phone', API_VERSION, :get, {phone: phone_number, api_key: api_key}.merge(options))
|
12
|
+
end
|
13
|
+
|
14
|
+
def api_key_valid?
|
15
|
+
true unless api_key.blank?
|
16
|
+
false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module TrestleData
|
5
|
+
module API
|
6
|
+
module Util
|
7
|
+
|
8
|
+
include TrestleData::Configurable
|
9
|
+
|
10
|
+
ROOT_URL = 'https://api.trestleiq.com'
|
11
|
+
|
12
|
+
def call(path, api_version = "3.0", type = :get, params = {})
|
13
|
+
|
14
|
+
uri = URI.parse(build_url(path, api_version))
|
15
|
+
uri.query = URI.encode_www_form(params)
|
16
|
+
|
17
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
18
|
+
|
19
|
+
http.use_ssl = true if uri.scheme.upcase == "HTTPS"
|
20
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if uri.scheme.upcase == "HTTPS"
|
21
|
+
|
22
|
+
case type
|
23
|
+
when :get
|
24
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
25
|
+
when :post
|
26
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
27
|
+
end
|
28
|
+
|
29
|
+
response = http.request(request)
|
30
|
+
JSON.parse(response.body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_url(path, api_version)
|
34
|
+
"#{ File.join(ROOT_URL, api_version, path) }"
|
35
|
+
end
|
36
|
+
|
37
|
+
def phone_number_valid?(phone_number)
|
38
|
+
return true
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'trestle-data/api/util'
|
2
|
+
require 'trestle-data/api/reverse_phone'
|
3
|
+
|
4
|
+
module TrestleData
|
5
|
+
|
6
|
+
class Client
|
7
|
+
include TrestleData::Configurable
|
8
|
+
include TrestleData::API::ReversePhone
|
9
|
+
|
10
|
+
def initialize(options={})
|
11
|
+
TrestleData::Configurable.keys.each do |key|
|
12
|
+
instance_variable_set(:"@#{key}", options[key] || TrestleData.instance_variable_get(:"@#{key}"))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
module TrestleData
|
3
|
+
module Configurable
|
4
|
+
|
5
|
+
attr_writer :api_key
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def keys
|
9
|
+
@keys ||= [
|
10
|
+
:api_key
|
11
|
+
]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield self
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def api_key
|
22
|
+
@api_key
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/trestle-data.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
require 'simplecov'
|
3
|
+
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter {|sf| sf.filename !~ /\/lib\//}
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'trestle-data'
|
9
|
+
|
10
|
+
# Require the debugger, if present.
|
11
|
+
begin
|
12
|
+
require 'debugger'
|
13
|
+
rescue LoadError
|
14
|
+
module Kernel
|
15
|
+
def debugger(*args, &block)
|
16
|
+
STDERR.puts "*** Debugger not available."
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
class TestAPIKeys
|
23
|
+
def TestAPIKeys.get_reverse_phone_key
|
24
|
+
YAML.load_file('api_keys.yml')["reverse_phone_key"]
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trestle-data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan De Jong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This gem is for interacting with the Trestle API
|
14
|
+
email: ''
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/trestle-data.rb
|
20
|
+
- lib/trestle-data/api/reverse_phone.rb
|
21
|
+
- lib/trestle-data/api/util.rb
|
22
|
+
- lib/trestle-data/client.rb
|
23
|
+
- lib/trestle-data/configurable.rb
|
24
|
+
- spec/api/phone_intelligence_spec.rb
|
25
|
+
- spec/api/reverse_phone_spec.rb
|
26
|
+
- spec/api/util_spec.rb
|
27
|
+
- spec/spec_helper.rb
|
28
|
+
homepage: http://rubygems.org/gems/trestle-data
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubygems_version: 3.0.9
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: Trestle Data
|
51
|
+
test_files: []
|