Class: Riddl::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/riddl/client.rb

Overview

}}}

Defined Under Namespace

Classes: Resource, SimulateRequest

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, riddl = nil, options = {}) ⇒ Client

{{{



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ruby/riddl/client.rb', line 86

def initialize(base, riddl=nil, options={})
  @base = base.nil? ? '' : base.gsub(/\/+$/,'')
  @options = options
  @wrapper = nil
  if @base !~ RIDDL_URL_PATTERN
    raise ConnectionError, 'An RFC 3986 URI as target is required. Pro tip: (http|https|xmpp)://...'
  end
  if @options[:custom_protocol]
    @options[:custom_protocol] = @options[:custom_protocol].new(@base,@options)
  end
  unless riddl.nil?
    @wrapper = (riddl.class == Riddl::Wrapper ? riddl : Riddl::Wrapper::new(riddl))
    if @wrapper.declaration? && !base.nil?
      @wrapper = @wrapper.declaration.description
    end
    raise SpecificationError, 'No RIDDL description or declaration found.' if !@wrapper.description? && !@wrapper.declaration?
    raise SpecificationError, 'RIDDL does not conform to specification' unless @wrapper.validate!
    @wrapper.load_necessary_handlers!
    @wrapper.load_necessary_roles!
  end
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



107
108
109
# File 'lib/ruby/riddl/client.rb', line 107

def base
  @base
end

Class Method Details

.facade(riddl, options = {}) ⇒ Object



115
116
117
# File 'lib/ruby/riddl/client.rb', line 115

def self::facade(riddl,options={})
  new(nil,riddl,options)
end

.interface(base, riddl, options = {}) ⇒ Object



112
113
114
# File 'lib/ruby/riddl/client.rb', line 112

def self::interface(base,riddl,options={})
  new(base,riddl,options)
end

.location(base, options = {}) ⇒ Object



109
110
111
# File 'lib/ruby/riddl/client.rb', line 109

def self::location(base,options={})
  new(base,nil,options)
end

Instance Method Details

#delete(parameters = []) ⇒ Object



129
# File 'lib/ruby/riddl/client.rb', line 129

def delete(parameters = []);          resource.delete(parameters);          end

#get(parameters = []) ⇒ Object



122
# File 'lib/ruby/riddl/client.rb', line 122

def get(parameters = []);             resource.get(parameters);             end

#patch(parameters = []) ⇒ Object



127
# File 'lib/ruby/riddl/client.rb', line 127

def patch(parameters = []);           resource.patch(parameters);           end

#post(parameters = []) ⇒ Object



124
# File 'lib/ruby/riddl/client.rb', line 124

def post(parameters = []);            resource.post(parameters);            end

#put(parameters = []) ⇒ Object



126
# File 'lib/ruby/riddl/client.rb', line 126

def put(parameters = []);             resource.put(parameters);             end

#request(what) ⇒ Object



131
# File 'lib/ruby/riddl/client.rb', line 131

def request(what)                     resource.request(what);               end

#resource(path = "") ⇒ Object



119
120
121
# File 'lib/ruby/riddl/client.rb', line 119

def resource(path="")
  Resource.new(@base,@wrapper,path,@options)
end

#simulate_delete(parameters = []) ⇒ Object



130
# File 'lib/ruby/riddl/client.rb', line 130

def simulate_delete(parameters = []); resource.simulate_delete(parameters); end

#simulate_get(parameters = []) ⇒ Object



123
# File 'lib/ruby/riddl/client.rb', line 123

def simulate_get(parameters = []);    resource.simulate_get(parameters);    end

#simulate_post(parameters = []) ⇒ Object



125
# File 'lib/ruby/riddl/client.rb', line 125

def simulate_post(parameters = []);   resource.simulate_post(parameters);   end

#simulate_put(parameters = []) ⇒ Object



128
# File 'lib/ruby/riddl/client.rb', line 128

def simulate_put(parameters = []);    resource.simulate_put(parameters);    end

#simulate_request(what) ⇒ Object



132
# File 'lib/ruby/riddl/client.rb', line 132

def simulate_request(what)            resource.simulate_request(what);      end

#ws(blk) ⇒ Object



133
# File 'lib/ruby/riddl/client.rb', line 133

def ws(blk)                           resource.ws(blk);                     end