Class: Bitmessage::ApiClient
- Inherits:
-
Object
- Object
- Bitmessage::ApiClient
show all
- Defined in:
- lib/bitmessage/api_client.rb
Defined Under Namespace
Classes: Address, Message
Instance Method Summary
collapse
-
#add(a, b) ⇒ Object
Returns the sum of the integers.
-
#add_subscription(address, label = "") ⇒ Object
-
#create_random_address(label, eighteen_byte_ripe = false, total_difficulty = 1, small_message_difficulty = 1) ⇒ Object
Creates one address using the random number generator.
-
#delete_subscription(address) ⇒ Object
-
#get_all_inbox_messages ⇒ Object
Does not include trashed messages.
-
#get_all_sent_messages ⇒ Object
-
#get_inbox_message_by_id(msgid) ⇒ Object
-
#get_sent_message_by_ack_data(ack_data) ⇒ Object
-
#get_sent_message_by_id(msgid) ⇒ Object
-
#get_sent_messages_by_sender(sender) ⇒ Object
-
#get_status(ack_data) ⇒ Object
-
#hello_world(first_word, second_word) ⇒ Object
Returns ‘first_word-second_word’.
-
#initialize(uri) ⇒ ApiClient
constructor
A new instance of ApiClient.
-
#list_addresses ⇒ Object
-
#list_subscriptions ⇒ Object
-
#send_broadcast(from, subject, message, encoding = Message::ENCODING_SIMPLE) ⇒ Object
-
#send_message(to, from, subject, message, encoding = Message::ENCODING_SIMPLE) ⇒ Object
-
#status_bar(text) ⇒ Object
Displays the message in the status bar on the GUI.
-
#trash_message(msgid) ⇒ Object
Constructor Details
#initialize(uri) ⇒ ApiClient
Returns a new instance of ApiClient.
64
65
66
|
# File 'lib/bitmessage/api_client.rb', line 64
def initialize uri
@client = XMLRPC::Client.new_from_uri(uri)
end
|
Instance Method Details
#add(a, b) ⇒ Object
Returns the sum of the integers. Used as a simple test of the API.
69
70
71
|
# File 'lib/bitmessage/api_client.rb', line 69
def add a, b
@client.call('add', a, b)
end
|
#add_subscription(address, label = "") ⇒ Object
155
156
157
|
# 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) ⇒ Object
Creates one address using the random number generator.
93
94
95
96
97
98
99
100
|
# 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) ⇒ Object
159
160
161
|
# File 'lib/bitmessage/api_client.rb', line 159
def delete_subscription address
@client.call('deleteSubscription', address)
end
|
#get_all_inbox_messages ⇒ Object
Does not include trashed messages.
103
104
105
106
107
108
|
# 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 ⇒ Object
115
116
117
118
119
120
|
# 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) ⇒ Object
110
111
112
113
|
# 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) ⇒ Object
127
128
129
130
|
# 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) ⇒ Object
122
123
124
125
|
# 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) ⇒ Object
132
133
134
135
136
137
|
# 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) ⇒ Object
147
148
149
|
# 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) ⇒ Object
Returns ‘first_word-second_word’. Used as a simple test of the API.
74
75
76
|
# 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 ⇒ Object
84
85
86
87
88
89
90
|
# 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 ⇒ Object
163
164
165
166
167
168
169
|
# 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) ⇒ Object
151
152
153
|
# 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) ⇒ Object
143
144
145
|
# 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) ⇒ Object
Displays the message in the status bar on the GUI
79
80
81
|
# File 'lib/bitmessage/api_client.rb', line 79
def status_bar text
@client.call('statusBar', text)
end
|
#trash_message(msgid) ⇒ Object
139
140
141
|
# File 'lib/bitmessage/api_client.rb', line 139
def trash_message msgid
@client.call('trashMessage', msgid)
end
|