The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Net::ThreeScale::Client - Client for 3Scale.com web API version 2.0

SYNOPSIS

 use Net::ThreeScale::Client;
 
 my $client = new Net::ThreeScale::Client(provider_key=>"my_assigned_provider_key", 
                                        url=>"http://su1.3Scale.net");
 
 my $response = $client->authorize(app_id  => $app_id,
                                   app_key => $app_key);
          
 if($response->is_success) {
       print "authorized ", $response->transaction,"\"n";
   ...

   my @transactions = (
      {
         app_id => $app_id,
         usage => {
           hits => 1,
         },

         timestamp => "2010-09-01 09:01:00",
      },

      {
         app_id => $app_id,
         usage => {
            hits => 1,
         },

         timestamp => "2010-09-02 09:02:00",
      }
   );

   my $report_response = $client->report(transactions=>\@transactions));
   if($report_response->is_success){
      print STDERR "Transactions reported\n";
   } else {
      print STDERR "Failed to report transactions",
                  $response->error_code(),":",
                  $response->error_message(),"\n";
   }
 } else {
   print STDERR "authorize failed with error :", 
      $response->error_message,"\n";
   if($response->error_code == TS_RC_AUTHORIZE_FAILED) {
      print "Provider key is invalid";
   } else { 
     ...
   }
 }

CONSTRUCTOR

 The class method new(...) creates a new 3Scale client object. This may 
 be used to conduct transactions with the 3Scale service. The object is 
 stateless and transactions may span multiple clients. The following 
 parameters are recognised as arguments to new():
provider_key

(required) The provider key used to identify you with the 3Scale service

url

(optional) The 3Scale service URL, usually this should be left to the default value

$response = $client->authorize(app_id=>$app_id, app_key=>$app_key)

Starts a new client transaction the call must include a application id (as a string) and (optionally) an application key (string), identifying the application to use.

Returns a Net::ThreeScale::Response object which indicates whether the authorization was successful or indicates an error if one occured.

$response = $client->report(transactions=>\@transactions)

Reports a list of transactions to 3Scale.

transactions=>{app_id=>value,...}

Should be an array similar to the following:

      my @transactions = (
        { 
          app_id => $app_id,
          usage => {
            hits => 1,
         }
         timestamp => "2010-09-01 09:01:00",
        },
        { 
          app_id => $app_id,
          usage => {
            hits => 1,
          }
          timestamp => "2010-09-01 09:02:00",
        },
      );

EXPORTS / ERROR CODES

The following constants are exported and correspond to error codes which may appear in calls to Net::ThreeScale::Response::error_code

TS_RC_SUCCESS

The operation completed successfully

TS_RC_AUTHORIZE_FAILED

The passed provider key was invalid

TS_RC_UNKNOWN_ERROR

An unspecified error occurred. See the corresponding message for more detail.

SEE ALSO

Net::ThreeScale::Response

Contains details of response contnet and values.

AUTHOR

(c) Owen Cliffe 2008, Eugene Oden 2010