View on
MetaCPAN
Carlos Fernando Avila Gratz > Net-Moip-V2-0.05 > Net::Moip::V2::Endpoint

Download:
Net-Moip-V2-0.05.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Source   Latest Release: Net-Moip-V2-0.06

NAME ^

Net::Moip::V2::Endpoint - Send HTTP requests to an endpoint.

SYNOPSIS ^

    use Net::Moip::V2;

    my $moip = Net::Moip::V2->new( ... );

    # List orders: GET /orders
    my $ep_orders = $moip->endpoint('orders');
    my $response = $ep_orders->get;   # $response is a Furl::Response object

DESCRIPTION ^

This class represents a single endpoint in the Moip API v2. It provides methods for sending raw http requests, handling the authorization and other required http headers for you.

METHDOS ^

get[$id])

Sends a GET request to the endpoint url. Can optionally append the a resource id to the url. Returns the raw Furl::Response object.

    # GET https://api.moip.com.br/v2/orders
    my $response = $moip->endpoint('orders')->get;

    if ($response->is_success) {
        my $data = $moip->decode_json($response->content);
        foreach my $order (@{ $data->{orders} }) {
            ...
        }
    }

    # GET https://api.moip.com.br/v2/orders/ORD-123456789012
    my $response = $moip->endpoint('orders')->get('ORD-123456789012');

    if ($response->is_success) {
        my $order = $moip->decode_json($response->content);
        ...
    }

For detailed information about the response format, see https://dev.moip.com.br/v2.0/reference#intro.

post(\%data)

Sends a GET request to the endpoint url. The \%data hashref is encoded to JSON and the proper content type and authentication headers are set. Returns the raw Furl::Response object.

    # POST https://api.moip.com.br/v2/orders
    my $response = $moip->endpoint('orders')->post({
        ownId: '12345',
        amount: { ... },
        ...
    });

    if ($response->is_success) {
        my $new_order = $moip->decode_json($response->content);
        ...
    }

Consult the official API reference for detailed information about the required data for each endpoint.

decode_json($json_string)

Helper method for decoding json string into perl data.

LICENSE ^

Copyright (C) Carlos Fernando Avila Gratz.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR ^

Carlos Fernando Avila Gratz <cafe@kreato.com.br>

syntax highlighting: