These client examples are provided here as supplementary material for the appendix to our API Manual, where further instructions and a full explanation of the call details can be found.
API Examples Using curl
GET cid
1
2
3
|
curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \ -H "Accept: application/json" \ |
PUT cid
1
2
3
4
5
|
curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \ -H "Accept: application/json" \ -X PUT \ --data-binary '{"firstname":"Gonzo"}' \ |
DELETE cid
1
2
3
4
|
curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \ -H "Accept: application/json" \ -X DELETE \ |
POST type
1
2
3
4
5
|
curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \ -H "Accept: application/json" \ -X POST \ --data-binary '{"title":"Big Bird''s Birthday","description":"Big Bird is six (again)","start": 1332216000,"stop":1332302399}' \ |
GET type
1
2
3
|
curl --user ExampleApp:fb349ef1-91e4-4b05-aaa2-52246b77ea66 \ -H "Accept: application/json" \ |
API Examples Using node.js
GET cid
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
33
34
35
|
#!/usr/bin/env node // load the https module var https = require( 'https' );
https.request({ host: 'api.circonus.com' ,
path: '/user/current' ,
headers: { 'X-Circonus-App-Name' : 'ExampleApp' ,
'X-Circonus-Auth-Token' : 'fb349ef1-91e4-4b05-aaa2-52246b77ea66' ,
'Accept' : 'application/json'
} }, function (response) {
// collect the body while we're getting chunks of it var body = ' ';
response.on(' data ', function (chunk) { body += chunk; });
// once we' ve got 'em all, handle them
response.on(' end', function () {
// parse the JSON body result = JSON.parse(body); // handle errors by extracting the code/message from the response if (response.statusCode < 200 || response.statusCode >= 300) {
console.log( response.statusCode + ": " + result.code + " (" + result.message + ")" );
return ;
} // result holds the data from the server console.log( "Hello " +result.firstname+ " " +result.lastname);
}); }).end(); |
PUT cid
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
33
34
35
36
37
38
39
40
41
42
43
|
#!/usr/bin/env node // load the https module var https = require( 'https' );
var r = https.request({
host: 'api.circonus.com' ,
path: '/user/current' ,
headers: { 'X-Circonus-App-Name' : 'ExampleApp' ,
'X-Circonus-Auth-Token' : 'fb349ef1-91e4-4b05-aaa2-52246b77ea66' ,
'Accept' : 'application/json'
}, method: "PUT"
}, function (response) {
// collect the body while we're getting chunks of it var body = ' ';
response.on(' data ', function (chunk) { body += chunk; });
// once we' ve got 'em all, handle them
response.on(' end ', function () {
// parse the JSON body result = JSON.parse(body); // handle errors by extracting the code/message from the response if (response.statusCode < 200 || response.statusCode >= 300) { console.log( response.statusCode + ": " + result.code + " (" + result.message + ")"); return; } // print out the new name console.log("Your firstname is now " + result.firstname); }); }); // here' s where we specify the updates for the user 's firstname
r.write(JSON.stringify({ ' firstname': "Gonzo"
})); r.end(); |
DELETE cid
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
33
34
|
#!/usr/bin/env node // load the https module var https = require( 'https' );
https.request({ host: 'api.circonus.com' ,
path: '/graph/123456' ,
headers: { 'X-Circonus-App-Name' : 'ExampleApp' ,
'X-Circonus-Auth-Token' : 'fb349ef1-91e4-4b05-aaa2-52246b77ea66' ,
'Accept' : 'application/json'
}, method: "DELETE"
}, function (response) {
// collect the body while we're getting chunks of it var body = ' ';
response.on(' data ', function (chunk) { body += chunk; });
// once we' ve got 'em all, handle them
response.on(' end', function () {
// handle errors by extracting the code/message from the response if (response.statusCode < 200 || response.statusCode >= 300) {
result = JSON.parse(body); console.log( response.statusCode + ": " + result.code + " (" + result.message + ")" );
return ;
} console.log( "DELETED!" );
}); }).end(); |
POST type
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#!/usr/bin/env node // load the https module var https = require( 'https' );
var r = https.request({
host: 'api.circonus.com' ,
path: '/annotation' ,
headers: { 'X-Circonus-App-Name' : 'ExampleApp' ,
'X-Circonus-Auth-Token' : 'fb349ef1-91e4-4b05-aaa2-52246b77ea66' ,
'Accept' : 'application/json'
}, method: "POST"
}, function (response) {
// collect the body while we're getting chunks of it var body = ' ';
response.on(' data ', function (chunk) { body += chunk; });
// once we' ve got 'em all, handle them
response.on(' end ', function () {
// parse the JSON body result = JSON.parse(body); // handle errors by extracting the code/message from the response if (response.statusCode < 200 || response.statusCode >= 300) { console.log( response.statusCode + ": " + result.code + " (" + result.message + ")"); return; } // print the new annotation details console.log("Created annotation: " + result[' _cid '] +
" (" + result.title + ")" ); }); }); // here' s where we specify the values for the new object
r.write(JSON.stringify({ 'title' : "Big Bird's Birthday" ,
'description ': "Big Bird is six (again)",
' start ': 1332216000,
' stop': 1332302399
})); r.end(); |
GET type
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
33
34
35
36
37
38
39
|
#!/usr/bin/env node // load the https module var https = require( 'https' );
https.request({ host: 'api.circonus.com' ,
path: '/user' ,
headers: { 'X-Circonus-App-Name' : 'ExampleApp' ,
'X-Circonus-Auth-Token' : 'fb349ef1-91e4-4b05-aaa2-52246b77ea66' ,
'Accept' : 'application/json'
} }, function (response) {
// collect the body while we're getting chunks of it var body = ' ';
response.on(' data ', function (chunk) { body += chunk; });
// once we' ve got 'em all, handle them
response.on(' end ', function () {
// parse the JSON body result = JSON.parse(body); // handle errors by extracting the code/message from the response if (response.statusCode < 200 || response.statusCode >= 300) { console.log( response.statusCode + ": " + result.code + " (" + result.message + ")"); return; } // print out each user' s details
console.log( "Users with access to the account:" );
result.forEach( function (user) {
console.log( " * " + user[ '_cid' ]
+ " (" +user.firstname + " " + user.lastname + ")" );
}); }); }).end(); |
API Examples Using PHP
GET cid
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
|
<?php require_once 'HTTP/Request2.php' ;
$APP = "ExampleApp" ;
$TOKEN = "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ;
# talk to the server $request = new HTTP_Request2(
"https://$APP:$TOKEN@api.circonus.com/user/current" ); $request ->setHeader( "Accept" , "application/json" );
$response = $request ->send();
# decode the JSON $result = json_decode( $response ->getBody());
# deal with exceptions by accessing the returned json and throwing why
if (!preg_match( "/^2/" , $response ->getStatus())) {
throw new Exception(
$response ->getStatus(). ": " . $result ->code. " (" . $result ->message. ")"
); } # Hello World print "Hello " . $result ->firstname. " " . $result ->lastname;
?> |
PUT cid
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
|
<?php require_once 'HTTP/Request2.php' ;
$APP = "ExampleApp" ;
$TOKEN = "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ;
# talk to the server $request = new HTTP_Request2(
"https://$APP:$TOKEN@api.circonus.com/user/current" ,
HTTP_Request2::METHOD_PUT ); $request ->setHeader( "Accept" , "application/json" );
$request ->setBody(json_encode( array (
"firstname" => "Gonzo" ,
))); $response = $request ->send();
# decode the JSON $result = json_decode( $response ->getBody());
# deal with exceptions by accessing the returned json and throwing why
if (!preg_match( "/^2/" , $response ->getStatus())) {
throw new Exception(
$response ->getStatus(). ": " . $result ->code. " (" . $result ->message. ")"
); } # And access the updated result returned from the server print "Your first name is now " . $result ->firstname. "\n" ;
?> |
DELETE cid
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
|
<?php require_once 'HTTP/Request2.php' ;
$APP = "ExampleApp" ;
$TOKEN = "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ;
# talk to the server $request = new HTTP_Request2(
"https://$APP:$TOKEN@api.circonus.com/graph/123456" ,
HTTP_Request2::METHOD_DELETE ); $request ->setHeader( "Accept" , "application/json" );
$response = $request ->send();
# decode the JSON $result = json_decode( $response ->getBody());
# deal with exceptions by accessing the returned json and throwing why
if (!preg_match( "/^2/" , $response ->getStatus())) {
throw new Exception(
$response ->getStatus(). ": " . $result ->code. " (" . $result ->message. ")"
); } # Hello World print "DELETED!\n" ;
?> |
POST type
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
33
|
<? php
require_once 'HTTP/Request2.php'; $ APP = "ExampleApp" ;
$ TOKEN = "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ;
# talk to the server $ request = new HTTP_Request2(
"https://$APP:$TOKEN@api.circonus.com/annotation", HTTP_Request2::METHOD_POST ); $request->setHeader("Accept","application/json"); $request->setBody(json_encode(array( "title" => "Big Bird's Birthday", "description" => "Big Bird is six (again)", "start" => 1332216000, "stop" => 1332302399, ))); $response = $request->send(); # decode the JSON $result = json_decode($response->getBody()); # deal with exceptions by accessing the returned json and throwing why if (!preg_match("/^2/", $response->getStatus())) { throw new Exception( $response->getStatus().": ".$result->code." (".$result->message.")" ); } # print out the new cid (and other details) print "Created annotation: ".$result->_cid." (".$result->title.")\n"; ?> |
GET type
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
|
<?php require_once 'HTTP/Request2.php' ;
$APP = "ExampleApp" ;
$TOKEN = "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ;
# talk to the server $request = new HTTP_Request2(
"https://$APP:$TOKEN@api.circonus.com/user" ); $request ->setHeader( "Accept" , "application/json" );
$response = $request ->send();
# decode the JSON $result = json_decode( $response ->getBody());
# deal with exceptions by accessing the returned json and throwing why
if (!preg_match( "/^2/" , $response ->getStatus())) {
throw new Exception(
$response ->getStatus(). ": " . $result ->code. " (" . $result ->message. ")"
); } # print out each user's details
print "Users with access to the account:\n" ;
foreach ( $result as $user ) {
print " * " . $user ->_cid. " (" . $user ->firstname. " " . $user ->lastname. ")\n" ;
} ?> |
API Examples Using Perl
GET cid
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
33
|
#!/usr/bin/env perl use strict;
use warnings;
# these are core modules since 5.13.9, or install them via the CPAN # You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we # can talk over https use HTTP::Tiny;
use JSON::PP qw(decode_json) ;
# create an agent my $agent = HTTP::Tiny->new(
default_headers => {
'X-Circonus-App-Name' => 'ExampleApp' ,
'X-Circonus-Auth-Token' => 'fb349ef1-91e4-4b05-aaa2-52246b77ea66' ,
'Accept' => "application/json" ,
}, ); # talk to the API over HTTP # parse the result as JSON my $result = $response ->{content} ? decode_json $response ->{content} : {};
# handle errors unless ( $response ->{success}) {
die "$response->{status}: $result->{code} ($result->{message})\n" ;
} # result holds the data from the server result print "Hello $result->{firstname} $result->{lastname}\n" ;
|
PUT cid
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
33
34
35
36
|
#!/usr/bin/env perl use strict;
use warnings;
# these are core modules since 5.13.9, or install them via the CPAN # You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we # can talk over https use HTTP::Tiny;
use JSON::PP qw(encode_json decode_json) ;
# create an agent my $agent = HTTP::Tiny->new(
default_headers => {
'X-Circonus-App-Name' => 'ExampleApp' ,
'X-Circonus-Auth-Token' => 'fb349ef1-91e4-4b05-aaa2-52246b77ea66' ,
'Accept' => "application/json" ,
}, ); # talk to the API over HTTP content => encode_json {
firstname => "Gonzo" ,
}, }); # parse the result as JSON my $result = $response ->{content} ? decode_json $response ->{content} : {};
# handle errors unless ( $response ->{success}) {
die "$response->{status}: $result->{code} ($result->{message})\n" ;
} print "Your first name is now $result->{firstname}\n" ;
|
DELETE cid
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
|
#!/usr/bin/env perl use strict;
use warnings;
# these are core modules since 5.13.9, or install them via the CPAN # You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we # can talk over https use HTTP::Tiny;
use JSON::PP qw(decode_json) ;
# create an agent my $agent = HTTP::Tiny->new(
default_headers => {
'X-Circonus-App-Name' => 'ExampleApp' ,
'X-Circonus-Auth-Token' => 'fb349ef1-91e4-4b05-aaa2-52246b77ea66' ,
'Accept' => "application/json" ,
}, ); # talk to the API over HTTP # parse the result as JSON my $result = $response ->{content} ? decode_json $response ->{content} : {};
# handle errors unless ( $response ->{success}) {
die "$response->{status}: $result->{code} ($result->{message})\n" ;
} print "DELETED!\n" ;
|
POST type
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
33
34
35
36
37
38
39
40
|
#!/usr/bin/env perl use strict;
use warnings;
# these are core modules since 5.13.9, or install them via the CPAN # You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we # can talk over https use HTTP::Tiny;
use JSON::PP qw(encode_json decode_json) ;
# create an agent my $agent = HTTP::Tiny->new(
default_headers => {
'X-Circonus-App-Name' => 'ExampleApp' ,
'X-Circonus-Auth-Token' => 'fb349ef1-91e4-4b05-aaa2-52246b77ea66' ,
'Accept' => "application/json" ,
}, ); # talk to the API over HTTP content => encode_json {
title => "Big Bird's Birthday" ,
description => "Big Bird is six (again)" ,
start => 1332216000,
stop => 1332302399,
} }); # parse the result as JSON my $result = $response ->{content} ? decode_json $response ->{content} : {};
# handle errors unless ( $response ->{success}) {
die "$response->{status}: $result->{code} ($result->{message})\n" ;
} # print out the new cid (and other details) print "Created annotation: $result->{_cid} ($result->{title})\n" ;
|
GET type
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
33
34
35
36
|
#!/usr/bin/env perl use strict;
use warnings;
# these are core modules since 5.13.9, or install them via the CPAN # You'll also need to have installed IO::Socket::SSL 1.56 from the CPAN so we # can talk over https use HTTP::Tiny;
use JSON::PP qw(decode_json) ;
# create an agent my $agent = HTTP::Tiny->new(
default_headers => {
'X-Circonus-App-Name' => 'ExampleApp' ,
'X-Circonus-Auth-Token' => 'fb349ef1-91e4-4b05-aaa2-52246b77ea66' ,
'Accept' => "application/json" ,
}, ); # talk to the API over HTTP # parse the result as JSON my $result = $response ->{content} ? decode_json $response ->{content} : {};
# handle errors unless ( $response ->{success}) {
die "$response->{status}: $result->{code} ($result->{message})\n" ;
} # print out each user's details print "Users with access to the account:\n" ;
foreach my $user (@{ $result }) {
print " * $user->{_cid} ($user->{firstname} $user->{lastname})\n" ;
} |
API Examples Using Python
GET cid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import requests;
try :
response = requests.get(
auth = ( "ExampleApp" , "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ),
headers = { 'Accept' : "application/json" }
); response.raise_for_status() print "Hello %s %s" % (
response.json[ 'firstname' ],
response.json[ 'lastname' ]
) # deal with exceptions by accessing the returned json and printing out why except requests.exceptions.HTTPError as e:
print "%s: %s (%s)" % (
e.response.status_code, e.response.json[ 'code' ],
e.response.json[ 'message' ]
) |
PUT cid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import requests;
import json;
try :
response = requests.put(
json.dumps({ 'firstname' : 'Gonzo'
}), auth = ( "ExampleApp" , "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ),
headers = { 'Accept' : "application/json" }
) response.raise_for_status() print "Your first name is now %s" % response.json[ 'firstname' ]
# deal with exceptions by accessing the returned json and printing out why except requests.exceptions.HTTPError as e:
print "%s: %s (%s)" % (
e.response.status_code, e.response.json[ 'code' ],
e.response.json[ 'message' ]
) |
DELETE cid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import requests;
try :
response = requests.delete(
auth = ( "ExampleApp" , "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ),
headers = { 'Accept' : "application/json" }
) response.raise_for_status() print "DELETED!"
# deal with exceptions by accessing the returned json and printing out why except requests.exceptions.HTTPError as e:
print "%s: %s (%s)" % (
e.response.status_code, e.response.json[ 'code' ],
e.response.json[ 'message' ]
) |
POST type
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
|
import requests;
import json;
try :
response = requests.post(
json.dumps({ "title" : "Big Bird's Birthday" ,
"description" : "Big Bird is six (again)" ,
"start" : 1332216000 ,
"stop" : 1332302399
}), auth = ( "ExampleApp" , "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ),
headers = { 'Accept' : "application/json" }
) response.raise_for_status() print "Created annotation: %s (%s)" % (
response.json[ "_cid" ],
response.json[ "title" ]
) # deal with exceptions by accessing the returned json and printing out why except requests.exceptions.HTTPError as e:
print "%s: %s (%s)" % (
e.response.status_code, e.response.json[ 'code' ],
e.response.json[ 'message' ]
) |
GET type
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
|
import requests;
try :
response = requests.get(
auth = ( "ExampleApp" , "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ),
headers = { 'Accept' : "application/json" }
); response.raise_for_status() # print out each user's details print "Users with access to the account:"
for user in response.json:
print " * %s (%s %s)" % (
user[ 'email' ],
user[ 'firstname' ],
user[ 'lastname' ],
) # deal with exceptions by accessing the returned json and printing out why except requests.exceptions.HTTPError as e:
print "%s: %s (%s)" % (
e.response.status_code, e.response.json[ 'code' ],
e.response.json[ 'message' ]
) |
API Examples Using Ruby
GET cid
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
|
#!/usr/bin/ruby require 'rubygems'
require 'json'
require 'rest_client'
# setup client :x_circonus_app_name => "ExampleApp" ,
:x_circonus_auth_token => "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ,
:accept => 'application/json' ,
}) begin # get and parse response = circonus[ "/user/current" ].get;
result = JSON .parse(response);
# print out the result puts "Hello #{result['firstname']} #{result['lastname']}" ;
rescue RestClient:: Exception => ex
# deal with exceptions by accessing the returned json and printing out why result = JSON .parse(ex.http_body)
puts "#{ex.http_code}: #{result['code']} (#{result['message']})"
end |
PUT cid
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
|
#!/usr/bin/ruby require 'rubygems'
require 'json'
require 'rest_client'
# setup client :x_circonus_app_name => "ExampleApp" ,
:x_circonus_auth_token => "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ,
:accept => 'application/json' ,
}) begin # put and parse the updated object response = circonus[ "/user/current" ].put(
{ :firstname => "Gonzo" }.to_json()
); result = JSON .parse(response);
puts "Your first name is now #{result['firstname']}" ;
rescue RestClient:: Exception => ex
# deal with exceptions by accessing the returned json and printing out why result = JSON .parse(ex.http_body)
puts "#{ex.http_code}: #{result['code']} (#{result['message']})"
end |
DELETE cid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#!/usr/bin/ruby require 'rubygems'
require 'json'
require 'rest_client'
# setup client :x_circonus_app_name => "ExampleApp" ,
:x_circonus_auth_token => "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ,
:accept => 'application/json' ,
}) begin # delete response = circonus[ "/graph/123456" ].delete;
puts "DELETED!"
rescue RestClient:: Exception => ex
# deal with exceptions by accessing the returned json and printing out why result = JSON .parse(ex.http_body)
puts "#{ex.http_code}: #{result['code']} (#{result['message']})"
end |
POST type
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
|
#!/usr/bin/ruby require 'rubygems'
require 'json'
require 'rest_client'
# setup client :x_circonus_app_name => "ExampleApp" ,
:x_circonus_auth_token => "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ,
:accept => 'application/json' ,
}) begin # put and parse the updated object response = circonus[ "/annotation" ].post(
{ :title => "Big Bird's Birthday" ,
:description => "Big Bird is six (again)" ,
:start => 1332216000 ,
:stop => 1332302399 ,
}.to_json() ); result = JSON .parse(response);
puts "Created annotation: #{result['_cid']} (#{result['title']})" ;
rescue RestClient:: Exception => ex
# deal with exceptions by accessing the returned json and printing out why result = JSON .parse(ex.http_body)
puts "#{ex.http_code}: #{result['code']} (#{result['message']})"
end |
GET type
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
|
#!/usr/bin/ruby require 'rubygems'
require 'json'
require 'rest_client'
# setup client :x_circonus_app_name => "ExampleApp" ,
:x_circonus_auth_token => "fb349ef1-91e4-4b05-aaa2-52246b77ea66" ,
:accept => 'application/json' ,
}) begin # get and parse response = circonus[ "/user" ].get;
result = JSON .parse(response);
# print out each user's details puts "Users with access to the account:" ;
result. each { |user|
puts " * #{user['_cid']} (#{user['firstname']} #{user['lastname']})\n" ;
} rescue RestClient:: Exception => ex
# deal with exceptions by accessing the returned json and printing out why result = JSON .parse(ex.http_body)
puts "#{ex.http_code}: #{result['code']} (#{result['message']})"
end |