blix-rest 0.8.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5db97b519f38052ee2b7272f3a25d6ec4d5e3ba71cae44bdcd83e25cdd6902f2
4
- data.tar.gz: e7fb1c1da94eb622629a718bd81763d6874dc14028bed0ba8328b42cac5c2152
3
+ metadata.gz: d876a893d297d43960e1d6a279a98268c81018c0a180633825e4457a04044041
4
+ data.tar.gz: '0482c6068226397b4ae4fe755268e28a33efbc2eba1cc0cae92750e9a72d8f2f'
5
5
  SHA512:
6
- metadata.gz: fb48999da4fffe47e1d52cb85319c7ed6473c756a55d6e87edef288a9a118f971c90d709ea73aaf566e1f927a7779056547a91d1cfae71b2cd1a157658c3d2a4
7
- data.tar.gz: 93d06074a5b66da9099c1d1bee4fb23a00ac18f994809efb9fb28f0be7d6bf3a889fdad45a2fb349dbabeec6c816c77a34975a8cd7de70efbcce4cff2af1acb2
6
+ metadata.gz: d2ea75d56a49de0989d60d2ee6e8708d847b840fb5fdb847c236075f7027d8607ff0c6e757b756b364b140022b8f146b0333720b40fb9d2f8f2331ab22202006
7
+ data.tar.gz: 6a713192c12649ab609ce1eb2ea0ea428b4fbef93e9f517827a9ac2d6cecb7251a2033a56f47945cba4a2a90b73afab47b06b9dcb6ed8a6f35cd03d669176c6c
data/README.md CHANGED
@@ -236,12 +236,14 @@ have access to a number of methods
236
236
  path_params : a hash of parameters constructed from variable parts of the path
237
237
  post_params : a hash of parameters passed in the body of the request
238
238
  params : all the params combined
239
+ allow_methods : allow the non standard http verbs in the controller. eg `:propfind `
239
240
  user : the user making this request ( or nil if
240
241
  format : the format the response should be in :json or :html
241
242
  before : before hook ( opts ) - remember to add 'super' as first line !!!
242
243
  after : after hook (opts,response)- remember to add 'super' as first line !!!
243
244
  proxy : forward the call to another service (service,path, opts={}) , :include_query=>true/false
244
245
  session : req.session
246
+ set_status : set the http response status ( 200 )
245
247
  redirect : (path, status=302) redirect to another url.
246
248
  request_ip : the ip of the request
247
249
  render_erb : (template_name [,:layout=>name])
@@ -300,7 +302,7 @@ example:
300
302
 
301
303
  before_route do |route|
302
304
  route.default_option(:level,:visitor)
303
- route.prefix_path('/app')
305
+ route.path_prefix('/app')
304
306
  end
305
307
  ...
306
308
  end
@@ -334,6 +336,9 @@ options can include:
334
336
 
335
337
  For more complete session management:
336
338
 
339
+ require 'blix/utils/redis_store'
340
+ require 'blix/rest/session'
341
+
337
342
  class MyController < Blix::Rest::Controller
338
343
  include Blix::Rest::Session
339
344
 
@@ -82,7 +82,7 @@ module Blix::Rest
82
82
 
83
83
  # ovverride the path method to return the internal path.
84
84
  def path
85
- p = req.path
85
+ p = CGI.unescape(req.path)
86
86
  p = '/' + p if p[0, 1] != '/' # ensure a leading slash on path
87
87
  idx = RequestMapper.path_root_length
88
88
  if idx > 0
@@ -671,6 +671,17 @@ module Blix::Rest
671
671
  end
672
672
  end
673
673
 
674
+ def allow_methods(*methods)
675
+ out = String.new
676
+ methods.each do |method|
677
+ method = method.to_s.upcase
678
+ next if (HTTP_VERBS + ['ALL']).include?(method)
679
+ out << "def #{method.downcase}(*a, &b);route '#{method}', *a, &b;end\n"
680
+ end
681
+ puts out if $DEBUG || $VERBOSE
682
+ eval out unless out.empty?
683
+ end
684
+
674
685
  end
675
686
 
676
687
  end
@@ -317,11 +317,9 @@ module Blix::Rest
317
317
  list.sort! { |a, b| a[0] <=> b[0] }
318
318
  str = String.new
319
319
  list.each do |route|
320
- #pairs = route[1]
321
- (HTTP_VERBS + ['ALL']).each do |verb|
322
- if route[1].key? verb
323
- str << verb << "\t" << route[0] << route[1][verb] << "\n"
324
- end
320
+ pairs = route[1].to_a.sort{|a,b| a[0]<=>b[0]}
321
+ pairs.each do |pair|
322
+ str << pair[0] << "\t" << route[0] << "\t" << pair[1] << "\n"
325
323
  end
326
324
  str << "\n"
327
325
  end
@@ -160,7 +160,7 @@ module Blix::Rest
160
160
 
161
161
  verb = env['REQUEST_METHOD']
162
162
  path = req.path
163
- path = CGI.unescape(path).gsub('+',' ') unless _options[:unescape] == false
163
+ path = CGI.unescape(path) unless _options[:unescape] == false
164
164
 
165
165
  blk, path_params, options, is_wild = RequestMapper.match(verb, path)
166
166
 
@@ -1,5 +1,5 @@
1
1
  module Blix
2
2
  module Rest
3
- VERSION = "0.8.2"
3
+ VERSION = "0.9.3"
4
4
  end
5
5
  end
data/lib/blix/rest.rb CHANGED
@@ -96,9 +96,14 @@ module Blix
96
96
 
97
97
  def initialize(message, status = nil, headers = nil)
98
98
  super(message || "")
99
- @status = status || 406
99
+ @status = (status || 406).to_i
100
100
  @headers = headers
101
101
  end
102
+
103
+ def to_i
104
+ @status
105
+ end
106
+
102
107
  end
103
108
 
104
109
  class RawResponse < StandardError
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blix-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clive Andrews
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-24 00:00:00.000000000 Z
11
+ date: 2023-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient