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