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