Module: Mackerel::Connection
- Included in:
- Client
- Defined in:
- lib/mackerel/connection.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #delete(url) ⇒ Object
- #get(url, params = {}) ⇒ Object
- #post(url, params = {}) ⇒ Object
- #put(url, params = {}) ⇒ Object
- #request(method, url, params = {}) ⇒ Object
Instance Method Details
#connection ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/mackerel/connection.rb', line 35 def connection @connection ||= Faraday.new(url: config.api_endpoint, headers: config.http_request_headers, request: config.request, proxy: config.proxy) do |faraday| faraday.use Mackerel::Response::RaiseError faraday.use Faraday::Response::Logger if ENV['DEBUG'] == '1' faraday.use FaradayMiddleware::Mashify faraday.use FaradayMiddleware::ParseJson faraday.adapter Faraday.default_adapter end end |
#delete(url) ⇒ Object
25 26 27 28 29 |
# File 'lib/mackerel/connection.rb', line 25 def delete(url) connection.delete(url) do |req| req.headers['Content-Type'] = 'application/json' end end |
#get(url, params = {}) ⇒ Object
7 8 9 |
# File 'lib/mackerel/connection.rb', line 7 def get(url, params = {}) connection.get(url, params) end |
#post(url, params = {}) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/mackerel/connection.rb', line 11 def post(url, params = {}) connection.post(url) do |req| req.headers['Content-Type'] = 'application/json' req.body = params.to_json end end |
#put(url, params = {}) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/mackerel/connection.rb', line 18 def put(url, params = {}) connection.put(url) do |req| req.headers['Content-Type'] = 'application/json' req.body = params.to_json end end |
#request(method, url, params = {}) ⇒ Object
31 32 33 |
# File 'lib/mackerel/connection.rb', line 31 def request(method, url, params = {}) connection.send(method, url, params) end |