duns-lookup 0.0.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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kali Donovan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ = duns-lookup
2
+
3
+ This provides a small wrapper around the Dun & Bradstreet website to retrieve business information from DUNS numbers.
4
+
5
+ == Usage
6
+
7
+ require 'rubygems'
8
+ require 'kdonovan-duns-lookup'
9
+
10
+ Duns.lookup_duns( *invalid_number* )
11
+ # => nil
12
+ Duns.lookup_duns( *some_valid_number* )
13
+ # => {:name => *a_name*, :address => *an_address*}
14
+
15
+
16
+ == Note on Patches/Pull Requests
17
+
18
+ * Fork the project.
19
+ * Make your feature addition or bug fix.
20
+ * Add tests for it. This is important so I don't break it in a
21
+ future version unintentionally.
22
+ * Commit, do not mess with rakefile, version, or history.
23
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
24
+ * Send me a pull request. Bonus points for topic branches.
25
+
26
+ == Copyright
27
+
28
+ Copyright (c) 2009 Kali Donovan. See LICENSE for details.
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "duns-lookup"
8
+ gem.summary = "Wrapper for looking up Dun & Bradstreet numbers (DUNS)"
9
+ gem.description = %Q{Provides a small wrapper around the Dun & Bradstreet website to retrieve business information from DUNS numbers.}
10
+ gem.email = "kali.donovan@gmail.com"
11
+ gem.homepage = "http://github.com/kdonovan/duns-lookup"
12
+ gem.authors = ["Kali Donovan"]
13
+ gem.add_development_dependency "rspec"
14
+ gem.add_dependency "mechanize"
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ if File.exist?('VERSION')
40
+ version = File.read('VERSION')
41
+ else
42
+ version = ""
43
+ end
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "duns-lookup #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.3
@@ -0,0 +1,265 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: Duns</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Duns</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/duns-lookup_rb.html">
59
+ lib/duns-lookup.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+ <div id="description">
82
+ <h1>Synopsis</h1>
83
+ <p>
84
+ The <a href="Duns.html">Duns</a> library provides a small wrapper around
85
+ the Dun &amp; Bradstreet website&#8216;s advanced search functionality.
86
+ Currently it only implements searching for company by DUNS number.
87
+ </p>
88
+ <h2>Example</h2>
89
+ <pre>
90
+ require 'rubygems'
91
+ require 'kdonovan-duns-lookup'
92
+
93
+ Duns.lookup_duns( *invalid_number* )
94
+ # =&gt; nil
95
+ Duns.lookup_duns( *some_valid_number* )
96
+ # =&gt; {:name =&gt; *a_name*, :address =&gt; *an_address*}
97
+ </pre>
98
+
99
+ </div>
100
+
101
+
102
+ </div>
103
+
104
+ <div id="method-list">
105
+ <h3 class="section-bar">Methods</h3>
106
+
107
+ <div class="name-list">
108
+ <a href="#M000006">enforce_duns_formatting</a>&nbsp;&nbsp;
109
+ <a href="#M000004">extract_address</a>&nbsp;&nbsp;
110
+ <a href="#M000005">extract_name</a>&nbsp;&nbsp;
111
+ <a href="#M000003">extract_search_results</a>&nbsp;&nbsp;
112
+ <a href="#M000001">lookup_duns</a>&nbsp;&nbsp;
113
+ <a href="#M000002">update_advanced_search_url</a>&nbsp;&nbsp;
114
+ </div>
115
+ </div>
116
+
117
+ </div>
118
+
119
+
120
+ <!-- if includes -->
121
+
122
+ <div id="section">
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+ <!-- if method_list -->
132
+ <div id="methods">
133
+ <h3 class="section-bar">Public Class methods</h3>
134
+
135
+ <div id="method-M000001" class="method-detail">
136
+ <a name="M000001"></a>
137
+
138
+ <div class="method-heading">
139
+ <a href="Duns.src/M000001.html" target="Code" class="method-signature"
140
+ onclick="popupCode('Duns.src/M000001.html');return false;">
141
+ <span class="method-name">lookup_duns</span><span class="method-args">(number)</span>
142
+ </a>
143
+ </div>
144
+
145
+ <div class="method-description">
146
+ <p>
147
+ Look up a given DUNS number in the D&amp;B database. If the number is
148
+ found, returns a hash with :name and :address keys. Otherwise, returns nil.
149
+ </p>
150
+ </div>
151
+ </div>
152
+
153
+ <div id="method-M000002" class="method-detail">
154
+ <a name="M000002"></a>
155
+
156
+ <div class="method-heading">
157
+ <a href="Duns.src/M000002.html" target="Code" class="method-signature"
158
+ onclick="popupCode('Duns.src/M000002.html');return false;">
159
+ <span class="method-name">update_advanced_search_url</span><span class="method-args">()</span>
160
+ </a>
161
+ </div>
162
+
163
+ <div class="method-description">
164
+ <p>
165
+ Updates the internal URL used as the base for advanced searches.
166
+ </p>
167
+ <p>
168
+ The D&amp;B website uses lots of extraneous (to us) URL params, and I have
169
+ no idea what they all mean. If the base URL stops working, this method will
170
+ try to set a new one by visiting the main page and finding &amp; clicking
171
+ an Advanced Search link.
172
+ </p>
173
+ <p>
174
+ This is mostly a precaution, but if searches stop working a good first bet
175
+ would be to try running this method. If search is still broken, something
176
+ actually changed in the D&amp;B HTML and we&#8216;ll need to retool the
177
+ gem.
178
+ </p>
179
+ </div>
180
+ </div>
181
+
182
+ <h3 class="section-bar">Protected Class methods</h3>
183
+
184
+ <div id="method-M000006" class="method-detail">
185
+ <a name="M000006"></a>
186
+
187
+ <div class="method-heading">
188
+ <a href="Duns.src/M000006.html" target="Code" class="method-signature"
189
+ onclick="popupCode('Duns.src/M000006.html');return false;">
190
+ <span class="method-name">enforce_duns_formatting</span><span class="method-args">(orig_number)</span>
191
+ </a>
192
+ </div>
193
+
194
+ <div class="method-description">
195
+ <p>
196
+ Strip out non-numeric characters, and raise error if remaining number is
197
+ still invalid
198
+ </p>
199
+ </div>
200
+ </div>
201
+
202
+ <div id="method-M000004" class="method-detail">
203
+ <a name="M000004"></a>
204
+
205
+ <div class="method-heading">
206
+ <a href="Duns.src/M000004.html" target="Code" class="method-signature"
207
+ onclick="popupCode('Duns.src/M000004.html');return false;">
208
+ <span class="method-name">extract_address</span><span class="method-args">(td)</span>
209
+ </a>
210
+ </div>
211
+
212
+ <div class="method-description">
213
+ <p>
214
+ Retrieve an address from the proper D&amp;B HTML for the td element
215
+ </p>
216
+ </div>
217
+ </div>
218
+
219
+ <div id="method-M000005" class="method-detail">
220
+ <a name="M000005"></a>
221
+
222
+ <div class="method-heading">
223
+ <a href="Duns.src/M000005.html" target="Code" class="method-signature"
224
+ onclick="popupCode('Duns.src/M000005.html');return false;">
225
+ <span class="method-name">extract_name</span><span class="method-args">(td)</span>
226
+ </a>
227
+ </div>
228
+
229
+ <div class="method-description">
230
+ <p>
231
+ Retrieve a name from the proper D&amp;B HTML for the td element
232
+ </p>
233
+ </div>
234
+ </div>
235
+
236
+ <div id="method-M000003" class="method-detail">
237
+ <a name="M000003"></a>
238
+
239
+ <div class="method-heading">
240
+ <a href="Duns.src/M000003.html" target="Code" class="method-signature"
241
+ onclick="popupCode('Duns.src/M000003.html');return false;">
242
+ <span class="method-name">extract_search_results</span><span class="method-args">(page)</span>
243
+ </a>
244
+ </div>
245
+
246
+ <div class="method-description">
247
+ <p>
248
+ Given a search page, extract the results
249
+ </p>
250
+ </div>
251
+ </div>
252
+
253
+
254
+ </div>
255
+
256
+
257
+ </div>
258
+
259
+
260
+ <div id="validator-badges">
261
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
262
+ </div>
263
+
264
+ </body>
265
+ </html>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>lookup_duns (Duns)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/duns-lookup.rb, line 39</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">lookup_duns</span>(<span class="ruby-identifier">number</span>)
15
+ <span class="ruby-identifier">form</span> = <span class="ruby-ivar">@@agent</span>.<span class="ruby-identifier">get</span>( <span class="ruby-ivar">@@dnb_advanced_search</span> ).<span class="ruby-identifier">form</span>(<span class="ruby-value str">'DunsSearchForm'</span>)
16
+ <span class="ruby-identifier">form</span>.<span class="ruby-identifier">dunsNumber</span> = <span class="ruby-identifier">enforce_duns_formatting</span>(<span class="ruby-identifier">number</span>)
17
+ <span class="ruby-identifier">page</span> = <span class="ruby-ivar">@@agent</span>.<span class="ruby-identifier">submit</span>(<span class="ruby-identifier">form</span>)
18
+
19
+ <span class="ruby-identifier">extract_search_results</span>(<span class="ruby-identifier">page</span>)
20
+ <span class="ruby-keyword kw">end</span></pre>
21
+ </body>
22
+ </html>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>update_advanced_search_url (Duns)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/duns-lookup.rb, line 59</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">update_advanced_search_url</span>
15
+ <span class="ruby-identifier">page</span> = <span class="ruby-ivar">@@agent</span>.<span class="ruby-identifier">get</span>( <span class="ruby-ivar">@@dnb_homepage</span> )
16
+ <span class="ruby-identifier">advanced_link</span> = <span class="ruby-identifier">page</span>.<span class="ruby-identifier">links</span>.<span class="ruby-identifier">find</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span> <span class="ruby-identifier">l</span>.<span class="ruby-identifier">text</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/search/i</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">l</span>.<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/AdvancedCompanySearch/</span>)}
17
+ <span class="ruby-identifier">raise</span>(<span class="ruby-constant">DunsError</span>, <span class="ruby-node">&quot;Unable to find an advanced search link at: #{@@dnb_homepage}&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">advanced_link</span>.<span class="ruby-identifier">nil?</span>
18
+ <span class="ruby-ivar">@@dnb_advanced_search</span> = <span class="ruby-identifier">advanced_link</span>.<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">to_s</span>
19
+ <span class="ruby-keyword kw">end</span></pre>
20
+ </body>
21
+ </html>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>extract_search_results (Duns)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/duns-lookup.rb, line 70</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">extract_search_results</span>(<span class="ruby-identifier">page</span>)
15
+ <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">page</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">'div.text-red'</span>).<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
16
+
17
+ <span class="ruby-comment cmt"># Given a DUNS number search, we only expect one result. For other search types (when/if implemented), loop over all TRs returned in this table</span>
18
+ <span class="ruby-identifier">company_name</span> = <span class="ruby-identifier">extract_name</span>( <span class="ruby-identifier">page</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">&quot;//table[@id='SearchResultsTable']//tr[1]/td[2]&quot;</span>) )
19
+ <span class="ruby-identifier">company_address</span> = <span class="ruby-identifier">extract_address</span>( <span class="ruby-identifier">page</span>.<span class="ruby-identifier">search</span>(<span class="ruby-value str">&quot;//table[@id='SearchResultsTable']//tr[1]/td[3]&quot;</span>) )
20
+
21
+ {<span class="ruby-identifier">:name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">company_name</span>, <span class="ruby-identifier">:address</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">company_address</span>}
22
+ <span class="ruby-keyword kw">end</span></pre>
23
+ </body>
24
+ </html>