All Projects → an-lee → mixin_bot

an-lee / mixin_bot

Licence: MIT license
A simple API wrapper for Mixin Network in Ruby

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to mixin bot

harvesting
Ruby wrapper for the Harvest API v2
Stars: ✭ 24 (+100%)
Mutual labels:  gem, api-wrapper
Instagram api gem
A Ruby wrapper for the Instagram API
Stars: ✭ 100 (+733.33%)
Mutual labels:  gem, api-wrapper
pinboard.net
Fully featured API wrapper for pinboard.in
Stars: ✭ 21 (+75%)
Mutual labels:  api-wrapper
python-pyfields
Define fields in python classes. Easily.
Stars: ✭ 39 (+225%)
Mutual labels:  mixin
active record-updated at
Touch `updated_at` by default with calls to `update_all` and `update_column(s)`
Stars: ✭ 27 (+125%)
Mutual labels:  gem
autopilot-api
A third-party JavaScript wrapper for Autopilot's REST API.
Stars: ✭ 14 (+16.67%)
Mutual labels:  api-wrapper
i18n lazy scope
Use lazy lookup with custom i18n scopes.
Stars: ✭ 11 (-8.33%)
Mutual labels:  gem
helm2-mixin
Helm mixin for Porter
Stars: ✭ 14 (+16.67%)
Mutual labels:  mixin
syobocal
Simle gem for Syboi Calendar
Stars: ✭ 13 (+8.33%)
Mutual labels:  gem
pagespeedParseR
pagespeedParseR is an R wrapper for Google Pagespeed Insights API, that also enables convenient parsing
Stars: ✭ 20 (+66.67%)
Mutual labels:  api-wrapper
cryptox
Common API wrapper for multiple crypto currency exchanges
Stars: ✭ 50 (+316.67%)
Mutual labels:  api-wrapper
southwest-checkin
Easy-to-use gem to check in to Southwest flights automatically. Also supports sending email notifications.
Stars: ✭ 67 (+458.33%)
Mutual labels:  gem
clash-api
Ruby wrapper for the Clash of Clans API
Stars: ✭ 14 (+16.67%)
Mutual labels:  api-wrapper
my api client
A framework of Web API Client. Provides features error handling, retrying, pagination and so on.
Stars: ✭ 19 (+58.33%)
Mutual labels:  gem
PowerSchool-API
A Node.js library for interacting with the PowerSchool SIS API.
Stars: ✭ 21 (+75%)
Mutual labels:  api-wrapper
covidtrackerapiwrapper
CovidSharp is a crossplatform C# API wrapper for the Coronavirus tracking API (https://github.com/ExpDev07/coronavirus-tracker-api)
Stars: ✭ 11 (-8.33%)
Mutual labels:  api-wrapper
drip-php
An object-oriented PHP wrapper for Drip's API
Stars: ✭ 22 (+83.33%)
Mutual labels:  api-wrapper
exception hunter
Crash reporting engine to hunt down bugs 🐞
Stars: ✭ 78 (+550%)
Mutual labels:  gem
tplink-smartplug-api
TP-Link HS1xx smart plug API wrapper.
Stars: ✭ 48 (+300%)
Mutual labels:  api-wrapper
backlog kit
Client library for the Nulab's Backlog API version 2 written in Ruby.
Stars: ✭ 28 (+133.33%)
Mutual labels:  gem

MixinBot

An API wrapper for Mixin Network

Installation

Add to gemfile, and bundle install

gem 'mixin_bot'

Or

gem install mixin_bot

Usage

CLI

Commands:
  mixinbot api PATH -k, --keystore=KEYSTORE                                   # request PATH of Mixin API
  mixinbot decodetx TRANSACTION                                               # decode raw transaction
  mixinbot encrypt PIN -k, --keystore=KEYSTORE                                # encrypt PIN using private key
  mixinbot generatetrace HASH                                                 # generate trace ID from Tx hash
  mixinbot help [COMMAND]                                                     # Describe available commands or one specific command
  mixinbot nftmemo -c, --collection=COLLECTION -h, --hash=HASH -t, --token=N  # memo for mint NFT
  mixinbot unique UUIDS                                                       # generate unique UUID for two or more UUIDs
  mixinbot version                                                            # Distay MixinBot version

Options:
  -a, [--apihost=APIHOST]        # Specify mixin api host
                                 # Default: api.mixin.one
  -r, [--pretty], [--no-pretty]  # Print output in pretty
                                 # Default: true

Example:

$ mixinbot api /me -k ~/.mixinbot/keystore.json

Initialize params

To use MixinBot api, you should set the keys first.

MixinBot.client_id = '25696f85-b7b4-4509-8c3f-2684a8fc4a2a'
MixinBot.client_secret = 'd9dc58107bacde671...'
MixinBot.session_id ='25696f85-b7b4-4509-8c3f-2684a8fc4a2a'
MixinBot.pin_token = 'b0pjBUKI0Vp9K+NspaL....'
MixinBot.private_key = <<~PRIVATE_KEY
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDQYjiR/Te6Bh/1bk8gWRbQkrX0AIGPja1DLUQHu5Uw9M4P53O3
f4pDCGoN3R5+LYjODtquOwmEjcMhbhp6XarrnJVXH8WGmJcpjVwGtwIjPTeRMu4Z
...
-----END RSA PRIVATE KEY-----
PRIVATE_KEY

# pin_code is not necessary unless you need to transfer assets
MixinBot.pin_code = '431005'

Call mixin apis

Then you can use MixinBot by call MixinBot.api, for example

# get the bot profile
MixinBot.api.read_me

# get assets of the bot
MixinBot.api.read_assets

# transfer asset to somebody
MixinBot.api
  .create_transfer(
    '123456', # pin_code
    asset_id: '965e5c6e-434c-3fa9-b780-c50f43cd955c', # the asset uuid to transfer
    opponent_id: '6ae1c7ae-1df1-498e-8f21-d48cb6d129b5', # receiver's mixin uuid
    amount: 0.00000001, # amount
    memo: 'test from MixinBot', # memo, 140 length at max
    trace_id: '0798327a-d499-416e-9b26-5cdc5b7d841e' # a uuid to trace transfer
)

# etc

Connect Mixin Blaze

Your bot can receive/send messages from/to any users in Mixin Network, including all users in Mixin Messenger by connecting to Mixin Blaze.

With MixinBot, doing this is super easy.

# run it in a EventMachine
EM.run {
  MixinBot.api.start_blaze_connect do
    # do something when the websocket connected
    def on_open(blaze, _event)
      p [Time.now.to_s, :on_open]

      # send the list_pending_message to receive messages
      blaze.send list_pending_message
    end

    # do something when receive message
    def on_message(blaze, event)
      raw = JSON.parse read_ws_message(event.data)
      p [Time.now.to_s, :on_message, raw&.[]('action')]

      blaze.send acknowledge_message_receipt(raw['data']['message_id']) unless raw&.[]('data')&.[]('message_id').nil?
    end

    # do something when websocket error
    def on_error(blaze, event)
      p [Time.now.to_s, :on_error]
    end

    # do something when websocket close
    def on_close(blaze, event)
      p [Time.now.to_s, :on_close, event.code, event.reason]
    end
  end
}

Multiple Bot management

If you need to manage multiple mixin bot, you can config like this.

bot1_api = MixinBot::API.new(
  client_id: '...',
  client_secret: '...',
  session_id: '...',
  pin_token: '...',
  private_key: '...',
  pin_code: '123456'
)

bot2_api = MixinBot::API.new(
  client_id: '...',
  client_secret: '...',
  session_id: '...',
  pin_token: '...',
  private_key: '...',
  pin_code: '123456'
)

bot1_api.read_me
bot2_api.read_me

More Example

See in the Spec files.

For WebSocket use case, see in examples/blaze.rb.

Test

Clone the project:

git clone https://github.com/an-lee/mixin_bot

Update the spec config.yml to your own Mixin App(create in developers.mixin.one).

cd mixin_bot
mv spec/config.yml.example spec/config.yml

Run the test.

rake

References

License

This project rocks and uses MIT-LICENSE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].