WebService-Gyazo

 view release on metacpan or  search on metacpan

lib/WebService/Gyazo.pm  view on Meta::CPAN

use WebService::Gyazo::Image;

use LWP::UserAgent;
use LWP::Protocol::socks;
use HTTP::Request::Common;
use URI::Simple;

our $VERSION = 0.03;

use constant {
	HTTP_PROXY => 'http',
	SOCKS4_PROXY => 'socks4',
	SOCKS5_PROXY => 'socks',
	HTTPS_PROXY => 'https',
};

sub new {
	my ($self, %args) = @_;
	$self = bless(\%args, $self);

	return $self;

lib/WebService/Gyazo.pm  view on Meta::CPAN

		
		#  Выбираем из него ip и port
		#my ($protocol, $ip, $port) = $proxyStr =~ m#(\w+)://(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})#;

		my $proxyUrl = URI::Simple->new($proxyStr);
		my ($protocol, $ip, $port) = ( $proxyUrl->protocol, $proxyUrl->host, ($proxyUrl->port || '80') );
		#print "\n\$protocol=$protocol\n\$ip=$ip\n\$port=$port\n";

		if ( defined($protocol) and defined($ip) and defined($port) ) {
			
			unless ( $protocol eq HTTP_PROXY or $protocol eq HTTPS_PROXY or $protocol eq SOCKS4_PROXY or $protocol eq SOCKS5_PROXY ) {
				$self->{error} = "Wrong protocol type [".$protocol."]";
				return 0;
			}

			# Проверяем правильность введённых значений
			if ( $port <= 65535 ) {
				$self->{proxy} = $protocol.'://'.$ip.':'.$port;
				return 1;
			} else {
				$self->{error} = 'Error proxy format!';

t/WebService_Gyazo_setId.t  view on Meta::CPAN


use strict;
use warnings;

use Data::Dumper;
use Test::More tests => 7;

use lib 'lib/';

use constant {
	HTTP_PROXY => 'http',
	SOCKS4_PROXY => 'socks4',
	SOCKS5_PROXY => 'socks',
	HTTPS_PROXY => 'https',
};

use_ok('WebService::Gyazo');

my $ua = WebService::Gyazo->new();
can_ok($ua, 'setId');

t/WebService_Gyazo_setProxy.t  view on Meta::CPAN

#!/usr/bin/env perl

use Data::Dumper;
use Test::More tests => 90;

use lib 'lib/';

use constant {
	HTTP_PROXY => 'http',
	SOCKS4_PROXY => 'socks4',
	SOCKS5_PROXY => 'socks',
	HTTPS_PROXY => 'https',
};

use_ok('WebService::Gyazo');

my $ua = WebService::Gyazo->new();
can_ok($ua, 'setProxy');

my @protocols_ok = (HTTP_PROXY, HTTPS_PROXY, SOCKS4_PROXY, SOCKS5_PROXY);
my @ips_ok = qw( 127.0.0.1 11.111.11.111 );
my @ports_ok = qw( 80 8080 100 200 65535 );

for my $protocol (@protocols_ok) {
	for my $ip (@ips_ok) {
		for my $ports (@ports_ok) {
			my $proxy = $protocol.'://'.$ip.':'.$ports;
			is($ua->setProxy($proxy), 1, '$ua->setProxy("'.$proxy.'") == 1 - '.$ua->error);
		}
	}



( run in 0.429 second using v1.01-cache-2.11-cpan-71847e10f99 )