Class: EnfApi::API
Instance Attribute Summary collapse
-
#api ⇒ Object
Returns the value of attribute api.
-
#headers ⇒ Object
Returns the value of attribute headers.
Instance Method Summary collapse
- #activate_domain(domain_network) ⇒ Object
- #activate_enfnw(subnet) ⇒ Object
- #authenticate(host, user, password) ⇒ Object
- #cancel_invite(email) ⇒ Object
- #create_domain(domain_hash) ⇒ Object
- #create_nw(nw_hash) ⇒ Object
- #deactivate_domain(domain_network) ⇒ Object
- #delete(request_uri) ⇒ Object
- #get(request_uri) ⇒ Object
- #get_domain(domain_id) ⇒ Object
- #get_domain_rate_limits(domain_network, filter = nil) ⇒ Object
- #get_endpoint(ipv6) ⇒ Object
- #get_ep_rate_limits(ipv6, filter = nil) ⇒ Object
- #get_network_rate_limits(network, filter = nil) ⇒ Object
- #invite(domain_network, hash) ⇒ Object
- #list_domain_invites(domain_network) ⇒ Object
-
#list_domain_nws(domain_id) ⇒ Object
NOT READY API.
- #list_domain_users(domain_network) ⇒ Object
- #list_domains ⇒ Object
- #list_endpoint_events(ipv6) ⇒ Object
- #list_enfnws ⇒ Object
- #list_network_events(network_cidr) ⇒ Object
- #list_nw_connections(domain_id, network_cidr, file = nil) ⇒ Object
- #post(request_uri, request_body = '') ⇒ Object
- #put(request_uri, request_body = '') ⇒ Object
- #resend_invite(email) ⇒ Object
- #update_domain_rate_limits(domain_network, limit, limits_hash) ⇒ Object
- #update_endpoint(ipv6, name) ⇒ Object
- #update_ep_rate_limits(ipv6, limit, limits_hash) ⇒ Object
- #update_network_rate_limits(network, limit, limits_hash) ⇒ Object
Instance Attribute Details
#api ⇒ Object
Returns the value of attribute api.
110 111 112 |
# File 'lib/enfapi.rb', line 110 def api @api end |
#headers ⇒ Object
Returns the value of attribute headers.
110 111 112 |
# File 'lib/enfapi.rb', line 110 def headers @headers end |
Instance Method Details
#activate_domain(domain_network) ⇒ Object
251 252 253 254 255 |
# File 'lib/enfapi.rb', line 251 def activate_domain(domain_network) @api["/api/xcr/v2/domains/#{domain_network}/status"].put( '', @headers) {|response, request, result| process_api_response response, request, result } end |
#activate_enfnw(subnet) ⇒ Object
304 305 306 307 308 |
# File 'lib/enfapi.rb', line 304 def activate_enfnw(subnet) @api["/api/xcr/v2/enfnws/#{subnet}"].put( '', @headers) {|response, request, result| process_api_response response, request, result } end |
#authenticate(host, user, password) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/enfapi.rb', line 112 def authenticate(host, user, password) # format url host = "https://#{host}" unless host =~ /^(http|https):\/\// # chomp trailing '/' host = host.chomp("/") # Initalize rest client @api = RestClient::Resource.new(host) # Create request json hash = { :username => user, :token => password } json = to_json( hash ) # call api @api["/api/xcr/v2/xauth"].post( json, {content_type: :json, accept: :json}) { |response, request, result| case response.code when 200 # get resp from json resp = from_json(response.body) # set request headers for subsequent api calls token = resp[:data][0][:token] @headers = {content_type: :json, accept: :json, "Authorization" => "Bearer #{token}"} # return resp resp else raise EnfApi::ERROR, "Login Failed! Invalid user or password!" end } end |
#cancel_invite(email) ⇒ Object
330 331 332 333 334 |
# File 'lib/enfapi.rb', line 330 def cancel_invite(email) @api["/api/xcr/v2/invites/#{email}"].delete( @headers) {|response, request, result| process_api_response response, request, result } end |
#create_domain(domain_hash) ⇒ Object
196 197 198 199 200 201 |
# File 'lib/enfapi.rb', line 196 def create_domain(domain_hash) json = to_json( domain_hash ) @api["/api/xcr/v2/domains"].post( json, @headers) {|response, request, result| process_api_response response, request, result } end |
#create_nw(nw_hash) ⇒ Object
263 264 265 266 267 268 269 |
# File 'lib/enfapi.rb', line 263 def create_nw(nw_hash) json = to_json(nw_hash) domain_id = nw_hash[:domain_id] @api["/api/xcr/v2/domains/#{domain_id}/nws"].post(json, @headers) {|response, request, result| process_api_response response, request, result } end |
#deactivate_domain(domain_network) ⇒ Object
257 258 259 260 261 |
# File 'lib/enfapi.rb', line 257 def deactivate_domain(domain_network) @api["/api/xcr/v2/domains/#{domain_network}/status"].delete( @headers) {|response, request, result| process_api_response response, request, result } end |
#delete(request_uri) ⇒ Object
163 164 165 166 167 |
# File 'lib/enfapi.rb', line 163 def delete(request_uri) @api[request_uri].delete(@headers) {|response, request, result| process_api_response response, request, result } end |
#get(request_uri) ⇒ Object
145 146 147 148 149 |
# File 'lib/enfapi.rb', line 145 def get(request_uri) @api[request_uri].get(@headers) {|response, request, result| process_api_response response, request, result } end |
#get_domain(domain_id) ⇒ Object
190 191 192 193 194 |
# File 'lib/enfapi.rb', line 190 def get_domain(domain_id) @api["/api/xcr/v2/domains/#{domain_id}"].get( @headers) {|response, request, result| process_api_response response, request, result } end |
#get_domain_rate_limits(domain_network, filter = nil) ⇒ Object
224 225 226 227 228 229 230 231 |
# File 'lib/enfapi.rb', line 224 def get_domain_rate_limits(domain_network, filter = nil) api_url = "/api/xcr/v2/domains/#{domain_network}/ep_rate_limits" api_url = "#{api_url}/#{filter}" if filter @api[api_url].get( @headers) {|response, request, result| process_api_response response, request, result } end |
#get_endpoint(ipv6) ⇒ Object
289 290 291 292 293 |
# File 'lib/enfapi.rb', line 289 def get_endpoint(ipv6) @api["/api/xcr/v2/cxns/#{ipv6}"].get(@headers) {|response, request, result| process_api_response response, request, result } end |
#get_ep_rate_limits(ipv6, filter = nil) ⇒ Object
242 243 244 245 246 247 248 249 |
# File 'lib/enfapi.rb', line 242 def get_ep_rate_limits(ipv6, filter = nil) api_url = "/api/xcr/v2/cxns/#{ipv6}/ep_rate_limits" api_url = "#{api_url}/#{filter}" if filter @api[api_url].get( @headers) {|response, request, result| process_api_response response, request, result } end |
#get_network_rate_limits(network, filter = nil) ⇒ Object
233 234 235 236 237 238 239 240 |
# File 'lib/enfapi.rb', line 233 def get_network_rate_limits(network, filter = nil) api_url = "/api/xcr/v2/nws/#{network}/ep_rate_limits" api_url = "#{api_url}/#{filter}" if filter @api[api_url].get( @headers) {|response, request, result| process_api_response response, request, result } end |
#invite(domain_network, hash) ⇒ Object
323 324 325 326 327 328 |
# File 'lib/enfapi.rb', line 323 def invite(domain_network, hash) json = to_json( hash ) @api["/api/xcr/v2/domains/#{domain_network}/invites"].post( json, @headers) { |response, request, result| process_api_response response, request, result } end |
#list_domain_invites(domain_network) ⇒ Object
317 318 319 320 321 |
# File 'lib/enfapi.rb', line 317 def list_domain_invites(domain_network) @api["/api/xcr/v2/domains/#{domain_network}/invites"].get(@headers) {|response, request, result| process_api_response response, request, result } end |
#list_domain_nws(domain_id) ⇒ Object
NOT READY API. MOVE ABOVE THIS LINE AFTER RSPEC OR INTO OWN CLASS
172 173 174 175 176 |
# File 'lib/enfapi.rb', line 172 def list_domain_nws(domain_id) @api["/api/xcr/v2/domains/#{domain_id}/nws"].get(@headers) {|response, request, result| process_api_response response, request, result } end |
#list_domain_users(domain_network) ⇒ Object
310 311 312 313 314 315 |
# File 'lib/enfapi.rb', line 310 def list_domain_users(domain_network) @api["/api/xcr/v2/domains/#{domain_network}/users"].get( @headers) {|response, request, result| puts response.code process_api_response response, request, result } end |
#list_domains ⇒ Object
184 185 186 187 188 |
# File 'lib/enfapi.rb', line 184 def list_domains @api["/api/xcr/v2/domains"].get( @headers) {|response, request, result| process_api_response response, request, result } end |
#list_endpoint_events(ipv6) ⇒ Object
277 278 279 280 281 |
# File 'lib/enfapi.rb', line 277 def list_endpoint_events(ipv6) @api["/api/xcr/v2/cxns/#{ipv6}/events"].get(@headers) {|response, request, result| process_api_response response, request, result } end |
#list_enfnws ⇒ Object
178 179 180 181 182 |
# File 'lib/enfapi.rb', line 178 def list_enfnws @api["/api/xcr/v2/enfnws"].get( @headers) {|response, request, result| process_api_response response, request, result } end |
#list_network_events(network_cidr) ⇒ Object
283 284 285 286 287 |
# File 'lib/enfapi.rb', line 283 def list_network_events(network_cidr) @api["/api/xcr/v2/nws/#{network_cidr}/events"].get(@headers) {|response, request, result| process_api_response response, request, result } end |
#list_nw_connections(domain_id, network_cidr, file = nil) ⇒ Object
271 272 273 274 275 |
# File 'lib/enfapi.rb', line 271 def list_nw_connections(domain_id, network_cidr, file = nil) @api["/api/xcr/v2/domains/#{domain_id}/nws/#{network_cidr}/cxns"].get(@headers) {|response, request, result| process_api_response response, request, result } end |
#post(request_uri, request_body = '') ⇒ Object
151 152 153 154 155 |
# File 'lib/enfapi.rb', line 151 def post(request_uri, request_body = '') @api[request_uri].post(request_body, @headers) {|response, request, result| process_api_response response, request, result } end |
#put(request_uri, request_body = '') ⇒ Object
157 158 159 160 161 |
# File 'lib/enfapi.rb', line 157 def put(request_uri, request_body = '') @api[request_uri].put(request_body, @headers) {|response, request, result| process_api_response response, request, result } end |
#resend_invite(email) ⇒ Object
336 337 338 339 340 |
# File 'lib/enfapi.rb', line 336 def resend_invite(email) @api["/api/xcr/v2/invites/#{email}"].put( "{}", @headers) {|response, request, result| process_api_response response, request, result } end |
#update_domain_rate_limits(domain_network, limit, limits_hash) ⇒ Object
203 204 205 206 207 208 |
# File 'lib/enfapi.rb', line 203 def update_domain_rate_limits(domain_network, limit, limits_hash) json = to_json( limits_hash ) @api["/api/xcr/v2/domains/#{domain_network}/ep_rate_limits/#{limit}"].put( json, @headers) {|response, request, result| process_api_response response, request, result } end |
#update_endpoint(ipv6, name) ⇒ Object
295 296 297 298 299 300 301 302 |
# File 'lib/enfapi.rb', line 295 def update_endpoint(ipv6, name) hash = { :ipv6 => ipv6, :name => name } json = to_json( hash ) @api["/api/xcr/v2/cxns/#{ipv6}"].put( json, @headers) {|response, request, result| process_api_response response, request, result } end |
#update_ep_rate_limits(ipv6, limit, limits_hash) ⇒ Object
217 218 219 220 221 222 |
# File 'lib/enfapi.rb', line 217 def update_ep_rate_limits(ipv6, limit, limits_hash) json = to_json( limits_hash ) @api["/api/xcr/v2/cxns/#{ipv6}/ep_rate_limits/#{limit}"].put( json, @headers) {|response, request, result| process_api_response response, request, result } end |
#update_network_rate_limits(network, limit, limits_hash) ⇒ Object
210 211 212 213 214 215 |
# File 'lib/enfapi.rb', line 210 def update_network_rate_limits(network, limit, limits_hash) json = to_json( limits_hash ) @api["/api/xcr/v2/nws/#{network}/ep_rate_limits/#{limit}"].put( json, @headers) {|response, request, result| process_api_response response, request, result } end |