Have ideas to improve npm?Join in the discussion! »

    medium-wrapi

    0.1.0 • Public • Published

    Medium API Wrapper

    Client interface for accessing Medium API.

    Usage

    Create a client object to connect to Medium API endpoints.

    var mediumWrapi = require('medium-wrapi');
     
    var client = new mediumWrapi("v1", API_BEARER_TOKEN));
     
    // Now you are ready to make API calls to medium.

    Provide parameters and a callback.

    API calls follow this syntax:

    client.action(param1, ..., callback);

    • param - (as required) url parameters - eg: For publications the value for {{userId}}.

    Examples

    Getting the authenticated user's details

    client.user(function(err, data) {
      if (!err) {
        console.log(data);
      }
    });

    Listing the user's publications

    client.publications("5303d74c64f66366f00cb9b2a94f3251bf5", 
      function(err, data) {
        if (!err) {
          console.log(data);
        }
      }
    );

    Fetching contributors for a publication

    client.contributors("b45573563f5a", function(err, data) {
      if (!err) {
        console.log(data);
      }
    });

    Creating a post

    client.posts("5303d74c64f66366f00cb9b2a94f3251bf5",
      {
        "title": "Liverpool FC",
        "contentFormat": "html",
        "content": "<h1>Liverpool FC</h1><p>You’ll never walk alone.</p>",
        "canonicalUrl": "http://jamietalbot.com/posts/liverpool-fc",
        "tags": ["football", "sport", "Liverpool"],
        "publishStatus": "public"
      },
        function(err, data) {
          if (!err) {
            console.log(data);
          }
        }
    );

    Creating a post under a publication

    client.publication.post("b45573563f5a",
      {
        "title": "Hard things in software development",
        "contentFormat": "html",
        "content": "<p>Cache invalidation</p><p>Naming things</p>",
        "tags": ["development", "design"],
        "publishStatus": "draft"
      },
      function(err, data) {
        if (!err) {
          console.log(data);
        } 
      }
    );

    Uploading an image

    client.images(
      {
        formData: {
          custom_file: {
            value:  fs.createReadStream('/path/to/myimage.png'),
            options: {
              filename: 'lenticular.png',
              contentType: 'image/png'
            }
          }
        }
      }, 
      function(err, data) {
        if (!err) {
          console.log(data);
        } 
      }
    );

    API Functions

    Users

    Publications

    Posts

    Images

    License

    MIT

    Install

    npm i medium-wrapi

    DownloadsWeekly Downloads

    1

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • avatar