forked from 3scale-labs/3scale_ws_api_for_perl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
119 lines (95 loc) · 3.57 KB
/
README
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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