Class: Rappfirst::Client
- Inherits:
-
Object
- Object
- Rappfirst::Client
- Includes:
- HTTParty
- Defined in:
- lib/rappfirst/client.rb
Instance Method Summary collapse
- #alert(id, json_data = nil) ⇒ Object
- #alerts ⇒ Object
-
#initialize(username = nil, api_key = nil) ⇒ Client
constructor
A new instance of Client.
- #server(id) ⇒ Object
- #servers(query_string = nil) ⇒ Object
Constructor Details
#initialize(username = nil, api_key = nil) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 11 12 13 14 |
# File 'lib/rappfirst/client.rb', line 6 def initialize(username=nil, api_key=nil) if username.nil? || api_key.nil? config = YAML::load( File.open( 'config.yml') ) username = config['username'] api_key = config['password'] end self.class.basic_auth username, api_key self.class.base_uri 'https://wwws.appfirst.com/api' end |
Instance Method Details
#alert(id, json_data = nil) ⇒ Object
43 44 45 46 |
# File 'lib/rappfirst/client.rb', line 43 def alert(id, json_data=nil) = self.class. Rappfirst::Alert.new(id, =, json_data=json_data) end |
#alerts ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/rappfirst/client.rb', line 34 def alerts response = get_alerts alerts = Array.new response.each do |r| alerts << alert(r['id'], json_data=r) end return alerts end |
#server(id) ⇒ Object
29 30 31 32 |
# File 'lib/rappfirst/client.rb', line 29 def server(id) = self.class. Rappfirst::Server.new(id, =) end |
#servers(query_string = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rappfirst/client.rb', line 16 def servers(query_string=nil) response = get_servers(query_string) if response.length == 1 && query_string return server(response.first['id']) else s = Array.new response.each do |r| s << server(r['id']) end return s end end |