Class: Dashbeautiful::API
- Inherits:
-
Object
- Object
- Dashbeautiful::API
- Defined in:
- lib/dashbeautiful/api.rb
Overview
description TODO
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #devices(network_id) ⇒ Object
- #get(path, **options) ⇒ Object
-
#initialize(key, requestor: HTTParty) ⇒ API
constructor
A new instance of API.
- #networks(organization_id) ⇒ Object
- #organizations ⇒ Object
- #put(path, valid_keys:, body:, **options) ⇒ Object
- #update_organization(organization_id, body) ⇒ Object
Constructor Details
#initialize(key, requestor: HTTParty) ⇒ API
Returns a new instance of API.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dashbeautiful/api.rb', line 8 def initialize(key, requestor: HTTParty) @key = key @base_url = 'https://api.meraki.com/api/v0' @headers = { 'X-Cisco-Meraki-API-Key' => key, 'Content-Type' => 'application/json' } @options = { headers: @headers } @requestor = requestor end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/dashbeautiful/api.rb', line 6 def key @key end |
Instance Method Details
#devices(network_id) ⇒ Object
38 39 40 |
# File 'lib/dashbeautiful/api.rb', line 38 def devices(network_id) get("/networks/#{network_id}/devices").map { |h| symbolize_keys(h) } end |
#get(path, **options) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/dashbeautiful/api.rb', line 42 def get(path, **) = @options.merge() response = @requestor.get(@base_url + path, ) raise APIRequestError if response.code != 200 response end |
#networks(organization_id) ⇒ Object
34 35 36 |
# File 'lib/dashbeautiful/api.rb', line 34 def networks(organization_id) get("/organizations/#{organization_id}/networks").map { |h| symbolize_keys(h) } end |
#organizations ⇒ Object
21 22 23 |
# File 'lib/dashbeautiful/api.rb', line 21 def organizations get('/organizations').map { |h| symbolize_keys(h) } end |
#put(path, valid_keys:, body:, **options) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dashbeautiful/api.rb', line 51 def put(path, valid_keys:, body:, **) raise ArgumentError, "body key can only be #{valid_keys}" unless valid_keys.all? { |key| body.key? key } = @options.merge() = .merge(body: body.to_json) response = @requestor.put(@base_url + path, ) raise APIRequestError if response.code != 200 response end |
#update_organization(organization_id, body) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/dashbeautiful/api.rb', line 25 def update_organization(organization_id, body) valid_keys = %i[name] raise ArgumentError, 'body must be a hash' unless body.is_a? Hash raise ArgumentError, 'body cannot be empty' if body.empty? put("/organizations/#{organization_id}", valid_keys: valid_keys, body: body) end |