line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
514
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
3
|
|
|
|
|
|
|
package TheGameCrafter::Client; |
4
|
|
|
|
|
|
|
BEGIN { |
5
|
1
|
|
|
1
|
|
18
|
$TheGameCrafter::Client::VERSION = '0.0103'; |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1059
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
46909
|
|
|
1
|
|
|
|
|
30
|
|
9
|
1
|
|
|
1
|
|
813
|
use HTTP::Request::Common; |
|
1
|
|
|
|
|
2323
|
|
|
1
|
|
|
|
|
96
|
|
10
|
1
|
|
|
1
|
|
10
|
use JSON; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
13
|
|
11
|
1
|
|
|
1
|
|
168
|
use URI; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
12
|
1
|
|
|
1
|
|
6
|
use Ouch; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
73
|
|
13
|
1
|
|
|
1
|
|
7
|
use parent 'Exporter'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT = qw(tgc_get tgc_delete tgc_put tgc_post); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
TheGameCrafter::Client - A simple client to TGC's web services. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 VERSION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
version 0.0103 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use TheGameCrafter::Client; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $game = tgc_get('game/528F18A2-F2C4-11E1-991D-40A48889CD00'); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $session = tgc_post('session', { username => 'me', password => '123qwe', api_key_id => 'abcdefghijklmnopqrztuz' }); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$game = tgc_put('game/528F18A2-F2C4-11E1-991D-40A48889CD00', { session_id => $session->{id}, name => 'Lacuna Expanse' }); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $status = tgc_delete('game/528F18A2-F2C4-11E1-991D-40A48889CD00', { session_id => $session->{id} }); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
A light-weight wrapper for The Game Crafter's (L) RESTful API (L). This wrapper basically hides the request cycle from you so that you can get down to the business of using the API. It doesn't attempt to manage the data structures or objects the web service interfaces with. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SUBROUTINES |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
The following subroutines are exported into your namespace wherever you C |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 tgc_get(path, params) |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Performs a C request, which is used for reading data from the service. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=over |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item path |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
The path to the REST interface you wish to call. You can abbreviate and leave off the C part if you wish. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item params |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
A hash reference of parameters you wish to pass to the web service. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=back |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub tgc_get { |
64
|
2
|
|
|
2
|
1
|
203328
|
my ($path, $params) = @_; |
65
|
2
|
|
|
|
|
8
|
my $uri = _create_uri($path); |
66
|
2
|
|
|
|
|
1712
|
$uri->query_form($params); |
67
|
2
|
|
|
|
|
293
|
return _process_request( GET $uri->as_string ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 tgc_delete(path, params) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Performs a C request, deleting data from the service. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=over |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item path |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The path to the REST interface you wish to call. You can abbreviate and leave off the C part if you wish. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item params |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
A hash reference of parameters you wish to pass to the web service. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=back |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub tgc_delete { |
89
|
0
|
|
|
0
|
1
|
0
|
my ($path, $params) = @_; |
90
|
0
|
|
|
|
|
0
|
my $uri = _create_uri($path); |
91
|
0
|
|
|
|
|
0
|
return _process_request( POST $uri->as_string, 'X-HTTP-Method' => 'DELETE', Content_Type => 'form-data', Content => $params ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 tgc_put(path, params) |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Performs a C request, which is used for updating data in the service. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=over |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item path |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
The path to the REST interface you wish to call. You can abbreviate and leave off the C part if you wish. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item params |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
A hash reference of parameters you wish to pass to the web service. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=back |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub tgc_put { |
113
|
1
|
|
|
1
|
1
|
2072
|
my ($path, $params) = @_; |
114
|
1
|
|
|
|
|
4
|
my $uri = _create_uri($path); |
115
|
1
|
|
|
|
|
59
|
return _process_request( POST $uri->as_string, 'X-HTTP-Method' => 'PUT', Content_Type => 'form-data', Content => $params ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 tgc_post(path, params) |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Performs a C request, which is used for creating data in the service. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=over |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item path |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
The path to the REST interface you wish to call. You can abbreviate and leave off the C part if you wish. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item params |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
A hash reference of parameters you wish to pass to the web service. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub tgc_post { |
137
|
0
|
|
|
0
|
1
|
0
|
my ($path, $params) = @_; |
138
|
0
|
|
|
|
|
0
|
my $uri = _create_uri($path); |
139
|
0
|
|
|
|
|
0
|
return _process_request( POST $uri->as_string, Content_Type => 'form-data', Content => $params ); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub _create_uri { |
143
|
3
|
|
|
3
|
|
6568
|
my $path = shift; |
144
|
3
|
100
|
|
|
|
20
|
unless ($path =~ m/^\/api/) { |
145
|
2
|
|
|
|
|
6
|
$path = '/api/'.$path; |
146
|
|
|
|
|
|
|
} |
147
|
3
|
|
|
|
|
30
|
return URI->new('https://www.thegamecrafter.com'.$path); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub _process_request { |
151
|
3
|
|
|
3
|
|
666
|
_process_response(LWP::UserAgent->new->request( @_ )); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub _process_response { |
155
|
4
|
|
|
4
|
|
5733
|
my $response = shift; |
156
|
4
|
|
|
|
|
7
|
my $result = eval { from_json($response->decoded_content) }; |
|
4
|
|
|
|
|
22
|
|
157
|
4
|
100
|
|
|
|
3699
|
if ($@) { |
|
|
50
|
|
|
|
|
|
158
|
3
|
|
|
|
|
12
|
ouch 500, 'Server returned unparsable content.', { error => $@, content => $response->decoded_content }; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
elsif ($response->is_success) { |
161
|
1
|
|
|
|
|
17
|
return $result->{result}; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else { |
164
|
0
|
|
|
|
|
|
ouch $result->{error}{code}, $result->{error}{message}, $result->{error}{data}; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 PREREQS |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L |
171
|
|
|
|
|
|
|
L |
172
|
|
|
|
|
|
|
L |
173
|
|
|
|
|
|
|
L |
174
|
|
|
|
|
|
|
L |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 SUPPORT |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=over |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item Repository |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item Bug Reports |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
L |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=back |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 AUTHOR |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
JT Smith |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 LEGAL |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This module is Copyright 2012 Plain Black Corporation. It is distributed under the same terms as Perl itself. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
1; |