protolink 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/protolink.rb +1 -0
- data/lib/protolink/channel.rb +3 -1
- data/lib/protolink/node.rb +24 -0
- data/lib/protolink/protonet.rb +33 -7
- data/lib/protolink/user.rb +3 -1
- data/lib/protolink/version.rb +1 -1
- data/protolink.gemspec +3 -3
- data/test/all_tests.rb +13 -7
- metadata +9 -8
data/lib/protolink.rb
CHANGED
data/lib/protolink/channel.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
module Protolink
|
2
2
|
class Channel
|
3
|
-
attr_reader :id, :name, :description
|
3
|
+
attr_reader :id, :name, :description, :global, :uuid
|
4
4
|
|
5
5
|
def initialize(connection, attributes = {})
|
6
6
|
@connection = connection
|
7
7
|
@id = attributes['id']
|
8
8
|
@name = attributes['name']
|
9
9
|
@description = attributes['description']
|
10
|
+
@global = attributes['global']
|
11
|
+
@uuid = attributes['uuid']
|
10
12
|
@loaded = false
|
11
13
|
end
|
12
14
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Protolink
|
2
|
+
class Node
|
3
|
+
attr_reader :id, :uuid, :name, :description
|
4
|
+
|
5
|
+
def initialize(connection, attributes = {})
|
6
|
+
@connection = connection
|
7
|
+
@id = attributes['id']
|
8
|
+
@uuid = attributes['uuid']
|
9
|
+
@name = attributes['name']
|
10
|
+
@description = attributes['description']
|
11
|
+
@loaded = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def coupled?
|
15
|
+
connection.get("/api/v1/couplings/#{id}")
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
def connection
|
20
|
+
@connection
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/protolink/protonet.rb
CHANGED
@@ -17,11 +17,11 @@ module Protolink
|
|
17
17
|
# * +:password+: your api users password
|
18
18
|
# * +:proxy+: a hash with your proxy options (e.g. {:uri => 'http://user:pass@example.com', :port => 8800})
|
19
19
|
#
|
20
|
-
def self.open(uri, username, password, proxy = nil)
|
20
|
+
def self.open(uri, username = nil, password = nil, proxy = nil)
|
21
21
|
# this allows you to use the httparty class helpers (base_uri...) with multiple connections
|
22
22
|
clazz = self.dup
|
23
23
|
clazz.base_uri(uri)
|
24
|
-
clazz.basic_auth(username, password)
|
24
|
+
clazz.basic_auth(username, password) if username && password
|
25
25
|
if proxy
|
26
26
|
clazz.http_proxy(proxy[:uri], proxy[:port])
|
27
27
|
end
|
@@ -32,7 +32,7 @@ module Protolink
|
|
32
32
|
|
33
33
|
# Get an array of all the available channels
|
34
34
|
def channels
|
35
|
-
get('/api/v1/channels
|
35
|
+
get('/api/v1/channels').map do |channel|
|
36
36
|
Channel.new(self, channel)
|
37
37
|
end
|
38
38
|
end
|
@@ -43,7 +43,8 @@ module Protolink
|
|
43
43
|
description = options[:description]
|
44
44
|
display_name = options[:display_name]
|
45
45
|
skip_autosubscribe = options[:skip_autosubscribe]
|
46
|
-
|
46
|
+
global = options[:global]
|
47
|
+
post('/api/v1/channels', :body => { :name => name, :description => description, :display_name => display_name, :skip_autosubscribe => skip_autosubscribe, :global => global } )
|
47
48
|
find_channel_by_name(name)
|
48
49
|
end
|
49
50
|
|
@@ -59,7 +60,12 @@ module Protolink
|
|
59
60
|
|
60
61
|
# Find a Channel by name
|
61
62
|
def find_channel_by_name(name)
|
62
|
-
response = get("/api/v1/channels/#{name}")
|
63
|
+
response = get("/api/v1/channels/find_by_name/#{name}")
|
64
|
+
Channel.new(self, response) if response
|
65
|
+
end
|
66
|
+
|
67
|
+
def find_channel_by_uuid(uuid)
|
68
|
+
response = get("/api/v1/channels/find_by_uuid/#{uuid}")
|
63
69
|
Channel.new(self, response) if response
|
64
70
|
end
|
65
71
|
|
@@ -73,6 +79,14 @@ module Protolink
|
|
73
79
|
Channel.new(self, response) if response
|
74
80
|
end
|
75
81
|
|
82
|
+
def global_channels
|
83
|
+
response = get('/api/v1/channels?global=true')
|
84
|
+
|
85
|
+
response && response.map do |channel|
|
86
|
+
Channel.new(self, channel)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
76
90
|
# USERS
|
77
91
|
|
78
92
|
# Get an array of all the available users
|
@@ -118,11 +132,23 @@ module Protolink
|
|
118
132
|
|
119
133
|
# LISTENS
|
120
134
|
def create_listen(user_id, channel_id)
|
121
|
-
|
135
|
+
channel_query = channel_id.to_s.match("-") ? {:channel_uuid => channel_id} : {:channel_id => channel_id}
|
136
|
+
post('/api/v1/listens', :body => {:user_id => user_id}.merge(channel_query) )
|
122
137
|
end
|
123
138
|
|
124
139
|
def destroy_listen(user_id, channel_id)
|
125
|
-
|
140
|
+
channel_query = channel_id.match("-") ? {:channel_uuid => channel_id} : {:channel_id => channel_id}
|
141
|
+
delete('/api/v1/listens', :body => {:user_id => user_id}.merge(channel_query) )
|
142
|
+
end
|
143
|
+
|
144
|
+
def couple(node_data)
|
145
|
+
response = post("/api/v1/couplings", :body => {:node_data => node_data})
|
146
|
+
[User.new(self, response[0]), response[1]] if response
|
147
|
+
end
|
148
|
+
|
149
|
+
def node
|
150
|
+
response = get("/api/v1/nodes/1")
|
151
|
+
Node.new(self, response) if response
|
126
152
|
end
|
127
153
|
|
128
154
|
[:get, :post, :update, :delete].each do |method|
|
data/lib/protolink/user.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Protolink
|
2
2
|
class User
|
3
|
-
attr_reader :id, :name, :login, :email, :avatar_url, :external_profile_url
|
3
|
+
attr_reader :id, :name, :login, :email, :avatar_url, :external_profile_url, :communication_token, :node_id
|
4
4
|
|
5
5
|
def initialize(connection, attributes = {})
|
6
6
|
@connection = connection
|
@@ -9,7 +9,9 @@ module Protolink
|
|
9
9
|
@login = attributes['login']
|
10
10
|
@email = attributes['email']
|
11
11
|
@avatar_url = attributes['avatar_url']
|
12
|
+
@node_id = attributes['node_id']
|
12
13
|
@external_profile_url = attributes['external_profile_url']
|
14
|
+
@communication_token = attributes['communication_token']
|
13
15
|
@loaded = false
|
14
16
|
end
|
15
17
|
|
data/lib/protolink/version.rb
CHANGED
data/protolink.gemspec
CHANGED
@@ -26,14 +26,14 @@ Gem::Specification.new do |s|
|
|
26
26
|
|
27
27
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
28
|
s.add_runtime_dependency(%q<crack>, [">= 0"])
|
29
|
-
s.add_runtime_dependency(%q<httparty>, ["~> 0.
|
29
|
+
s.add_runtime_dependency(%q<httparty>, ["~> 0.7.4"])
|
30
30
|
else
|
31
31
|
s.add_dependency(%q<crack>, [">= 0"])
|
32
|
-
s.add_dependency(%q<httparty>, ["~> 0.
|
32
|
+
s.add_dependency(%q<httparty>, ["~> 0.7.4"])
|
33
33
|
end
|
34
34
|
else
|
35
35
|
s.add_dependency(%q<crack>, [">= 0"])
|
36
|
-
s.add_dependency(%q<httparty>, ["~> 0.
|
36
|
+
s.add_dependency(%q<httparty>, ["~> 0.7.4"])
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
data/test/all_tests.rb
CHANGED
@@ -8,8 +8,8 @@ require 'ruby-debug'
|
|
8
8
|
Debugger.start
|
9
9
|
# change this if you need to connect to another server
|
10
10
|
PTN_SERVER = "http://localhost:3000"
|
11
|
-
PTN_USER = "
|
12
|
-
PTN_PASS = "
|
11
|
+
PTN_USER = "test_suite"
|
12
|
+
PTN_PASS = "testtest"
|
13
13
|
|
14
14
|
class TestAll < Test::Unit::TestCase
|
15
15
|
|
@@ -20,15 +20,15 @@ class TestAll < Test::Unit::TestCase
|
|
20
20
|
user_4 = protonet.find_user_by_login("test_3")
|
21
21
|
|
22
22
|
channel = protonet.find_rendezvous(user_3.id, user_1.id)
|
23
|
-
channel.delete!
|
23
|
+
channel && channel.delete!
|
24
24
|
|
25
25
|
user_1.delete!
|
26
26
|
user_3.delete!
|
27
27
|
user_4.delete!
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
["test_foobar", "test_foobar_2", "global"].each do |channel|
|
29
|
+
protonet.find_channel_by_name(channel).delete! rescue nil
|
30
|
+
end
|
31
|
+
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_all
|
@@ -79,5 +79,11 @@ class TestAll < Test::Unit::TestCase
|
|
79
79
|
|
80
80
|
rendezvous = protonet.create_rendezvous(user_3.id, user_1.id)
|
81
81
|
assert_equal [user_1.id, user_3.id], rendezvous.listener.map {|u| u.id.to_i}.sort
|
82
|
+
|
83
|
+
channel_1 = protonet.create_channel(:name => "global", :skip_autosubscribe => true, :global => true)
|
84
|
+
assert_equal true, channel_1.global
|
85
|
+
|
86
|
+
assert_equal channel_1.id, protonet.global_channels.first.id
|
87
|
+
assert_equal 1, protonet.global_channels.size
|
82
88
|
end
|
83
89
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protolink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 7
|
10
|
+
version: 0.2.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Bj\xC3\xB6rn B. Dorra"
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-10-11 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -41,12 +41,12 @@ dependencies:
|
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
hash:
|
44
|
+
hash: 11
|
45
45
|
segments:
|
46
46
|
- 0
|
47
|
-
-
|
48
|
-
-
|
49
|
-
version: 0.
|
47
|
+
- 7
|
48
|
+
- 4
|
49
|
+
version: 0.7.4
|
50
50
|
type: :runtime
|
51
51
|
version_requirements: *id002
|
52
52
|
description: A Ruby API for interfacing with Protonet, the next-gen internet infrastructure. Truly social and people-powered.
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- lib/protolink.rb
|
69
69
|
- lib/protolink/channel.rb
|
70
70
|
- lib/protolink/listen.rb
|
71
|
+
- lib/protolink/node.rb
|
71
72
|
- lib/protolink/protonet.rb
|
72
73
|
- lib/protolink/user.rb
|
73
74
|
- lib/protolink/version.rb
|