qa 0.6.0 → 0.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16b9b7d34d5db8f520bb0a0c3330f75b836d0d01
4
- data.tar.gz: fcea780be638d13a57f4ccd539f3ce90c5fcca48
3
+ metadata.gz: 85e4df1dd651f734f74b024a0414e4d9f7a919ca
4
+ data.tar.gz: 8308624003069a7af0b16a5248683691acd4ccdc
5
5
  SHA512:
6
- metadata.gz: 85bdd4ca0d32bb58b07326aad0a19721fc3efc8139a16af66d8ab54f2c132458a4205e185bf0f5f9038f33f6a5a72d6f964bec722f9a711f8a93c370899dd012
7
- data.tar.gz: 1a7a76fdc4e0c1b8cb843f95d122f9c21785023779bf19b2ea078845c1aed829a8c9b9709f2947e26b5c81c5d5333f225a6a82995a483544cd39a6ed2bf8c4c9
6
+ metadata.gz: 579dbb01782116c072173f4ca96ae6b142f20a98161c308edb08365da03d52520123483d9d63ea4ed8159197fd94739a1483f91a965920f57aa432b4ef1eee25
7
+ data.tar.gz: 3ac918adcb01206d99ac08c97ef1e9185f6b2f35c9442fa4cabf2d86dad64ee892c11478488144b320c3da1a97aa2aca6cb4f6ad49ce49eec2d72903b71afcf4
data/README.md CHANGED
@@ -148,6 +148,22 @@ Make sure you handle these correctly in your form.
148
148
  For more details on this OCLC API, see
149
149
  http://www.oclc.org/developer/develop/web-services/fast-api/assign-fast.en.html
150
150
 
151
+ ### Geonames
152
+ Make sure you register an account and enable it to see search results.
153
+
154
+ Ensure you can run a query like this:
155
+
156
+ ```
157
+ http://api.geonames.org/searchJSON?q=port&&maxRows=10username=MY_ACCOUNT_NAME
158
+ ```
159
+
160
+ Then you can set your username like this:
161
+
162
+ ```ruby
163
+ Qa::Authorities::Geonames.username = 'myAccountName'
164
+
165
+ ```
166
+
151
167
  ### Local Authorities
152
168
 
153
169
  For simple use cases when you have a few terms that don't change very often.
@@ -1,6 +1,7 @@
1
- # This controller is used for all requests to all authorities. It will verify params and figure out
2
- # which class to instantiate based on the "vocab" param. All the authotirty classes inherit from a
3
- # super class so they implement the same methods.
1
+ # This controller is used for all requests to all authorities. It will verify
2
+ # params and figure out which class to instantiate based on the "vocab" param.
3
+ # All the authority classes inherit from a super class so they implement the
4
+ # same methods.
4
5
 
5
6
  class Qa::TermsController < ApplicationController
6
7
 
@@ -4,6 +4,7 @@ module Qa::Authorities
4
4
  autoload :AuthorityWithSubAuthority
5
5
  autoload :Base
6
6
  autoload :Getty
7
+ autoload :Geonames
7
8
  autoload :Loc
8
9
  autoload :LocSubauthority
9
10
  autoload :Local
@@ -0,0 +1,43 @@
1
+ module Qa::Authorities
2
+ class Geonames < Base
3
+ include WebServiceBase
4
+
5
+ class_attribute :username
6
+
7
+ def search q
8
+ parse_authority_response(json(build_query_url(q)))
9
+ end
10
+
11
+ # get_json is not ideomatic, so we'll make an alias
12
+ def json(*args)
13
+ get_json(*args)
14
+ end
15
+
16
+ def build_query_url q
17
+ query = URI.escape(untaint(q))
18
+ "http://api.geonames.org/searchJSON?q=#{query}&username=#{username}&maxRows=10"
19
+ end
20
+
21
+ def untaint(q)
22
+ q.gsub(/[^\w\s-]/, '')
23
+ end
24
+
25
+ def find id
26
+ json(find_url(id))
27
+ end
28
+
29
+ def find_url id
30
+ "http://www.geonames.org/getJSON?geonameId=#{id}&username=#{username}"
31
+ end
32
+
33
+ private
34
+
35
+ # Reformats the data received from the service
36
+ def parse_authority_response(response)
37
+ response['geonames'].map do |result|
38
+ { 'id' => "http://sws.geonames.org/#{result['geonameId']}",
39
+ 'label' => result['name'] }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -3,7 +3,7 @@ module Qa::Authorities
3
3
 
4
4
  def search q
5
5
  begin
6
- r = Qa::SubjectMeshTerm.where('term_lower LIKE ?', "#{@q}%").limit(10)
6
+ r = Qa::SubjectMeshTerm.where('term_lower LIKE ?', "#{q}%").limit(10)
7
7
  r.map { |t| {id: t.term_id, label: t.term} }
8
8
  end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module Qa
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -0,0 +1 @@
1
+ {"timezone":{"gmtOffset":10,"timeZoneId":"Pacific/Port_Moresby","dstOffset":10},"bbox":{"east":147.24973454378284,"south":-9.512216673431235,"north":-9.37405361970154,"west":147.10970149137341},"asciiName":"Port Moresby","countryId":"2088628","fcl":"P","srtm3":79,"countryCode":"PG","adminId1":"2089856","lat":"-9.44314","fcode":"PPLC","continentCode":"OC","adminCode1":"20","lng":"147.17972","geonameId":2088122,"toponymName":"Port Moresby","population":283733,"wikipediaURL":"en.wikipedia.org/wiki/Port_Moresby","adminName5":"","adminName4":"","adminName3":"","alternateNames":[{"name":"ፖርት ሞርስቢ","lang":"am"},{"name":"포트모르즈비","lang":"ko"},{"name":"ポートモレスビー","lang":"ja"},{"name":"พอร์ตมอร์สบี","lang":"th"},{"name":"http://en.wikipedia.org/wiki/Port_Moresby","lang":"link"},{"name":"http://ru.wikipedia.org/wiki/%D0%9F%D0%BE%D1%80%D1%82-%D0%9C%D0%BE%D1%80%D1%81%D0%B1%D0%B8","lang":"link"},{"name":"POM","lang":"iata"},{"name":"Pò Moresbi","lang":"ht"},{"name":"Port-Moresbo","lang":"eo"},{"name":"Port Moresby","lang":"cs"},{"name":"Port Moresby","lang":"da"},{"name":"Port Moresby","lang":"de"},{"name":"Port Moresby","lang":"en"},{"name":"Port Moresby","lang":"et"},{"name":"Port Moresby","lang":"eu"},{"name":"Port Moresby","lang":"fi"},{"name":"Port Moresby","lang":"fr"},{"name":"Port Moresby","lang":"id"},{"name":"Port Moresby","lang":"io"},{"name":"Port Moresby","lang":"it"},{"name":"Port Moresby","lang":"nl"},{"name":"Port Moresby","lang":"pl"},{"name":"Port Moresby","lang":"pt"},{"name":"Port Moresby","lang":"sk"},{"name":"Port Moresby","lang":"sv"},{"name":"Portmorsbi","lang":"lv"},{"name":"Port Morsbi","lang":"az"},{"name":"Port Morsbis","lang":"lt"},{"name":"Portus Moresbiensis","lang":"la"},{"name":"Pot Mosbi","lang":"tpi"},{"name":"Puerto Moresby","lang":"es"},{"name":"بورت مورسبي","lang":"ar"},{"name":"پۆرت مۆرسبی","lang":"ckb"},{"name":"پورت مورسبی","lang":"fa"},{"name":"پورٹ مورسبی","lang":"ur"},{"name":"صوبہ پورٹ مورسبائی","lang":"pnb"},{"name":"مورېسبى پورتى","lang":"ug"},{"name":"פורט מורסבי","lang":"he"},{"name":"Πορτ Μόρεσμπι","lang":"el"},{"name":"Горад Порт-Морсбі","lang":"be"},{"name":"Порт Морсби","lang":"bg"},{"name":"Порт Морсби","lang":"mk"},{"name":"Порт Морсби","lang":"sah"},{"name":"Порт Морсби","lang":"sr"},{"name":"Порт-Морсби","lang":"mrj"},{"name":"Порт-Морсби","lang":"ru"},{"name":"Порт-Морсбі","lang":"uk"},{"name":"པོ་རོ་ཊི་མོ་རེ་སི་བི།","lang":"bo"},{"name":"Պորտ Մորսբի","lang":"hy"},{"name":"პორტ-მორზბი","lang":"ka"},{"name":"पोर्ट मॉरेस्बी","lang":"mr"},{"name":"पोर्ट मोरेस्बी","lang":"hi"},{"name":"ਪੋਰਟ ਮੋਰੈਸਬੀ","lang":"pa"},{"name":"莫尔兹比港","lang":"zh"},{"name":"莫尔兹比港","lang":"zh-CN"}],"adminName2":"","name":"Port Moresby","fclName":"city, village,...","countryName":"Papua New Guinea","fcodeName":"capital of a political entity","adminName1":"National Capital"}
@@ -0,0 +1 @@
1
+ {"totalResultsCount":12041,"geonames":[{"countryId":"2088628","adminCode1":"20","countryName":"Papua New Guinea","fclName":"city, village,...","countryCode":"PG","lng":"147.17972","fcodeName":"capital of a political entity","toponymName":"Port Moresby","fcl":"P","name":"Port Moresby","fcode":"PPLC","geonameId":2088122,"lat":"-9.44314","adminName1":"National Capital","population":283733},{"countryId":"934292","adminCode1":"18","countryName":"Mauritius","fclName":"city, village,...","countryCode":"MU","lng":"57.49889","fcodeName":"capital of a political entity","toponymName":"Port Louis","fcl":"P","name":"Port Louis","fcode":"PPLC","geonameId":934154,"lat":"-20.16194","adminName1":"Port Louis","population":155226},{"countryId":"3723988","adminCode1":"11","countryName":"Haiti","fclName":"city, village,...","countryCode":"HT","lng":"-72.335","fcodeName":"capital of a political entity","toponymName":"Port-au-Prince","fcl":"P","name":"Port-au-Prince","fcode":"PPLC","geonameId":3718426,"lat":"18.53917","adminName1":"Ouest","population":1234742},{"countryId":"2134431","adminCode1":"18","countryName":"Vanuatu","fclName":"city, village,...","countryCode":"VU","lng":"168.32188","fcodeName":"capital of a political entity","toponymName":"Port-Vila","fcl":"P","name":"Port Vila","fcode":"PPLC","geonameId":2135171,"lat":"-17.73381","adminName1":"Shefa","population":35901},{"countryId":"2328926","adminCode1":"50","countryName":"Nigeria","fclName":"city, village,...","countryCode":"NG","lng":"7.0134","fcodeName":"seat of a first-order administrative division","toponymName":"Port Harcourt","fcl":"P","name":"Port Harcourt","fcode":"PPLA","geonameId":2324774,"lat":"4.77742","adminName1":"Rivers","population":1148665},{"countryId":"357994","adminCode1":"19","countryName":"Egypt","fclName":"city, village,...","countryCode":"EG","lng":"32.28412","fcodeName":"seat of a first-order administrative division","toponymName":"Port Said","fcl":"P","name":"Port Said","fcode":"PPLA","geonameId":358619,"lat":"31.25654","adminName1":"Port Said","population":538378},{"countryId":"3042362","adminCode1":"6417228","countryName":"Guernsey","fclName":"city, village,...","countryCode":"GG","lng":"-2.53527","fcodeName":"capital of a political entity","toponymName":"Saint Peter Port","fcl":"P","name":"St Peter Port","fcode":"PPLC","geonameId":3042287,"lat":"49.45981","adminName1":"St Peter Port","population":16488},{"countryId":"3573591","adminCode1":"05","countryName":"Trinidad and Tobago","fclName":"city, village,...","countryCode":"TT","lng":"-61.51889","fcodeName":"capital of a political entity","toponymName":"Port of Spain","fcl":"P","name":"Port of Spain","fcode":"PPLC","geonameId":3573890,"lat":"10.66668","adminName1":"City of Port of Spain","population":49031},{"countryId":"2400553","adminCode1":"08","countryName":"Gabon","fclName":"city, village,...","countryCode":"GA","lng":"8.78151","fcodeName":"seat of a first-order administrative division","toponymName":"Port-Gentil","fcl":"P","name":"Port-Gentil","fcode":"PPLA","geonameId":2396518,"lat":"-0.71933","adminName1":"Ogooué-Maritime","population":109163},{"countryId":"366755","adminCode1":"36","countryName":"Sudan","fclName":"city, village,...","countryCode":"SD","lng":"37.21644","fcodeName":"seat of a first-order administrative division","toponymName":"Port Sudan","fcl":"P","name":"Port Sudan","fcode":"PPLA","geonameId":377039,"lat":"19.61745","adminName1":"Red Sea","population":489725}]}
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Qa::Authorities::Geonames do
4
+
5
+ before do
6
+ described_class.username = 'dummy'
7
+ end
8
+
9
+ let(:authority) { described_class.new }
10
+
11
+ describe "#build_query_url" do
12
+ subject { authority.build_query_url("foo") }
13
+ it { is_expected.to eq 'http://api.geonames.org/searchJSON?q=foo&username=dummy&maxRows=10' }
14
+ end
15
+
16
+ describe "#find_url" do
17
+ subject { authority.find_url("1028772") }
18
+ it { is_expected.to eq "http://www.geonames.org/getJSON?geonameId=1028772&username=dummy" }
19
+ end
20
+
21
+ describe "#search" do
22
+ context "authorities" do
23
+ before do
24
+ stub_request(:get, /api\.geonames\.org.*/).
25
+ to_return(:body => webmock_fixture("geonames-response.json"), status: 200)
26
+ end
27
+
28
+ subject { authority.search('whatever') }
29
+
30
+ it "has id and label keys" do
31
+ expect(subject.first).to eq("id" => 'http://sws.geonames.org/2088122',
32
+ "label" => "Port Moresby")
33
+ expect(subject.last).to eq("id" => 'http://sws.geonames.org/377039',
34
+ "label" => "Port Sudan")
35
+ expect(subject.size).to eq(10)
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "#untaint" do
41
+ subject { authority.untaint(value) }
42
+
43
+ context "with a good string" do
44
+ let(:value) { 'Cawood' }
45
+ it { is_expected.to eq 'Cawood' }
46
+ end
47
+
48
+ context "bad stuff" do
49
+ let(:value) { './"' }
50
+ it { is_expected.to eq '' }
51
+ end
52
+ end
53
+
54
+ describe "#find" do
55
+ context "using a subject id" do
56
+ before do
57
+ stub_request(:get, "http://www.geonames.org/getJSON?geonameId=2088122&username=dummy").
58
+ to_return(status: 200, body: webmock_fixture("geonames-find-response.json"))
59
+ end
60
+ subject { authority.find("2088122") }
61
+
62
+ it "returns the complete record for a given subject" do
63
+ expect(subject['geonameId']).to eq 2088122
64
+ expect(subject['name']).to eq "Port Moresby"
65
+ end
66
+ end
67
+ end
68
+ end
@@ -30,9 +30,11 @@ describe Qa::Authorities::Mesh do
30
30
  let(:m) { Qa::Authorities::Mesh.new }
31
31
 
32
32
  it "handles queries" do
33
- results = m.search('mr')
33
+ results = m.search('mr ')
34
+ expect(results.length).to eq(2)
34
35
  expect(results).to include( {id: '1', label: 'Mr Plow'} )
35
- expect(results.length).to eq(3)
36
+ expect(results).to include( {id: '2', label: 'Mr Snow'} )
37
+ expect(results).not_to include( {id: '3', label: 'Mrs Fields'} )
36
38
  end
37
39
 
38
40
  it "returns individual records" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Anderson
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2016-03-29 00:00:00.000000000 Z
18
+ date: 2016-06-27 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rails
@@ -218,6 +218,7 @@ files:
218
218
  - lib/qa/authorities/assign_fast_subauthority.rb
219
219
  - lib/qa/authorities/authority_with_sub_authority.rb
220
220
  - lib/qa/authorities/base.rb
221
+ - lib/qa/authorities/geonames.rb
221
222
  - lib/qa/authorities/getty.rb
222
223
  - lib/qa/authorities/getty/aat.rb
223
224
  - lib/qa/authorities/getty/tgn.rb
@@ -251,6 +252,8 @@ files:
251
252
  - spec/fixtures/authorities/authority_B.yml
252
253
  - spec/fixtures/authorities/authority_C.yml
253
254
  - spec/fixtures/authorities/authority_D.yml
255
+ - spec/fixtures/geonames-find-response.json
256
+ - spec/fixtures/geonames-response.json
254
257
  - spec/fixtures/getty-aat-find-response.json
255
258
  - spec/fixtures/getty-tgn-find-response.json
256
259
  - spec/fixtures/getty-ulan-find-response.json
@@ -266,6 +269,7 @@ files:
266
269
  - spec/fixtures/ulan-response.txt
267
270
  - spec/lib/authorities/assign_fast_spec.rb
268
271
  - spec/lib/authorities/file_based_authority_spec.rb
272
+ - spec/lib/authorities/geonames_spec.rb
269
273
  - spec/lib/authorities/getty/aat_spec.rb
270
274
  - spec/lib/authorities/getty/tgn_spec.rb
271
275
  - spec/lib/authorities/getty/ulan_spec.rb
@@ -303,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
303
307
  version: '0'
304
308
  requirements: []
305
309
  rubyforge_project:
306
- rubygems_version: 2.4.5.1
310
+ rubygems_version: 2.5.1
307
311
  signing_key:
308
312
  specification_version: 4
309
313
  summary: You should question your authorities.
@@ -318,6 +322,8 @@ test_files:
318
322
  - spec/fixtures/authorities/authority_B.yml
319
323
  - spec/fixtures/authorities/authority_C.yml
320
324
  - spec/fixtures/authorities/authority_D.yml
325
+ - spec/fixtures/geonames-find-response.json
326
+ - spec/fixtures/geonames-response.json
321
327
  - spec/fixtures/getty-aat-find-response.json
322
328
  - spec/fixtures/getty-tgn-find-response.json
323
329
  - spec/fixtures/getty-ulan-find-response.json
@@ -333,6 +339,7 @@ test_files:
333
339
  - spec/fixtures/ulan-response.txt
334
340
  - spec/lib/authorities/assign_fast_spec.rb
335
341
  - spec/lib/authorities/file_based_authority_spec.rb
342
+ - spec/lib/authorities/geonames_spec.rb
336
343
  - spec/lib/authorities/getty/aat_spec.rb
337
344
  - spec/lib/authorities/getty/tgn_spec.rb
338
345
  - spec/lib/authorities/getty/ulan_spec.rb
@@ -350,3 +357,4 @@ test_files:
350
357
  - spec/routing/route_spec.rb
351
358
  - spec/spec_helper.rb
352
359
  - spec/test_app_templates/lib/generators/test_app_generator.rb
360
+ has_rdoc: