Add more functions to the Utopian api npm package

New Features

What feature(s) did you add?

I have added three more functions to the npm package.

  • To get post by username and permlink.
utopian.getPost = (username, permlink) => {
  return new Promise((resolve, reject) => {
    requestURL(ENDPOINT_POSTS + '/' + username + '/' + permlink).then((data) => {
      resolve(JSON.parse(data))
    }).catch((err) => reject(err))
  })
}
  • To get post URL by postid
utopian.getPostURL = (postID) => {
  return new Promise((resolve, reject) => {
    requestURL(ENDPOINT_POSTS + '/byid/' + postID).then((data) => {
      resolve('https://utopian.io' + JSON.parse(data).url)
    }).catch((err) => reject(err))
  })
}
  • To get posts by a user
utopian.getPostByAuthor = (username, options) => {
  return new Promise((resolve, reject) => {
    if (!options) options = {}
    if (options.limit > 20 || options.limit < 1) {
      options.limit = 20
    }
    if (options.length === 0) {
      options.limit = 20
      options.skip = 0
    }
    options.section = 'author'
    options.author = username
    requestURL(ENDPOINT_POSTS + '?' + encodeQueryData(options)).then((data) => {
      resolve(JSON.parse(data))
    }).catch((err) => reject(err))
  })
}
How did you implement it/them?

I referred to the Utopian docs for checking out the endpoints to add these specific features. I have added relevant tests for these features. You can see the commits in the attached pull request.

Tests were written usng chaiJS and mochaJS and code qulity was checked by standard.



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center