Oauth Client For fanfou, Written in Perl 6
Branch: master
Clone or download
Latest commit 1de9693 Nov 28, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib multipart/form-data Nov 12, 2018
t
.gitignore FanFou Client 0.0.1 version May 11, 2018
.travis.yml
LICENSE
META6.json rename fanfou to FanFou May 15, 2018
README.md Update README.md Nov 28, 2018
dist.ini FanFou Client 0.0.1 version May 11, 2018

README.md

DESCRIPTION

FanFou is a oauth client inspared by fanfou-py.

The module provides several ways to authorize, see Fanfou API OAuth for more details.

Write Your Own Robot

img

use FanFou;
my %oauth_consumer = key => 'your_consumer_key', secret => 'your_secret_key';

# get client
my $client = FanFou::XAuth.new(oauth_consumer => %oauth_consumer, username => 'your_username', password => 'your_password');

# get response
my $resp = from-json await $client.request('/statuses/home_timeline', 'GET').body-text;
say $resp.perl;

# post a message
my %body = 'status' => "Hi, fan, I'm a robot";
$client.request('/statuses/update', 'POST', %body);

You can use Terminal::ANSIColor and Terminal::Spinners for better format and experience:

use FanFou;
use JSON::Fast;
use Terminal::ANSIColor;
use Terminal::Spinners;

sub MAIN($str?) {
    my %oauth_consumer = key => 'xxx', secret => 'xxx';
    my $client = FanFou::XAuth.new(oauth_consumer => %oauth_consumer, username => 'xxx', password => 'xxx');

    if $str.defined {
        # post a message
        my %body = 'status' => "$str";
        $client.request('/statuses/update', 'POST', %body);
    } else {

        my $dots = Spinner.new: type => 'dots';
        my $promise = start {
            my $resp = from-json await $client.request('/statuses/home_timeline', 'GET').body-text;
            say '';
            for @$resp.sort(*.{'user'}.{'unique_id'}) -> $p {
                say '[' , colored("{$p.{'user'}.{'name'}}", "{(^256).pick}"), '] ', $p.{'text'};
            }
        }; # promise of your long running process
        until $promise.status {
            $dots.next; # prints the next spinner frame
        }
    }
}

AUTHOR

ohmycloud@gmail.com

COPYRIGHT AND LICENSE

Copyright 2018

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.