dnb-direct-ruby 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +43 -0
  9. data/Rakefile +10 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/dnb-direct.gemspec +35 -0
  13. data/lib/dnb/direct.rb +45 -0
  14. data/lib/dnb/direct/mapping.rb +3 -0
  15. data/lib/dnb/direct/model.rb +14 -0
  16. data/lib/dnb/direct/one.rb +42 -0
  17. data/lib/dnb/direct/plus.rb +59 -0
  18. data/lib/dnb/direct/plus/content.rb +29 -0
  19. data/lib/dnb/direct/plus/mappings/address.rb +26 -0
  20. data/lib/dnb/direct/plus/mappings/business_entity_type.rb +14 -0
  21. data/lib/dnb/direct/plus/mappings/duns_control_status.rb +19 -0
  22. data/lib/dnb/direct/plus/mappings/industry_code.rb +16 -0
  23. data/lib/dnb/direct/plus/mappings/organization.rb +32 -0
  24. data/lib/dnb/direct/plus/mappings/registration_number.rb +14 -0
  25. data/lib/dnb/direct/plus/mappings/telephone.rb +15 -0
  26. data/lib/dnb/direct/plus/match.rb +21 -0
  27. data/lib/dnb/direct/plus/models/address.rb +18 -0
  28. data/lib/dnb/direct/plus/models/business_entity_type.rb +6 -0
  29. data/lib/dnb/direct/plus/models/duns_control_status.rb +12 -0
  30. data/lib/dnb/direct/plus/models/industry_code.rb +9 -0
  31. data/lib/dnb/direct/plus/models/organization.rb +18 -0
  32. data/lib/dnb/direct/plus/models/registration_number.rb +7 -0
  33. data/lib/dnb/direct/plus/models/telephone.rb +7 -0
  34. data/lib/dnb/direct/plus/search.rb +20 -0
  35. data/lib/dnb/direct/ruby.rb +1 -0
  36. data/lib/dnb/direct/two.rb +44 -0
  37. data/lib/dnb/direct/version.rb +5 -0
  38. metadata +198 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cb5fbbbb28197765ad5c80d8160bad130bac6a6a
4
+ data.tar.gz: 59b04fe198401ac3b031847ff5cdb144ccdd4002
5
+ SHA512:
6
+ metadata.gz: cb4bbd71743eebae48e0310b10463aba87b12f1d67d722709e82450f89c2af91fba631ef8e55b24cb5c4c10b625da92f7384a97408f98bbe0d6e72ab85ce6237
7
+ data.tar.gz: d97e5863c2b4cfe9a7f704f881e6f0f0bfc699c58a739e23700d2a1a9d6392399eba0c4a148d42ff68756f892180472cd2f03df0fb2c22970eeb7d28ad6923d2
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1 @@
1
+ 2.3.0
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
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.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
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
22
+
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 jason@buildit.io. 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 ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dnb-direct.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jason Ihaia
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.
@@ -0,0 +1,43 @@
1
+ [![Gem Version](https://badge.fury.io/rb/dnb-direct.svg)](https://badge.fury.io/rb/dnb-direct)
2
+
3
+ # Dnb::Direct
4
+
5
+ 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/dnb/direct`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ TODO: Delete this and the text above, and describe your gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'dnb-direct'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install dnb-direct
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dnb-direct. 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.
38
+
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
43
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dnb/direct"
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
@@ -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
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dnb/direct/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dnb-direct-ruby"
8
+ spec.version = DnB::Direct::VERSION
9
+ spec.authors = ["Jason Ihaia"]
10
+ spec.email = ["ihaiaj@dnb.com"]
11
+
12
+ spec.summary = 'Write a short summary, because Rubygems requires one.'
13
+ spec.description = 'Write a longer description or delete this line.'
14
+ spec.homepage = 'https://developer.dnb.com'
15
+ spec.license = "MIT"
16
+
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 "activesupport", '> 3.0', '< 5.1'
26
+ spec.add_dependency "faraday", '~> 0.9.1'
27
+ spec.add_dependency "colored"
28
+ spec.add_dependency 'virtus', '~> 1.0.3'
29
+ spec.add_dependency 'kartograph'
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.13"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "minitest", "~> 5.0"
34
+
35
+ end
@@ -0,0 +1,45 @@
1
+ require "dnb/direct/version"
2
+ require 'active_support/all'
3
+ require 'colored'
4
+ require 'kartograph'
5
+
6
+ module DnB
7
+ module Direct
8
+
9
+ # Direct+
10
+ autoload :Plus, 'dnb/direct/plus'
11
+ autoload :Model, 'dnb/direct/model'
12
+ autoload :Mapping, 'dnb/direct/mapping'
13
+
14
+ class Plus
15
+
16
+ ## Services
17
+ autoload :Content, 'dnb/direct/plus/content'
18
+ autoload :Search, 'dnb/direct/plus/search'
19
+
20
+ ## Models
21
+ autoload :Organization, 'dnb/direct/plus/models/organization'
22
+ autoload :DunsControlStatus, 'dnb/direct/plus/models/duns_control_status'
23
+ autoload :IndustryCode, 'dnb/direct/plus/models/industry_code'
24
+ autoload :RegistrationNumber, 'dnb/direct/plus/models/registration_number'
25
+ autoload :Telephone, 'dnb/direct/plus/models/telephone'
26
+ autoload :Address, 'dnb/direct/plus/models/address'
27
+ autoload :BusinessEntityType, 'dnb/direct/plus/models/business_entity_type'
28
+
29
+ module Mappings
30
+ autoload :Organization, 'dnb/direct/plus/mappings/organization'
31
+ autoload :DunsControlStatus, 'dnb/direct/plus/mappings/duns_control_status'
32
+ autoload :IndustryCode, 'dnb/direct/plus/mappings/industry_code'
33
+ autoload :RegistrationNumber, 'dnb/direct/plus/mappings/registration_number'
34
+ autoload :Telephone, 'dnb/direct/plus/mappings/telephone'
35
+ autoload :Address, 'dnb/direct/plus/mappings/address'
36
+ autoload :BusinessEntityType, 'dnb/direct/plus/mappings/business_entity_type'
37
+ end
38
+
39
+ end
40
+
41
+ # Direct 2.0
42
+ autoload :Two, 'dnb/direct/two'
43
+
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ class DnB::Direct::Mapping
2
+ include ::Kartograph::DSL
3
+ end
@@ -0,0 +1,14 @@
1
+ require 'virtus'
2
+
3
+ module DnB::Direct
4
+ class Model
5
+ include Virtus.model
6
+ include Virtus::Equalizer.new(name || inspect)
7
+
8
+ def inspect
9
+ values = Hash[instance_variables.map { |name| [name, instance_variable_get(name)] } ]
10
+ "<#{self.class.name} #{values}>"
11
+ end # def inspect
12
+
13
+ end
14
+ end
@@ -0,0 +1,42 @@
1
+ require 'base64'
2
+ require 'faraday'
3
+
4
+ module DnB
5
+ module Direct
6
+ class One
7
+ BASE_URL = 'http://dnbdirect-api.dnb.com/DnBAPI-17/rest'.freeze
8
+ class << self
9
+ attr_accessor :api_key, :api_secret, :token, :api_base_url, :conn
10
+
11
+ def use_credentials username, password, key
12
+ @api_username = username
13
+ @api_password = password
14
+ @api_key = key
15
+ end
16
+
17
+
18
+ def connection
19
+ @conn ||= Faraday.new(connection_options) do |faraday|
20
+ faraday.request :url_encoded # form-encode POST params
21
+ faraday.response(:logger) if $LOG_DNB
22
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def connection_options
29
+ {
30
+ url: BASE_URL,
31
+ headers: {
32
+ content_type: 'application/json',
33
+ username: @api_username,
34
+ password: @api_password,
35
+ "API-KEY": @api_key
36
+ }
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,59 @@
1
+ require 'base64'
2
+ require 'faraday'
3
+
4
+ module DnB
5
+ module Direct
6
+ class Plus
7
+ BASE_URL = 'https://plus.dnb.com'.freeze
8
+ class << self
9
+ attr_accessor :api_key, :api_secret, :token, :api_base_url, :conn
10
+
11
+ # Constructs the authorization key by encoding {{api_key}}:{{api_secret}}
12
+ # to a base64 encoded string. Both required attributes must be set prior
13
+ # to generating the key.
14
+ def api_auth
15
+ raise ArgumentError, 'api_key is missing' if api_key.blank?
16
+ raise ArgumentError, 'api_secret is missing' if api_secret.blank?
17
+ Base64.strict_encode64(api_key + ':' + api_secret)
18
+ end # def api_auth
19
+
20
+ def use_credentials key, secret
21
+ @api_key = key
22
+ @api_secret = secret
23
+ end
24
+
25
+ # Fetches the token from the authorization service.
26
+ def api_token
27
+ if @token.nil?
28
+ response = connection.post do |req|
29
+ req.url '/v2/token'
30
+ req.headers[:authorization] = "Basic #{api_auth}"
31
+ req.body = '{ "grant_type" : "client_credentials" }'
32
+ end
33
+ @token = JSON.parse(response.body)['access_token']
34
+ end
35
+ token
36
+ end # def api_token
37
+
38
+ def connection
39
+ @conn ||= Faraday.new(connection_options) do |faraday|
40
+ faraday.request :url_encoded # form-encode POST params
41
+ faraday.response(:logger) if $LOG_DNB
42
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def connection_options
49
+ {
50
+ url: BASE_URL,
51
+ headers: {
52
+ content_type: 'application/json'
53
+ }
54
+ }
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,29 @@
1
+ class DnB::Direct::Plus::Content
2
+
3
+ # This service is the most efficient way to gain basic marketing information
4
+ # about an existing customer or potential prospect such as business name,
5
+ # address, D&B® D-U-N-S® Number, phone and trade style. Includes business
6
+ # intelligence such as senior executive name, activities, sales, number of
7
+ # employees and owners.
8
+ def self.profile_with_linkage(params = {})
9
+ start = Time.now
10
+ puts "== Started profile_with_linkage at #{start}" if $LOG_DNB
11
+ response = DnB::Direct::Plus.connection.get do |req|
12
+ req.url "/v1/data/duns/#{params[:duns]}?productId=cmplnk&versionId=v1"
13
+ req.headers[:authorization] = "Bearer #{DnB::Direct::Plus.api_token}"
14
+ end
15
+ puts "== Completed in #{Time.now - start}s"
16
+ DnB::Direct::Plus::Mappings::Organization.extract_single(response.body, :read)
17
+ end # def self.profile_with_linkage
18
+
19
+
20
+ def self.plus_executives(params = {})
21
+ response = DnB::Direct::Plus.connection.get do |req|
22
+ req.url "/v1/data/duns/#{params[:duns]}?productId=cmpelk&versionId=v1"
23
+ req.headers[:authorization] = "Bearer #{DnB::Direct::Plus.api_token}"
24
+ end
25
+
26
+ JSON.parse(response.body)
27
+ end # def self.plus_executives
28
+
29
+ end # class
@@ -0,0 +1,26 @@
1
+ class DnB::Direct::Plus::Mappings::Address < DnB::Direct::Mapping
2
+
3
+ kartograph do
4
+ mapping DnB::Direct::Plus::Address
5
+
6
+ scoped :read do
7
+ property :postalCode
8
+ property :streetNumber
9
+ property :streetName
10
+ property :isRegisteredAddress
11
+ property :minorTownName
12
+
13
+ property :language
14
+ property :addressCountry
15
+ property :continentalRegion
16
+ property :addressLocality
17
+ property :addressRegion
18
+ property :addressCounty
19
+ property :streetAddress
20
+ property :postOfficeBox
21
+ end # scoped :read
22
+
23
+
24
+ end # kartograph
25
+
26
+ end # class
@@ -0,0 +1,14 @@
1
+ class DnB::Direct::Plus::Mappings::BusinessEntityType < DnB::Direct::Mapping
2
+
3
+ kartograph do
4
+ mapping DnB::Direct::Plus::BusinessEntityType
5
+
6
+ scoped :read do
7
+ property :description
8
+ property :dnbCode
9
+ end # scoped :read
10
+
11
+
12
+ end # kartograph
13
+
14
+ end # class
@@ -0,0 +1,19 @@
1
+ class DnB::Direct::Plus::Mappings::DunsControlStatus < DnB::Direct::Mapping
2
+
3
+ kartograph do
4
+ mapping DnB::Direct::Plus::DunsControlStatus
5
+
6
+ scoped :read do
7
+ property :isMarketable
8
+ property :isMailUndeliverable
9
+ property :isTelephoneDisconnected
10
+ property :isDelisted
11
+ property :fullReportDate
12
+ property :operatingStatus
13
+ property :subjectHandlingDetails
14
+ end # scoped :read
15
+
16
+
17
+ end # kartograph
18
+
19
+ end # class
@@ -0,0 +1,16 @@
1
+ class DnB::Direct::Plus::Mappings::IndustryCode < DnB::Direct::Mapping
2
+
3
+ kartograph do
4
+ mapping DnB::Direct::Plus::IndustryCode
5
+
6
+ scoped :read do
7
+ property :code
8
+ property :decription
9
+ property :typeDescription
10
+ property :typeDnBCode
11
+ property :priority
12
+ end # scoped :read
13
+
14
+ end # kartograph
15
+
16
+ end # class
@@ -0,0 +1,32 @@
1
+ class DnB::Direct::Plus::Mappings::Organization < DnB::Direct::Mapping
2
+
3
+ kartograph do
4
+ mapping DnB::Direct::Plus::Organization
5
+ root_key singular: 'organization', plural: 'organizations', scopes: [:read]
6
+
7
+ scoped :read do
8
+
9
+ # fields
10
+ property :duns
11
+ property :primaryName
12
+ property :tradeStyleNames
13
+
14
+ # has one
15
+ property :dunsControlStatus, plural: false, include: DnB::Direct::Plus::Mappings::DunsControlStatus
16
+ property :businessEntityType, plural: false, include: DnB::Direct::Plus::Mappings::BusinessEntityType
17
+ property :primaryAddress, plural: false, include: DnB::Direct::Plus::Mappings::Address
18
+ property :registeredAddress, plural: false, include: DnB::Direct::Plus::Mappings::Address
19
+ property :mailingAddress, plural: false, include: DnB::Direct::Plus::Mappings::Address
20
+
21
+ # has many
22
+ property :industryCodes, plural: true, include: DnB::Direct::Plus::Mappings::IndustryCode
23
+ property :registrationNumbers, plural: true, include: DnB::Direct::Plus::Mappings::RegistrationNumber
24
+ property :telephone, plural: true, include: DnB::Direct::Plus::Mappings::Telephone
25
+ property :fax, plural: true, include: DnB::Direct::Plus::Mappings::Telephone
26
+
27
+ end # scoped :read
28
+
29
+
30
+ end # kartograph
31
+
32
+ end # class
@@ -0,0 +1,14 @@
1
+ class DnB::Direct::Plus::Mappings::RegistrationNumber < DnB::Direct::Mapping
2
+
3
+ kartograph do
4
+ mapping DnB::Direct::Plus::RegistrationNumber
5
+
6
+ scoped :read do
7
+ property :registrationNumber
8
+ property :typeDescription
9
+ property :typeDnBCode
10
+ end # scoped :read
11
+
12
+ end # kartograph
13
+
14
+ end # class
@@ -0,0 +1,15 @@
1
+ class DnB::Direct::Plus::Mappings::Telephone < DnB::Direct::Mapping
2
+
3
+ kartograph do
4
+ mapping DnB::Direct::Plus::Telephone
5
+
6
+ scoped :read do
7
+ property :telephoneNumber
8
+ property :isdCode
9
+ property :isUnreachable
10
+ end # scoped :read
11
+
12
+
13
+ end # kartograph
14
+
15
+ end # class
@@ -0,0 +1,21 @@
1
+ class DnB::Direct::Plus::Match
2
+
3
+
4
+ def self.cleanse_match(params = {})
5
+ started_at = Time.now
6
+
7
+ response = DnB::Direct::Plus.connection.get do |req|
8
+ url = "/v1/search/typeahead?searchTerm=#{params[:term]}"
9
+ url << "&countryISOAlpha2Code=#{params[:country]}" if params[:country]
10
+ req.url url
11
+ req.headers[:authorization] = "Bearer #{DnB::Direct::Plus.api_token}"
12
+ end
13
+ puts "== [TYPEAHEAD] Completed in #{((Time.now - started_at)*1000).round}ms".cyan.bold
14
+
15
+ JSON.parse(response.body)
16
+ end # def self.profile_with_linkage
17
+
18
+
19
+
20
+
21
+ end # class DnB::Direct::Plus::Match
@@ -0,0 +1,18 @@
1
+ class DnB::Direct::Plus::Address < DnB::Direct::Model
2
+
3
+ attribute :postalCode
4
+ attribute :streetNumber
5
+ attribute :streetName
6
+ attribute :isRegisteredAddress
7
+ attribute :minorTownName
8
+
9
+ attribute :language
10
+ attribute :addressCountry
11
+ attribute :continentalRegion
12
+ attribute :addressLocality
13
+ attribute :addressRegion
14
+ attribute :addressCounty
15
+ attribute :streetAddress
16
+ attribute :postOfficeBox
17
+
18
+ end
@@ -0,0 +1,6 @@
1
+ class DnB::Direct::Plus::BusinessEntityType < DnB::Direct::Model
2
+
3
+ attribute :description
4
+ attribute :dnbCode
5
+
6
+ end
@@ -0,0 +1,12 @@
1
+ class DnB::Direct::Plus::DunsControlStatus < DnB::Direct::Model
2
+
3
+ attribute :isMarketable
4
+ attribute :isMailUndeliverable
5
+ attribute :isTelephoneDisconnected
6
+ attribute :isDelisted
7
+ attribute :fullReportDate
8
+ attribute :operatingStatus
9
+ attribute :subjectHandlingDetails
10
+
11
+
12
+ end
@@ -0,0 +1,9 @@
1
+ class DnB::Direct::Plus::IndustryCode < DnB::Direct::Model
2
+
3
+ attribute :code
4
+ attribute :decription
5
+ attribute :typeDescription
6
+ attribute :typeDnBCode
7
+ attribute :priority
8
+
9
+ end
@@ -0,0 +1,18 @@
1
+ class DnB::Direct::Plus::Organization < DnB::Direct::Model
2
+
3
+ attribute :duns
4
+ attribute :primaryName
5
+ attribute :tradeStyleNames
6
+
7
+ attribute :dunsControlStatus
8
+ attribute :primaryAddress
9
+ attribute :registeredAddress
10
+ attribute :mailingAddress
11
+ attribute :businessEntityType
12
+
13
+ attribute :industryCodes
14
+ attribute :registrationNumbers
15
+ attribute :telephone
16
+ attribute :fax
17
+
18
+ end
@@ -0,0 +1,7 @@
1
+ class DnB::Direct::Plus::RegistrationNumber < DnB::Direct::Model
2
+
3
+ attribute :registrationNumber
4
+ attribute :typeDescription
5
+ attribute :typeDnBCode
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ class DnB::Direct::Plus::Telephone < DnB::Direct::Model
2
+
3
+ attribute :telephoneNumber
4
+ attribute :isdCode
5
+ attribute :isUnreachable
6
+
7
+ end
@@ -0,0 +1,20 @@
1
+ class DnB::Direct::Plus::Search
2
+
3
+
4
+ def self.typeahead(params = {})
5
+ started_at = Time.now
6
+ country_code = params[:country] || 'US'
7
+ response = DnB::Direct::Plus.connection.get do |req|
8
+ url = "/v1/search/typeahead?searchTerm=#{params[:term]}&countryISOAlpha2Code=#{country_code}"
9
+ req.url url
10
+ req.headers[:authorization] = "Bearer #{DnB::Direct::Plus.api_token}"
11
+ end
12
+ puts "== [TYPEAHEAD] Completed in #{((Time.now - started_at)*1000).round}ms".cyan.bold
13
+
14
+ JSON.parse(response.body)
15
+ end # def self.profile_with_linkage
16
+
17
+
18
+
19
+
20
+ end # class
@@ -0,0 +1 @@
1
+ require 'dnb/direct'
@@ -0,0 +1,44 @@
1
+ require 'faraday'
2
+
3
+ module DnB
4
+ module Direct
5
+ class Two
6
+ BASE_URL = 'https://direct.dnb.com'.freeze
7
+ class << self
8
+ attr_accessor :username, :password, :token, :api_base_url, :conn
9
+
10
+ # Fetches the token from the authorization service.
11
+ def api_token
12
+ raise ArgumentError, 'username is missing' if username.blank?
13
+ raise ArgumentError, 'password is missing' if password.blank?
14
+ response = connection.post do |req|
15
+ req.url '/Authentication/V2.0'
16
+ req.headers['x-dnb-user'] = username
17
+ req.headers['x-dnb-pwd'] = password
18
+ end
19
+ response.headers['Authorization']
20
+ end
21
+
22
+ private
23
+
24
+ def connection
25
+ @conn ||= Faraday.new(connection_options) do |faraday|
26
+ faraday.request :url_encoded # form-encode POST params
27
+ faraday.response :logger # log requests to STDOUT
28
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
29
+ end
30
+ end
31
+
32
+ def connection_options
33
+ {
34
+ url: BASE_URL,
35
+ headers: {
36
+ content_type: 'application/json',
37
+ accept: 'application/json'
38
+ }
39
+ }
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ module DnB
2
+ module Direct
3
+ VERSION = "0.0.5"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dnb-direct-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Jason Ihaia
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: faraday
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.9.1
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.9.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: colored
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: virtus
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 1.0.3
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 1.0.3
75
+ - !ruby/object:Gem::Dependency
76
+ name: kartograph
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: bundler
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.13'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.13'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '10.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '10.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: minitest
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '5.0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '5.0'
131
+ description: Write a longer description or delete this line.
132
+ email:
133
+ - ihaiaj@dnb.com
134
+ executables: []
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - ".gitignore"
139
+ - ".ruby-version"
140
+ - ".travis.yml"
141
+ - CODE_OF_CONDUCT.md
142
+ - Gemfile
143
+ - LICENSE.txt
144
+ - README.md
145
+ - Rakefile
146
+ - bin/console
147
+ - bin/setup
148
+ - dnb-direct.gemspec
149
+ - lib/dnb/direct.rb
150
+ - lib/dnb/direct/mapping.rb
151
+ - lib/dnb/direct/model.rb
152
+ - lib/dnb/direct/one.rb
153
+ - lib/dnb/direct/plus.rb
154
+ - lib/dnb/direct/plus/content.rb
155
+ - lib/dnb/direct/plus/mappings/address.rb
156
+ - lib/dnb/direct/plus/mappings/business_entity_type.rb
157
+ - lib/dnb/direct/plus/mappings/duns_control_status.rb
158
+ - lib/dnb/direct/plus/mappings/industry_code.rb
159
+ - lib/dnb/direct/plus/mappings/organization.rb
160
+ - lib/dnb/direct/plus/mappings/registration_number.rb
161
+ - lib/dnb/direct/plus/mappings/telephone.rb
162
+ - lib/dnb/direct/plus/match.rb
163
+ - lib/dnb/direct/plus/models/address.rb
164
+ - lib/dnb/direct/plus/models/business_entity_type.rb
165
+ - lib/dnb/direct/plus/models/duns_control_status.rb
166
+ - lib/dnb/direct/plus/models/industry_code.rb
167
+ - lib/dnb/direct/plus/models/organization.rb
168
+ - lib/dnb/direct/plus/models/registration_number.rb
169
+ - lib/dnb/direct/plus/models/telephone.rb
170
+ - lib/dnb/direct/plus/search.rb
171
+ - lib/dnb/direct/ruby.rb
172
+ - lib/dnb/direct/two.rb
173
+ - lib/dnb/direct/version.rb
174
+ homepage: https://developer.dnb.com
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.6.10
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Write a short summary, because Rubygems requires one.
198
+ test_files: []