module Difi
General methods for working with the public APIs at hotell.difi.no
This module is meant to extend a Difi
registry class.
For instance the Brreg::Enhetsregisteret
class
Constants
- VERSION
Public Instance Methods
conn()
click to toggle source
The API connection
# File lib/difi.rb, line 20 def conn @@conn ||= Faraday.new(:url => url) do |faraday| faraday.request :url_encoded # form-encode POST params faraday.response :logger # log requests to STDOUT faraday.adapter :excon # make requests with Excon end end
dataset()
click to toggle source
The current dataset
# File lib/difi.rb, line 29 def dataset self.to_s.downcase.sub("::", "/") end
fields()
click to toggle source
Return the fields of the current dataset
# File lib/difi.rb, line 39 def fields get "fields" json end
get(query)
click to toggle source
Perform a GET HTTP query on the current dataset
# File lib/difi.rb, line 34 def get(query) @@response = conn.get([url, dataset, query].join("/")) end
json()
click to toggle source
Return the last HTTP response body as JSON
# File lib/difi.rb, line 57 def json JSON.parse @@response.body end
response()
click to toggle source
Return the last HTTP response
# File lib/difi.rb, line 52 def response @@response end
search(string)
click to toggle source
Search for entries from the current dataset with the given fields Input is expected to be a String
# File lib/difi.rb, line 46 def search(string) @@response = conn.get [url, dataset].join("/") + "?query=" + URI.escape(string) json end
url()
click to toggle source
The API source URL
# File lib/difi.rb, line 15 def url @@url ||= "http://hotell.difi.no/api/json" end