Class: Gnfinder::Client
- Inherits:
-
Object
- Object
- Gnfinder::Client
- Defined in:
- lib/gnfinder/client.rb
Overview
Gnfinder::Client connects to gnfinder server
Instance Method Summary collapse
- #find_file(path, opts = {}) ⇒ Object
- #find_names(text, opts = {}) ⇒ Object
- #find_url(url, opts = {}) ⇒ Object
- #gnfinder_version ⇒ Object
-
#initialize(host = 'https://finder.globalnames.org', port = '') ⇒ Client
constructor
A new instance of Client.
- #ping ⇒ Object
Constructor Details
#initialize(host = 'https://finder.globalnames.org', port = '') ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 11 12 |
# File 'lib/gnfinder/client.rb', line 6 def initialize(host = 'https://finder.globalnames.org', port = '') api_path = '/api/v1' url = host + api_path url = "#{host}:#{port}#{api_path}" if port.to_s != '' @site = RestClient::Resource.new(url, read_timeout: 60) @port = port end |
Instance Method Details
#find_file(path, opts = {}) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/gnfinder/client.rb', line 24 def find_file(path, opts = {}) params = {} update_params(params, opts) file = File.new(path, 'rb') params = params.merge(file: file) resp = @site['find'].post(params) prepare_result(resp) end |
#find_names(text, opts = {}) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/gnfinder/client.rb', line 40 def find_names(text, opts = {}) return to_open_struct({ "names": [] }) if text.to_s.strip == '' params = { text: text } find(params, opts) end |
#find_url(url, opts = {}) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/gnfinder/client.rb', line 33 def find_url(url, opts = {}) return to_open_struct({ "names": [] }) if url.to_s.strip == '' params = { url: url } find(params, opts) end |
#gnfinder_version ⇒ Object
14 15 16 17 18 |
# File 'lib/gnfinder/client.rb', line 14 def gnfinder_version resp = @site['/version'].get ver = JSON.parse(resp.body, symbolize_names: true) OpenStruct.new(ver) end |
#ping ⇒ Object
20 21 22 |
# File 'lib/gnfinder/client.rb', line 20 def ping @site['/ping'].get.body end |