Mohit Sharma avatar

[Utopian.js] - Final Release with all features added

ms10398

Published: 12 Feb 2018 › Updated: 12 Feb 2018[Utopian.js] - Final Release with all features added

[Utopian.js] - Final Release with all features added

New Features

What feature(s) did you add?

Now the library has more functions like -

  • getPost() by username and permlink
  • getPostURL() by postID
  • getPostsByAuthor by username
  • getPostsByGithubProject

How did you implement it/them?

For this functions there was following lines of code-

utopian.getPost = function (username, permlink) {
    return new Promise(function (resolve, reject) {
        $.ajax({
            url: ENDPOINT_POST + '/' + username + '/' + permlink,
            success: function success(data) {
                resolve(data);
            },
            error: function error(xhr, status, _error6) {
                reject(_error6);
            }
        });
    });
};
 utopian.getPostURL = function (postID) {
    return new Promise(function (resolve, reject) {
        $.ajax({
            url: ENDPOINT_POST + '/byid/' + postID,
            success: function success(data) {
                resolve('https://utopian.io' + data.url);
            },
            error: function error(xhr, status, _error7) {
                reject(_error7);
            }
        });
    });
};
utopian.getPostsByAuthor = (username, options={}) => {
    let ENDPOINT_POSTS = ENDPOINT_POST
 
  if (options.limit > 20 || options.limit < 1) {
    options.limit = 20
  }
 
  if (Object.keys(options).length === 0) {
    options.limit = 20
    options.skip = 0
  }
  options.section = 'author'
  options.author = username
  ENDPOINT_POSTS+= '?';
  for(let x in options)
  {
    ENDPOINT_POSTS = `${ENDPOINT_POSTS}` + `${x}=${options[x]}&`
  }
  ENDPOINT_POSTS = ENDPOINT_POSTS.slice(0,-1)
  return new Promise((resolve, reject) => {
    $.ajax(
        {
            url: ENDPOINT_POSTS,
            success: function(result) {
                resolve(result);
            },
            error: function(xhr, status, error) {
                reject(error)
            }
        })
    })
}
utopian.getPostsByGithubProject = (repoName, options) => {
  return new Promise((resolve, reject) => {
    return getGithubRepoIdByRepoName(repoName)
      .then(projectId => {
        return utopian.getPosts(Object.assign({
          section: 'project',
          sortBy: 'created',
          platform: 'github',
          projectId,
          type: 'all'
        }, options || {})).then(resolve).catch(reject)
      }).catch(reject)
  })
}

Roadmap

This would be its alpha release and maybe more features would be added if there are more endpoints added to the API or requested by the users.

  • How to contribute?
    You may contribute to the repository by forking it and making a PR.
    PR's are always welcome :)

Thanks for reading.



Posted on Utopian.io - Rewarding Open Source Contributors

Leave [Utopian.js] - Final Release with all features added to:

Written by

Full Stack Web Developer | Utopian Community Manager

Read more #utopian-io posts


Best Posts From Mohit Sharma

We have not curated any of ms10398's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Mohit Sharma