sinatra-jsonapi 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +8 -0
- data/.yardopts +3 -0
- data/README.md +1 -1
- data/lib/sinatra/jsonapi.rb +1 -1
- data/lib/sinatra/jsonapi/version.rb +1 -1
- data/sinatra-jsonapi.gemspec +1 -2
- data/test/jsonapi_spec.rb +13 -8
- metadata +3 -17
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Sinatra::JSONAPI
|
1
|
+
# Sinatra::JSONAPI [![](https://secure.travis-ci.org/kyledrake/sinatra-jsonapi.png)](http://travis-ci.org/kyledrake/sinatra-jsonapi)
|
2
2
|
|
3
3
|
This is an extension for Sinatra that makes the Base class return JSON for 404 and 500 errors, and gives you api\_response and api\_error for quick JSON responses.
|
4
4
|
|
data/lib/sinatra/jsonapi.rb
CHANGED
data/sinatra-jsonapi.gemspec
CHANGED
@@ -16,11 +16,10 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
-
|
19
|
+
|
20
20
|
gem.add_dependency 'json'
|
21
21
|
gem.add_dependency 'sinatra'
|
22
22
|
gem.add_development_dependency 'rake'
|
23
23
|
gem.add_development_dependency 'minitest'
|
24
24
|
gem.add_development_dependency 'rack-test'
|
25
|
-
gem.add_development_dependency 'pry'
|
26
25
|
end
|
data/test/jsonapi_spec.rb
CHANGED
@@ -29,7 +29,10 @@ describe Sinatra::JSONAPI do
|
|
29
29
|
}
|
30
30
|
get '/notfound'
|
31
31
|
last_response.body.wont_equal '<h1>Not Found</h1>'
|
32
|
-
|
32
|
+
|
33
|
+
error_resp = {:error => {:type => 'not_found', :message => 'The requested method was not found: /notfound'}}
|
34
|
+
|
35
|
+
last_response.body.must_equal as_json(error_resp)
|
33
36
|
end
|
34
37
|
|
35
38
|
it 'should return generic 500 JSON on uncaught exception' do
|
@@ -42,9 +45,9 @@ describe Sinatra::JSONAPI do
|
|
42
45
|
|
43
46
|
get '/error'
|
44
47
|
|
45
|
-
|
48
|
+
error_resp = {:error => {:type => 'unexpected_error', :message => 'An unexpected error has occured, please try your request again later'}}
|
46
49
|
|
47
|
-
last_response.body.must_equal
|
50
|
+
last_response.body.must_equal as_json(error_resp)
|
48
51
|
end
|
49
52
|
|
50
53
|
it 'should return custom 500 JSON error' do
|
@@ -55,32 +58,34 @@ describe Sinatra::JSONAPI do
|
|
55
58
|
}
|
56
59
|
|
57
60
|
get '/custom'
|
58
|
-
last_response.body.must_equal(as_json(error
|
61
|
+
last_response.body.must_equal(as_json(:error => {:type => 'wrong_argument', :message => 'no arguments'}))
|
59
62
|
end
|
60
63
|
|
61
64
|
it 'should return hello world json' do
|
62
65
|
|
63
66
|
mock_app {
|
64
67
|
get '/hello' do
|
65
|
-
api_response
|
68
|
+
api_response(:response => 'hello')
|
66
69
|
end
|
67
70
|
}
|
68
71
|
|
69
72
|
get '/hello'
|
70
|
-
last_response.body.must_equal(as_json(response
|
73
|
+
last_response.body.must_equal(as_json(:response => 'hello'))
|
71
74
|
end
|
72
75
|
|
73
76
|
it 'should return jsonp when requested' do
|
74
77
|
mock_app {
|
75
78
|
get '/' do
|
76
|
-
api_response
|
79
|
+
api_response(:response => 'hello')
|
77
80
|
end
|
78
81
|
}
|
79
82
|
|
80
83
|
get '/?callback=abc123'
|
81
84
|
|
85
|
+
expected_resp = {:response => 'hello'}
|
86
|
+
|
82
87
|
expected = "abc123({\n"+
|
83
|
-
" #{as_json
|
88
|
+
" #{as_json expected_resp}\n"+
|
84
89
|
"})"
|
85
90
|
|
86
91
|
last_response.body.must_equal expected
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-jsonapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -91,22 +91,6 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: pry
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ! '>='
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
94
|
description: Turns a Sinatra Base class into a JSON api
|
111
95
|
email:
|
112
96
|
- kyledrake@gmail.com
|
@@ -115,6 +99,8 @@ extensions: []
|
|
115
99
|
extra_rdoc_files: []
|
116
100
|
files:
|
117
101
|
- .gitignore
|
102
|
+
- .travis.yml
|
103
|
+
- .yardopts
|
118
104
|
- Gemfile
|
119
105
|
- LICENSE.txt
|
120
106
|
- README.md
|