Class: Dashboarder::Api
- Inherits:
-
Object
- Object
- Dashboarder::Api
- Defined in:
- lib/dashboarder/api.rb
Instance Method Summary collapse
- #api_pass ⇒ Object
- #api_url ⇒ Object
- #api_user ⇒ Object
- #connect ⇒ Object
- #connection ⇒ Object
- #get(path, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Api
constructor
A new instance of Api.
- #post(path, body, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Api
Returns a new instance of Api.
3 4 5 6 7 8 |
# File 'lib/dashboarder/api.rb', line 3 def initialize(={}) @options = @options[:api_url] = Config.librato_api_url || 'https://metrics-api.librato.com' @options[:api_user] = Config.librato_email @options[:api_pass] = Config.librato_key end |
Instance Method Details
#api_pass ⇒ Object
35 36 37 |
# File 'lib/dashboarder/api.rb', line 35 def api_pass @options[:api_pass] end |
#api_url ⇒ Object
27 28 29 |
# File 'lib/dashboarder/api.rb', line 27 def api_url @options[:api_url] end |
#api_user ⇒ Object
31 32 33 |
# File 'lib/dashboarder/api.rb', line 31 def api_user @options[:api_user] end |
#connect ⇒ Object
22 23 24 25 |
# File 'lib/dashboarder/api.rb', line 22 def connect uri = URI.parse(@options[:api_url]) Excon.new(api_url, :headers => { 'Authorization' => 'Basic ' + [api_user.sub('%40', '@') + ':' + api_pass].pack('m').delete(Excon::CR_NL) }) end |
#connection ⇒ Object
10 11 12 |
# File 'lib/dashboarder/api.rb', line 10 def connection @connection ||= connect end |
#get(path, options = {}) ⇒ Object
14 15 16 |
# File 'lib/dashboarder/api.rb', line 14 def get(path, = {}) JSON.load(connection.get(.merge(:path => path, :idempotent => true)).body) end |
#post(path, body, options = {}) ⇒ Object
18 19 20 |
# File 'lib/dashboarder/api.rb', line 18 def post(path, body, = {}) JSON.load(connection.post(.merge(:path => path, :body => body.to_json, :headers => { 'Content-Type' => 'application/json' })).body) end |