Class: OTX::Base
- Inherits:
-
Object
- Object
- OTX::Base
- Defined in:
- lib/otx_ruby/base.rb
Overview
Base Class for API access, provides initial wrapper around Faraday performs base request
Direct Known Subclasses
Instance Method Summary collapse
-
#get(url, params = {}) ⇒ Object
Get the provided URL.
-
#initialize(key, server = "https://otx.alienvault.com") ⇒ Base
constructor
Initialise object.
Constructor Details
#initialize(key, server = "https://otx.alienvault.com") ⇒ Base
Initialise object
13 14 15 16 17 18 19 20 21 |
# File 'lib/otx_ruby/base.rb', line 13 def initialize(key, server="https://otx.alienvault.com") @key = key @server = server @conn = Faraday.new(:url => @server) do |faraday| faraday.request :url_encoded # form-encode POST params faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end end |
Instance Method Details
#get(url, params = {}) ⇒ Object
Get the provided URL
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/otx_ruby/base.rb', line 29 def get(url, params={}) response = @conn.get do |req| req.url url req.headers['X-OTX-API-KEY'] = @key req.params = params end # Parse and return JSON object as hash to caller return Oj.load(response.body) end |