API-Medium

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


    use API::Medium;
    my $m = new({
        access_token=>'your_token',
    });
    my $hash = $m->get_current_user;
    say $hash->{id};

    my $url       = $m->create_post( $user_id, $post );

    my $other_url = $m->create_publication_post( $publication_id, $post );

# DESCRIPTION

It's probably a good idea to read [the Medium API
docs](https://github.com/Medium/medium-api-docs) first, especially as
the various data structures you have to send (or might get back) are
**not** documented here.

See `example/hello_medium.pl` for a complete script.

README.md  view on Meta::CPAN

## get\_current\_user

    my $data = $m->get_current_user;

Fetch the User "object".

You will need this to get the user `id` for posting. Depending on
your app you might want to store your `id` in some config file to
save one API call.

## publications

Not implemented yet. Listing the user's publications

    /users/{{userId}}/publications

## contributors

Not implemented yet. Fetching contributors for a publication.

    /publications/{{publicationId}}/contributors

## create\_post

    my $url = $m->create_post( $user_id, $post_data );

Create a new post. If you pass in bad data, Medium will probably
report an error.

`publishStatus` is set to 'draft' unless you pass in another value.

## create\_publication\_post

    my $url = $m->create_publication_post( $publication_id, $post_data );

Create a new post under a publication. You will need to figure out the
publication\_id by calling the API from the commandline (until
`publications` is implemented.)

If you pass in bad data, Medium will probably report an error.

`publishStatus` is set to 'draft' unless you pass in another value.

## TODO

- OAuth2 Login
- Get a new access\_token from refresh\_token
- `publications`
- `contributors`

## Thanks

Thanks to Dave Cross for starting [Cultured
Perl](https://medium.com/cultured-perl), which prompted me to write
this module so I can auto-post blogposts from [my private
blog](http://domm.plix.at) to medium.

# AUTHOR

lib/API/Medium.pm  view on Meta::CPAN


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';

    my $res =
        $self->_request( 'POST', 'publications/' . $publication_id . '/posts',
        $post );
    return $res->{data}{url};
}

sub _request {
    my ( $self, $method, $endpoint, $data ) = @_;

    my $url = join( '/', $self->server, $endpoint );

    my $res;

lib/API/Medium.pm  view on Meta::CPAN


  use API::Medium;
  my $m = new({
      access_token=>'your_token',
  });
  my $hash = $m->get_current_user;
  say $hash->{id};

  my $url       = $m->create_post( $user_id, $post );

  my $other_url = $m->create_publication_post( $publication_id, $post );

=head1 DESCRIPTION

It's probably a good idea to read L<the Medium API
docs|https://github.com/Medium/medium-api-docs> first, especially as
the various data structures you have to send (or might get back) are
B<not> documented here.

See F<example/hello_medium.pl> for a complete script.

lib/API/Medium.pm  view on Meta::CPAN

=head2 get_current_user

  my $data = $m->get_current_user;

Fetch the User "object".

You will need this to get the user C<id> for posting. Depending on
your app you might want to store your C<id> in some config file to
save one API call.

=head2 publications

Not implemented yet. Listing the user's publications

  /users/{{userId}}/publications

=head2 contributors

Not implemented yet. Fetching contributors for a publication.

  /publications/{{publicationId}}/contributors

=head2 create_post

  my $url = $m->create_post( $user_id, $post_data );

Create a new post. If you pass in bad data, Medium will probably
report an error.

C<publishStatus> is set to 'draft' unless you pass in another value.

=head2 create_publication_post

  my $url = $m->create_publication_post( $publication_id, $post_data );

Create a new post under a publication. You will need to figure out the
publication_id by calling the API from the commandline (until
C<publications> is implemented.)

If you pass in bad data, Medium will probably report an error.

C<publishStatus> is set to 'draft' unless you pass in another value.

=head2 TODO

=over

=item * OAuth2 Login

=item * Get a new access_token from refresh_token

=item * C<publications>

=item * C<contributors>

=back

=head2 Thanks

Thanks to Dave Cross for starting L<Cultured
Perl|https://medium.com/cultured-perl>, which prompted me to write
this module so I can auto-post blogposts from L<my private



( run in 0.333 second using v1.01-cache-2.11-cpan-64827b87656 )