Skip to content
This repository has been archived by the owner on Jul 17, 2018. It is now read-only.

Commit

Permalink
Share Static Controller Methods
Browse files Browse the repository at this point in the history
* Expose `/api/videos`
  • Loading branch information
seanpdoyle committed Nov 14, 2014
1 parent bd9a514 commit 1e0212a
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 149 deletions.
9 changes: 1 addition & 8 deletions app/controllers/lookbooks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class LookbooksController < ApplicationController
class LookbooksController < StaticController
def index
@lookbooks = build_lookbooks

Expand All @@ -17,11 +17,4 @@ def build_lookbooks
]
}]
end

def image_url(name)
URI.join(
root_url,
self.class.helpers.asset_url(name),
).to_s
end
end
85 changes: 37 additions & 48 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ProjectsController < InheritedResources::Base
class ProjectsController < StaticController
def index
@projects = find_projects

Expand All @@ -10,69 +10,58 @@ def index
def find_projects
[{
id: 1,
name: "The Philadelphia Experiment",
numeral: "I",
slug: "the-philadelphia-experiment",
pages: [
{ url: image_url("the-philadelphia-experiment/1.jpg") },
{ url: image_url("the-philadelphia-experiment/2.jpg") },
{ url: image_url("the-philadelphia-experiment/3.jpg") },
{ url: image_url("the-philadelphia-experiment/4.jpg") },
{ url: image_url("the-philadelphia-experiment/5.jpg") },
{ url: image_url("the-philadelphia-experiment/6.jpg") },
{ url: image_url("the-philadelphia-experiment/7.jpg") },
{ url: image_url("the-philadelphia-experiment/8.jpg") },
{ url: image_url("the-philadelphia-experiment/9.jpg") },
{ url: image_url("the-philadelphia-experiment/10.jpg") },
{ url: vimeo_url(61014435), is_video: true },
{ url: image_url("the-philadelphia-experiment/12.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/1.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/2.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/3.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/4.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/5.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/6.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/7.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/8.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/9.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/10.jpg") },
{ url: vimeo_url(61014435), video: true },
{ url: image_url("projects/the-philadelphia-experiment/12.jpg") },
]
}, {
id: 2,
name: "Zachary Armstrong",
numeral: "II",
slug: "zachary-armstrong",
pages: [
{ url: image_url("zachary-armstrong/1.jpg") },
{ url: image_url("zachary-armstrong/2.jpg") },
{ url: image_url("zachary-armstrong/3.jpg") },
{ url: image_url("zachary-armstrong/4.jpg") },
{ url: image_url("zachary-armstrong/5.jpg") },
{ url: image_url("zachary-armstrong/6.jpg") },
{ url: image_url("zachary-armstrong/7.jpg") },
{ url: image_url("zachary-armstrong/8.jpg") },
{ url: image_url("zachary-armstrong/9.jpg") },
{ url: vimeo_url(86785302), is_video: true },
{ url: image_url("zachary-armstrong/11.jpg") },
{ url: image_url("projects/zachary-armstrong/1.jpg") },
{ url: image_url("projects/zachary-armstrong/2.jpg") },
{ url: image_url("projects/zachary-armstrong/3.jpg") },
{ url: image_url("projects/zachary-armstrong/4.jpg") },
{ url: image_url("projects/zachary-armstrong/5.jpg") },
{ url: image_url("projects/zachary-armstrong/6.jpg") },
{ url: image_url("projects/zachary-armstrong/7.jpg") },
{ url: image_url("projects/zachary-armstrong/8.jpg") },
{ url: image_url("projects/zachary-armstrong/9.jpg") },
{ url: vimeo_url(86785302), video: true },
{ url: image_url("projects/zachary-armstrong/11.jpg") },
]
}, {
id: 3,
name: "Magenta",
numeral: "III",
slug: "magenta",
pages: [
{ url: image_url("magenta/1.jpg") },
{ url: image_url("magenta/2.jpg") },
{ url: image_url("magenta/3.jpg") },
{ url: image_url("magenta/4.jpg") },
{ url: image_url("magenta/5.jpg") },
{ url: vimeo_url(90116548), is_video: true },
{ url: image_url("magenta/7.jpg") },
{ url: image_url("magenta/8.jpg") },
{ url: image_url("magenta/9.jpg") },
{ url: image_url("magenta/10.jpg") },
{ url: image_url("magenta/11.jpg") },
{ url: vimeo_url(93339618), is_video: true },
{ url: image_url("magenta/13.jpg") },
{ url: image_url("projects/magenta/1.jpg") },
{ url: image_url("projects/magenta/2.jpg") },
{ url: image_url("projects/magenta/3.jpg") },
{ url: image_url("projects/magenta/4.jpg") },
{ url: image_url("projects/magenta/5.jpg") },
{ url: vimeo_url(90116548), video: true },
{ url: image_url("projects/magenta/7.jpg") },
{ url: image_url("projects/magenta/8.jpg") },
{ url: image_url("projects/magenta/9.jpg") },
{ url: image_url("projects/magenta/10.jpg") },
{ url: image_url("projects/magenta/11.jpg") },
{ url: vimeo_url(93339618), video: true },
{ url: image_url("projects/magenta/13.jpg") },
]
}]
end

def image_url(name)
self.class.helpers.image_url("projects/#{name}")
end

def vimeo_url(id)
"http://player.vimeo.com/video/#{id}?title=0&amp;byline=0&amp;portrait=0&amp;color=cfcfcf%22%20width=%22888"
end
end
22 changes: 14 additions & 8 deletions app/controllers/redis_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
class RedisController < ApplicationController
def index
version = params[:version].presence || "current"
with_redis do |redis|
version = params[:version].presence || "current"

html_key = "index:#{version}"
html_key = "index:#{version}"

html = redis.get(html_key)
html = redis.get(html_key)

raise ActionController::RoutingError, "#{html_key} not found" if html.blank?
raise ActionController::RoutingError, "#{html_key} not found" if html.blank?

insert_csrf_meta(html)
insert_csrf_meta(html)

render text: html
render text: html
end
end

private
Expand All @@ -28,13 +30,17 @@ def body_bottom_pos(html)
html.index("</body>")
end

def redis
def with_redis
uri = URI.parse(ENV["REDISTOGO_URL"])

Redis.new(
redis = Redis.new(
host: uri.host,
port: uri.port,
password: uri.password
)

yield redis

redis.quit
end
end
7 changes: 0 additions & 7 deletions app/controllers/splashes_controller.rb

This file was deleted.

15 changes: 15 additions & 0 deletions app/controllers/static_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class StaticController < ApplicationController

protected

def image_url(name)
URI.join(
root_url,
self.class.helpers.asset_url(name),
).to_s
end

def vimeo_url(id)
"http://player.vimeo.com/video/#{id}?title=0&amp;byline=0&amp;portrait=0&amp;color=cfcfcf%22%20width=%22888"
end
end
36 changes: 36 additions & 0 deletions app/controllers/videos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class VideosController < StaticController
def index
@videos = find_videos

render json: { videos: @videos }
end

private

def find_videos
[{
id: 6,
url: vimeo_url(109002548),
},
{
id: 5,
url: vimeo_url(99653555),
},
{
id: 4,
url: vimeo_url(84338572),
},
{
id: 3,
url: vimeo_url(83601495),
},
{
id: 2,
url: vimeo_url(81305762),
},
{
id: 1,
url: vimeo_url(73152136),
}]
end
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
resources :posts, only: [:index]
resources :projects
resources :lookbooks, only: [:index]
resources :splashes, only: [:index]
resources :videos, only: [:index]
resources :visuals, only: [:index]
end

Expand Down
4 changes: 0 additions & 4 deletions spec/models/project_spec.rb

This file was deleted.

37 changes: 0 additions & 37 deletions spec/models/splash_spec.rb

This file was deleted.

10 changes: 0 additions & 10 deletions spec/requests/splashes_spec.rb

This file was deleted.

8 changes: 8 additions & 0 deletions spec/requests/videos_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
describe "GET /api/videos" do
it "returns published videos" do
get "/api/videos", {}, json_header

expect(response.status).to eq 200
expect(response).to match_response_schema("videos")
end
end
6 changes: 3 additions & 3 deletions spec/support/api/schemas/projects.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
"items": {
"required": [
"id",
"name",
"numeral",
"pages",
"slug"
],
"properties" : {
"id": { "type": "integer" },
"name": { "type": "string" },
"numeral": { "type": "string" },
"slug": { "type": "string" },
"pages": {
"type": "array",
"items": {
"url": { "type": "string" },
"is_video": { "type": "boolean" }
"video": { "type": "boolean" }
}
}
}
Expand Down
23 changes: 0 additions & 23 deletions spec/support/api/schemas/splashes.json

This file was deleted.

19 changes: 19 additions & 0 deletions spec/support/api/schemas/videos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "object",
"required": ["videos"],
"properties": {
"videos": {
"type": "array",
"items": {
"required": [
"id",
"url"
],
"properties" : {
"id": { "type": "integer" },
"url": { "type": "string" }
}
}
}
}
}

0 comments on commit 1e0212a

Please sign in to comment.