Class: DashboardAPI
- Inherits:
-
Object
- Object
- DashboardAPI
- Includes:
- Admins, Clients, DashboardAPIVersion, Devices, HTTParty, Networks, Organizations, Phones, SAML, SSIDs, Switchports, Templates, VLANs
- Defined in:
- lib/dashboard-api.rb
Overview
Ruby Implementation of the Meraki Dashboard api
Constant Summary
Constants included from DashboardAPIVersion
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key) ⇒ DashboardAPI
constructor
A new instance of DashboardAPI.
-
#make_api_call(endpoint_url, http_method, options_hash = {}) ⇒ Object
Inner function, not to be called directly.
Methods included from SAML
#create_saml_role, #list_saml_roles, #remove_saml_role, #return_saml_role, #update_saml_role
Methods included from Templates
#list_templates, #remove_template
Methods included from Phones
#add_phone_contact, #delete_phone_contact, #list_phone_contacts, #update_phone_contact
Methods included from VLANs
#add_vlan, #delete_vlan, #list_vlans, #return_vlan, #update_vlan
Methods included from Switchports
#get_single_switch_port, #get_switch_ports, #update_switchport
Methods included from Admins
#add_admin, #list_admins, #revoke_admin, #update_admin
Methods included from SSIDs
#get_single_ssid, #list_ssids_in_network, #update_single_ssid
Methods included from Devices
#claim_device_into_network, #get_device_uplink_stats, #get_single_device, #list_devices_in_network, #remove_device_from_network, #update_device_attributes
Methods included from Clients
Methods included from Networks
#bind_network_to_template, #create_network, #delete_network, #get_auto_vpn_settings, #get_ms_access_policies, #get_networks, #get_single_network, #traffic_analysis, #unbind_network_to_template, #update_auto_vpn_settings, #update_network
Methods included from Organizations
#claim, #clone_organization, #create_organization, #get_inventory, #get_license_state, #get_organization, #get_snmp_settings, #get_third_party_peers, #list_all_organizations, #update_organization, #update_snmp_settings, #update_third_party_peers
Constructor Details
#initialize(key) ⇒ DashboardAPI
Returns a new instance of DashboardAPI.
36 37 38 |
# File 'lib/dashboard-api.rb', line 36 def initialize(key) @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
34 35 36 |
# File 'lib/dashboard-api.rb', line 34 def key @key end |
Instance Method Details
#make_api_call(endpoint_url, http_method, options_hash = {}) ⇒ Object
Eventually this will need to support POST, PUT and DELETE. It also needs to be a bit more resillient, instead of relying on HTTParty for exception handling
Inner function, not to be called directly
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/dashboard-api.rb', line 45 def make_api_call(endpoint_url, http_method, ={}) headers = {"X-Cisco-Meraki-API-Key" => @key, 'Content-Type' => 'application/json'} = {:headers => headers, :body => .to_json} case http_method when 'GET' res = HTTParty.get("#{self.class.base_uri}/#{endpoint_url}", ) raise "404 returned. Are you sure you are using the proper IDs?" if res.code == 404 raise "Bad request due to the following error(s): #{JSON.parse(res.body)['errors']}" if res.body.include?('errors') return JSON.parse(res.body) when 'POST' res = HTTParty.post("#{self.class.base_uri}/#{endpoint_url}", ) raise "Bad Request due to the following error(s): #{res['errors']}" if res['errors'] raise "404 returned. Are you sure you are using the proper IDs?" if res.code == 404 begin return JSON.parse(res.body) rescue JSON::ParserError => e return res.code rescue TypeError => e return res.code end when 'PUT' res = HTTParty.put("#{self.class.base_uri}/#{endpoint_url}", ) # needs to check for is an array, because when you update a 3rd party VPN peer, it returns as an array # if you screw something up, it returns as a Hash, and will hit the normal if res['errors' (raise "Bad Request due to the following error(s): #{res['errors']}" if res['errors']) unless JSON.parse(res.body).is_a? Array raise "404 returned. Are you sure you are using the proper IDs?" if res.code == 404 return JSON.parse(res.body) when 'DELETE' res = HTTParty.delete("#{self.class.base_uri}/#{endpoint_url}", ) raise "Bad Request due to the following error(s): #{res['errors']}" if res['errors'] raise "404 returned. Are you sure you are using the proper IDs?" if res.code == 404 return res else raise 'Invalid HTTP Method. Only GET, POST, PUT and DELETE are supported.' end end |