acts_as_api 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +2 -1
- data/.travis.yml +3 -1
- data/Gemfile +4 -0
- data/README.md +2 -17
- data/acts_as_api.gemspec +1 -1
- data/lib/acts_as_api.rb +5 -0
- data/lib/acts_as_api/rails_renderer.rb +1 -1
- data/lib/acts_as_api/responder.rb +11 -17
- data/lib/acts_as_api/version.rb +1 -1
- data/spec/controllers/plain_objects_controller_spec.rb +1 -1
- data/spec/controllers/respond_with_users_controller_spec.rb +1 -1
- data/spec/controllers/users_controller_spec.rb +2 -2
- data/spec/mongoid_dummy/Gemfile +2 -2
- data/spec/shared_engine/shared_engine.gemspec +5 -6
- data/spec/support/api_test_helpers.rb +6 -6
- data/spec/support/controller_examples.rb +14 -2
- data/spec/support/model_examples/enabled.rb +1 -1
- data/spec/support/model_examples/untouched.rb +2 -2
- metadata +20 -20
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
M2VlNDBlNzUyMzJmNzM2MjdjNTA5ODQzYzBlNTJiM2ZjYzliOGQ4Yw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 750c497db915d3d79eb40810cdaf5913c9444fa9
|
4
|
+
data.tar.gz: e30520e560f3381f58f683784cf906f910a1bdcc
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NDMwYTUzZmQyZmNmZjY1NzlkYzRiMjc4MjlhZTFhNWJkNjkxNzE2YTM4ZDcy
|
11
|
-
YzIyYzg5ZTYyYTY1N2FmYmVlNzZhZmMwNzBjYmI3ODMxM2ZhYTA=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NjEwMmZiMjFmMTFlNDIzMmViMzdmMDk1OGEwM2UwMmExZDZhNWJhNmY1Mzhj
|
14
|
-
NTRlYTVlMWQwNzg3MzI3MTBiZjJiOTkzMDBmZWRmOWE1MzUzMzM2NDU2ZWNj
|
15
|
-
NGQzYzBlM2RmZTE2OTM2ODM2MDA5NjFkZjhmNDQwN2U4NTg1MDk=
|
6
|
+
metadata.gz: 0ef61479b5003497864d5849ac686e07afea4a4cbf40d321beb40e9ef5446cc79945f46578a0c4b7938b3f3987d4ff68499700f935a18d9b3c0e2b2515875a72
|
7
|
+
data.tar.gz: ad9dbf1e35bac88887795d19f414fd7eef6d7a5113e0e00fb04ecdf95158a15f74e3cbc0ec788e3b263a77c941dd452e3a6e1c9cddbb081b89c5bb08a5a52fc8
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -4,9 +4,13 @@ source "http://rubygems.org"
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
group :test do
|
7
|
+
gem 'test-unit', '~> 3.0'
|
7
8
|
gem 'sqlite3-ruby'
|
8
9
|
gem 'mongoid', '>= 3.0.1'
|
9
10
|
gem 'rspec', '>= 2.9.0'
|
11
|
+
gem 'rspec-its'
|
12
|
+
gem 'rspec-collection_matchers'
|
13
|
+
gem 'capybara'
|
10
14
|
gem 'rspec-rails', '>= 2.5.0'
|
11
15
|
gem 'webrat'
|
12
16
|
gem 'shared_engine', :path => './spec/shared_engine'
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ acts_as_api makes creating XML/JSON responses in Rails 3 easy and fun.
|
|
4
4
|
|
5
5
|
It provides a simple interface to determine the representation of your model data, that should be rendered in your API responses.
|
6
6
|
|
7
|
-
In addition to Rails it theoretically can be used with any ruby app and any database (__ActiveRecord__ and
|
7
|
+
In addition to Rails it theoretically can be used with any ruby app and any database (__ActiveRecord__, __Mongoid__ and __ActiveResource__ are supported out of the box) as it only has few dependencies.
|
8
8
|
|
9
9
|
The lib is _very_ fast in generating your responses and battle tested in production with platforms like [Diaspora](https://joindiaspora.com) or [flinc](https://flinc.org).
|
10
10
|
|
@@ -80,21 +80,6 @@ There are a lot of how-tos like:
|
|
80
80
|
|
81
81
|
* Want to contribute - the spec suite is explained here: https://github.com/fabrik42/acts_as_api/tree/master/spec
|
82
82
|
|
83
|
-
### Travis CI build status ![acts_as_api on travis ci](https://secure.travis-ci.org/fabrik42/acts_as_api.png?branch=master)
|
84
|
-
|
85
|
-
Specs run with 1.9.3: http://travis-ci.org/#!/fabrik42/acts_as_api
|
86
|
-
|
87
|
-
### Tested with:
|
88
|
-
|
89
|
-
It has been used in production with the following ruby versions.
|
90
|
-
|
91
|
-
They are not integrated in Travis, because optional dependencies (like Mongoid 3) don't support these Ruby versions.
|
92
|
-
|
93
|
-
* MRI 1.9.3-p125
|
94
|
-
* MRI 1.9.2-p290
|
95
|
-
* MRI 1.8.7-p358
|
96
|
-
* But it just should work fine with other versions too... :)
|
97
|
-
|
98
83
|
### Downwards Compatibility
|
99
84
|
|
100
85
|
Note that upgrading to 0.3.0 will break code that worked with previous versions due to a complete overhaul of the lib.
|
@@ -123,4 +108,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
123
108
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
124
109
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
125
110
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
126
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
111
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/acts_as_api.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.add_dependency('activesupport','>= 3.0.0')
|
17
17
|
s.add_dependency('rack','>= 1.1.0')
|
18
18
|
|
19
|
-
s.add_development_dependency('rails', ['>= 3.2.
|
19
|
+
s.add_development_dependency('rails', ['>= 3.2.22.2'])
|
20
20
|
s.add_development_dependency('mongoid', ['>= 3.0.1'])
|
21
21
|
|
22
22
|
s.rdoc_options = ['--charset=UTF-8']
|
data/lib/acts_as_api.rb
CHANGED
@@ -30,6 +30,11 @@ if defined?(ActiveRecord::Base)
|
|
30
30
|
ActiveRecord::Base.extend ActsAsApi::Base
|
31
31
|
end
|
32
32
|
|
33
|
+
# Attach ourselves to ActiveResource
|
34
|
+
if defined?(ActiveResource::Base)
|
35
|
+
ActiveResource::Base.extend ActsAsApi::Base
|
36
|
+
end
|
37
|
+
|
33
38
|
# Attach ourselves to Mongoid
|
34
39
|
if defined?(Mongoid::Document)
|
35
40
|
Mongoid::Document.send :include, ActsAsApi::Adapters::Mongoid
|
@@ -8,7 +8,7 @@ module ActsAsApi
|
|
8
8
|
ActionController.add_renderer :acts_as_api_jsonp do |json, options|
|
9
9
|
json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str)
|
10
10
|
json = "#{options[:callback]}(#{json}, #{response.status})" unless options[:callback].blank?
|
11
|
-
self.content_type ||= Mime::JSON
|
11
|
+
self.content_type ||= options[:callback].blank ? Mime::JSON : Mime::JS
|
12
12
|
self.response_body = json
|
13
13
|
end
|
14
14
|
end
|
@@ -20,26 +20,20 @@ module ActsAsApi
|
|
20
20
|
# The `:api_template` parameter is required so the responder knows which api template it should render.
|
21
21
|
|
22
22
|
class Responder < ActionController::Responder
|
23
|
+
module Module
|
24
|
+
# Overrides the base implementation of display, replacing it with
|
25
|
+
# the render_for_api method whenever api_template is specified.
|
26
|
+
def display(resource, given_options={})
|
27
|
+
api_template = options[:api_template]
|
23
28
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
def initialize(controller, resources, options={})
|
30
|
-
@api_template = options.delete(:api_template)
|
31
|
-
super(controller, resources, options)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Overrides the base implementation of display, replacing it with
|
35
|
-
# the render_for_api method whenever api_template is specified.
|
36
|
-
def display(resource, given_options={})
|
37
|
-
if api_template.nil? || !resource.respond_to?(:as_api_response)
|
38
|
-
controller.render given_options.merge!(options).merge!(format => resource)
|
39
|
-
else
|
40
|
-
controller.render_for_api api_template, given_options.merge!(options).merge!(format => resource)
|
29
|
+
if api_template.nil? || !resource.respond_to?(:as_api_response)
|
30
|
+
controller.render given_options.merge!(options).merge!(format => resource)
|
31
|
+
else
|
32
|
+
controller.render_for_api api_template, given_options.merge!(options).merge!(format => resource)
|
33
|
+
end
|
41
34
|
end
|
42
35
|
end
|
43
36
|
|
37
|
+
include Module
|
44
38
|
end
|
45
39
|
end
|
data/lib/acts_as_api/version.rb
CHANGED
data/spec/mongoid_dummy/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'rails', '3.2.
|
3
|
+
gem 'rails', '3.2.22.2'
|
4
4
|
|
5
5
|
# Bundle edge Rails instead:
|
6
6
|
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
@@ -14,5 +14,5 @@ gem 'acts_as_api', :path => '../../'
|
|
14
14
|
|
15
15
|
group :test do
|
16
16
|
gem 'rspec-rails', '>= 2.5.0'
|
17
|
-
gem 'webrat'
|
17
|
+
gem 'webrat'
|
18
18
|
end
|
@@ -7,15 +7,14 @@ require "shared_engine/version"
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "shared_engine"
|
9
9
|
s.version = SharedEngine::VERSION
|
10
|
-
s.authors = ["
|
11
|
-
s.email = ["
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.description = "TODO: Description of SharedEngine."
|
10
|
+
s.authors = ["Your name"]
|
11
|
+
s.email = ["Your email"]
|
12
|
+
s.summary = "Summary of SharedEngine."
|
13
|
+
s.description = "Description of SharedEngine."
|
15
14
|
|
16
15
|
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
|
17
16
|
|
18
|
-
s.add_dependency "rails", "~> 3.2.
|
17
|
+
s.add_dependency "rails", "~> 3.2.22.2"
|
19
18
|
# s.add_dependency "jquery-rails"
|
20
19
|
|
21
20
|
s.add_development_dependency "sqlite3"
|
@@ -1,23 +1,23 @@
|
|
1
1
|
module ApiTestHelpers
|
2
|
-
|
2
|
+
|
3
3
|
def response_body
|
4
4
|
response.body.strip
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
def response_body_json
|
8
8
|
ActiveSupport::JSON.decode(response_body)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def response_body_jsonp(callback)
|
12
12
|
jsonp_callback(callback).match(response_body)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def jsonp_callback(callback)
|
16
16
|
/\A#{callback}\((.*),\s+\d{3}\)\z/
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
end
|
20
20
|
|
21
21
|
RSpec.configure do |c|
|
22
22
|
c.include ApiTestHelpers
|
23
|
-
end
|
23
|
+
end
|
@@ -94,7 +94,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
describe 'get all users as a ActiveRecord::Relation (or similar chained) object, autodetecting the root node name' do
|
99
99
|
|
100
100
|
before(:each) do
|
@@ -119,7 +119,7 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
119
119
|
response_body_json["users"].first["last_name"].should eql("Solo")
|
120
120
|
end
|
121
121
|
|
122
|
-
end
|
122
|
+
end
|
123
123
|
|
124
124
|
describe 'get a single user' do
|
125
125
|
|
@@ -301,6 +301,18 @@ shared_examples_for "a controller with ActsAsApi responses" do
|
|
301
301
|
|
302
302
|
end
|
303
303
|
|
304
|
+
describe 'Requesting the JSONP content as JavaScript' do
|
305
|
+
|
306
|
+
before(:each) do
|
307
|
+
get :index, :format => :js, :api_template => :name_only, :callback => @callback
|
308
|
+
end
|
309
|
+
|
310
|
+
it "should set the content type to JavaScript" do
|
311
|
+
response.content_type.should == Mime::JS
|
312
|
+
end
|
313
|
+
|
314
|
+
end
|
315
|
+
|
304
316
|
end
|
305
317
|
end
|
306
318
|
|
@@ -2,7 +2,7 @@ shared_examples_for "untouched models" do
|
|
2
2
|
|
3
3
|
describe "has disabled acts_as_api by default" do
|
4
4
|
it "indicates that acts_as_api is disabled" do
|
5
|
-
Untouched.acts_as_api?.should
|
5
|
+
Untouched.acts_as_api?.should == false
|
6
6
|
end
|
7
7
|
|
8
8
|
it "does not respond to api_accessible" do
|
@@ -10,4 +10,4 @@ shared_examples_for "untouched models" do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Bäuerlein
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 3.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rack
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 1.1.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.1.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.2.
|
61
|
+
version: 3.2.22.2
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.2.
|
68
|
+
version: 3.2.22.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: mongoid
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 3.0.1
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 3.0.1
|
83
83
|
description: acts_as_api enriches the models and controllers of your app in a rails-like
|
@@ -88,8 +88,8 @@ executables: []
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
-
- .gitignore
|
92
|
-
- .travis.yml
|
91
|
+
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
93
93
|
- Gemfile
|
94
94
|
- History.txt
|
95
95
|
- README.md
|
@@ -297,22 +297,22 @@ licenses: []
|
|
297
297
|
metadata: {}
|
298
298
|
post_install_message:
|
299
299
|
rdoc_options:
|
300
|
-
- --charset=UTF-8
|
300
|
+
- "--charset=UTF-8"
|
301
301
|
require_paths:
|
302
302
|
- lib
|
303
303
|
required_ruby_version: !ruby/object:Gem::Requirement
|
304
304
|
requirements:
|
305
|
-
- -
|
305
|
+
- - ">="
|
306
306
|
- !ruby/object:Gem::Version
|
307
307
|
version: '0'
|
308
308
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
309
309
|
requirements:
|
310
|
-
- -
|
310
|
+
- - ">="
|
311
311
|
- !ruby/object:Gem::Version
|
312
312
|
version: '0'
|
313
313
|
requirements: []
|
314
314
|
rubyforge_project:
|
315
|
-
rubygems_version: 2.1
|
315
|
+
rubygems_version: 2.5.1
|
316
316
|
signing_key:
|
317
317
|
specification_version: 4
|
318
318
|
summary: Makes creating XML/JSON responses in Rails 3 easy and fun.
|