ethavatar icon indicating copy to clipboard operation
ethavatar copied to clipboard

JavaScript API for using in other programs

Open filips123 opened this issue 5 years ago • 8 comments

There could be some simple library / API for JavaScript (and for other languages) that would automatically get or set avatar for address with code.

There is already https://github.com/gitcoinco/ethavatar#to-integrate-into-your-app, but it will be better to have pre-built library for this.

filips123 avatar Sep 28 '18 13:09 filips123

I could probably do this, but I have few questions.

How many methods should this library have? Should it only have method to get and set avatar or also some others? Also, it is probably better to have separate repository called ethavatar.js for this, because it would allowed to also make libraries in other languages.

filips123 avatar Sep 28 '18 19:09 filips123

If I had my druthers, I'd say keep everything in one repository and start with a clients/, sdk/, or some other similar subdirectory. So maybe clients|sdk/js ?

Once we get rolling on a base for clients, I'll introduce automated releases that's deterministic based on changes.

Ideally, we'll start rolling out the deployments of ethavatar on kubeless, aws lambda, or k8s.

mbeacom avatar Sep 29 '18 14:09 mbeacom

Maybe we could also use Git Submodules for multiple languages. I also recommend to clean the current root repository, because it is a bit messy.

How many methods should this library have? Should it only have method to get and set avatar or also some others?

filips123 avatar Sep 29 '18 17:09 filips123

I created basic EthAvatar library for JavaScript. It is available on https://github.com/filips123/EthAvatar.JS. It will be in my repository for now, but when it become stable, it could maybe be transferred to this repository. It is asynchronous, so users could use promises or async/await.

I will also create basic command line program to get and set avatars from command line.

It supports getting and setting avatars. It currently not support smart contract events and Web3 1.0, but this should be implemented.

The program is currently not stable so it should not be used in main EthAvatar website for now.


TODO

  • [x] ~~Command line program~~
  • [x] ~~Watching for contract events~~
  • [x] ~~Deleting avatars~~
  • [x] ~~Uploading avatars from files or URLs~~
  • [x] ~~Better tests~~
  • [ ] Support for JavaScript fronted frameworks

Also, this repository should be cleaned because it is a bit messy. We could use Git Submodules for that, or split it into multiple repositories. The problem with multiple libraries in same repository is that some dependencies managers (e.g Packagist for PHP) don't support this (see composer/composer#2588).

It's parts should be split in different folders or repositories:

  • contracts: Folder with smart contract files and Truffle Framework
  • website: Folder with main EthAvatar website
  • libraries: Folder with client libraries
    • javascript: Folder with JavaScript library
    • java: Folder with Java library
    • python: Folder with Python library
    • php: Folder with PHP library

There should be some automated system (e.g. Travis CI) to build and deploy those parts automatically. In the future, smart contract should also be published to EthPM which can be done with Truffle.

filips123 avatar Oct 14 '18 08:10 filips123

nice!! is there a demo somewhere we can play with

owocki avatar Oct 14 '18 21:10 owocki

There is exemple file, but it currently only supports getting avatars. I will also create example for setting avatars.

filips123 avatar Oct 15 '18 06:10 filips123

I created command line program, and it is probably the best thing to look how this library works and how to use it.

https://github.com/filips123/EthAvatar.JS/blob/master/src/console.js

filips123 avatar Oct 15 '18 18:10 filips123

@owocki @mbeacom I completed almost all TODOs so library is almost finished. There could still be some fixes and updates, but I think it will soon be time for stable release. What do you think?

One problem is that when posting avatar to URL, address and avatar should be left trimmed on the server side. This is because of form-data/form-data#414 and axios/axios#1892.

filips123 avatar Nov 27 '18 20:11 filips123