Sha256: 3b21e6a21ca02ee865a8d1f0145a89416acc25a93bacc3ab85997cb843b090f5

Contents?: true

Size: 1.23 KB

Versions: 14

Compression:

Stored size: 1.23 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

14 entries across 14 versions & 3 rubygems

Version Path
adhearsion-1.2.0 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-1.1.1 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-1.1.0 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-1.0.3 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-1.0.2 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-cw-1.0.2.3 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-cw-1.0.2.2 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-cw-1.0.2.1 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-1.0.1 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-1.0.0 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
rene-adhearsion-0.8.6 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-0.8.6 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-0.8.5 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
adhearsion-0.8.4 app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb