Aion-Surf
view release on metacpan or search on metacpan
use common::sense;
# mock
*LWP::UserAgent::request = sub {
my ($ua, $request) = @_;
my $response = HTTP::Response->new(200, "OK");
given ($request->method . " " . $request->uri) {
$response->content("get") when $_ eq "GET http://example/ex";
$response->content("head") when $_ eq "HEAD http://example/ex";
$response->content("post") when $_ eq "POST http://example/ex";
$response->content("put") when $_ eq "PUT http://example/ex";
$response->content("patch") when $_ eq "PATCH http://example/ex";
$response->content("delete") when $_ eq "DELETE http://example/ex";
$response->content('{"a":10}') when $_ eq "PATCH http://example/json";
default {
$response = HTTP::Response->new(404, "Not Found");
$response->content("nf");
}
}
get "http://example/ex" # => get
surf "http://example/ex" # => get
head "http://example/ex" # -> 1
head "http://example/not-found" # -> ""
surf HEAD => "http://example/ex" # -> 1
surf HEAD => "http://example/not-found" # -> ""
[map { surf $_ => "http://example/ex" } qw/GET HEAD POST PUT PATCH DELETE/] # --> [qw/get 1 post put patch delete/]
patch "http://example/json" # --> {a => 10}
[map patch, qw! http://example/ex http://example/json !] # --> ["patch", {a => 10}]
get ["http://example/ex", headers => {Accept => "*/*"}] # => get
surf "http://example/ex", headers => [Accept => "*/*"] # => get
```
# DESCRIPTION
```
## head (;$url)
Check resurce in internet. Returns `1` if exists resurce in internet, otherwice returns `""`.
## get (;$url)
Get content from resurce in internet.
## post (;$url, \[$headers_href], %params)
Add content resurce in internet.
## put (;$url, \[$headers_href], %params)
Create or update resurce in internet.
## patch (;$url, \[$headers_href], %params)
Set attributes on resurce in internet.
lib/Aion/Surf.md view on Meta::CPAN
use common::sense;
# mock
*LWP::UserAgent::request = sub {
my ($ua, $request) = @_;
my $response = HTTP::Response->new(200, "OK");
given ($request->method . " " . $request->uri) {
$response->content("get") when $_ eq "GET http://example/ex";
$response->content("head") when $_ eq "HEAD http://example/ex";
$response->content("post") when $_ eq "POST http://example/ex";
$response->content("put") when $_ eq "PUT http://example/ex";
$response->content("patch") when $_ eq "PATCH http://example/ex";
$response->content("delete") when $_ eq "DELETE http://example/ex";
$response->content('{"a":10}') when $_ eq "PATCH http://example/json";
default {
$response = HTTP::Response->new(404, "Not Found");
$response->content("nf");
}
}
lib/Aion/Surf.md view on Meta::CPAN
get "http://example/ex" # => get
surf "http://example/ex" # => get
head "http://example/ex" # -> 1
head "http://example/not-found" # -> ""
surf HEAD => "http://example/ex" # -> 1
surf HEAD => "http://example/not-found" # -> ""
[map { surf $_ => "http://example/ex" } qw/GET HEAD POST PUT PATCH DELETE/] # --> [qw/get 1 post put patch delete/]
patch "http://example/json" # --> {a => 10}
[map patch, qw! http://example/ex http://example/json !] # --> ["patch", {a => 10}]
get ["http://example/ex", headers => {Accept => "*/*"}] # => get
surf "http://example/ex", headers => [Accept => "*/*"] # => get
```
# DESCRIPTION
lib/Aion/Surf.md view on Meta::CPAN
```
## head (;$url)
Check resurce in internet. Returns `1` if exists resurce in internet, otherwice returns `""`.
## get (;$url)
Get content from resurce in internet.
## post (;$url, \[$headers_href], %params)
Add content resurce in internet.
## put (;$url, \[$headers_href], %params)
Create or update resurce in internet.
## patch (;$url, \[$headers_href], %params)
Set attributes on resurce in internet.
lib/Aion/Surf.pm view on Meta::CPAN
return $response->is_success if $method eq "HEAD";
my $content = $response->decoded_content;
eval { $content = Aion::Format::Json::from_json($content) } if $content =~ m!^\{!;
$content
}
sub head (;$) { my $x = @_ == 0? $_: shift; surf HEAD => ref $x? @{$x}: $x }
sub get (;$) { my $x = @_ == 0? $_: shift; surf GET => ref $x? @{$x}: $x }
sub post (@) { my $x = @_ == 0? $_: \@_; surf POST => ref $x? @{$x}: $x }
sub put (@) { my $x = @_ == 0? $_: \@_; surf PUT => ref $x? @{$x}: $x }
sub patch(@) { my $x = @_ == 0? $_: \@_; surf PATCH => ref $x? @{$x}: $x }
sub del (;$) { my $x = @_ == 0? $_: shift; surf DELETE => ref $x? @{$x}: $x }
use config TELEGRAM_BOT_TOKEN => undef;
# ÐÑпÑавлÑÐµÑ ÑообÑение ÑелегÑам
sub chat_message($$) {
my ($chat_id, $message) = @_;
my $ok = post "https://api.telegram.org/bot${\ TELEGRAM_BOT_TOKEN}/sendMessage", response => \my $response, json => {
chat_id => $chat_id,
text => $message,
disable_web_page_preview => 1,
parse_mode => 'Html',
};
die $ok->{description} if !$ok->{ok};
$ok
}
lib/Aion/Surf.pm view on Meta::CPAN
# ÐÑпÑавлÑÐµÑ ÑообÑение в ÑеÑ
ниÑеÑкий ÑелегÑам канал
sub tech_message(;$) { chat_message TELEGRAM_BOT_TECH_ID, @_ == 0? $_: $_[0] }
# ÐолÑÑÐ°ÐµÑ Ð¿Ð¾Ñледние ÑообÑÐµÐ½Ð¸Ñ Ð¾ÑпÑавленнÑе боÑÑ
sub bot_update() {
my @updates;
for(my $offset = 0;;) {
my $ok = post "https://api.telegram.org/bot${\ TELEGRAM_BOT_TOKEN}/getUpdates", json => {
offset => $offset,
};
die $ok->{description} if !$ok->{ok};
my $result = $ok->{result};
return \@updates if !@$result;
push @updates, map $_->{message}, grep $_->{message}, @$result;
lib/Aion/Surf.pm view on Meta::CPAN
use common::sense;
# mock
*LWP::UserAgent::request = sub {
my ($ua, $request) = @_;
my $response = HTTP::Response->new(200, "OK");
given ($request->method . " " . $request->uri) {
$response->content("get") when $_ eq "GET http://example/ex";
$response->content("head") when $_ eq "HEAD http://example/ex";
$response->content("post") when $_ eq "POST http://example/ex";
$response->content("put") when $_ eq "PUT http://example/ex";
$response->content("patch") when $_ eq "PATCH http://example/ex";
$response->content("delete") when $_ eq "DELETE http://example/ex";
$response->content('{"a":10}') when $_ eq "PATCH http://example/json";
default {
$response = HTTP::Response->new(404, "Not Found");
$response->content("nf");
}
}
lib/Aion/Surf.pm view on Meta::CPAN
get "http://example/ex" # => get
surf "http://example/ex" # => get
head "http://example/ex" # -> 1
head "http://example/not-found" # -> ""
surf HEAD => "http://example/ex" # -> 1
surf HEAD => "http://example/not-found" # -> ""
[map { surf $_ => "http://example/ex" } qw/GET HEAD POST PUT PATCH DELETE/] # --> [qw/get 1 post put patch delete/]
patch "http://example/json" # --> {a => 10}
[map patch, qw! http://example/ex http://example/json !] # --> ["patch", {a => 10}]
get ["http://example/ex", headers => {Accept => "*/*"}] # => get
surf "http://example/ex", headers => [Accept => "*/*"] # => get
=head1 DESCRIPTION
lib/Aion/Surf.pm view on Meta::CPAN
ref $response # => HTTP::Response
=head2 head (;$url)
Check resurce in internet. Returns C<1> if exists resurce in internet, otherwice returns C<"">.
=head2 get (;$url)
Get content from resurce in internet.
=head2 post (;$url, [$headers_href], %params)
Add content resurce in internet.
=head2 put (;$url, [$headers_href], %params)
Create or update resurce in internet.
=head2 patch (;$url, [$headers_href], %params)
Set attributes on resurce in internet.
t/aion/surf.t view on Meta::CPAN
use common::sense;
# mock
*LWP::UserAgent::request = sub {
my ($ua, $request) = @_;
my $response = HTTP::Response->new(200, "OK");
given ($request->method . " " . $request->uri) {
$response->content("get") when $_ eq "GET http://example/ex";
$response->content("head") when $_ eq "HEAD http://example/ex";
$response->content("post") when $_ eq "POST http://example/ex";
$response->content("put") when $_ eq "PUT http://example/ex";
$response->content("patch") when $_ eq "PATCH http://example/ex";
$response->content("delete") when $_ eq "DELETE http://example/ex";
$response->content('{"a":10}') when $_ eq "PATCH http://example/json";
default {
$response = HTTP::Response->new(404, "Not Found");
$response->content("nf");
}
}
t/aion/surf.t view on Meta::CPAN
::is scalar do {get "http://example/ex"}, "get", 'get "http://example/ex" # => get';
::is scalar do {surf "http://example/ex"}, "get", 'surf "http://example/ex" # => get';
::is scalar do {head "http://example/ex"}, scalar do{1}, 'head "http://example/ex" # -> 1';
::is scalar do {head "http://example/not-found"}, scalar do{""}, 'head "http://example/not-found" # -> ""';
::is scalar do {surf HEAD => "http://example/ex"}, scalar do{1}, 'surf HEAD => "http://example/ex" # -> 1';
::is scalar do {surf HEAD => "http://example/not-found"}, scalar do{""}, 'surf HEAD => "http://example/not-found" # -> ""';
::is_deeply scalar do {[map { surf $_ => "http://example/ex" } qw/GET HEAD POST PUT PATCH DELETE/]}, scalar do {[qw/get 1 post put patch delete/]}, '[map { surf $_ => "http://example/ex" } qw/GET HEAD POST PUT PATCH DELETE/] # --> [qw/get 1 post put ...
::is_deeply scalar do {patch "http://example/json"}, scalar do {{a => 10}}, 'patch "http://example/json" # --> {a => 10}';
::is_deeply scalar do {[map patch, qw! http://example/ex http://example/json !]}, scalar do {["patch", {a => 10}]}, '[map patch, qw! http://example/ex http://example/json !] # --> ["patch", {a => 10}]';
::is scalar do {get ["http://example/ex", headers => {Accept => "*/*"}]}, "get", 'get ["http://example/ex", headers => {Accept => "*/*"}] # => get';
::is scalar do {surf "http://example/ex", headers => [Accept => "*/*"]}, "get", 'surf "http://example/ex", headers => [Accept => "*/*"] # => get';
#
# # DESCRIPTION
t/aion/surf.t view on Meta::CPAN
#
# ## head (;$url)
#
# Check resurce in internet. Returns `1` if exists resurce in internet, otherwice returns `""`.
#
# ## get (;$url)
#
# Get content from resurce in internet.
#
# ## post (;$url, \[$headers_href], %params)
#
# Add content resurce in internet.
#
# ## put (;$url, \[$headers_href], %params)
#
# Create or update resurce in internet.
#
# ## patch (;$url, \[$headers_href], %params)
#
# Set attributes on resurce in internet.
( run in 1.090 second using v1.01-cache-2.11-cpan-97f6503c9c8 )