Class: CIF::Client
- Inherits:
-
Object
- Object
- CIF::Client
- Defined in:
- lib/cif/client.rb,
lib/cif/client/version.rb
Constant Summary collapse
- VERSION =
"1.0.6"
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#restriction ⇒ Object
writeonly
Sets the attribute restriction.
-
#severity ⇒ Object
writeonly
Sets the attribute severity.
Instance Method Summary collapse
-
#initialize(host, apikey, severity = nil, restriction = nil, nolog = false) ⇒ Client
constructor
A new instance of Client.
- #query(q, severity = nil, restriction = nil, nolog = false) ⇒ Object
Constructor Details
#initialize(host, apikey, severity = nil, restriction = nil, nolog = false) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 |
# File 'lib/cif/client.rb', line 15 def initialize(host,apikey,severity=nil,restriction=nil,nolog=false) @host = host @apikey = apikey @severity = severity @nolog = nolog @restriction = restriction end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
13 14 15 |
# File 'lib/cif/client.rb', line 13 def fields @fields end |
#restriction=(value) ⇒ Object (writeonly)
Sets the attribute restriction
14 15 16 |
# File 'lib/cif/client.rb', line 14 def restriction=(value) @restriction = value end |
#severity=(value) ⇒ Object (writeonly)
Sets the attribute severity
14 15 16 |
# File 'lib/cif/client.rb', line 14 def severity=(value) @severity = value end |
Instance Method Details
#query(q, severity = nil, restriction = nil, nolog = false) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cif/client.rb', line 23 def query(q,severity=nil,restriction=nil,nolog=false) params = {'apikey' => @apikey} params['restriction'] = restriction || @restriction if restriction || @restriction params['severity'] = severity || @severity if severity || @severity params['nolog'] = 1 if nolog || @nolog s = "#{@host}/#{q}?"+params.map{|k,v| "#{k}=#{v}"}.join("&") url = URI.parse s http = Net::HTTP.new(url.host, url.port) http.use_ssl = (url.scheme == 'https') http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.verify_depth = 5 request = Net::HTTP::Get.new(url.path+"?"+url.query) request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} cif-client v#{CIF::Client::VERSION}") request.add_field("Accept", "application/json") response = http.request(request) doc = response.body data = JSON.parse(doc) @response_code = data['status'] if data['data'] and data['data']['feed'] feed = data['data']['feed'] end feed end |