Class: Ishapi::SitesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ishapi/sites_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#test

Instance Method Details

#indexObject



6
7
8
9
# File 'app/controllers/ishapi/sites_controller.rb', line 6

def index
  authorize! :index, ::Site
  @sites = ::Site.all
end

#showObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/ishapi/sites_controller.rb', line 11

def show
  if params[:domain].include?(".json")
    domain = params[:domain][0...-5]
  else
    domain = params[:domain]
  end
  @site = ::Site.find_by :domain => domain, :lang => :en
  authorize! :show, @site


  if @site.is_private
    if !params[:accessToken]
      render :json => { :status => :unauthorized}, :status => :unauthorized
      return
    end
    access_token = params[:accessToken]
    @graph = Koala::Facebook::API.new( access_token, ::FB[@site.domain][:secret] )
    @profile = @graph.get_object "me", :fields => 'email'
    if @site.private_user_emails.include?( @profile['email'] )
      ;
    else
      render :json => { :status => :unauthorized}, :status => :unauthorized
      render :status => :unauthorized
    end
  end

  @galleries    = @site.galleries.limit( 10 )
  @newsitems    = @site.newsitems.limit(10)
  @reports      = @site.reports.limit( 10 )
  @langs        = ::Site.where( :domain => domain ).map( &:lang )
  @feature_tags = @site.tags.where( :is_feature => true )

end