Class: Pingdom::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pingdom/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#connObject

Returns the value of attribute conn.



7
8
9
# File 'lib/pingdom/client.rb', line 7

def conn
  @conn
end

#keyObject

Returns the value of attribute key.



7
8
9
# File 'lib/pingdom/client.rb', line 7

def key
  @key
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/pingdom/client.rb', line 7

def password
  @password
end

#usernameObject

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

Returns:

  • (Boolean)


17
18
19
# File 'lib/pingdom/client.rb', line 17

def has_connection?
  get( params: { limit: 1 }, path: '/checks').status == 200
end