protolink 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +16 -0
- data/README.markdown +18 -8
- data/example/create_and_subscribe.rb +3 -3
- data/lib/protolink.rb +0 -6
- data/lib/protolink/channel.rb +11 -1
- data/lib/protolink/protonet.rb +71 -37
- data/lib/protolink/user.rb +5 -5
- data/lib/protolink/version.rb +1 -1
- data/protolink.gemspec +6 -24
- data/test/all_tests.rb +82 -0
- metadata +14 -95
- data/lib/protolink/connection.rb +0 -83
- data/lib/protolink/middleware.rb +0 -30
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
coverage
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.8.7@protolink
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.markdown
CHANGED
@@ -9,13 +9,8 @@ Sorry, there are no tests at all yet...
|
|
9
9
|
|
10
10
|
## Dependencies
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
multipart-post
|
15
|
-
mime-types
|
16
|
-
twitter-stream (for streaming listening in future)
|
17
|
-
eventmachine
|
18
|
-
|
12
|
+
httparty
|
13
|
+
crack
|
19
14
|
|
20
15
|
## Usage
|
21
16
|
|
@@ -25,7 +20,7 @@ Sorry, there are no tests at all yet...
|
|
25
20
|
require 'rubygems'
|
26
21
|
require 'protolink'
|
27
22
|
|
28
|
-
protonet = Protolink::Protonet.new('SUBDOMAIN.DOMAIN.DE', 'USERLOGIN', 'PASSWORD'
|
23
|
+
protonet = Protolink::Protonet.new('HTTP://SUBDOMAIN.DOMAIN.DE', 'USERLOGIN', 'PASSWORD')
|
29
24
|
channel = protonet.channels.first
|
30
25
|
channel.speak 'Hello world!'
|
31
26
|
|
@@ -48,6 +43,15 @@ Sorry, there are no tests at all yet...
|
|
48
43
|
channel.speak 'Hello world!'
|
49
44
|
|
50
45
|
|
46
|
+
# find channel by id
|
47
|
+
require 'rubygems'
|
48
|
+
require 'protolink'
|
49
|
+
|
50
|
+
protonet = Protolink::Protonet.new('SUBDOMAIN.DOMAIN.DE', 'USERLOGIN', 'PASSWORD', :ssl => false)
|
51
|
+
channel = protonet.find_channel(117)
|
52
|
+
channel.speak 'Hello world!'
|
53
|
+
|
54
|
+
|
51
55
|
# find or create a channel
|
52
56
|
require 'rubygems'
|
53
57
|
require 'protolink'
|
@@ -66,6 +70,12 @@ Sorry, there are no tests at all yet...
|
|
66
70
|
protonet = Protolink::Protonet.new('SUBDOMAIN.DOMAIN.DE', 'USERLOGIN', 'PASSWORD', :ssl => false)
|
67
71
|
user = protonet.find_user_by_login("bjoern.dorra")
|
68
72
|
|
73
|
+
# find user by id
|
74
|
+
require 'rubygems'
|
75
|
+
require 'protolink'
|
76
|
+
|
77
|
+
protonet = Protolink::Protonet.new('SUBDOMAIN.DOMAIN.DE', 'USERLOGIN', 'PASSWORD', :ssl => false)
|
78
|
+
user = protonet.find_user(117)
|
69
79
|
|
70
80
|
# create a user
|
71
81
|
require 'rubygems'
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'protolink'
|
3
3
|
|
4
|
-
protonet = Protolink::Protonet.
|
4
|
+
protonet = Protolink::Protonet.open('http://localhost:3000', 'bjoern.dorra', 'geheim')
|
5
5
|
|
6
|
-
user = protonet.find_or_create_user_by_login("johndoe", "password", "John Doe", "john@doe.com")
|
6
|
+
user = protonet.find_or_create_user_by_login("johndoe", :password => "password", :name => "John Doe", :email => "john@doe.com")
|
7
7
|
auth_token = user.auth_token
|
8
8
|
puts "user_id : #{user.id}"
|
9
9
|
puts "user_login : #{user.login}"
|
10
10
|
puts "auth_token : #{auth_token}"
|
11
11
|
|
12
|
-
channel = protonet.find_or_create_channel_by_name("test", "This is a test channel!")
|
12
|
+
channel = protonet.find_or_create_channel_by_name("test", :description => "This is a test channel!")
|
13
13
|
puts "channel_id : #{channel.id}"
|
14
14
|
puts "channel_name: #{channel.name}"
|
15
15
|
puts "channel_desc: #{channel.description}"
|
data/lib/protolink.rb
CHANGED
@@ -1,13 +1,7 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
require 'active_support/json'
|
3
|
-
require 'mime/types'
|
4
|
-
|
5
|
-
require 'protolink/connection'
|
6
1
|
require 'protolink/protonet'
|
7
2
|
require 'protolink/channel'
|
8
3
|
require 'protolink/user'
|
9
4
|
require 'protolink/listen'
|
10
|
-
require 'protolink/middleware'
|
11
5
|
|
12
6
|
module Protolink
|
13
7
|
class Error < StandardError; end
|
data/lib/protolink/channel.rb
CHANGED
@@ -16,6 +16,16 @@ module Protolink
|
|
16
16
|
send_message(message)
|
17
17
|
end
|
18
18
|
|
19
|
+
def delete!
|
20
|
+
connection.delete("/api/v1/channels/#{self.id}")
|
21
|
+
end
|
22
|
+
|
23
|
+
def listener
|
24
|
+
users = connection.get("/api/v1/channels/#{self.id}/users")
|
25
|
+
users && users.map do |user|
|
26
|
+
User.new(connection, user)
|
27
|
+
end
|
28
|
+
end
|
19
29
|
|
20
30
|
protected
|
21
31
|
|
@@ -34,7 +44,7 @@ module Protolink
|
|
34
44
|
end
|
35
45
|
|
36
46
|
def send_message(message)
|
37
|
-
connection.post("/api/v1/meeps/create", {:channel_id => self.id, :message => message})
|
47
|
+
connection.post("/api/v1/meeps/create", :body => {:channel_id => self.id, :message => message})
|
38
48
|
end
|
39
49
|
|
40
50
|
def connection
|
data/lib/protolink/protonet.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
1
3
|
module Protolink
|
2
4
|
|
3
5
|
# protonet = Protolink::Protonet.new 'domain', :user => 'john.doe', :password => 'secret', :token => 'xyz'
|
@@ -5,87 +7,119 @@ module Protolink
|
|
5
7
|
# channel = protonet.find_channel_by_name 'home'
|
6
8
|
# channel.speak 'Hello world!'
|
7
9
|
class Protonet
|
8
|
-
|
9
|
-
|
10
|
-
# Create a new connection to the account with the given +
|
10
|
+
include HTTParty
|
11
|
+
|
12
|
+
# Create a new connection to the account with the given +uri+.
|
11
13
|
#
|
12
14
|
# == Options:
|
13
|
-
# * +:
|
14
|
-
#
|
15
|
-
# * +:proxy+: a proxy
|
15
|
+
# * +:username+: your api users username
|
16
|
+
# * +:password+: your api users password
|
17
|
+
# * +:proxy+: a hash with your proxy options (e.g. {:uri => 'http://user:pass@example.com', :port => 8800})
|
16
18
|
#
|
17
|
-
def
|
18
|
-
|
19
|
+
def self.open(uri, username, password, proxy = nil)
|
20
|
+
# this allows you to use the httparty class helpers (base_uri...) with multiple connections
|
21
|
+
clazz = self.dup
|
22
|
+
clazz.base_uri(uri)
|
23
|
+
clazz.basic_auth(username, password)
|
24
|
+
if proxy
|
25
|
+
clazz.http_proxy(proxy[:uri], proxy[:port])
|
26
|
+
end
|
27
|
+
clazz.new
|
19
28
|
end
|
20
|
-
|
21
|
-
|
29
|
+
|
22
30
|
# CHANNELS
|
23
31
|
|
24
32
|
# Get an array of all the available channels
|
25
33
|
def channels
|
26
|
-
|
27
|
-
|
28
|
-
s['channels'].map do |channel|
|
29
|
-
Channel.new(connection, channel)
|
34
|
+
get('/api/v1/channels.json').map do |channel|
|
35
|
+
Channel.new(self, channel)
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
33
|
-
# Find a Channel by name
|
34
|
-
def find_channel_by_name(name)
|
35
|
-
channels.detect { |channel| channel.name == name }
|
36
|
-
end
|
37
|
-
|
38
39
|
# Creates and returns a new Channel with the given +name+ and optionally a +description+
|
39
|
-
def create_channel(
|
40
|
-
|
40
|
+
def create_channel(options={})
|
41
|
+
name = options[:name] || raise(ArgumentError, "Please provide a name for the channel")
|
42
|
+
description = options[:description]
|
43
|
+
skip_autosubscribe = options[:skip_autosubscribe]
|
44
|
+
post('/api/v1/channels', :body => { :name => name, :description => description, :skip_autosubscribe => skip_autosubscribe } )
|
41
45
|
find_channel_by_name(name)
|
42
46
|
end
|
43
47
|
|
44
|
-
def find_or_create_channel_by_name(name,
|
45
|
-
find_channel_by_name(name) || create_channel(name
|
48
|
+
def find_or_create_channel_by_name(name, options = {})
|
49
|
+
find_channel_by_name(name) || create_channel({:name => name}.merge(options))
|
46
50
|
end
|
47
51
|
|
52
|
+
# Find a Channel by id
|
53
|
+
def find_channel(id)
|
54
|
+
response = get("/api/v1/channels/#{id}")
|
55
|
+
Channel.new(self, response) if response
|
56
|
+
end
|
57
|
+
|
58
|
+
# Find a Channel by name
|
59
|
+
def find_channel_by_name(name)
|
60
|
+
response = get("/api/v1/channels/#{name}")
|
61
|
+
Channel.new(self, response) if response
|
62
|
+
end
|
48
63
|
|
49
64
|
# USERS
|
50
65
|
|
51
66
|
# Get an array of all the available users
|
52
67
|
def users
|
53
|
-
|
54
|
-
|
55
|
-
s['users'].map do |user|
|
56
|
-
User.new(connection, user)
|
68
|
+
get('/api/v1/users.json').map do |user|
|
69
|
+
User.new(self, user)
|
57
70
|
end
|
58
71
|
end
|
59
72
|
|
60
73
|
# Creates and returns a new user with the given attributes
|
61
|
-
def create_user(
|
74
|
+
def create_user(options)
|
75
|
+
login = options[:login] || raise(ArgumentError, "Please provide a login for this user")
|
76
|
+
password = options[:password]
|
77
|
+
name = options[:name]
|
78
|
+
email = options[:email] || raise(ArgumentError, "Please provide an email for this user")
|
79
|
+
avatar_url = options[:avatar_url]
|
80
|
+
profile_url = options[:profile_url]
|
81
|
+
channels = options[:channels]
|
62
82
|
if channels
|
63
83
|
# not implemented yet
|
64
84
|
no_channels = "true"
|
65
85
|
else
|
66
86
|
no_channels = "true"
|
67
87
|
end
|
68
|
-
|
88
|
+
post('/api/v1/users', :body => {:login => login, :name => name, :password => password, :email => email, :avatar_url => avatar_url, :no_channels => no_channels, :channels_to_subscribe => nil } )
|
69
89
|
find_user_by_login(login)
|
70
90
|
end
|
71
91
|
|
72
|
-
|
73
|
-
|
74
|
-
users.detect { |user| user.login == login }
|
92
|
+
def find_or_create_user_by_login(login, options = {})
|
93
|
+
find_user_by_login(login) || create_user({:login => login}.merge(options))
|
75
94
|
end
|
76
95
|
|
77
|
-
|
78
|
-
|
96
|
+
# Find a user by id
|
97
|
+
def find_user(id)
|
98
|
+
response = get("/api/v1/users/#{id}")
|
99
|
+
User.new(self, response) if response
|
100
|
+
end
|
101
|
+
|
102
|
+
def find_user_by_login(login)
|
103
|
+
response = get("/api/v1/users/#{login}")
|
104
|
+
User.new(self, response) if response
|
79
105
|
end
|
80
|
-
|
81
106
|
|
82
107
|
# LISTENS
|
83
108
|
def create_listen(user_id, channel_id)
|
84
|
-
|
109
|
+
post('/api/v1/listens', :body => {:user_id => user_id, :channel_id => channel_id } )
|
85
110
|
end
|
86
111
|
|
87
112
|
def destroy_listen(user_id, channel_id)
|
88
|
-
|
113
|
+
delete('/api/v1/listens', :body => {:user_id => user_id, :channel_id => channel_id } )
|
114
|
+
end
|
115
|
+
|
116
|
+
[:get, :post, :update, :delete].each do |method|
|
117
|
+
class_eval <<-EOS
|
118
|
+
def #{method}(uri, options = {})
|
119
|
+
response = self.class.#{method}(uri, options)
|
120
|
+
response.code.to_s.match(/2../) ? response : nil
|
121
|
+
end
|
122
|
+
EOS
|
89
123
|
end
|
90
124
|
|
91
125
|
end
|
data/lib/protolink/user.rb
CHANGED
@@ -14,15 +14,15 @@ module Protolink
|
|
14
14
|
|
15
15
|
# get token for autologin
|
16
16
|
def auth_token
|
17
|
-
|
17
|
+
connection.get("/api/v1/users/#{self.id}/auth_token.json")["token"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete!
|
21
|
+
connection.delete("/api/v1/users/#{self.id}")
|
18
22
|
end
|
19
23
|
|
20
24
|
protected
|
21
25
|
|
22
|
-
def receive_auth_token
|
23
|
-
connection.get("/api/v1/users/auth_token.json?user_id=#{self.id}")['token']
|
24
|
-
end
|
25
|
-
|
26
26
|
def load
|
27
27
|
reload! unless @loaded
|
28
28
|
end
|
data/lib/protolink/version.rb
CHANGED
data/protolink.gemspec
CHANGED
@@ -25,33 +25,15 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.specification_version = 3
|
26
26
|
|
27
27
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
-
s.add_runtime_dependency(%q<
|
29
|
-
s.add_runtime_dependency(%q<
|
30
|
-
s.add_runtime_dependency(%q<multipart-post>, [">= 0"])
|
31
|
-
s.add_runtime_dependency(%q<mime-types>, [">= 0"])
|
32
|
-
s.add_runtime_dependency(%q<twitter-stream>, [">= 0"])
|
33
|
-
s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
|
34
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
35
|
-
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
28
|
+
s.add_runtime_dependency(%q<crack>, [">= 0"])
|
29
|
+
s.add_runtime_dependency(%q<httparty>, ["~> 0.5.1"])
|
36
30
|
else
|
37
|
-
s.add_dependency(%q<
|
38
|
-
s.add_dependency(%q<
|
39
|
-
s.add_dependency(%q<multipart-post>, [">= 0"])
|
40
|
-
s.add_dependency(%q<mime-types>, [">= 0"])
|
41
|
-
s.add_dependency(%q<twitter-stream>, [">= 0"])
|
42
|
-
s.add_dependency(%q<eventmachine>, [">= 0"])
|
43
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
44
|
-
s.add_dependency(%q<fakeweb>, [">= 0"])
|
31
|
+
s.add_dependency(%q<crack>, [">= 0"])
|
32
|
+
s.add_dependency(%q<httparty>, ["~> 0.5.1"])
|
45
33
|
end
|
46
34
|
else
|
47
|
-
s.add_dependency(%q<
|
48
|
-
s.add_dependency(%q<
|
49
|
-
s.add_dependency(%q<multipart-post>, [">= 0"])
|
50
|
-
s.add_dependency(%q<mime-types>, [">= 0"])
|
51
|
-
s.add_dependency(%q<twitter-stream>, [">= 0"])
|
52
|
-
s.add_dependency(%q<eventmachine>, [">= 0"])
|
53
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
54
|
-
s.add_dependency(%q<fakeweb>, [">= 0"])
|
35
|
+
s.add_dependency(%q<crack>, [">= 0"])
|
36
|
+
s.add_dependency(%q<httparty>, ["~> 0.5.1"])
|
55
37
|
end
|
56
38
|
end
|
57
39
|
|
data/test/all_tests.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'protolink'
|
5
|
+
require "test/unit"
|
6
|
+
|
7
|
+
# require 'ruby-debug'
|
8
|
+
# Debugger.start
|
9
|
+
# change this if you need to connect to another server
|
10
|
+
PTN_SERVER = "http://localhost:3000"
|
11
|
+
PTN_USER = "dude"
|
12
|
+
PTN_PASS = "geheim"
|
13
|
+
# protonet = Protolink::Protonet.new('localhost:3000', 'bjoern.dorra', 'geheim')
|
14
|
+
#
|
15
|
+
# user = protonet.find_or_create_user_by_login("johndoe", "password", "John Doe", "john@doe.com")
|
16
|
+
# auth_token = user.auth_token
|
17
|
+
# puts "user_id : #{user.id}"
|
18
|
+
# puts "user_login : #{user.login}"
|
19
|
+
# puts "auth_token : #{auth_token}"
|
20
|
+
#
|
21
|
+
# channel = protonet.find_or_create_channel_by_name("test", "This is a test channel!")
|
22
|
+
# puts "channel_id : #{channel.id}"
|
23
|
+
# puts "channel_name: #{channel.name}"
|
24
|
+
# puts "channel_desc: #{channel.description}"
|
25
|
+
#
|
26
|
+
# protonet.create_listen(user.id, channel.id)
|
27
|
+
#
|
28
|
+
# puts "\nhttp://localhost:3000/?auth_token=#{auth_token}"
|
29
|
+
|
30
|
+
class TestAll < Test::Unit::TestCase
|
31
|
+
|
32
|
+
def teardown
|
33
|
+
protonet = Protolink::Protonet.open(PTN_SERVER, PTN_USER, PTN_PASS)
|
34
|
+
user = protonet.find_user_by_login("test")
|
35
|
+
user.delete!
|
36
|
+
user = protonet.find_user_by_login("test_2")
|
37
|
+
user.delete!
|
38
|
+
channel = protonet.find_channel_by_name("test_foobar")
|
39
|
+
channel.delete!
|
40
|
+
channel = protonet.find_channel_by_name("test_foobar_2")
|
41
|
+
channel.delete!
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_all
|
45
|
+
protonet = Protolink::Protonet.open(PTN_SERVER, PTN_USER, PTN_PASS)
|
46
|
+
assert protonet, "Couldn't create connection instance"
|
47
|
+
|
48
|
+
user_1 = protonet.create_user(:login => 'test', :email => 'test@test.com')
|
49
|
+
assert user_1.is_a?(Protolink::User), "Couldn't create user"
|
50
|
+
assert_equal 'test', user_1.login
|
51
|
+
assert_equal 'test@test.com', user_1.email
|
52
|
+
assert user_1.auth_token.match(/\w+/)
|
53
|
+
|
54
|
+
user_2 = protonet.find_or_create_user_by_login('test', :email => 'test@test.com')
|
55
|
+
assert_equal user_1.id, user_2.id
|
56
|
+
|
57
|
+
user_3 = protonet.find_or_create_user_by_login('test_2', :email => 'test_2@test.com')
|
58
|
+
assert user_3.is_a?(Protolink::User), "Couldn't create user"
|
59
|
+
assert_equal 'test_2', user_3.login
|
60
|
+
assert_equal 'test_2@test.com', user_3.email
|
61
|
+
|
62
|
+
channel_1 = protonet.create_channel(:name => "test_foobar", :skip_autosubscribe => true)
|
63
|
+
assert channel_1.is_a?(Protolink::Channel), "Couldn't create channel"
|
64
|
+
assert_equal 'test_foobar', channel_1.name
|
65
|
+
|
66
|
+
channel_2 = protonet.find_or_create_channel_by_name("test_foobar")
|
67
|
+
assert_equal channel_1.id, channel_2.id
|
68
|
+
|
69
|
+
channel_3 = protonet.find_or_create_channel_by_name("test_foobar_2")
|
70
|
+
assert channel_3.is_a?(Protolink::Channel), "Couldn't create channel"
|
71
|
+
assert_equal 'test_foobar_2', channel_3.name
|
72
|
+
|
73
|
+
protonet.create_listen(user_1.id, channel_1.id)
|
74
|
+
protonet.create_listen(user_3.id, channel_1.id)
|
75
|
+
|
76
|
+
assert_equal [user_1.id, user_3.id].sort, channel_1.listener.map {|u| u.id}.sort
|
77
|
+
|
78
|
+
protonet.destroy_listen(user_1.id, channel_1.id)
|
79
|
+
|
80
|
+
assert_equal [user_3.id], channel_1.listener.map {|u| u.id}.sort
|
81
|
+
end
|
82
|
+
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:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Bj\xC3\xB6rn B. Dorra"
|
@@ -16,11 +16,10 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-07-25 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
|
-
name: activesupport
|
24
23
|
prerelease: false
|
25
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
25
|
none: false
|
@@ -32,9 +31,9 @@ dependencies:
|
|
32
31
|
- 0
|
33
32
|
version: "0"
|
34
33
|
type: :runtime
|
34
|
+
name: crack
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name: faraday
|
38
37
|
prerelease: false
|
39
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
@@ -48,91 +47,8 @@ dependencies:
|
|
48
47
|
- 1
|
49
48
|
version: 0.5.1
|
50
49
|
type: :runtime
|
50
|
+
name: httparty
|
51
51
|
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: multipart-post
|
54
|
-
prerelease: false
|
55
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
|
-
requirements:
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
hash: 3
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
version: "0"
|
64
|
-
type: :runtime
|
65
|
-
version_requirements: *id003
|
66
|
-
- !ruby/object:Gem::Dependency
|
67
|
-
name: mime-types
|
68
|
-
prerelease: false
|
69
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
|
-
requirements:
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
hash: 3
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
version: "0"
|
78
|
-
type: :runtime
|
79
|
-
version_requirements: *id004
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
name: twitter-stream
|
82
|
-
prerelease: false
|
83
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
|
-
requirements:
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
hash: 3
|
89
|
-
segments:
|
90
|
-
- 0
|
91
|
-
version: "0"
|
92
|
-
type: :runtime
|
93
|
-
version_requirements: *id005
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: eventmachine
|
96
|
-
prerelease: false
|
97
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
98
|
-
none: false
|
99
|
-
requirements:
|
100
|
-
- - ">="
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
hash: 3
|
103
|
-
segments:
|
104
|
-
- 0
|
105
|
-
version: "0"
|
106
|
-
type: :runtime
|
107
|
-
version_requirements: *id006
|
108
|
-
- !ruby/object:Gem::Dependency
|
109
|
-
name: rspec
|
110
|
-
prerelease: false
|
111
|
-
requirement: &id007 !ruby/object:Gem::Requirement
|
112
|
-
none: false
|
113
|
-
requirements:
|
114
|
-
- - ">="
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
hash: 3
|
117
|
-
segments:
|
118
|
-
- 0
|
119
|
-
version: "0"
|
120
|
-
type: :development
|
121
|
-
version_requirements: *id007
|
122
|
-
- !ruby/object:Gem::Dependency
|
123
|
-
name: fakeweb
|
124
|
-
prerelease: false
|
125
|
-
requirement: &id008 !ruby/object:Gem::Requirement
|
126
|
-
none: false
|
127
|
-
requirements:
|
128
|
-
- - ">="
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
hash: 3
|
131
|
-
segments:
|
132
|
-
- 0
|
133
|
-
version: "0"
|
134
|
-
type: :development
|
135
|
-
version_requirements: *id008
|
136
52
|
description: A Ruby API for interfacing with Protonet, the next-gen internet infrastructure. Truly social and people-powered.
|
137
53
|
email: dorra@d-1.comg
|
138
54
|
executables: []
|
@@ -142,18 +58,21 @@ extensions: []
|
|
142
58
|
extra_rdoc_files:
|
143
59
|
- README.markdown
|
144
60
|
files:
|
61
|
+
- .gitignore
|
62
|
+
- .rvmrc
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
145
65
|
- README.markdown
|
146
66
|
- Rakefile
|
147
67
|
- example/create_and_subscribe.rb
|
148
68
|
- lib/protolink.rb
|
149
69
|
- lib/protolink/channel.rb
|
150
|
-
- lib/protolink/connection.rb
|
151
70
|
- lib/protolink/listen.rb
|
152
|
-
- lib/protolink/middleware.rb
|
153
71
|
- lib/protolink/protonet.rb
|
154
72
|
- lib/protolink/user.rb
|
155
73
|
- lib/protolink/version.rb
|
156
74
|
- protolink.gemspec
|
75
|
+
- test/all_tests.rb
|
157
76
|
has_rdoc: true
|
158
77
|
homepage: http://github.com/protonet/protolink
|
159
78
|
licenses: []
|
@@ -184,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
103
|
requirements: []
|
185
104
|
|
186
105
|
rubyforge_project: protolink
|
187
|
-
rubygems_version: 1.
|
106
|
+
rubygems_version: 1.6.2
|
188
107
|
signing_key:
|
189
108
|
specification_version: 3
|
190
109
|
summary: Ruby wrapper for the ProtoNet API
|
data/lib/protolink/connection.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'faraday'
|
3
|
-
|
4
|
-
module Protolink
|
5
|
-
class Connection
|
6
|
-
|
7
|
-
attr_reader :domain, :username, :password, :uri, :options
|
8
|
-
|
9
|
-
def self.connection
|
10
|
-
@connection ||= Faraday::Connection.new do |conn|
|
11
|
-
conn.use Faraday::Request::ActiveSupportJson
|
12
|
-
conn.adapter :net_http
|
13
|
-
conn.use Protolink::FaradayResponse::RaiseOnAuthenticationFailure
|
14
|
-
conn.use Faraday::Response::ActiveSupportJson
|
15
|
-
conn.use Protolink::FaradayResponse::WithIndifferentAccess
|
16
|
-
|
17
|
-
conn.headers['Content-Type'] = 'application/json'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.raw_connection
|
22
|
-
@raw_connection ||= Faraday::Connection.new do |conn|
|
23
|
-
conn.adapter Faraday.default_adapter
|
24
|
-
conn.use Protolink::FaradayResponse::RaiseOnAuthenticationFailure
|
25
|
-
conn.use Faraday::Response::ActiveSupportJson
|
26
|
-
conn.use Protolink::FaradayResponse::WithIndifferentAccess
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def initialize(domainname, username, password, options = {})
|
31
|
-
@domainname = domainname
|
32
|
-
@username = username
|
33
|
-
@password = password
|
34
|
-
@options = { :ssl => false, :proxy => ENV['HTTP_PROXY'] }.merge(options)
|
35
|
-
@uri = URI.parse("#{@options[:ssl] ? 'https' : 'http' }://#{domainname}")
|
36
|
-
|
37
|
-
connection.basic_auth username, password
|
38
|
-
raw_connection.basic_auth username, password
|
39
|
-
end
|
40
|
-
|
41
|
-
def connection
|
42
|
-
@connection ||= begin
|
43
|
-
conn = self.class.connection.dup
|
44
|
-
conn.url_prefix = @uri.to_s
|
45
|
-
conn.proxy options[:proxy]
|
46
|
-
conn
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def raw_connection
|
51
|
-
@raw_connection ||= begin
|
52
|
-
conn = self.class.raw_connection.dup
|
53
|
-
conn.url_prefix = @uri.to_s
|
54
|
-
conn.proxy options[:proxy]
|
55
|
-
conn
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def get(url, *args)
|
60
|
-
response = connection.get(url, *args)
|
61
|
-
response.body
|
62
|
-
end
|
63
|
-
|
64
|
-
def post(url, body = nil, *args)
|
65
|
-
response = connection.post(url, body, *args)
|
66
|
-
response.body
|
67
|
-
end
|
68
|
-
|
69
|
-
def raw_post(url, body = nil, *args)
|
70
|
-
response = raw_connection.post(url, body, *args)
|
71
|
-
end
|
72
|
-
|
73
|
-
def put(url, body = nil, *args)
|
74
|
-
response = connection.put(url, body, *args)
|
75
|
-
response.body
|
76
|
-
end
|
77
|
-
|
78
|
-
# Is the connection using ssl?
|
79
|
-
def ssl?
|
80
|
-
uri.scheme == 'https'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
data/lib/protolink/middleware.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
module Protolink
|
2
|
-
module FaradayResponse
|
3
|
-
class WithIndifferentAccess < ::Faraday::Response::Middleware
|
4
|
-
begin
|
5
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
6
|
-
rescue LoadError, NameError => error
|
7
|
-
self.load_error = error
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.register_on_complete(env)
|
11
|
-
env[:response].on_complete do |response|
|
12
|
-
json = response[:body]
|
13
|
-
if json.is_a?(Hash)
|
14
|
-
response[:body] = ::HashWithIndifferentAccess.new(json)
|
15
|
-
elsif json.is_a?(Array) and json.first.is_a?(Hash)
|
16
|
-
response[:body] = json.map{|item| ::HashWithIndifferentAccess.new(item) }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class RaiseOnAuthenticationFailure < ::Faraday::Response::Middleware
|
23
|
-
def self.register_on_complete(env)
|
24
|
-
env[:response].on_complete do |response|
|
25
|
-
raise AuthenticationFailed if response[:status] == 401
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|