https://github.com/dryruby/calimero.rb
https://github.com/dryruby/calimero.rb
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/dryruby/calimero.rb
- Owner: dryruby
- License: unlicense
- Created: 2025-03-13T00:06:41.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-03-18T17:27:54.000Z (11 months ago)
- Last Synced: 2025-06-22T02:03:56.474Z (7 months ago)
- Language: Ruby
- Size: 19.5 KB
- Stars: 11
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Codeowners: CODEOWNERS
- Authors: AUTHORS
Awesome Lists containing this project
README
# Calimero Network for Ruby
[](https://unlicense.org)
[](https://rubygems.org/gems/calimero)
[](https://rubygems.org/gems/calimero)
[](https://rubydoc.info/gems/calimero)
**Calimero.rb** is a [Ruby] client library for the [Calimero Network].
> [!TIP]
> π§ _We are building in public. This is presently under heavy construction._
## β¨ Features
- Implemented natively in Ruby with minimal dependencies, ensuring low overhead and efficient performance.
- Implements a `JsonRpcClient` for sending queries and updates to the applications in Calimero nodes.
- Handles write and read calls to Calimero network applications.
- Handles config management of Calimero nodes.
- Manages authentication workflow using Ed25519-keypair.
- π§ Manages authentication workflow using token acquisitions and refresh.
- π§Implements a `WsSubscriptionsClient` for subscribing to real-time updates from the Calimero nodes.
- π§ Supports interaction with Calimero Admin and Calimero Node APIs.
- Adheres to the Ruby API Guidelines in its [naming conventions].
- 100% free and unencumbered public domain software.
## π οΈ Prerequisites
- [Ruby] 3.0+
## β¬οΈ Installation
### Installation via RubyGems
```bash
gem install calimero
```
## π Examples
### Importing the library
```ruby
require 'calimero'
```
### Loading the Calimero config
You can load a Calimero config file the following way:
```ruby
require 'calimero'
config_path = "/path/to/your/calimero/config.toml"
config = Calimero::load_config(config_path)
```
If you would like to utilize the default Calimero config folder:
```ruby
require 'calimero'
config_path = "#{Calimero::default_config_folder}/node1/config.toml"
config = Calimero::load_config(config_path)
```
### Importing `Ed25519Keypair` from the config and signing an arbitrary message with it
```ruby
require 'calimero'
config_path = "#{Calimero::default_config_folder}/node1/config.toml"
config = Calimero::load_config(config_path)
message = "Hello, Calimero"
signature = config.keypair.sign(message)
```
### Importing `Ed25519Keypair` from base58-encoded protobuf message and signing an arbitrary message with it
```ruby
require 'calimero'
# The keypair should be base58-encoded protobuf message (using `libp2p_identity::Keypair`)
keypair_base58_protobuf = ""
keypair = Ed25519Keypair.new(keypair_base58_protobuf)
message = "Hello, Calimero"
signature = keypair.sign(message)
```
### Executing arbitrary method in Calimero Application with authentication using dev JSONRPC endpoint
```ruby
require 'calimero'
require 'base58'
client = JsonRpcClient.new('http://localhost:2428', '/jsonrpc/dev')
params = RpcQueryParams.new('your_application_context_id', 'some_method', { 'some': 'args' }, 'executor_public_key')
config_path = "#{Calimero::default_config_folder}/node1/config.toml"
config = Calimero::load_config(config_path)
timestamp = Time.now.utc.to_i.to_s
signature = config.keypair.sign(timestamp)
signature_b58 = Base58.binary_to_base58(signature, :bitcoin)
headers = {
'Content-Type' => 'application/json',
'X-Signature' => signature_b58,
'X-Timestamp' => timestamp
}
request_config = RequestConfig.new(timeout: 1000, headers: headers)
result = client.execute(query_params, request_config)
if result.error
puts "Error: #{result.error}"
else
puts "Result: #{result.result}"
end
```
### Executing arbitrary method in Calimero Application
```ruby
require 'calimero'
client = JsonRpcClient.new('http://localhost:2428', '/jsonrpc')
params = RpcQueryParams.new('your_application_context_id', 'some_method', { 'some': 'args' }, 'executor_public_key')
bearer_auth_token = "some bearer auth token"
headers = {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{bearer_auth_token}"
}
request_config = RequestConfig.new(timeout: 1000, headers: headers)
result = client.execute(params, request_config)
if result.error
puts "Error: #{result.error}"
else
puts "Result: #{result.result}"
end
```
### Fetching all posts from OnlyPeers application
You can query all the posts in the given [OnlyPeers] demo application, by using the following example:
```sh
CONTEXT_ID= EXECUTOR_PUBLIC_KEY= ruby examples/onlypeers_get_all_posts.rb
```
That example also contains an example on how to use the `Config` and `Ed25519Keypair` to authenticate your requests to the Calimero node.
## π Reference
https://rubydoc.info/gems/calimero
## π¨βπ» Development
```bash
git clone https://github.com/dryruby/calimero.rb.git
```
- - -
[](https://x.com/share?url=https://github.com/dryruby/calimero.rb&text=calimero.rb)
[](https://reddit.com/submit?url=https://github.com/dryruby/calimero.rb&title=calimero.rb)
[](https://news.ycombinator.com/submitlink?u=https://github.com/dryruby/calimero.rb&t=calimero.rb)
[](https://www.facebook.com/sharer/sharer.php?u=https://github.com/dryruby/calimero.rb)
[Calimero Network]: https://calimero.network/
[Ruby]: https://ruby-lang.org
[OnlyPeers]: https://calimero-network.github.io/tutorials/awesome-projects/only-peers/