remoteling-ruby 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.
- data/Manifest +5 -0
- data/README.rdoc +24 -0
- data/Rakefile +14 -0
- data/lib/remoteling.rb +88 -0
- data/remoteling-ruby.gemspec +31 -0
- data/test/remoteling_test.rb +76 -0
- metadata +66 -0
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Remoteling-Ruby
|
2
|
+
=====
|
3
|
+
This is the Ruby gem for [Remoteling][website].
|
4
|
+
|
5
|
+
* See the [website][] for docs and to get an account.
|
6
|
+
* We'd love to hear about any bugs or suggestions you have.
|
7
|
+
|
8
|
+
Synopsis:
|
9
|
+
======
|
10
|
+
|
11
|
+
require 'remoteling-ruby'
|
12
|
+
|
13
|
+
@remoteling = Remoteling.new('adrian@pikeapps.com','password')
|
14
|
+
@remoteling.set('example','value')
|
15
|
+
@remoteling.get('example')
|
16
|
+
@remoteling.push('queue1','value')
|
17
|
+
@remoteling.pop('queue1')
|
18
|
+
@remoteling.run('proc_name','variables_to_send')
|
19
|
+
@remoteling.run_serialized('p "foo"','more_variables_to_send')
|
20
|
+
|
21
|
+
|
22
|
+
Copyright (c) 2009 Pike Engineering, released under the MIT license
|
23
|
+
|
24
|
+
website: http://remoteling.com
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('remoteling-ruby', '0.0.1') do |p|
|
6
|
+
p.description = "Ruby gem for working with Remoteling (http://remoteling.com)"
|
7
|
+
p.url = "http://github.com/adrianpike/remoteling-ruby"
|
8
|
+
p.author = "Adrian Pike"
|
9
|
+
p.email = "adrian@pikeapps.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/lib/remoteling.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
require 'cgi'
|
5
|
+
require 'ruby2ruby'
|
6
|
+
|
7
|
+
class Remoteling
|
8
|
+
class OurBad < Exception; end
|
9
|
+
class Unauthorized < Exception; end
|
10
|
+
class Timeout < Exception; end
|
11
|
+
|
12
|
+
CONFIG = {
|
13
|
+
:timeout => 2,
|
14
|
+
# :remoteling_host => 'http://remoteling.com/'
|
15
|
+
:remoteling_host => 'http://localhost:3000/'
|
16
|
+
}
|
17
|
+
|
18
|
+
def initialize(login,password)
|
19
|
+
@login = login
|
20
|
+
@password = password
|
21
|
+
end
|
22
|
+
|
23
|
+
def set(key,value)
|
24
|
+
call_action('store', :put, key, serialize(value))
|
25
|
+
end
|
26
|
+
|
27
|
+
def get(key)
|
28
|
+
deserialize(call_action('store', :get, key))
|
29
|
+
end
|
30
|
+
|
31
|
+
def push(queue_name, item)
|
32
|
+
call_action('queue', :put, queue_name, serialize(item))
|
33
|
+
end
|
34
|
+
|
35
|
+
def pop(queue_name)
|
36
|
+
deserialize(call_action('queue', :get, queue_name))
|
37
|
+
end
|
38
|
+
|
39
|
+
def run_serialized(code, vars)
|
40
|
+
call_action('process',:post,'',{'process[language]' => 'Ruby', 'process[code]' => code, 'process[variables]' => vars})
|
41
|
+
end
|
42
|
+
|
43
|
+
def run(proc_name, args)
|
44
|
+
call_action('process',:put, proc_name, args)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
# Action can be 'queue', 'store', or 'process'
|
50
|
+
# Method can be :get, :post, or :put
|
51
|
+
def call_action(action,method,item='',data=nil)
|
52
|
+
url = URI.parse(CONFIG[:remoteling_host]+action+'/'+item)
|
53
|
+
case method
|
54
|
+
when :get
|
55
|
+
req = Net::HTTP::Get.new(url.path)
|
56
|
+
when :post
|
57
|
+
req = Net::HTTP::Post.new(url.path)
|
58
|
+
when :put
|
59
|
+
req = Net::HTTP::Put.new(url.path)
|
60
|
+
end
|
61
|
+
|
62
|
+
req.basic_auth @login, @password
|
63
|
+
res = Net::HTTP.new(url.host, url.port).start {|http|
|
64
|
+
if data.is_a?(Hash) then
|
65
|
+
req.set_form_data(data)
|
66
|
+
data = nil
|
67
|
+
end
|
68
|
+
data ? http.request(req,data) : http.request(req)
|
69
|
+
}
|
70
|
+
case res
|
71
|
+
when Net::HTTPSuccess
|
72
|
+
res.body
|
73
|
+
when Net::HTTPMethodNotAllowed
|
74
|
+
raise OurBad
|
75
|
+
when Net::HTTPUnauthorized
|
76
|
+
raise Unauthorized
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def deserialize(data)
|
81
|
+
YAML.load(data)
|
82
|
+
end
|
83
|
+
|
84
|
+
def serialize(data)
|
85
|
+
data.to_yaml
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{remoteling-ruby}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Adrian Pike"]
|
9
|
+
s.date = %q{2009-10-07}
|
10
|
+
s.description = %q{Ruby gem for working with Remoteling (http://remoteling.com)}
|
11
|
+
s.email = %q{adrian@pikeapps.com}
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/remoteling.rb"]
|
13
|
+
s.files = ["Manifest", "README.rdoc", "Rakefile", "lib/remoteling.rb", "test/remoteling_test.rb", "remoteling-ruby.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/adrianpike/remoteling-ruby}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Remoteling-ruby", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{remoteling-ruby}
|
18
|
+
s.rubygems_version = %q{1.3.3}
|
19
|
+
s.summary = %q{Ruby gem for working with Remoteling (http://remoteling.com)}
|
20
|
+
s.test_files = ["test/remoteling_test.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 3
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
else
|
28
|
+
end
|
29
|
+
else
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'shoulda'
|
3
|
+
require 'lib/remoteling'
|
4
|
+
|
5
|
+
class RemotelingTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
context 'a simple remoteling client' do
|
8
|
+
setup do
|
9
|
+
@r = Remoteling.new('adrian@pikeapps.com','testing')
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'be able to set and get something' do
|
13
|
+
@r.set('foobar','testing')
|
14
|
+
val = @r.get('foobar')
|
15
|
+
assert_equal 'testing', val
|
16
|
+
end
|
17
|
+
|
18
|
+
should 'be able to push and pop something' do
|
19
|
+
@r.push('foobar','lolwat')
|
20
|
+
val = @r.pop('foobar')
|
21
|
+
assert_equal 'lolwat', val
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'pop falses off an empty queue' do
|
25
|
+
vals = []
|
26
|
+
2.times do
|
27
|
+
vals << @r.pop('foobar')
|
28
|
+
end
|
29
|
+
assert_equal false, vals.last
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'be able to execute a stored process' do
|
33
|
+
# We'll have to set up a stored process to be able to execute it.
|
34
|
+
end
|
35
|
+
|
36
|
+
should 'be able to execute a serialized process' do
|
37
|
+
@r.set('foobar_test_results',nil)
|
38
|
+
code = <<EOM
|
39
|
+
Remoteling.store('foobar_test_results','yarr')
|
40
|
+
EOM
|
41
|
+
@r.run_serialized(code, 'foobar')
|
42
|
+
sleep 2
|
43
|
+
assert_equal 'yarr', @r.get('foobar_test_results')
|
44
|
+
end
|
45
|
+
|
46
|
+
should 'be able to pass variables to a serialized process' do
|
47
|
+
var = ''
|
48
|
+
5.times { var << rand(93) + 33 }
|
49
|
+
code = <<EOM
|
50
|
+
Remoteling.store('foobar_results',Remoteling.variables)
|
51
|
+
EOM
|
52
|
+
@r.run_serialized(code, var)
|
53
|
+
sleep 2
|
54
|
+
assert_equal var, @r.get('foobar_results')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'a remoteling client with bad login/password information' do
|
59
|
+
setup do
|
60
|
+
@r = Remoteling.new('foo','bar')
|
61
|
+
end
|
62
|
+
|
63
|
+
should 'not be able to set' do
|
64
|
+
assert_raise Remoteling::Unauthorized do
|
65
|
+
@r.set('foo','bar')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
should 'not be able to get' do
|
70
|
+
assert_raise Remoteling::Unauthorized do
|
71
|
+
@r.get('foo')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: remoteling-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adrian Pike
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-07 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ruby gem for working with Remoteling (http://remoteling.com)
|
17
|
+
email: adrian@pikeapps.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- lib/remoteling.rb
|
25
|
+
files:
|
26
|
+
- Manifest
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- lib/remoteling.rb
|
30
|
+
- test/remoteling_test.rb
|
31
|
+
- remoteling-ruby.gemspec
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://github.com/adrianpike/remoteling-ruby
|
34
|
+
licenses: []
|
35
|
+
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --line-numbers
|
39
|
+
- --inline-source
|
40
|
+
- --title
|
41
|
+
- Remoteling-ruby
|
42
|
+
- --main
|
43
|
+
- README.rdoc
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "1.2"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project: remoteling-ruby
|
61
|
+
rubygems_version: 1.3.3
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Ruby gem for working with Remoteling (http://remoteling.com)
|
65
|
+
test_files:
|
66
|
+
- test/remoteling_test.rb
|