API-Medium
view release on metacpan or search on metacpan
lib/API/Medium.pm view on Meta::CPAN
package API::Medium;
# ABSTRACT: Talk with medium.com using their REST API
our $VERSION = '0.902'; # VERSION
use Moose;
use HTTP::Tiny;
use Log::Any qw($log);
use JSON::MaybeXS;
use Module::Runtime 'use_module';
has 'server' => (
isa => 'Str',
is => 'ro',
default => 'https://api.medium.com/v1',
);
has 'access_token' => (
isa => 'Str',
is => 'rw',
required => 1,
);
has 'refresh_token' => (
isa => 'Str',
is => 'ro',
);
has '_client' => (
isa => 'HTTP::Tiny',
is => 'ro',
lazy_build => 1,
);
sub _build__client {
my $self = shift;
return HTTP::Tiny->new(
agent => join( '/', __PACKAGE__, $VERSION ),
default_headers => {
'Authorization' => 'Bearer ' . $self->access_token,
'Accept' => 'application/json',
'Content-Type' => 'application/json',
}
);
}
sub get_current_user {
my $self = shift;
my $res = $self->_request( 'GET', 'me' );
return $res->{data};
}
sub create_post {
my ( $self, $user_id, $post ) = @_;
$post->{publishStatus} ||= 'draft';
my $res = $self->_request( 'POST', 'users/' . $user_id . '/posts', $post );
return $res->{data}{url};
}
sub create_publication_post {
my ( $self, $publication_id, $post ) = @_;
$post->{publishStatus} ||= 'draft';
( run in 0.629 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )