tox 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # tox.rb - Ruby interface for libtoxcore
4
+ # Copyright (C) 2015-2017 Braiden Vasco
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ module Tox
20
+ class Friend
21
+ ##
22
+ # Outgoing friend message representation in Tox client.
23
+ #
24
+ class OutMessage
25
+ include Tox::OutMessage
26
+
27
+ attr_reader :friend, :id
28
+
29
+ def initialize(friend, id)
30
+ self.friend = friend
31
+ self.id = id
32
+ end
33
+
34
+ def client
35
+ friend.client
36
+ end
37
+
38
+ private
39
+
40
+ def friend=(value)
41
+ unless value.is_a? Friend
42
+ raise TypeError, "expected friend to be a #{Friend}"
43
+ end
44
+ @friend = value
45
+ end
46
+
47
+ def id=(value)
48
+ unless value.is_a? Integer
49
+ raise TypeError, "expected id to be an #{Integer}"
50
+ end
51
+ unless value >= 0
52
+ raise ArgumentError, 'expected id to be greater than or equal to zero'
53
+ end
54
+ @id = value
55
+ end
56
+ end
57
+ end
58
+ end
@@ -32,19 +32,24 @@ module Tox
32
32
  @ipv4 ||=
33
33
  begin
34
34
  value = @data[:ipv4]
35
- raise TypeError, "expected value to be a #{String}" unless value.is_a? String
35
+ unless value.is_a? String
36
+ raise TypeError, "expected value to be a #{String}"
37
+ end
36
38
  value.frozen? ? value : value.dup.freeze
37
39
  end
38
40
  end
39
41
 
40
42
  def port
41
- @port ||=
42
- begin
43
- value = @data[:port]
44
- raise TypeError, "expected value to be an #{Integer}" unless value.is_a? Integer
45
- raise ArgumentError, 'expected value to be between 0 and 65535' unless PORT_RANGE.cover? value
46
- value
43
+ @port ||= begin
44
+ value = @data[:port]
45
+ unless value.is_a? Integer
46
+ raise TypeError, "expected value to be an #{Integer}"
47
+ end
48
+ unless PORT_RANGE.cover? value
49
+ raise ArgumentError, 'expected value to be between 0 and 65535'
47
50
  end
51
+ value
52
+ end
48
53
  end
49
54
 
50
55
  def public_key
@@ -59,6 +64,10 @@ module Tox
59
64
  @status_udp ||= !!@data[:status_udp]
60
65
  end
61
66
 
67
+ def status_tcp
68
+ @status_tcp ||= !!@data[:status_tcp]
69
+ end
70
+
62
71
  def resolv_ipv4
63
72
  @resolv_ipv4 ||= Resolv.getaddress ipv4
64
73
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # tox.rb - Ruby interface for libtoxcore
4
+ # Copyright (C) 2015-2017 Braiden Vasco
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ module Tox
20
+ ##
21
+ # Nospam primitive.
22
+ #
23
+ class Nospam < Binary
24
+ def self.bytesize
25
+ 4
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # tox.rb - Ruby interface for libtoxcore
4
+ # Copyright (C) 2015-2017 Braiden Vasco
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ module Tox
20
+ ##
21
+ # Startup options for Tox client.
22
+ #
23
+ class Options
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # tox.rb - Ruby interface for libtoxcore
4
+ # Copyright (C) 2015-2017 Braiden Vasco
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ module Tox
20
+ ##
21
+ # Abstract module for outgoing message representation in Tox client.
22
+ #
23
+ module OutMessage
24
+ def initialize(*)
25
+ raise NotImplementedError, "#{self.class}#initialize"
26
+ end
27
+
28
+ def client
29
+ raise NotImplementedError, "#{self.class}#client"
30
+ end
31
+
32
+ class SendQueueAllocError < NoMemoryError; end
33
+ class TooLongError < RuntimeError; end
34
+ class EmptyError < RuntimeError; end
35
+ end
36
+ end
@@ -31,7 +31,9 @@ module Tox
31
31
  end
32
32
 
33
33
  def inspect
34
- @inspect ||= "#<#{self.class} last_refresh: #{last_refresh}, last_scan: #{last_scan}>"
34
+ @inspect ||= "#<#{self.class} " \
35
+ "last_refresh: #{last_refresh}, " \
36
+ "last_scan: #{last_scan}>"
35
37
  end
36
38
 
37
39
  def last_refresh
@@ -42,8 +44,16 @@ module Tox
42
44
  @last_scan ||= Time.at(data['last_scan']).utc.freeze
43
45
  end
44
46
 
45
- def nodes
46
- @nodes ||= data['nodes'].map { |node_data| Node.new node_data }.select(&:status_udp).compact.freeze
47
+ def all_nodes
48
+ @all_nodes ||= data['nodes'].map { |node_data| Node.new node_data }.freeze
49
+ end
50
+
51
+ def udp_nodes
52
+ @udp_nodes ||= all_nodes.select(&:status_udp).freeze
53
+ end
54
+
55
+ def tcp_nodes
56
+ @tcp_nodes ||= all_nodes.select(&:status_tcp).freeze
47
57
  end
48
58
 
49
59
  private
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # tox.rb - Ruby interface for libtoxcore
4
+ # Copyright (C) 2015-2017 Braiden Vasco
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ module Tox
20
+ ##
21
+ # Represents the possible statuses a client can have.
22
+ #
23
+ module UserStatus
24
+ # User is online and available.
25
+ NONE = :none
26
+
27
+ # User is away. Clients can set this e.g. after a user defined
28
+ # inactivity time.
29
+ AWAY = :away
30
+
31
+ # User is busy. Signals to other clients that this client does not
32
+ # currently wish to communicate.
33
+ BUSY = :busy
34
+ end
35
+ end
@@ -17,6 +17,20 @@
17
17
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
 
19
19
  module Tox
20
- # Gem version.
21
- VERSION = '0.0.1'
20
+ ##
21
+ # Gem, library API and ABI version strings and component numbers.
22
+ #
23
+ module Version
24
+ # Gem version.
25
+ GEM_VERSION = '0.0.2'
26
+
27
+ def self.const_missing(name)
28
+ return "#{API_MAJOR}.#{API_MINOR}.#{API_PATCH}" if name == :API_VERSION
29
+ super
30
+ end
31
+
32
+ def self.abi_version
33
+ "#{abi_major}.#{abi_minor}.#{abi_patch}"
34
+ end
35
+ end
22
36
  end
@@ -8,7 +8,7 @@ require 'tox/version'
8
8
 
9
9
  Gem::Specification.new do |spec|
10
10
  spec.name = 'tox'
11
- spec.version = Tox::VERSION
11
+ spec.version = Tox::Version::GEM_VERSION
12
12
  spec.license = 'GPL-3.0'
13
13
  spec.homepage = 'https://github.com/toxon/tox.rb'
14
14
  spec.summary = 'Ruby interface for libtoxcore'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Braiden Vasco
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-20 00:00:00.000000000 Z
11
+ date: 2018-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -162,24 +162,25 @@ files:
162
162
  - bin/console
163
163
  - examples/echo_bot.rb
164
164
  - ext/tox/client.c
165
- - ext/tox/client.h
166
165
  - ext/tox/extconf.rb
167
166
  - ext/tox/friend.c
168
- - ext/tox/friend.h
169
- - ext/tox/node.c
170
- - ext/tox/node.h
171
167
  - ext/tox/options.c
172
- - ext/tox/options.h
173
168
  - ext/tox/tox.c
174
169
  - ext/tox/tox.h
170
+ - ext/tox/version.c
175
171
  - lib/tox.rb
176
172
  - lib/tox/address.rb
177
173
  - lib/tox/binary.rb
178
174
  - lib/tox/client.rb
179
175
  - lib/tox/friend.rb
176
+ - lib/tox/friend/out_message.rb
180
177
  - lib/tox/node.rb
178
+ - lib/tox/nospam.rb
179
+ - lib/tox/options.rb
180
+ - lib/tox/out_message.rb
181
181
  - lib/tox/public_key.rb
182
182
  - lib/tox/status.rb
183
+ - lib/tox/user_status.rb
183
184
  - lib/tox/version.rb
184
185
  - tox.gemspec
185
186
  homepage: https://github.com/toxon/tox.rb
@@ -202,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
203
  version: '0'
203
204
  requirements: []
204
205
  rubyforge_project:
205
- rubygems_version: 2.5.2
206
+ rubygems_version: 2.6.14
206
207
  signing_key:
207
208
  specification_version: 4
208
209
  summary: Ruby interface for libtoxcore
@@ -1,29 +0,0 @@
1
- /*
2
- * tox.rb - Ruby interface for libtoxcore
3
- * Copyright (C) 2015-2017 Braiden Vasco
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
- #include <ruby.h>
20
-
21
- #include <tox/tox.h>
22
-
23
- void mTox_cClient_INIT();
24
-
25
- extern VALUE mTox_cClient;
26
-
27
- typedef struct {
28
- Tox *tox;
29
- } mTox_cClient_CDATA;
@@ -1,25 +0,0 @@
1
- /*
2
- * tox.rb - Ruby interface for libtoxcore
3
- * Copyright (C) 2015-2017 Braiden Vasco
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
- #include <ruby.h>
20
-
21
- #include <tox/tox.h>
22
-
23
- void mTox_cFriend_INIT();
24
-
25
- extern VALUE mTox_cFriend;
@@ -1,33 +0,0 @@
1
- /*
2
- * tox.rb - Ruby interface for libtoxcore
3
- * Copyright (C) 2015-2017 Braiden Vasco
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
- #include "tox.h"
20
- #include "node.h"
21
-
22
- // Instance
23
- VALUE mTox_cNode;
24
-
25
- /*************************************************************
26
- * Initialization
27
- *************************************************************/
28
-
29
- void mTox_cNode_INIT()
30
- {
31
- // Instance
32
- mTox_cNode = rb_define_class_under(mTox, "Node", rb_cObject);
33
- }
@@ -1,25 +0,0 @@
1
- /*
2
- * tox.rb - Ruby interface for libtoxcore
3
- * Copyright (C) 2015-2017 Braiden Vasco
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
- #include <ruby.h>
20
-
21
- #include <tox/tox.h>
22
-
23
- void mTox_cNode_INIT();
24
-
25
- extern VALUE mTox_cNode;