GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Twitter::API::Role::RequestArgs(3) User Contributed Perl Documentation Twitter::API::Role::RequestArgs(3)

Twitter::API::Role::RequestArgs - API request method helpers

version 1.0006

    package MyApiMethods;
    use Moo::Role;

    sub timeline {
        shift->request_with_id(get => 'statuses/user_timeline, @_);
    }

Then, in your application code:

    use Twitter::API;

    my $client = Twitter::API->new_with_traits(
        traits => '+MyApiMethods',
        %othe_new_options,
    );

    my $statuses = $client->timeline('semifor');

    # equivalent to:
    my $statuses = $client->get('statuses/user_timeline', {
        screen_name => 'semifor',
    });

Helper methods for implementers of custom traits for creating concise Twitter API methods. Used in Twitter::API::Trait::ApiMethods.

Transforms an argument list with a required "screen_name" or "user_id", optionally passed as a leading, positional argument, a hashref argument.

If a hashref follows the optional plain scalar, the user_id or screen_name is added to it. Otherwise a new hashref is created and inserted into @_.

If the optional plain scalar argument is missing, and there is hashref of arguments, or if the hashref does not contain the key "screen_name" or "user_id", request_with_id croaks.

Examples:

    $self->request_with_id(get => 'some/endpoint', 'foo');
    # is transformed to:
    $self->request(get => 'some/endpoint', { screen_name => 'foo' });

    $self->request_with_id(get => 'some/endpoint', 8575429);
    # is transformed to:
    $self->request(get => 'some/endpoint', { user_id => 8675429 });

    $self->request_with_id(get => 'some/endpoint', {
        screen_name => 'semifor',
    });
    # is transformed to:
    $self->request(get => 'some/endpoint', { screen_name => 'semifor' });

    $self->request_with_id(get => 'some/endpoint', {
        foo => 'bar',
    }); ### croaks ###

Transforms a list of required arguments, optionally provided positionally in a determined order, into a hashref of named arguments. If a hashref follows the positional arguments, the named arguments are added to it. Otherwise, a new hashref in inserted into @_.

Zero or more of the required arguments may be provided positionally, as long as the appear in the specified order. I any of the required arguments are not provided positionally, they must be provided in the hashref or request_with_pos_args croaks.

The positional name ":ID" is treated specially. It is transformed to "user_id" if the value it represents contains only digits. Otherwise, it is transformed to "screen_name".

Examples:

    $self->request_with_pos_args(
        [ 'id', 'name' ], get => 'some/endpoint',
        '007', 'Bond'
    );
    # is transformed to:
    $self->request(get => 'some/endpoint', {
        id   => '007',
        name => 'Bond',
    });

    $self->request_with_pos_args(
        [ 'id', 'name' ], get => 'some/endpoint',
        '007', { name => 'Bond' }
    );
    # is also transformed to:
    $self->request(get => 'some/endpoint', {
        id   => '007',
        name => 'Bond',
    });

    $self->request_with_pos_args(
        [ ':ID', 'status' ], get => 'some/endpoint',
        'alice', 'down the rabbit hole'
    );
    # is transformed to:
    $self->request(get => 'some/endpoint', {
        sreen_name => 'alice',
        status     => 'down the rabbit hole',
    });

Helper method for "request_with_pos_args". Takes the same arguments described in "request_with_pos_args" above, and returns a list of arguments ready for a call to "request".

Individual methods in Twitter::API::Trait::ApiMethods use "normalize_pos_args" if they need to do further processing on the args hashref before calling "request".

Some Twitter API arguments take a list of values as a string of comma separated items. To allow callers to pass an array reference of items instead, this method is used to flatten array references to strings. The key or keys identify which values to flatten in the "\%args" hash reference, if they exist.

Marc Mims <marc@questright.com>

This software is copyright (c) 2015-2021 by Marc Mims.

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

2021-04-01 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.