atheme-ruby 0.0.4 → 0.0.5
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.
- data/Rakefile +20 -0
- data/atheme-ruby.gemspec +1 -0
- data/lib/atheme/entity.rb +8 -0
- data/lib/atheme/service.rb +5 -5
- data/lib/atheme/session.rb +35 -6
- data/lib/atheme/version.rb +1 -1
- data/test/test_helper.rb +3 -0
- data/test/user_test.rb +24 -0
- metadata +23 -3
data/Rakefile
CHANGED
@@ -1 +1,21 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rdoc/task'
|
4
|
+
|
5
|
+
Rake::TestTask.new(:test) do |t|
|
6
|
+
t.libs << 'test'
|
7
|
+
t.pattern = 'test/**/*_test.rb'
|
8
|
+
t.verbose = true
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Run tests"
|
12
|
+
task :default => :test
|
13
|
+
|
14
|
+
desc 'Generate documentation for Atheme-Ruby.'
|
15
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Atheme-Ruby'
|
18
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
19
|
+
rdoc.rdoc_files.include('README.md')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
data/atheme-ruby.gemspec
CHANGED
data/lib/atheme/entity.rb
CHANGED
data/lib/atheme/service.rb
CHANGED
@@ -75,10 +75,9 @@ module Atheme
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def method_missing(method, *args, &block)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
return Atheme::Error.new
|
78
|
+
raw_output = @session.service_call(service_name, method, *args)
|
79
|
+
if raw_output.kind_of?(Atheme::Error)
|
80
|
+
return raw_output
|
82
81
|
end
|
83
82
|
response = {raw_output: raw_output}
|
84
83
|
parser = @@parsers.has_key?(service_name) && @@parsers[service_name][method]
|
@@ -88,7 +87,8 @@ module Atheme
|
|
88
87
|
parser.commands.each do |command|
|
89
88
|
response[command.name] = command.call(@session, raw_output)
|
90
89
|
end
|
91
|
-
parser.responder.new(@session, response, &block) if parser.responder
|
90
|
+
return parser.responder.new(@session, response, &block) if parser.responder
|
91
|
+
return response
|
92
92
|
end
|
93
93
|
|
94
94
|
private
|
data/lib/atheme/session.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
module Atheme
|
2
2
|
class Session
|
3
3
|
|
4
|
+
# Connection settings which are used on default
|
4
5
|
DEFAULT_CONNECTION_SETTINGS = {
|
5
6
|
protocol: 'http',
|
6
7
|
hostname: 'localhost',
|
7
8
|
port: '8080'
|
8
9
|
}
|
10
|
+
# Default IP for connections if noone is specified on login
|
9
11
|
DEFAULT_IP = '127.0.0.1'
|
10
12
|
|
11
13
|
def initialize(opts={})
|
@@ -21,17 +23,29 @@ module Atheme
|
|
21
23
|
@cookie, @user, @ip = '.', '.', DEFAULT_IP
|
22
24
|
end
|
23
25
|
|
26
|
+
# Login with an username and passwortd into atheme.
|
27
|
+
# The creditials are the same as in IRC.
|
28
|
+
# IP is optional and only for logging purposes, defaults to 127.0.0.1.
|
29
|
+
# Returns a cookie on success, an Atheme::Error otherwise
|
24
30
|
def login(user, password, ip=DEFAULT_IP)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
cookie_or_error = self.call("atheme.login", user, password, ip)
|
32
|
+
if cookie_or_error.kind_of?(String)
|
33
|
+
@cookie, @user, @ip = cookie_or_error, user, ip
|
34
|
+
else # should be Atheme::Error
|
35
|
+
@cookie, @user, @ip = '.', '.', DEFAULT_IP
|
36
|
+
end
|
37
|
+
return cookie_or_error
|
29
38
|
end
|
30
39
|
|
40
|
+
# Relogin into the services using a previously created cookie
|
41
|
+
# and the associated username.
|
31
42
|
def relogin(cookie, user, ip=DEFAULT_IP)
|
32
43
|
@cookie, @user, @ip = cookie, user, ip
|
44
|
+
logged_in?
|
33
45
|
end
|
34
46
|
|
47
|
+
# Logs out from the current session if previously logged in.
|
48
|
+
# Always returns true
|
35
49
|
def logout
|
36
50
|
return true unless logged_in?
|
37
51
|
self.call("atheme.logout", @cookie, @user, @ip)
|
@@ -39,15 +53,30 @@ module Atheme
|
|
39
53
|
true
|
40
54
|
end
|
41
55
|
|
56
|
+
# Returns true if we are currently logged in and the cookie is a valid one; false otherwise.
|
42
57
|
def logged_in?
|
43
|
-
@cookie
|
58
|
+
return false if @cookie.nil? || @cookie=='.'
|
59
|
+
#need to call a dummy command to decide if the cookie is still valid
|
60
|
+
#as we think that we are a valid user, /ns info 'self' should succeed
|
61
|
+
self.nickserv.info(@user).success?
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns an Atheme::User object of the current user who is logged in
|
65
|
+
# Returns false, if noone is currently logged in
|
66
|
+
def myself
|
67
|
+
return false unless logged_in?
|
68
|
+
self.nickserv.info(@user)
|
44
69
|
end
|
45
70
|
|
71
|
+
# Send raw XMLRPC calls to the Atheme API
|
46
72
|
def call(*args)
|
47
73
|
@server ||= connect_client
|
48
|
-
@server.call(*args)
|
74
|
+
return @server.call(*args)
|
75
|
+
rescue
|
76
|
+
return Atheme::Error.new
|
49
77
|
end
|
50
78
|
|
79
|
+
# Shorthand method for service-calls through the Atheme API
|
51
80
|
def service_call(service, method, *args)
|
52
81
|
self.call("atheme.command", @cookie, @user, @ip, service, method, *args)
|
53
82
|
end
|
data/lib/atheme/version.rb
CHANGED
data/test/test_helper.rb
ADDED
data/test/user_test.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UserTest < Test::Unit::TestCase
|
4
|
+
context "an user" do
|
5
|
+
setup do
|
6
|
+
@session = Atheme::Session.new
|
7
|
+
@cookie = @session.login("oper", "oper123")
|
8
|
+
raise "Cannot login into oper (pw: oper123)" unless @cookie.kind_of?(String)
|
9
|
+
end
|
10
|
+
|
11
|
+
should "call #myself, returning own Atheme::User" do
|
12
|
+
assert_equal true, @session.myself.respond_to?(:name) && @session.myself.name == "oper"
|
13
|
+
end
|
14
|
+
|
15
|
+
should "logout successfully" do
|
16
|
+
assert_equal true, @session.logout
|
17
|
+
assert_equal false, @session.logged_in?
|
18
|
+
end
|
19
|
+
|
20
|
+
should "relogin successfully" do
|
21
|
+
assert_equal true, @session.relogin(@cookie, "oper")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atheme-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: shoulda-context
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
description: Provides a ruby interface for Atheme's XMLRPC API
|
47
63
|
email:
|
48
64
|
- noxx@penya.de
|
@@ -77,6 +93,8 @@ files:
|
|
77
93
|
- lib/atheme/services/statserv.rb
|
78
94
|
- lib/atheme/session.rb
|
79
95
|
- lib/atheme/version.rb
|
96
|
+
- test/test_helper.rb
|
97
|
+
- test/user_test.rb
|
80
98
|
homepage: http://github.com/Flauschbaellchen/atheme-ruby
|
81
99
|
licenses:
|
82
100
|
- MIT
|
@@ -102,5 +120,7 @@ rubygems_version: 1.8.25
|
|
102
120
|
signing_key:
|
103
121
|
specification_version: 3
|
104
122
|
summary: Atheme-XMLRPC interface for Ruby
|
105
|
-
test_files:
|
123
|
+
test_files:
|
124
|
+
- test/test_helper.rb
|
125
|
+
- test/user_test.rb
|
106
126
|
has_rdoc:
|