forked from meraki/automation-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetNetworks.rb
32 lines (25 loc) · 857 Bytes
/
getNetworks.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'faraday'
require 'faraday_middleware'
require 'json'
# Define the following vars in your bash/zsh profile
#
# export DASHBOARD_API_KEY='api-key-here'
# export DASHBOARD_API_SHARD_ID='XX'
# export DASHBOARD_API_ORG_ID='X'
dash_api_key = ENV['DASHBOARD_API_KEY']
dash_org_id = ENV['DASHBOARD_API_ORG_ID']
dash_shard_id = ENV['DASHBOARD_API_SHARD_ID']
conn = Faraday.new(:url => "https://#{dash_shard_id}.meraki.com") do |faraday|
faraday.request :url_encoded
faraday.response :json
faraday.adapter Faraday.default_adapter
end
response = conn.get do |request|
request.url "api/v0/organizations/#{dash_org_id}/networks"
request.headers['X-Cisco-Meraki-API-Key'] = "#{dash_api_key}"
request.headers['Content-Type'] = 'application/json'
end
hash_array = response.body
hash_array.each do |x|
puts "#{x['id']} :: #{x['name']}"
end