Class: Riddl::Client::Resource

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

Overview

}}}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, wrapper, path, options) ⇒ Resource

{{{



137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/ruby/riddl/client.rb', line 137

def initialize(base,wrapper,path,options) #{{{
  @base = base
  @wrapper = wrapper
  @rpath = "/#{path}".gsub(/\/+/,'/')
  @options = options
  @path = if @wrapper.nil?
    @rpath
  else
    @path = @wrapper.paths.find{ |e| e[1] =~ @rpath }
    raise PathError, 'Path not found.' if @path.nil?
    @path[0]
  end
  @rpath = @rpath == '/' ? '' : @rpath
end

Instance Attribute Details

#rpathObject (readonly)

}}}



151
152
153
# File 'lib/ruby/riddl/client.rb', line 151

def rpath
  @rpath
end

Instance Method Details

#delete(parameters = []) ⇒ Object

}}}



195
196
197
# File 'lib/ruby/riddl/client.rb', line 195

def delete(parameters = []) #{{{
  exec_request('DELETE',parameters,false)
end

#get(parameters = []) ⇒ Object

}}}



167
168
169
# File 'lib/ruby/riddl/client.rb', line 167

def get(parameters = []) #{{{
  exec_request('GET',parameters,false)
end

#patch(parameters = []) ⇒ Object

}}}



188
189
190
# File 'lib/ruby/riddl/client.rb', line 188

def patch(parameters = []) #{{{
  exec_request('PATCH',parameters,false)
end

#post(parameters = []) ⇒ Object

}}}



174
175
176
# File 'lib/ruby/riddl/client.rb', line 174

def post(parameters = []) #{{{
  exec_request('POST',parameters,false)
end

#put(parameters = []) ⇒ Object

}}}



181
182
183
# File 'lib/ruby/riddl/client.rb', line 181

def put(parameters = []) #{{{
  exec_request('PUT',parameters,false)
end

#request(what) ⇒ Object

}}}



202
203
204
# File 'lib/ruby/riddl/client.rb', line 202

def request(what) #{{{
  priv_request(what,false)
end

#simulate_delete(parameters = []) ⇒ Object

}}}



198
199
200
# File 'lib/ruby/riddl/client.rb', line 198

def simulate_delete(parameters = []) #{{{
  exec_request('DELETE',parameters,true)
end

#simulate_get(parameters = []) ⇒ Object

}}}



170
171
172
# File 'lib/ruby/riddl/client.rb', line 170

def simulate_get(parameters = []) #{{{
  exec_request('GET',parameters,true)
end

#simulate_patch(parameters = []) ⇒ Object

}}}



191
192
193
# File 'lib/ruby/riddl/client.rb', line 191

def simulate_patch(parameters = []) #{{{
  exec_request('PATCH',parameters,true)
end

#simulate_post(parameters = []) ⇒ Object

}}}



177
178
179
# File 'lib/ruby/riddl/client.rb', line 177

def simulate_post(parameters = []) #{{{
  exec_request('POST',parameters,true)
end

#simulate_put(parameters = []) ⇒ Object

}}}



184
185
186
# File 'lib/ruby/riddl/client.rb', line 184

def simulate_put(parameters = []) #{{{
  exec_request('PUT',parameters,true)
end

#simulate_request(what) ⇒ Object

}}}



205
206
207
# File 'lib/ruby/riddl/client.rb', line 205

def simulate_request(what) #{{{
  priv_request(what,true)
end

#ws(&blk) ⇒ Object

{{{



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/ruby/riddl/client.rb', line 153

def ws(&blk) #{{{
  EM.run do
    conn = Faye::WebSocket::Client.new((@base + @rpath).sub(/^http/,'ws'))

    if @options[:debug]
      conn.on :error do |e|
        @options[:debug].puts "WS ERROR: #{e}"
      end
    end

    blk.call(conn)
  end
end