Skip to content

A Crystal library to easily communicate with the ejabberd admin API.

License

Notifications You must be signed in to change notification settings

c1tt1/ejabberd.cr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ejabberd.cr

A Crystal library to easily communicate with the ejabberd admin API. It implements all ejabberd rest api reference.
This library is small and simple, it can be read and understood in no more than 10 minutes.

Installation

Add this to your application's shard.yml:

dependencies:
  ejabberd:
    github: kndt/ejabberd.cr

Usage

require "ejabberd"

# ejabberd = Ejabberd.new "api_url"
ejabberd = Ejabberd.new "http://127.0.0.1:5280"

This library implements same method names as the ejabberd rest api reference and take same value types as the api reference.
For example add_rosteritem in the api reference like the following:

POST /api/add_rosteritem
{
  "localuser": "user1",
  "localserver": "myserver.com",
  "user": "user2",
  "server": "myserver.com",
  "nick": "User 2",
  "group": "Friends",
  "subs": "both"
}

HTTP/1.1 200 OK
""

With this library the above becomes the following:

ejabberd.add_rosteritem("user1", "myserver.com", "user2", "myserver.com", "User 2", "Friends", "both")

You can also add the argument names like the following:

ejabberd.add_rosteritem(localuser: "user1", localserver: "myserver.com", user: "user2", server: "myserver.com", nick: "User 2", group: "Friends", subs: "both")

Return types

Each method return an HTTP::Client::Response instance, so you can any call methods like body or status_code on it.

Memory footprint

The library resides on the stack which makes it fast and cheap due to to no allocation on the heap.

Development

This project requires a locally running ejabberd server running with http api set in ejabberd.yml file. The test specs are currently in implementation.

Contributing

  1. Fork it ( https://github.com/kndt/ejabberd.cr/ )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • Bug reports and pull requests are welcome on GitHub at kndt - creator, maintainer

About

A Crystal library to easily communicate with the ejabberd admin API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published