aepic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02a135b8f945df6ce5bc603d613d4e7618f5797c
4
+ data.tar.gz: 8a80b4f63e684fec3af33334ed7cc9add21d3201
5
+ SHA512:
6
+ metadata.gz: 3aa6e4eef60ce11e7999dc574ffb1f9ad0ea622afbe7aeb4dfe6e037a1b6089adbf667ba08a037cc6649a2aba3741e0a84173499c67880f2c15f0a9a9a97fbed
7
+ data.tar.gz: 4e8eb70e130b0168f3b92d65b63c4a44ef11aa4464484cd0581edc1b6ce80c516792e5eeab991fa36ec9721c4d6c24497c2b582922b0e1f12dbfe2e4fa11c49c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aepic.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alexander Semyonov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Æpic is for your epic APIs
2
+
3
+ Æpic gives you ability to easily add standards-based ([JSON-API][] and [JSON-LD][]) [API][] for
4
+ your existing [RESTful][REST] controllers.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'aepic'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install aepic
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Roadmap
25
+
26
+ * TODO: Provide similar Atom-based XML representation
27
+ * TODO: Provide [WADL][] for [API][]
28
+ * TODO: Provide [RSDL][] for [API][]
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
37
+
38
+ [JSON-API]: http://jsonapi.org/
39
+ [JSON-LD]: http://json-ld.org/
40
+ [REST]: http://en.wikipedia.org/wiki/Representational_state_transfer
41
+ [API]: http://en.wikipedia.org/wiki/Application_programming_interface
42
+ [WADL]: http://en.wikipedia.org/wiki/WADL
43
+ [RSDL]: http://en.wikipedia.org/wiki/RSDL
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/aepic.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aepic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'aepic'
8
+ spec.version = Aepic::VERSION
9
+ spec.authors = ['Alexander Semyonov']
10
+ spec.email = %w(al@semyonov.us)
11
+ spec.description = %q{Build your epic APIs same time you are building your website. Docs included}
12
+ spec.summary = %q{Æpic is for your epic APIs}
13
+ spec.homepage = 'http://github.com/alsemyonov/aepic'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = %w(lib)
20
+
21
+ spec.add_runtime_dependency 'actionpack', '>= 3.2'
22
+ spec.add_runtime_dependency 'active_model_serializers'
23
+ spec.add_runtime_dependency 'inherited_resources'
24
+ spec.add_runtime_dependency 'has_scope'
25
+ spec.add_runtime_dependency 'responders'
26
+ spec.add_runtime_dependency 'draper'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.3'
29
+ spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency 'rspec'
31
+ end
@@ -0,0 +1,26 @@
1
+ %h1= page_title(resource_class: resource_class.model_name.human)
2
+
3
+ %h2 JSON LD Context:
4
+ %pre
5
+ %code= resource_serializer.jsonld
6
+
7
+ %h2 Available endpoints:
8
+ %ul
9
+ - if controller.respond_to?(:index)
10
+ %li
11
+ %code GET #{collection_path(format: :json)}
12
+ - if controller.respond_to?(:create)
13
+ %li
14
+ %code POST #{collection_path(format: :json)}
15
+ - if controller.respond_to?(:show)
16
+ %li
17
+ %code GET #{resource_path(':id', format: :json)}
18
+ - if controller.respond_to?(:update)
19
+ %li
20
+ %code PUT #{resource_path(':id', format: :json)}
21
+ - if controller.respond_to?(:update)
22
+ %li
23
+ %code PATCH #{resource_path(':id', format: :json)}
24
+ - if controller.respond_to?(:destroy)
25
+ %li
26
+ %code DELETE #{resource_path(':id', format: :json)}
@@ -0,0 +1,19 @@
1
+ xml.application(
2
+ xsi: 'http://www.w3.org/2001/XMLSchema-instance',
3
+ 'xsi:schemaLocation' => 'http://wadl.dev.java.net/2009/02 wadl.xsd',
4
+ xsd: 'http://www.w3.org/2001/XMLSchema',
5
+ xmlns: 'http://wadl.dev.java.net/2009/02') do
6
+
7
+ schema = Aepic::Schema.default
8
+ schema.controllers.each do |controller|
9
+ xml.resources base: root_url do
10
+ xml.resource path: "#{controller.controller_name}", id: controller.controller_name do
11
+ controller.action_methods.each do |action|
12
+ xml.method name: schema.method_for(action) do
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/aepic.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'aepic/version'
2
+ require 'active_support'
3
+
4
+ module Aepic
5
+ extend ActiveSupport::Autoload
6
+
7
+ autoload :Controller
8
+ autoload :Schema
9
+
10
+ module Concerns
11
+ extend ActiveSupport::Autoload
12
+
13
+ autoload :Controller
14
+ autoload :Serializer
15
+ end
16
+ end
@@ -0,0 +1,60 @@
1
+ # coding: utf-8
2
+ require 'aepic'
3
+ require 'active_support/concern'
4
+ require 'inherited_resources'
5
+
6
+ module Aepic
7
+ module Concerns
8
+ module Controller
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ inherit_resources
13
+
14
+ respond_to :json
15
+ respond_to :jsonld, only: :index
16
+
17
+ has_scope :ids, only: :index do |controller, scope, ids|
18
+ ids = ids.to_s.split(',').map { |id| id.to_i }
19
+ scope.where(id: ids)
20
+ end
21
+ helper_method :resource_serializer
22
+
23
+ api_schema << self
24
+ end
25
+
26
+ module ClassMethods
27
+ # @return [ActiveModel::Serializer]
28
+ def resource_serializer
29
+ resource_class.active_model_serializer
30
+ end
31
+
32
+ def api_schema
33
+ @api_schema ||= Schema.default
34
+ end
35
+ end
36
+
37
+ protected
38
+
39
+ # @return [ActiveModel::Serializer]
40
+ def resource_serializer
41
+ self.class.resource_serializer
42
+ end
43
+
44
+ # @return [Draper::Decorator]
45
+ def resource
46
+ get_resource_ivar || set_resource_ivar(super.decorate)
47
+ end
48
+
49
+ # @return [Draper::Decorator]
50
+ def build_resource
51
+ get_resource_ivar || set_resource_ivar(super.decorate)
52
+ end
53
+
54
+ # @return [Draper::CollectionDecorator]
55
+ def collection
56
+ get_collection_ivar || set_collection_ivar(super.decorate)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,11 @@
1
+ # coding: utf-8
2
+
3
+ module Aepic
4
+ module Concerns
5
+ module Decorator
6
+ def jsonld_context
7
+ h.polymorphic_url(object.class, format: :jsonld)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ require 'aepic'
3
+
4
+ module Aepic
5
+ module Concerns
6
+ module Serializer
7
+ attributes :id
8
+
9
+ XSD_TYPES = Hash.new { |hash, key| hash[key] = "xsd:#{key}"}.merge({
10
+ })
11
+
12
+ def self.jsonld_context
13
+ {}.tap do |context|
14
+ schema[:attributes].each do |name, type|
15
+ context[name] = XSD_TYPES[type]
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.jsonld
21
+ {'@context' => jsonld_context.merge(xsd: 'http://www.w3.org/2001/XMLSchema#')}
22
+ end
23
+
24
+ def attributes
25
+ hash = super
26
+ hash['@context'] = object.jsonld_context
27
+ hash
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ # coding: utf-8
2
+ require 'aepic'
3
+
4
+ module Aepic
5
+ class Controller < ApplicationController
6
+ include Aepic::Concerns::Controller
7
+ end
8
+ end
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ require 'aepic'
3
+
4
+ module Aepic
5
+ class Schema
6
+ METHODS = {
7
+ :index => :get,
8
+ :show => :get,
9
+ :update => [:put, :patch],
10
+ :create => :post,
11
+ :destroy => :delete,
12
+ :edit => :get,
13
+ }
14
+
15
+ def self.default
16
+ @default ||= new
17
+ end
18
+
19
+ def resources
20
+ controllers.each do |controller|
21
+ if controller.action_methods.include?('index')
22
+
23
+ end
24
+ end
25
+ end
26
+
27
+ def controllers
28
+ @controllers ||= Set.new
29
+ end
30
+
31
+ def <<(controller)
32
+ controllers << controller
33
+ end
34
+
35
+ def method_for(action)
36
+ METHODS[action.to_sym].to_s.upcase
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Aepic
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aepic do
4
+ it 'should have a version number' do
5
+ Aepic::VERSION.should_not be_nil
6
+ end
7
+
8
+ it 'should do something useful' do
9
+ false.should be_true
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'aepic'
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aepic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Semyonov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: active_model_serializers
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: inherited_resources
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: has_scope
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: responders
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: draper
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Build your epic APIs same time you are building your website. Docs included
140
+ email:
141
+ - al@semyonov.us
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - .gitignore
147
+ - .rspec
148
+ - .travis.yml
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - aepic.gemspec
154
+ - app/views/application/api.html.haml
155
+ - app/views/application/api.xml.builder
156
+ - lib/aepic.rb
157
+ - lib/aepic/concerns/controller.rb
158
+ - lib/aepic/concerns/decorator.rb
159
+ - lib/aepic/concerns/serializer.rb
160
+ - lib/aepic/controller.rb
161
+ - lib/aepic/schema.rb
162
+ - lib/aepic/version.rb
163
+ - spec/aepic_spec.rb
164
+ - spec/spec_helper.rb
165
+ homepage: http://github.com/alsemyonov/aepic
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.0.3
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Æpic is for your epic APIs
189
+ test_files:
190
+ - spec/aepic_spec.rb
191
+ - spec/spec_helper.rb