| 1 | package OpenData::ShortNumberInfo; | ||
| 2 | |||
| 3 | 1 | ▶ | use v5.36; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Object::Pad; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | class OpenData::ShortNumberInfo { | ||
| 7 | 1 | ▶ | use HTTP::Tiny; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use URI; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use JSON; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | |||
| 11 | field $number : | ||
| 12 | param //= 103; | ||
| 13 | |||
| 14 | method name ( ) { | ||
| 15 | # Construct API URL | ||
| 16 | my $uri = URI -> new( 'https://api.opendata.az' ); | ||
| 17 | $uri -> path_segments( | ||
| 18 | 'v1', # version | ||
| 19 | 'json', # format | ||
| 20 | 'nrytn', # organization | ||
| 21 | 'ShortNumberInfo', # service | ||
| 22 | $number # parameter | ||
| 23 | ); | ||
| 24 | |||
| 25 | # Issue HTTP request to get the web page | ||
| 26 | my $http = HTTP::Tiny -> new(); | ||
| 27 | my $response = $http -> get( $uri ); # RV: HR | ||
| 28 | |||
| 29 | # Convert JSON from HTTP response into Perl hash | ||
| 30 | my $json = JSON -> new(); | ||
| 31 | my $content = $json -> decode( $response -> {content} ); | ||
| 32 | |||
| 33 | unless ( defined( $content -> {StatusMessage} ) ) { | ||
| 34 | return $content -> {Response} -> [0] -> {Name}; | ||
| 35 | } | ||
| 36 | else { | ||
| 37 | STDERR -> say( $content -> {StatusMessage} ); | ||
| 38 | exit 2; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | ||