Skip to content

Commit

Permalink
add active_api
Browse files Browse the repository at this point in the history
  • Loading branch information
Blair Anderson committed Mar 8, 2015
1 parent ba9203b commit 35a67b0
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
9 changes: 8 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
source 'https://rubygems.org'

gem 'active_model_serializers'
if ENV["RAILS_ENV"]=="production"
gem 'active_api', github: 'blairanderson/active_api'
else
gem 'active_api', path: '../active_api'
end
gem 'jquery-rails'
gem 'pg'
gem 'rails', '4.2.0'
Expand All @@ -12,13 +18,14 @@ gem 'validate_url'


group :development, :test do

# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
# gem 'spring'

gem 'swagger-docs'

Expand Down
15 changes: 13 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
PATH
remote: ../active_api
specs:
active_api (0.0.1)
active_model_serializers
rails (~> 4.2.0)
will_paginate

GEM
remote: https://rubygems.org/
specs:
Expand All @@ -20,6 +28,8 @@ GEM
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
active_model_serializers (0.9.3)
activemodel (>= 3.2)
activejob (4.2.0)
activesupport (= 4.2.0)
globalid (>= 0.3.0)
Expand Down Expand Up @@ -167,7 +177,6 @@ GEM
bcrypt (~> 3.1)
oauth (~> 0.4, >= 0.4.4)
oauth2 (>= 0.8.0)
spring (1.3.2)
sprockets (2.12.3)
hike (~> 1.2)
multi_json (~> 1.0)
Expand Down Expand Up @@ -198,11 +207,14 @@ GEM
binding_of_caller (>= 0.7.2)
railties (~> 4.0)
sprockets-rails (>= 2.0, < 4.0)
will_paginate (3.0.7)

PLATFORMS
ruby

DEPENDENCIES
active_api!
active_model_serializers
byebug
factory_girl_rails
faker
Expand All @@ -214,7 +226,6 @@ DEPENDENCIES
sass-rails (~> 5.0)
simple_form
sorcery (= 0.9.0)
spring
swagger-docs
turbolinks
uglifier (>= 1.3.0)
Expand Down
1 change: 1 addition & 0 deletions app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ class Item < ActiveRecord::Base


scope :active, -> { where(disabled: false) }
scope :disabled, -> { where(disabled: true) }
scope :newest, -> { order(score: :desc) }
end
20 changes: 20 additions & 0 deletions app/serializers/item_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ItemSerializer < ActiveModel::Serializer
# self.per_page = 1

has_scope :newest, type: :boolean
has_scope :disabled, type: :boolean
# has_scope :by_degree
# has_scope :by_period, :using => [:started_at, :ended_at], :type => :hash


# filter #(optional) - Filters are used to narrow down the events used in an analysis request based on event property values.
# timeframe #(optional) - A Timeframe specifies the events to use for analysis based on a window of time.
# property_names #(optional) - A URL-encoded array of strings containing properties you wish to extract. If this parameter is omitted, all properties will be returned.

# cache key: 'posts', expires_in: 3.hours
attributes :id, :title, :content, :url, :created_at, :updated_at

# has_many :comments
#
# url :post
end
3 changes: 3 additions & 0 deletions config/initializers/active_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ActiveApi::Engine.config.route_config = {
resources: [:items, :users]
}
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Rails.application.routes.draw do
root :to => 'items#index'
mount ActiveApi::Engine => '/aappii'

root to: 'items#index'
resources :user_sessions, only: [:new, :create, :destroy]
resources :users, except: [:index]
resources :items, except: [:destroy] do
Expand Down

0 comments on commit 35a67b0

Please sign in to comment.