Skip to content

perltaiwan/Finance-Currency-Convert-Esunbank

Repository files navigation

NAME

    Finance::Currency::Convert::Esunbank - Query currency exchange rates
    from Esunbank

VERSION

    v0.1.1

DESCRIPTION

    This module crawl and parses currency exchange rates listed on this web
    page:
    https://www.esunbank.com.tw/bank/iframe/widget/rate/foreign-exchange-rate
    . All prices on this page are in TWD (Taiwan Dollar.) For this reason,
    it can only convert non-TWD currencies to TWD.

FUNCTIONS

    The following functions are exportable, but not exported by default.

    Some annotations with fictional Types are used in the following
    documentation just for the purpose of explaination. No Type-validation
    are implemented, nor are they defined. Not in this module.

    "Num" referrer to a number, "Currency" is a short string such as 'TWD',
    'USD'. The notation `Maybe[T]` means that the variable can contain a
    value either be of type T, or undef. See: Types::Standard or
    Moose::Util::TypeConstraints for more description of these notations.

 convert_currency

    Definition:

        ($error :Maybe[Str], $result :Maybe[Num]) =
            convert_currency(
                $amount :Num
                $from :Currency,
                $to :Currency
            )

    When it is successful, $error is undef and $result contained the parsed
    output.

    When error of some kind happens, $error contains the error message and
    $result is undef.

    Example Usage:

        # Error-checking
        my ($err, $n) = convert_currency(100, 'USD', 'TWD');
        die "Error: $err": if $err;
        say "100 USD is about $n TWD";
    
        # Ignore error message. Checks the result directly.
        my $n = convert_currency(100, 'USD', 'TWD');
        if ( defined($n) ) {
            say "100 USD is about $n TWD";
        } else {
            say "Failed to convert 100 USD to TWD";
        }

 get_currencies

    With this function, the entire exchange rate table are parsed and
    returned in the special strucutre.

    Definition:

        ($error :Maybe[Str], $result :Maybe[ArrayRef[Rate]]) =
            convert_currency(
                $amount :Num,
                $from :Currency,
                $to :Currency
            )

    When it is successful, $error is undef and $result contained the parsed
    output.

    When error of some kind happens, $error contains the error message and
    $result is undef.

    Usage:

        # Error-checking
        my ($err, $o) = get_currencies();
        die "Error: $err": if $err;
        do_something($o);
    
        # Ignore error message. Checks the result directly.
        my $o = get_currencies();
        if ($o) {
            ...
        } else {
            ...
        }

    The "Rate" type is a HashRef with 5 specific key-value pairs that looks
    like this:

        {
            currency         => "USD",
            zh_currency_name => "美金",
            en_currency_name => "USD",
            buy_at           => 33.06,
            sell_at          => 33.56
        }

    This structure is just a directly translation of the rate exchange
    table shown on the source web page.

AUTHOR

    Kang-min Liu <[email protected]>

LICENSE

    This is free software, licensed under:

      The MIT (X11) License

About

For querying currency exchange rates on Esunbank

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages