prolenea 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b033eef5b018688e6f6db15fa6f31a4ad2bca7b
4
+ data.tar.gz: 98d60848c9065075acbe086c97e4496f3049ac4e
5
+ SHA512:
6
+ metadata.gz: f78d1bf61a29c579dd43b1225a90fc0c4a75136eb2ce0c9543edbb9514192cbbebc9d50fe3ded1afa7fb378654e576a5b2598ebdc71c598644b71f2ef6367e41
7
+ data.tar.gz: 1e30bc25f72bab38bb6a81bce0e05b7c4d27b771c061837af2c79b6e3e41c2957fcbb333074614894041da6955efa0fa3e6d99af19ba915cc6da405e787885e7
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /*.gem
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in prolenea.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Keith Larrimore
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 ADDED
@@ -0,0 +1 @@
1
+
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Prolenea
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ $ gem install prolenea
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ### CLI Usage
12
+
13
+ ```bash
14
+ $ prolenea-client -u http://prolenea.example.com -n 12125551000
15
+ ```
16
+
17
+ ### Ruby Usage
18
+
19
+ ```ruby
20
+ require 'prolenea'
21
+
22
+ options = {}
23
+ options[:uri] = 'http://prolenea.example.com'
24
+ number = '12125551000'
25
+
26
+ Prolenea.connect options
27
+
28
+ result = Prolenea.lookup_number number
29
+
30
+ puts JSON.pretty_generate result
31
+ ```
32
+
33
+ ### Output
34
+
35
+ ```javascript
36
+ {
37
+ "number": "2125551000",
38
+ "local_routing_number": null,
39
+ "ported_date": null,
40
+ "alternative_spid": null,
41
+ "alternative_spid_name": null,
42
+ "line_type": null,
43
+ "operating_company_number": "MULT",
44
+ "operating_company_name": "MULTIPLE OCN LISTING",
45
+ "lata": "99999",
46
+ "city": "CUSTOMER DIRECTORY ASSISTANCE",
47
+ "state": "NY"
48
+ }
49
+ ```
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
54
+
55
+ 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).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/klarrimore/prolenea.
60
+
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
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
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'optparse'
5
+ require 'pry'
6
+ require 'prolenea'
7
+
8
+ include Prolenea
9
+
10
+ options, config = {}, {}
11
+
12
+ OptionParser.new do |opts|
13
+ opts.on("-u", "--uri URI", String, "Prolenea URI") do |uri|
14
+ options[:uri] = uri
15
+ end
16
+
17
+ opts.on("-n", "--number Number", String, "Number to lookup") do |number|
18
+ options[:number] = number
19
+ end
20
+ end.parse!
21
+
22
+ begin
23
+ config[:uri] = options[:uri]
24
+ number = options[:number]
25
+
26
+ Prolenea.connect config
27
+
28
+ result = Prolenea.lookup_number number
29
+
30
+ puts JSON.pretty_generate result
31
+ rescue ProleneaError => pe
32
+ STDERR.puts pe.message
33
+ STDERR.puts pe.backtrace.join("\n")
34
+ end
data/lib/prolenea.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'prolenea/version'
4
+ require 'prolenea/errors'
5
+ require 'prolenea/connection'
6
+ require 'prolenea/middleware/prolenea_response_middleware'
7
+
8
+ module Prolenea
9
+ include Error
10
+
11
+ module ClassMethods
12
+
13
+ def connection
14
+ @connection ? @connection : (raise StandardError)
15
+ end
16
+
17
+ def connect(config = {})
18
+ @connection = Connection.new(:uri => config[:uri])
19
+ end
20
+
21
+ def lookup_number(number)
22
+ params = {:dial => number}
23
+
24
+ response = self.connection.get '/', params
25
+
26
+ response.env[:parsed_body]
27
+ rescue ProleneaError => pe
28
+ raise ProleneaLookupError.new({:parent_error => pe}), pe.message
29
+ rescue StandardError => se
30
+ raise ProleneaLookupError.new({:parent_error => se}), se.message
31
+ end
32
+
33
+ end
34
+
35
+ extend ClassMethods
36
+
37
+ Faraday::Response.register_middleware :prolenea_response => lambda { ProleneaResponseMiddleware }
38
+ end
@@ -0,0 +1,74 @@
1
+ module Prolenea
2
+ class Connection
3
+
4
+ USER_AGENT = "prolenea-client v#{Prolenea::VERSION}"
5
+
6
+ attr_accessor :options, :faraday
7
+
8
+ def initialize(options = {})
9
+ uri = options.delete :uri
10
+ @options = options
11
+ @faraday = self.create_faraday(uri, @options)
12
+ end
13
+
14
+ def create_faraday(uri, options = {})
15
+ @faraday = Faraday.new uri, options do |c|
16
+ c.headers['User-Agent'] = USER_AGENT
17
+
18
+ c.request :multipart
19
+ c.request :url_encoded
20
+
21
+ c.response :prolenea_response
22
+
23
+ c.adapter Faraday.default_adapter
24
+ end
25
+ end
26
+
27
+ def request(method, path, params, options, &callback)
28
+ sent_at = nil
29
+
30
+ response = @faraday.send(method) { |request|
31
+ sent_at = Time.now
32
+ request = config_request(request, method, path, params, options)
33
+ }.on_complete { |env|
34
+ env[:total_time] = Time.now.utc.to_f - sent_at.utc.to_f if sent_at
35
+ env[:request_params] = params
36
+ env[:request_options] = options
37
+ callback.call(env) if callback
38
+ }
39
+
40
+ response
41
+ rescue Faraday::Error => fe
42
+ raise ProleneaRequestError.new({:parent_error => fe}), fe.message
43
+ end
44
+
45
+ def config_request(request, method, path, params, options)
46
+ case method.to_sym
47
+ when :delete, :get
48
+ request.url(path, params)
49
+ when :post, :put
50
+ request.path = path
51
+ request.body = params unless params.empty?
52
+ end
53
+
54
+ request
55
+ end
56
+
57
+ def get(path, params={}, options={}, &callback)
58
+ request(:get, path, params, options, &callback)
59
+ end
60
+
61
+ def delete(path, params={}, options={}, &callback)
62
+ request(:delete, path, params, options, &callback)
63
+ end
64
+
65
+ def post(path, params={}, options={}, &callback)
66
+ request(:post, path, params, options, &callback)
67
+ end
68
+
69
+ def put(path, params={}, options={}, &callback)
70
+ request(:put, path, params, options, &callback)
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,18 @@
1
+ module Prolenea
2
+ module Error
3
+ class ProleneaError < StandardError #:nodoc:
4
+ attr_accessor :options
5
+
6
+ def initialize(message, options = {})
7
+ @options = options
8
+ super message
9
+ end
10
+ end
11
+
12
+ class ProleneaRequestError < ProleneaError #:nodoc:
13
+ end
14
+
15
+ class ProleneaLookupError < ProleneaError #:nodoc:
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,45 @@
1
+ module Prolenea
2
+ class ProleneaResponseMiddleware < Faraday::Response::Middleware
3
+
4
+ RESPONSE_ROW_NAMES = %w(
5
+ number
6
+ local_routing_number
7
+ ported_date
8
+ alternative_spid
9
+ alternative_spid_name
10
+ line_type
11
+ operating_company_number
12
+ operating_company_name
13
+ lata
14
+ city
15
+ state
16
+ )
17
+
18
+ def on_complete(env)
19
+ case env[:status]
20
+ when 200
21
+ env[:parsed_body] = self.parse_body env[:body]
22
+ else
23
+ raise ProleneaRequestError.new({}), "Recieved an unexpected HTTP response code #{env[:status]}"
24
+ end
25
+
26
+ env
27
+ end
28
+
29
+ def parse_body(body)
30
+ number_info = {}
31
+ rows = body.split("\r\n")
32
+
33
+ if rows.length != RESPONSE_ROW_NAMES.length
34
+ raise ProleneaRequestError.new({}), "Unable to parse HTTP response body"
35
+ end
36
+
37
+ rows.each_with_index do |row, i|
38
+ number_info[RESPONSE_ROW_NAMES[i]] = (row == '-' ? nil : row)
39
+ end
40
+
41
+ number_info
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module Prolenea
2
+ VERSION = '0.1.3'
3
+ end
data/prolenea.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'prolenea/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'prolenea'
8
+ spec.version = Prolenea::VERSION
9
+ spec.authors = ['Keith Larrimore']
10
+ spec.email = ['keithlarrimore@gmail.com']
11
+
12
+ spec.summary = %q{IceHook System's Basic Ruby Client for Prolenea's LNP Query Service.}
13
+ spec.description = %q{Executes queries to Prolenea's LNP API and parses the results and returns a cleaner JSON response.}
14
+ spec.homepage = 'https://prolenea.com/'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'bin'
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.14'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'webmock', '~> 3.4.2'
28
+ spec.add_runtime_dependency 'faraday', '~> 0.15.2'
29
+ spec.add_runtime_dependency 'pry', '~> 0.11.3'
30
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prolenea
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Keith Larrimore
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.4.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.4.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.15.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.15.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.11.3
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.11.3
97
+ description: Executes queries to Prolenea's LNP API and parses the results and returns
98
+ a cleaner JSON response.
99
+ email:
100
+ - keithlarrimore@gmail.com
101
+ executables:
102
+ - prolenea-client
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README
112
+ - README.md
113
+ - Rakefile
114
+ - bin/prolenea-client
115
+ - lib/prolenea.rb
116
+ - lib/prolenea/connection.rb
117
+ - lib/prolenea/errors.rb
118
+ - lib/prolenea/middleware/prolenea_response_middleware.rb
119
+ - lib/prolenea/version.rb
120
+ - prolenea.gemspec
121
+ homepage: https://prolenea.com/
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.5.2
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: IceHook System's Basic Ruby Client for Prolenea's LNP Query Service.
145
+ test_files: []
146
+ has_rdoc: