Class: Courgette::Client
- Inherits:
-
Object
- Object
- Courgette::Client
- Includes:
- HTTParty
- Defined in:
- lib/courgette/client.rb
Instance Method Summary collapse
- #devices ⇒ Object
-
#initialize(aubergine, token) ⇒ Client
constructor
A new instance of Client.
- #update_device(ip, configuration) ⇒ Object
Constructor Details
#initialize(aubergine, token) ⇒ Client
Returns a new instance of Client.
5 6 7 8 |
# File 'lib/courgette/client.rb', line 5 def initialize(aubergine, token) @base = aubergine @headers = { headers: { 'Courgette' => token } } end |
Instance Method Details
#devices ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/courgette/client.rb', line 10 def devices response = self.class.get("#{@base}/configuration.json", @headers) if response.code == 200 response.parsed_response.map { |raw| Device.new(raw) } else raise "Configuration not found." end end |
#update_device(ip, configuration) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/courgette/client.rb', line 19 def update_device(ip, configuration) response = self.class.post("#{@base}/devices/#{ip}", @headers.merge(body: { configuration: configuration })) if [200, 201, 202].include?(response.code) { 200 => "no changes", 201 => "created", 202 => "updated" }[response.code] else raise "Can't push configuration." end end |