Class: Pingdom::Client
- Inherits:
-
Object
- Object
- Pingdom::Client
- Defined in:
- lib/pingdom/client.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
Returns the value of attribute conn.
-
#key ⇒ Object
Returns the value of attribute key.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #get(params: {}, path: '') ⇒ Object
- #has_connection? ⇒ Boolean
-
#initialize(u: nil, p: nil, k: nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(u: nil, p: nil, k: nil) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 |
# File 'lib/pingdom/client.rb', line 9 def initialize u: nil , p: nil, k: nil @username= u || ENV['PINGDOM_USERNAME'] @password= p || ENV['PINGDOM_PASSWORD'] @key= k || ENV['PINGDOM_KEY'] @conn = Faraday.new(url: 'https://api.pingdom.com' ) @conn.basic_auth(username, password) end |
Instance Attribute Details
#conn ⇒ Object
Returns the value of attribute conn.
7 8 9 |
# File 'lib/pingdom/client.rb', line 7 def conn @conn end |
#key ⇒ Object
Returns the value of attribute key.
7 8 9 |
# File 'lib/pingdom/client.rb', line 7 def key @key end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/pingdom/client.rb', line 7 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/pingdom/client.rb', line 7 def username @username end |
Instance Method Details
#get(params: {}, path: '') ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pingdom/client.rb', line 21 def get( params: {} , path: '' ) conn.get do |req| req.url "/api/#{ENV['PINGDOM_API_VERSION'] || '2.0'}#{path}" req.params=params req.headers['Content-Type'] = 'application/json' req.headers['App-Key'] = key end end |
#has_connection? ⇒ Boolean
17 18 19 |
# File 'lib/pingdom/client.rb', line 17 def has_connection? get( params: { limit: 1 }, path: '/checks').status == 200 end |