line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Scriptogram; |
2
|
1
|
|
|
1
|
|
23640
|
use base qw( WebService::Simple ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
728
|
|
3
|
|
|
|
|
|
|
use 5.006; |
4
|
|
|
|
|
|
|
use strict; |
5
|
|
|
|
|
|
|
use warnings; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
binmode STDOUT, ":encoding(UTF-8)"; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Carp; |
10
|
|
|
|
|
|
|
use Params::Validate qw( :all ); |
11
|
|
|
|
|
|
|
use Readonly; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
WebService::Scriptogram - Scriptogr.am API |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This module provides a Perl wrapper around the Scriptogr.am ( <http://scriptogr.am> ) API. You'll need a Scriptogr.am blog and an API key before you'll be able to do anything interesting with this module. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
See <http://scriptogr.am/dashboard#api_documentation> for authoritative documentation of API calls. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 VERSION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Version v0.0.2 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# constants |
28
|
|
|
|
|
|
|
use version; our $VERSION = 'v0.0.2'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Readonly my $SCRIPTOGRAM_API => 'http://scriptogr.am/api'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Readonly my $REGEX_APPKEY => '^[[:alnum:]]{42}$'; |
33
|
|
|
|
|
|
|
Readonly my $REGEX_USERID => '^[[:alnum:]]{42}$'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__PACKAGE__->config( |
36
|
|
|
|
|
|
|
base_url => $SCRIPTOGRAM_API, |
37
|
|
|
|
|
|
|
article_url => "$SCRIPTOGRAM_API/article/post/", |
38
|
|
|
|
|
|
|
delete_url => "$SCRIPTOGRAM_API/article/delete/", |
39
|
|
|
|
|
|
|
response_parser => 'JSON', |
40
|
|
|
|
|
|
|
debug => 1, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
use WebService::Scriptogram; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $sg = WebService::Scriptogram->new; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $text = <<TEXT; |
50
|
|
|
|
|
|
|
**Hello, World!** |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
First post! |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
I'm using [WebService::Scriptogram](https://github.com/hakamadare/webservice-scriptogram). |
55
|
|
|
|
|
|
|
TEXT |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $status = $sg->article( |
58
|
|
|
|
|
|
|
app_key => 'Scriptogr.am App Key', |
59
|
|
|
|
|
|
|
user_id => 'Scriptogr.am User ID', |
60
|
|
|
|
|
|
|
name => 'My First API Post', |
61
|
|
|
|
|
|
|
text => $text, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Each method corresponds to an API call; methods accept a hash of parameters, and return a hashref representing the status returned by the API (see Scriptogr.am API documentation for an explanation of status values). |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 METHODS |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 article |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Post a new article or edit an existing article. Accepts the following parameters: |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=over |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item app_key |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Scriptogr.am API key. Register an application with Scriptogr.am to obtain one. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item user_id |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Scriptogr.am user ID. Get this from the settings pane of the Scriptogr.am dashboard. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item name |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Title of the article as you would like it to appear on your blog. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item text |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
(Optional) text of the article, in Markdown format. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=back |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my %article_spec = ( |
95
|
|
|
|
|
|
|
app_key => { |
96
|
|
|
|
|
|
|
type => SCALAR, |
97
|
|
|
|
|
|
|
regex => qr/$REGEX_APPKEY/, |
98
|
|
|
|
|
|
|
}, |
99
|
|
|
|
|
|
|
user_id => { |
100
|
|
|
|
|
|
|
type => SCALAR, |
101
|
|
|
|
|
|
|
regex => qr/$REGEX_USERID/, |
102
|
|
|
|
|
|
|
}, |
103
|
|
|
|
|
|
|
name => { |
104
|
|
|
|
|
|
|
type => SCALAR, |
105
|
|
|
|
|
|
|
}, |
106
|
|
|
|
|
|
|
text => { |
107
|
|
|
|
|
|
|
optional => 1, |
108
|
|
|
|
|
|
|
type => SCALAR, |
109
|
|
|
|
|
|
|
}, |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub article { |
113
|
|
|
|
|
|
|
my $self = shift; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
local $self->{base_url} = $self->config->{article_url}; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my %params = validate( @_, \%article_spec ); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my $response = $self->post( \%params ); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my $status = $response->parse_response; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
return $status; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 delete |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Delete an existing article. Accepts the following parameters: |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=over |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item app_key |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Scriptogr.am API key. Register an application with Scriptogr.am to obtain one. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item user_id |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Scriptogr.am user ID. Get this from the settings pane of the Scriptogr.am dashboard. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item filename |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Name of the file as it appears in your Dropbox folder. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item text |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
(Optional) text of the article, in Markdown format. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=back |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my %delete_spec = ( |
153
|
|
|
|
|
|
|
app_key => { |
154
|
|
|
|
|
|
|
type => SCALAR, |
155
|
|
|
|
|
|
|
regex => qr/$REGEX_APPKEY/, |
156
|
|
|
|
|
|
|
}, |
157
|
|
|
|
|
|
|
user_id => { |
158
|
|
|
|
|
|
|
type => SCALAR, |
159
|
|
|
|
|
|
|
regex => qr/$REGEX_USERID/, |
160
|
|
|
|
|
|
|
}, |
161
|
|
|
|
|
|
|
filename => { |
162
|
|
|
|
|
|
|
type => SCALAR, |
163
|
|
|
|
|
|
|
}, |
164
|
|
|
|
|
|
|
); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub delete { |
167
|
|
|
|
|
|
|
my $self = shift; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
local $self->{base_url} = $self->config->{delete_url}; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
my %params = validate( @_, \%delete_spec ); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
my $response = $self->post( \%params ); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
my $status = $response->parse_response; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
return $status; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 AUTHOR |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Steve Huff, C<< <shuff at cpan.org> >> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 BUGS |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-webservice-scriptogram at rt.cpan.org>, or through |
187
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WebService-Scriptogram>. I will be notified, and then you'll |
188
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 SUPPORT |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
perldoc WebService::Scriptogram |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
You can also look for information at: |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=over 4 |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WebService-Scriptogram> |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
L<http://annocpan.org/dist/WebService-Scriptogram> |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item * CPAN Ratings |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/WebService-Scriptogram> |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item * Search CPAN |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/WebService-Scriptogram/> |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=back |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Thanks to the fine folks at #crimsonfu for bringing Scriptogr.am to my attention. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Copyright 2012 Steve Huff. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
228
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
229
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=cut |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
1; # End of WebService::Scriptogram |