Sha256: 917482fe42bbdca0a5d61f744556932b84ab17e635645ff86e63c36bcd6271a5

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

require 'rubygems'
require 'rest_client'
require 'json'

# You must have the "rest-client" and "json" gems installed for this file to work.

class RESTfulAdhearsion
  
  DEFAULT_OPTIONS = {
    # Note: :user and :password are non-existent by default
    :host => "localhost",
    :port => "5000",
    :path_nesting => "/"
  }
  
  def initialize(options={})
    @options = DEFAULT_OPTIONS.merge options
    
    @path_nesting = @options.delete :path_nesting
    @host = @options.delete :host
    @port = @options.delete :port
    
    @url_beginning = "http://#{@host}:#{@port}#{@path_nesting}"
  end
  
  def method_missing(method_name, *args)
    JSON.parse RestClient::Resource.new(@url_beginning + method_name.to_s, @options).post(args.to_json)
  end
  
end

Adhearsion = RESTfulAdhearsion.new :host => "localhost", :port => 5000, :user => "jicksta", :password => "roflcopterz"

# ### Sample component code. Try doing "ahn create component testing123" and pasting this code in.
#
# methods_for :rpc do
#   def i_like_hashes(options={})
#     options.has_key?(:foo)
#   end
#   def i_like_arrays(*args)
#     args.reverse
#   end
# end

# Note: everything returned will be wrapped in an Array

p Adhearsion.i_like_hashes(:foo => "bar")
p Adhearsion.i_like_arrays(1,2,3,4,5)

Version data entries

9 entries across 9 versions & 4 rubygems

Version Path
jicksta-adhearsion-0.7.999 app_generators/ahn/templates/components/restful_rpc/example-client.rb
jicksta-adhearsion-0.8.2 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
jicksta-adhearsion-0.8.3 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
kenwiesner-adhearsioncw-0.8.3 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
mtrudel-adhearsion-0.8.3 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-0.8.3 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-0.8.0 app_generators/ahn/templates/components/restful_rpc/example-client.rb
adhearsion-0.8.2 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-0.8.1 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb