AnyEvent::HTTP::Spark - Syncrnous/Asyncrnous HTTP Rest Client for Cisco Spark
use AnyEvent::HTTP::Spark; my $obj=new AnyEvent::HTTP::Spark(token=>$ENV{SPARK_TOKEN});
Dual Nature Syncrnous/Asyncrnous AnyEvent friendly Spark v1 HTTP Client library.
This class uses the following Moo Roles
HTTP::MultiGet::Role Log::LogMethods Data::Result::Moo AnyEvent::SpakBot::SharedRole
Required OO Arguments
token: required for spark authentication
Optional OO Arguments
logger: sets the logging object agent: AnyEvent::HTTP::MultiGet object api_url: https://api.ciscospark.com/v1/ # sets the web service the requests point to retryCount: 1, how many retries to attempt when getting a 429 error
Options set at runtime
retries: anymous hash, used to trak AnyEvent->timer objects
Each web method has a blocking and a non blocking context.
Any Method with a prefix of que_ can be called in either a blocking or a non blocking context. Most people will use the blocking interface of the client.
Non Blocking context for use with AnyEvent Loops
my $cb=sub { my ($self,$id,$result,$request,$response)=@_; if($result) { print Dumper($result->get_data); } else { ... } }; my $id=$self->que_listPeople($cb,$args); $self->agent->run_next;
Blocking Context
my $result=$self->listPeople($args); if($result) { print Dumper($result->get_data); } else { die $result; }
Blocking my $result=$self->getMe()
Returns a Data::Result Object, when true it contains the data, when false it contains why it failed.
Non-Blocking my $id=$self->que_getMe($cb)
Example Callback
$cb=sub { my ($self,$id,$result,$request,$response,$hashRef)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->listPeople($hashRef)
Non-Blocking my $id=$self->que_listPeople($cb,$hashRef)
Blocking my $result=$self->getPerson($personId)
Non-Blocking my $id=$self->que_getPerson($cb,$personId)
$cb=sub { my ($self,$id,$result,$request,$response,$personId)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->createPerson($hashRef)
Non-Blocking my $id=$self->que_createPerson($cb,$hashRef)
Blocking my $result=$self->deletePerson($personId)
Non-Blocking my $id=$self->que_deletePerson($cb,$personId)
Blocking my $result=$self->updatePerson($personId,$hashRef)
Non-Blocking my $id=$self->que_updatePerson($cb,$personId,$hashRef)
$cb=sub { my ($self,$id,$result,$request,$response,$personId,$hashRef)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->listRooms($hashRef)
Non-Blocking my $id=$self->que_listRooms($cb,$hashRef)
Blocking my $result=$self->getRoom($roomId)
Non-Blocking my $id=$self->que_getRoom($cb,$roomId)
$cb=sub { my ($self,$id,$result,$request,$response,$roomId)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->createRoom($hashRef)
Non-Blocking my $id=$self->que_createRoom($cb,$hashRef)
Blocking my $result=$self->deleteRoom($roomId)
Non-Blocking my $id=$self->que_deleteRoom($cb,$roomId)
Blocking my $result=$self->updateRoom($roomId,$hashRef)
Non-Blocking my $id=$self->que_updateRoom($cb,$roomId,$hashRef)
$cb=sub { my ($self,$id,$result,$request,$response,$roomId,$hashRef)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->listMemberships($hashRef)
Non-Blocking my $id=$self->que_listMemberships($cb,$hashRef)
Blocking my $result=$self->getMembership($membershipId)
Non-Blocking my $id=$self->que_getMembership($cb,$membershipId)
$cb=sub { my ($self,$id,$result,$request,$response,$membershipId)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->createMembership($hashRef)
Non-Blocking my $id=$self->que_createMembership($cb,$hashRef)
Blocking my $result=$self->deleteMembership($membershipId)
Non-Blocking my $id=$self->que_deleteMembership($cb,$membershipId)
Blocking my $result=$self->updateMembership($membershipId,$hashRef)
Non-Blocking my $id=$self->que_updateMembership($cb,$membershipId,$hashRef)
$cb=sub { my ($self,$id,$result,$request,$response,$membershipId,$hashRef)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Special Notes on bots for this method, bots can only list messages refering to the bot itself. This means there are 2 manditory arguments when using a bot. If mentionedPeople is not set to the litteral string 'me' a bot will encounter a 403 error.
$hashRef Required options
roomId: the id for the room mentionedPeople: me
Blocking my $result=$self->listMessages($hashRef)
Non-Blocking my $id=$self->que_listMessages($cb,$hashRef)
Blocking my $result=$self->getMessage($messageId)
Non-Blocking my $id=$self->que_getMessage($cb,$messageId)
$cb=sub { my ($self,$id,$result,$request,$response,$messageId)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->createMessage($hashRef)
Non-Blocking my $id=$self->que_createMessage($cb,$hashRef)
Blocking my $result=$self->deleteMessage($messageId)
Non-Blocking my $id=$self->que_deleteMessage($cb,$messageId)
Blocking my $result=$self->listTeams($hashRef)
Non-Blocking my $id=$self->que_listTeams($cb,$hashRef)
Blocking my $result=$self->getTeam($teamId)
Non-Blocking my $id=$self->que_getTeam($cb,$teamId)
$cb=sub { my ($self,$id,$result,$request,$response,$teamId)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->createTeam($hashRef)
Non-Blocking my $id=$self->que_createTeam($cb,$hashRef)
Blocking my $result=$self->deleteTeam($teamId)
Non-Blocking my $id=$self->que_deleteTeam($cb,$teamId)
Blocking my $result=$self->updateTeam($teamId,$hashRef)
Non-Blocking my $id=$self->que_updateTeam($cb,$teamId,$hashRef)
$cb=sub { my ($self,$id,$result,$request,$response,$teamId,$hashRef)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->listTeamMemberships($hashRef)
Non-Blocking my $id=$self->que_listTeamMemberships($cb,$hashRef)
Blocking my $result=$self->getTeamMembership($teamMembershipId)
Non-Blocking my $id=$self->que_getTeamMembership($cb,$teamMembershipId)
$cb=sub { my ($self,$id,$result,$request,$response,$teamMembershipId)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->createTeamMembership($hashRef)
Non-Blocking my $id=$self->que_createTeamMembership($cb,$hashRef)
Blocking my $result=$self->deleteTeamMembership($teamMembershipId)
Non-Blocking my $id=$self->que_deleteTeamMembership($cb,$teamMembershipId)
Blocking my $result=$self->updateTeamMembership($teamMembershipId,$hashRef)
Non-Blocking my $id=$self->que_updateTeamMembership($cb,$teamMembershipId,$hashRef)
$cb=sub { my ($self,$id,$result,$request,$response,$teamMembershipId,$hashRef)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->listWebhooks($hashRef)
Non-Blocking my $id=$self->que_listWebhooks($cb,$hashRef)
Blocking my $result=$self->getWebhook($webhookId)
Non-Blocking my $id=$self->que_getWebhook($cb,$webhookId)
$cb=sub { my ($self,$id,$result,$request,$response,$webhookId)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->createWebhook($hashRef)
Non-Blocking my $id=$self->que_createWebhook($cb,$hashRef)
Blocking my $result=$self->deleteWebhook($webhookId)
Non-Blocking my $id=$self->que_deleteWebhook($cb,$webhookId)
Blocking my $result=$self->updateWebhook($webhookId,$hashRef)
Non-Blocking my $id=$self->que_updateWebhook($cb,$webhookId,$hashRef)
$cb=sub { my ($self,$id,$result,$request,$response,$webhookId,$hashRef)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->listOrganizations($hashRef)
Non-Blocking my $id=$self->que_listOrganizations($cb,$hashRef)
Blocking my $result=$self->getOrganization($organizationId)
Non-Blocking my $id=$self->que_getOrganization($cb,$organizationId)
$cb=sub { my ($self,$id,$result,$request,$response,$organizationId)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->listLicenses($hashRef)
Non-Blocking my $id=$self->que_listLicenses($cb,$hashRef)
Blocking my $result=$self->getLicense($licenseId)
Non-Blocking my $id=$self->que_getLicense($cb,$licenseId)
$cb=sub { my ($self,$id,$result,$request,$response,$licenseId)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->listRoles($hashRef)
Non-Blocking my $id=$self->que_listRoles($cb,$hashRef)
Blocking my $result=$self->getRole($roleId)
Non-Blocking my $id=$self->que_getRole($cb,$roleId)
$cb=sub { my ($self,$id,$result,$request,$response,$roleId)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->listEvents($hashRef)
Non-Blocking my $id=$self->que_listEvents($cb,$hashRef)
Blocking my $result=$self->getEvent($eventId)
Non-Blocking my $id=$self->que_getEvent($cb,$eventId)
$cb=sub { my ($self,$id,$result,$request,$response,$eventId)=@_; # 0: $self The current AnyEvent::HTTP::Slack object # 1: $id the id of the http request # 2: Data::Result Object # 3: HTTP::Request Object # 4: HTTP::Result Object };
Blocking my $result=$self->listMeetingss($hashRef)
Non-Blocking my $id=$self->que_listMeetingss($cb,$hashRef)
Blocking my $result=$self->getMeetings($roomId)
Non-Blocking my $id=$self->que_getMeetings($cb,$roomId)
Blocking my $result=$self->createMeetings($hashRef)
Non-Blocking my $id=$self->que_createMeetings($cb,$hashRef)
Blocking my $result=$self->deleteMeetings($roomId)
Non-Blocking my $id=$self->que_deleteMeetings($cb,$roomId)
Blocking my $result=$self->updateMeetings($roomId,$hashRef)
Non-Blocking my $id=$self->que_updateMeetings($cb,$roomId,$hashRef)
Posting files to channel steps outside of the traditional json data format.
Blocking my $result=$self->uploadFile('/path/to/file',%args);
Non-Blocking my $result=$self->que_uploadFile($cb,'/path/to/file',%args);
This section documents low level request functions.
$self->handle_paginate($id,$result,$request,$response,$cb)
Internal Method wrapper for parsing pagination headers.
Example:
my $code=sub { my ($self,$id,$result,$request,$response)=@_; $self->handle_paginate($id,$result,$request,$response,$cb); }; return $self->que_get($code,$url,$args);
Pagination information can be found in the following result fields.
cursorPosition: last|next|prev|first pageLink: (undef when cursorPosition eq 'last') Url to the next page
my $result=$self->build_post_json($url,$data);
Returns a Data::Result object; When true it contains an HTTP::Request Object For $url, the body will consist of $data converted to json. When false it contains why it failed.
my $id=$self->queue_builder($cb,$method,$url,$data);
Returns the ID of the object in the request for $method.
my $id=$self->que_post_json($cb,$url,$data);
Queue's a json post and returns the id
my $result=$self->build_put_json($url,$data);
my $id=$self->que_put_json($cb,$url,$data);
Queue's a json put and returns the id
my $result=$self->build_post_form($url,$data);
Returns a Data::Result Object, when true it contains the correctly fromatted HTTP::Request Object, when false it contains why it failed.
my $id=$self->que_post_form($cb,$url,$data);
Queue's a form post and returns the id
my $result=$self->build_get($url,$data);
my $self->que_getRaw($cb,$raw_url)
Que's a diy get request
my $id=$self->que_get($cb,$url,$data);
my $result=$self->build_head($url,$data);
my $id=$self->que_head($cb,$url,$data);
my $result=$self->build_delete($url,$data);
Returns a Data::Result Object, when true it contains the delete request, when false it contains why it failed.
my $id=$self->que_delete($cb,$url,$data);
Ques a delete to run.
$self->handle_delete($cb,$id,$result,$result)
Internal handler for delete results
Michael Shipper <AKALINUX@CPAN.ORG>
To install AnyEvent::SparkBot, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::SparkBot
CPAN shell
perl -MCPAN -e shell install AnyEvent::SparkBot
For more information on module installation, please visit the detailed CPAN module installation guide.