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 CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby-18mode
6
+ - jruby-19mode
7
+ - rbx-18mode
8
+ - rbx-19mode
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --markup markdown
2
+ -
3
+ LICENSE.md
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
 
@@ -32,7 +32,7 @@ module Sinatra
32
32
 
33
33
  app.helpers do
34
34
  def api_error(type, message)
35
- payload = {error: {type: type, message: message}}
35
+ payload = {:error => {:type => type, :message => message}}
36
36
  halt process_payload(payload)
37
37
  end
38
38
 
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module JSONAPI
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -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
- last_response.body.must_equal(as_json(error: {type: 'not_found', message: 'The requested method was not found: /notfound'}))
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
- error_msg = {error: {type: 'unexpected_error', message: 'An unexpected error has occured, please try your request again later'}}
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 error_msg.to_json
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: {type: 'wrong_argument', message: 'no arguments'}))
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 response: 'hello'
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: 'hello'))
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 response: 'hello'
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(response: 'hello')}\n"+
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.1
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