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_enfnw(subnet) ⇒ Object
- #authenticate(host, user, password) ⇒ Object
- #cancel_invite(email) ⇒ Object
- #create_domain(domain_hash) ⇒ Object
- #create_nw(nw_hash) ⇒ 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
- #get_nw(network_cidr) ⇒ 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_domain_status(domain_network, status) ⇒ Object
- #update_endpoint(ipv6, name) ⇒ Object
- #update_ep_rate_limits(ipv6, limit, limits_hash) ⇒ Object
- #update_network_rate_limits(network, limit, limits_hash) ⇒ Object
- #update_nw(network_cidr, nw_hash) ⇒ Object
- #update_user_status(user_id, status) ⇒ Object
Instance Attribute Details
#api ⇒ Object
Returns the value of attribute api.
301 302 303 |
# File 'lib/enfapi.rb', line 301 def api @api end |
#headers ⇒ Object
Returns the value of attribute headers.
301 302 303 |
# File 'lib/enfapi.rb', line 301 def headers @headers end |
Instance Method Details
#activate_enfnw(subnet) ⇒ Object
503 504 505 506 507 |
# File 'lib/enfapi.rb', line 503 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
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/enfapi.rb', line 303 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
528 529 530 531 532 |
# File 'lib/enfapi.rb', line 528 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
387 388 389 390 391 392 |
# File 'lib/enfapi.rb', line 387 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
449 450 451 452 453 454 455 |
# File 'lib/enfapi.rb', line 449 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 |
#delete(request_uri) ⇒ Object
354 355 356 357 358 |
# File 'lib/enfapi.rb', line 354 def delete(request_uri) @api[request_uri].delete(@headers) {|response, request, result| process_api_response response, request, result } end |
#get(request_uri) ⇒ Object
336 337 338 339 340 |
# File 'lib/enfapi.rb', line 336 def get(request_uri) @api[request_uri].get(@headers) {|response, request, result| process_api_response response, request, result } end |
#get_domain(domain_id) ⇒ Object
381 382 383 384 385 |
# File 'lib/enfapi.rb', line 381 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
415 416 417 418 419 420 421 422 |
# File 'lib/enfapi.rb', line 415 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
488 489 490 491 492 |
# File 'lib/enfapi.rb', line 488 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
433 434 435 436 437 438 439 440 |
# File 'lib/enfapi.rb', line 433 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
424 425 426 427 428 429 430 431 |
# File 'lib/enfapi.rb', line 424 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 |
#get_nw(network_cidr) ⇒ Object
464 465 466 467 468 |
# File 'lib/enfapi.rb', line 464 def get_nw(network_cidr) @api["/api/xcr/v2/nws/#{network_cidr}"].get(@headers) {|response, request, result| process_api_response response, request, result } end |
#invite(domain_network, hash) ⇒ Object
521 522 523 524 525 526 |
# File 'lib/enfapi.rb', line 521 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
515 516 517 518 519 |
# File 'lib/enfapi.rb', line 515 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
363 364 365 366 367 |
# File 'lib/enfapi.rb', line 363 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
509 510 511 512 513 |
# File 'lib/enfapi.rb', line 509 def list_domain_users(domain_network) @api["/api/xcr/v2/domains/#{domain_network}/users"].get( @headers) {|response, request, result| process_api_response response, request, result } end |
#list_domains ⇒ Object
375 376 377 378 379 |
# File 'lib/enfapi.rb', line 375 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
476 477 478 479 480 |
# File 'lib/enfapi.rb', line 476 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
369 370 371 372 373 |
# File 'lib/enfapi.rb', line 369 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
482 483 484 485 486 |
# File 'lib/enfapi.rb', line 482 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
470 471 472 473 474 |
# File 'lib/enfapi.rb', line 470 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
342 343 344 345 346 |
# File 'lib/enfapi.rb', line 342 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
348 349 350 351 352 |
# File 'lib/enfapi.rb', line 348 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
534 535 536 537 538 |
# File 'lib/enfapi.rb', line 534 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
394 395 396 397 398 399 |
# File 'lib/enfapi.rb', line 394 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_domain_status(domain_network, status) ⇒ Object
442 443 444 445 446 447 |
# File 'lib/enfapi.rb', line 442 def update_domain_status(domain_network, status) json = to_json(status) @api["/api/xcr/v2/domains/#{domain_network}/status"].put(json, @headers) {|response, request, result| process_api_response response, request, result } end |
#update_endpoint(ipv6, name) ⇒ Object
494 495 496 497 498 499 500 501 |
# File 'lib/enfapi.rb', line 494 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
408 409 410 411 412 413 |
# File 'lib/enfapi.rb', line 408 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
401 402 403 404 405 406 |
# File 'lib/enfapi.rb', line 401 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 |
#update_nw(network_cidr, nw_hash) ⇒ Object
457 458 459 460 461 462 |
# File 'lib/enfapi.rb', line 457 def update_nw(network_cidr, nw_hash) json = to_json(nw_hash) @api["/api/xcr/v2/nws/#{network_cidr}"].put(json, @headers) {|response, request, result| process_api_response response, request, result } end |
#update_user_status(user_id, status) ⇒ Object
540 541 542 543 544 545 |
# File 'lib/enfapi.rb', line 540 def update_user_status(user_id, status) json = to_json( status ) @api["/api/xcr/v2/users/#{user_id}/status"].put( json, @headers) { |response, request, result| process_api_response response, request, result } end |