Module: Kjson::Roda::RequestMethods
- Defined in:
- lib/kjson/roda.rb
Instance Method Summary collapse
- #api(&_b) ⇒ Object
- #auth ⇒ Object
- #data ⇒ Object
- #endpoint(path = nil, &_b) ⇒ Object
- #error(msg = INTERNAL) ⇒ Object
- #kjson? ⇒ Boolean
- #success(data = nil) ⇒ Object
Instance Method Details
#api(&_b) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/kjson/roda.rb', line 49 def api(&_b) return unless kjson? catch_error do catch_success do kjson_parse kjson_api yield throw :error, [UNIMPLEMENTED, REQUEST_ERROR] end end end |
#auth ⇒ Object
86 87 88 |
# File 'lib/kjson/roda.rb', line 86 def auth env[KJSON_REQUEST_KEY]["auth"] end |
#data ⇒ Object
90 91 92 |
# File 'lib/kjson/roda.rb', line 90 def data env[KJSON_REQUEST_KEY]["data"] end |
#endpoint(path = nil, &_b) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/kjson/roda.rb', line 61 def endpoint(path=nil, &_b) return @remaining_endpoints.join(ENDPOINT_SEPARATOR) unless path path = path.to_s.split(ENDPOINT_SEPARATOR) index = @remaining_endpoints.zip(path).index{|z| z.first == z.last} if index && index == path.size - 1 stored_endpoints = @remaining_endpoints @remaining_endpoints = @remaining_endpoints.drop(path.size) if @remaining_endpoints.empty? yield throw :error, [NO_DATA, RESPONSE_ERROR] if @remaining_endpoints.empty? else yield end @remaining_endpoints = stored_endpoints end end |
#error(msg = INTERNAL) ⇒ Object
82 83 84 |
# File 'lib/kjson/roda.rb', line 82 def error(msg=INTERNAL) throw :error, msg end |
#kjson? ⇒ Boolean
94 95 96 |
# File 'lib/kjson/roda.rb', line 94 def kjson? post? && content_type =~ roda_class.opts[:kjson_content_type] end |
#success(data = nil) ⇒ Object
78 79 80 |
# File 'lib/kjson/roda.rb', line 78 def success(data=nil) throw :success, data end |