bitmessage 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b36761f53068136c1e4bb97eb7af896cbac07bf
4
+ data.tar.gz: b105955e147e26b6f64761583d98870c385e341a
5
+ SHA512:
6
+ metadata.gz: 7afc55a36373519b094f600a80ac8fc93d653891c9117933c4dec1e917061ac0021d0302bfa3c08ab1b692e979c92068ed3b3a49624a1dc4e998df71513cc7e1
7
+ data.tar.gz: 5a639623ab8786f9f5adb063508810aeae86bc3cdd45fffdbfc65271dc4148b48ddf669a8273a3b987ee2fb483efb1a516e8b8a448a75ab690d0c4949d072652
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bitmessage.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2013 Robert Nasiadek
3
+ Copyright (c) 2013 Adam Thorsen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Adam Thorsen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ ## Bitmessage API Ruby Wrapper
2
+
3
+ Thin API wrapper for the official BitMessage Python client. This gem is based on the [original library](https://github.com/robzon/bitmessage-api-ruby)
4
+ created by [robzon](https://github.com/robzon).
5
+
6
+ ## Requirements
7
+
8
+ Running [Bitmessage client](https://github.com/Bitmessage/PyBitmessage) with API enabled.
9
+
10
+ ## Usage
11
+
12
+ require 'bitmessage'
13
+
14
+ api = Bitmessage::ApiClient.new 'http://user:password@host:port/'
15
+
16
+ api.add 3, 5
17
+
18
+ ### Getting a list of messages
19
+
20
+ inbox = api.get_all_inbox_messages
21
+
22
+ puts "You have #{inbox.count} messages:"
23
+
24
+ inbox.each do |msg|
25
+ puts "#{msg.msgid} #{msg.from} #{msg.subject}"
26
+ end
27
+
28
+ ### Sending a message
29
+
30
+
31
+ to = "BM-orkCbppXWSqPpAxnz6jnfTZ2djb5pJKDb" # echo service
32
+ from = api.list_addresses.first.address
33
+
34
+ api.send_message to, from, "This is subject", "This is message"
35
+
36
+ ### Running the tests
37
+
38
+ For tests to to pass it is necessary to set the BM_URI environment
39
+ variable. For example:
40
+
41
+ BM_URI=http://user:password@host:port/ rake test
42
+
43
+ ## FAQ
44
+
45
+ Q: Does this cover 100% of the API?
46
+
47
+ A: Not yet.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'lib/bitmessage'
6
+ t.test_files = FileList['test/lib/bitmessage/*_test.rb']
7
+ end
8
+
9
+ desc "Run tests"
10
+ task :default => :test
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bitmessage/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bitmessage"
8
+ spec.version = Bitmessage::VERSION
9
+ spec.authors = ["Adam Thorsen"]
10
+ spec.email = ["awt@fastmail.fm"]
11
+ spec.description = %q{This gem provides an client library for the PyBitmessage API.}
12
+ spec.summary = %q{This gem allows listing, sending, generating, etc messages via the Bitmessage protocol.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
data/lib/bitmessage.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "bitmessage/version"
2
+ require "bitmessage/api_client"
3
+
4
+ module Bitmessage
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,171 @@
1
+ require 'xmlrpc/client'
2
+ require 'json'
3
+ require 'base64'
4
+
5
+ module Bitmessage
6
+ class ApiClient
7
+ class Address
8
+ attr_accessor :label, :address, :stream, :enabled
9
+
10
+ def initialize hash, label_encoded = false
11
+ self.label = label_encoded ? Base64.decode64(hash['label']) : hash['label']
12
+ self.address = hash['address']
13
+ self.stream = hash['stream'] if hash.keys.include?('stream')
14
+ self.enabled = hash['enabled']
15
+ end
16
+
17
+ def to_s
18
+ "#{self.label} (#{self.address})"
19
+ end
20
+ end
21
+
22
+ class Message
23
+ ENCODING_IGNORE = 0
24
+ ENCODING_TRIVIAL = 1
25
+ ENCODING_SIMPLE = 2
26
+
27
+ FOLDER_UNKNOWN = :unknown
28
+ FOLDER_INBOX = :inbox
29
+ FOLDER_OUTBOX = :outbox
30
+
31
+ # common attributes
32
+ attr_accessor :msgid, :to, :from, :subject, :message, :encoding, :folder
33
+ # inbox attributes
34
+ attr_accessor :read, :received_at
35
+ # outbox attributes
36
+ attr_accessor :last_action_at, :status, :ack_data
37
+
38
+ def initialize hash
39
+ self.folder = FOLDER_UNKNOWN
40
+ self.msgid = hash['msgid']
41
+ self.to = hash['toAddress']
42
+ self.from = hash['fromAddress']
43
+ self.subject = Base64.decode64(hash['subject'])
44
+ self.message = Base64.decode64(hash['message'])
45
+ self.encoding = hash['encodingType'].to_i
46
+
47
+ if hash.keys.include?('receivedTime')
48
+ self.folder = FOLDER_INBOX
49
+ self.received_at = Time.at(hash['receivedTime'].to_i)
50
+ self.read = hash['read'] == 0 ? false : true
51
+ elsif hash.keys.include?('ackData')
52
+ self.folder = FOLDER_OUTBOX
53
+ self.last_action_at = Time.at(hash['lastActionTime'].to_i)
54
+ self.status = hash['status']
55
+ self.ack_data = hash['ackData']
56
+ end
57
+ end
58
+
59
+ def to_s
60
+ self.msgid
61
+ end
62
+ end
63
+
64
+ def initialize uri
65
+ @client = XMLRPC::Client.new_from_uri(uri)
66
+ end
67
+
68
+ # Returns the sum of the integers. Used as a simple test of the API.
69
+ def add a, b
70
+ @client.call('add', a, b)
71
+ end
72
+
73
+ # Returns 'first_word-second_word'. Used as a simple test of the API.
74
+ def hello_world first_word, second_word
75
+ @client.call('helloWorld', first_word, second_word)
76
+ end
77
+
78
+ # Displays the message in the status bar on the GUI
79
+ def status_bar text
80
+ @client.call('statusBar', text)
81
+ end
82
+
83
+ # Lists all addresses
84
+ def list_addresses
85
+ json = JSON.parse(@client.call('listAddresses'))
86
+
87
+ json['addresses'].map do |j|
88
+ Address.new j
89
+ end
90
+ end
91
+
92
+ # Creates one address using the random number generator.
93
+ def create_random_address label, eighteen_byte_ripe = false, total_difficulty = 1, small_message_difficulty = 1
94
+ @client.call(
95
+ 'createRandomAddress',
96
+ Base64.encode64(label),
97
+ eighteen_byte_ripe,
98
+ total_difficulty,
99
+ small_message_difficulty)
100
+ end
101
+
102
+ # Does not include trashed messages.
103
+ def get_all_inbox_messages
104
+ json = JSON.parse(@client.call('getAllInboxMessages'))
105
+ json['inboxMessages'].map do |j|
106
+ Message.new j
107
+ end
108
+ end
109
+
110
+ def get_inbox_message_by_id msgid
111
+ hash = JSON.parse(@client.call('getInboxMessageById', msgid))
112
+ Message.new hash['inboxMessage'].first
113
+ end
114
+
115
+ def get_all_sent_messages
116
+ json = JSON.parse(@client.call('getAllSentMessages'))
117
+ json['sentMessages'].map do |j|
118
+ Message.new j
119
+ end
120
+ end
121
+
122
+ def get_sent_message_by_id msgid
123
+ hash = JSON.parse(@client.call('getSentMessageById', msgid))
124
+ Message.new hash['sentMessage'].first
125
+ end
126
+
127
+ def get_sent_message_by_ack_data ack_data
128
+ hash = JSON.parse(@client.call('getSentMessageByAckData', ack_data))
129
+ Message.new hash['sentMessage'].first
130
+ end
131
+
132
+ def get_sent_messages_by_sender sender
133
+ json = JSON.parse(@client.call('getSentMessagesBySender', sender))
134
+ json['sentMessages'].map do |j|
135
+ Message.new j
136
+ end
137
+ end
138
+
139
+ def trash_message msgid
140
+ @client.call('trashMessage', msgid)
141
+ end
142
+
143
+ def send_message to, from, subject, message, encoding = Message::ENCODING_SIMPLE
144
+ @client.call('sendMessage', to, from, Base64.encode64(subject), Base64.encode64(message), encoding)
145
+ end
146
+
147
+ def get_status ack_data
148
+ @client.call('getStatus', ack_data)
149
+ end
150
+
151
+ def send_broadcast from, subject, message, encoding = Message::ENCODING_SIMPLE
152
+ @client.call('sendBroadcast', from, Base64.encode64(subject), Base64.encode64(message), encoding)
153
+ end
154
+
155
+ def add_subscription address, label = ""
156
+ @client.call('addSubscription', address, Base64.encode64(label))
157
+ end
158
+
159
+ def delete_subscription address
160
+ @client.call('deleteSubscription', address)
161
+ end
162
+
163
+ def list_subscriptions
164
+ hash = JSON.parse(@client.call('listSubscriptions'))
165
+
166
+ hash['subscriptions'].map do |s|
167
+ Address.new s, true
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,3 @@
1
+ module Bitmessage
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+ require_relative '../../test_helper'
3
+ class BitmessageTest < Test::Unit::TestCase
4
+ def test_get_messages
5
+ api = Bitmessage::ApiClient.new ENV['BM_URI']
6
+ result = api.add 1, 1
7
+ assert_equal 2, result
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require File.expand_path('../../lib/bitmessage.rb', __FILE__)
4
+ require 'pp'
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitmessage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Thorsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This gem provides an client library for the PyBitmessage API.
42
+ email:
43
+ - awt@fastmail.fm
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bitmessage.gemspec
55
+ - lib/bitmessage.rb
56
+ - lib/bitmessage/api_client.rb
57
+ - lib/bitmessage/version.rb
58
+ - test/lib/bitmessage/bitmessage_test.rb
59
+ - test/test_helper.rb
60
+ homepage: ''
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.0.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: This gem allows listing, sending, generating, etc messages via the Bitmessage
84
+ protocol.
85
+ test_files:
86
+ - test/lib/bitmessage/bitmessage_test.rb
87
+ - test/test_helper.rb