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

in utopian-io •  7 years ago  (edited)

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

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
  ·  7 years ago (edited)

Are you flash? :D

Hey @wehmoen, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

Hey @ms10398 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x