my
$datapath
;
my
$content
;
my
$fdebug
=0;
sub
AUTOLOAD
{
$AUTOLOAD
=~ s/.*:://;
for
my
$name
(
qw/
GET PUT _buildAccessors _buildUseragent getUseragent setUseragent
request _prepareURL getHost getTimeout
getCert getCa getPkcs12 getFollow getContentFile responseCode
responseHeader responseContent setHost
/
)
{
if
(
$AUTOLOAD
eq
$name
)
{
return
1;
}
}
shift
->${\
"NEXT::$AUTOLOAD"
}(
@_
);
}
BEGIN {
my
$rcpath
;
my
$thispath
=
$INC
{
'REST/Client.pm'
};
$datapath
=
$thispath
;
$datapath
=~s
$datapath
=~s
$datapath
=
$datapath
.
"/Data"
;
}
sub
new
{
return
bless
{};
}
sub
POST{
my
(
$self
,
$url
,
$jdata
,
$headers
)=
@_
;
local
$"=
', '
;
my
$jheaders
=JSON->new->canonical->encode(
$headers
);
if
(
$jdata
)
{
$jdata
=~s/(
"identifier"
:)(
"[^"
]+
")/$1"
igusername"/g;
$jdata
=~s/(
"password"
:)(
"[^"
]+
")/$1"
ig_correct_password"/g;
}
$jheaders
=~s/(
"X-IG-API-KEY"
:)(
"[^"
]+)
"/$1"
securitykey"/g;
$jheaders
=~s/(
"X-SECURITY-TOKEN"
:)(
"[^"
]+)
"/$1"
."/g;
$jheaders
=~s/(
"CST"
:)(
"[^"
]+)
"/$1"
."/g;
$fdebug
and
print
" url=$url\n jdata=$jdata\n jheaders=$jheaders\n"
;
my
$file
=
"$datapath/"
.md5_hex(
$url
,
$jdata
,
$jheaders
).
".txt"
;
$fdebug
and
print
"Reading $file\n"
;
open
(F,
"<"
,
$file
) or
die
"Cannot open file $file for read"
;
binmode
(F);
read
F,
$content
, 1000000;
close
F;
}
sub
responseCode
{
return
200;
}
sub
responseContent
{
$content
=~s/,
"headers"
:\{[^}]+\}\}//;
$content
=~s/\{
"content"
://;
return
$content
;
}
sub
XSECURITYTOKEN
{
die
$content
;
}
sub
responseHeader
{
my
(
$self
,
$header
)=
@_
;
my
$c
=decode_json(
$content
);
my
$headers
=
$c
->{headers};
return
$headers
->{
$header
};
}
sub
CST
{
}
sub
GET
{
my
(
$self
,
$url
,
$headers
)=
@_
;
POST(
$self
,
$url
,
undef
,
$headers
);
}
1;