class Bitmessage::ApiClient

Public Class Methods

new(uri) click to toggle source
# File lib/bitmessage/api_client.rb, line 64
def initialize uri
  @client = XMLRPC::Client.new_from_uri(uri)
end

Public Instance Methods

add(a, b) click to toggle source

Returns the sum of the integers. Used as a simple test of the API.

# File lib/bitmessage/api_client.rb, line 69
def add a, b
  @client.call('add', a, b)
end
add_subscription(address, label = "") click to toggle source
# File lib/bitmessage/api_client.rb, line 155
def add_subscription address, label = ""
  @client.call('addSubscription', address, Base64.encode64(label))
end
create_random_address(label, eighteen_byte_ripe = false, total_difficulty = 1, small_message_difficulty = 1) click to toggle source

Creates one address using the random number generator.

# File lib/bitmessage/api_client.rb, line 93
def create_random_address label, eighteen_byte_ripe = false, total_difficulty = 1, small_message_difficulty = 1
  @client.call(
    'createRandomAddress',
    Base64.encode64(label),
    eighteen_byte_ripe,
    total_difficulty,
    small_message_difficulty)
end
delete_subscription(address) click to toggle source
# File lib/bitmessage/api_client.rb, line 159
def delete_subscription address
  @client.call('deleteSubscription', address)
end
get_all_inbox_messages() click to toggle source

Does not include trashed messages.

# File lib/bitmessage/api_client.rb, line 103
def get_all_inbox_messages
  json = JSON.parse(@client.call('getAllInboxMessages'))
  json['inboxMessages'].map do |j|
    Message.new j
  end
end
get_all_sent_messages() click to toggle source
# File lib/bitmessage/api_client.rb, line 115
def get_all_sent_messages
  json = JSON.parse(@client.call('getAllSentMessages'))
  json['sentMessages'].map do |j|
    Message.new j
  end
end
get_inbox_message_by_id(msgid) click to toggle source
# File lib/bitmessage/api_client.rb, line 110
def get_inbox_message_by_id msgid
  hash = JSON.parse(@client.call('getInboxMessageById', msgid))
  Message.new hash['inboxMessage'].first
end
get_sent_message_by_ack_data(ack_data) click to toggle source
# File lib/bitmessage/api_client.rb, line 127
def get_sent_message_by_ack_data ack_data
  hash = JSON.parse(@client.call('getSentMessageByAckData', ack_data))
  Message.new hash['sentMessage'].first
end
get_sent_message_by_id(msgid) click to toggle source
# File lib/bitmessage/api_client.rb, line 122
def get_sent_message_by_id msgid
  hash = JSON.parse(@client.call('getSentMessageById', msgid))
  Message.new hash['sentMessage'].first
end
get_sent_messages_by_sender(sender) click to toggle source
# File lib/bitmessage/api_client.rb, line 132
def get_sent_messages_by_sender sender
  json = JSON.parse(@client.call('getSentMessagesBySender', sender))
  json['sentMessages'].map do |j|
    Message.new j
  end
end
get_status(ack_data) click to toggle source
# File lib/bitmessage/api_client.rb, line 147
def get_status ack_data
  @client.call('getStatus', ack_data)
end
hello_world(first_word, second_word) click to toggle source

Returns ‘first_word-second_word’. Used as a simple test of the API.

# File lib/bitmessage/api_client.rb, line 74
def hello_world first_word, second_word
  @client.call('helloWorld', first_word, second_word)
end
list_addresses() click to toggle source

Lists all addresses

# File lib/bitmessage/api_client.rb, line 84
def list_addresses
  json = JSON.parse(@client.call('listAddresses'))

  json['addresses'].map do |j|
    Address.new j
  end
end
list_subscriptions() click to toggle source
# File lib/bitmessage/api_client.rb, line 163
def list_subscriptions
  hash = JSON.parse(@client.call('listSubscriptions'))

  hash['subscriptions'].map do |s|
    Address.new s, true
  end
end
send_broadcast(from, subject, message, encoding = Message::ENCODING_SIMPLE) click to toggle source
# File lib/bitmessage/api_client.rb, line 151
def send_broadcast from, subject, message, encoding = Message::ENCODING_SIMPLE
  @client.call('sendBroadcast', from, Base64.encode64(subject), Base64.encode64(message), encoding)
end
send_message(to, from, subject, message, encoding = Message::ENCODING_SIMPLE) click to toggle source
# File lib/bitmessage/api_client.rb, line 143
def send_message to, from, subject, message, encoding = Message::ENCODING_SIMPLE
  @client.call('sendMessage', to, from, Base64.encode64(subject), Base64.encode64(message), encoding)
end
status_bar(text) click to toggle source

Displays the message in the status bar on the GUI

# File lib/bitmessage/api_client.rb, line 79
def status_bar text
  @client.call('statusBar', text)
end
trash_message(msgid) click to toggle source
# File lib/bitmessage/api_client.rb, line 139
def trash_message msgid
  @client.call('trashMessage', msgid)
end