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");

# Or initialize by service_token/service_id
# my $client = new Net::ThreeScale::Client(service_token=>"SERVICE_TOKEN",
#                                       service_id=>"SERVICE_ID");

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

service_token

(required) Service API key with 3scale (also known as service token).

service_id

(required) Service id. Required.

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.

SUPPORT

3scale support say, We do not have anyone in 3scale actively maintaining it, but we will certainly monitor pull requests and consider merging any useful contributions.

SEE ALSO

Net::ThreeScale::Response

Contains details of response content and values.

https://www.3scale.net

The service with which this package integrates.

AUTHOR

(c) Owen Cliffe 2008, Eugene Oden 2010.

CONTRIBUTORS

  • Dave Lambley

  • Ed Freyfogle

  • Marc Metten

LICENSE

Released under the MIT license. Please see the LICENSE file in the root directory of the distribution.