Class: Ishapi::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/ishapi/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#homeObject



40
41
42
43
44
# File 'app/controllers/ishapi/application_controller.rb', line 40

def home
  authorize! :welcome_home, Ishapi
  render :json => { :status => :ok, :message => 'Ishapi::ApiController.home',
                    :n_reports => Report.count, :n_cities => City.count }
end

#long_term_tokenObject



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
# File 'app/controllers/ishapi/application_controller.rb', line 14

def long_term_token
  accessToken   = request.headers[:accessToken]
  accessToken ||= params[:accessToken]

  params['domain'] = 'tgm.piousbox.com'

  response = ::HTTParty.get "https://graph.facebook.com/v5.0/oauth/access_token?grant_type=fb_exchange_token&" +
    "client_id=#{FB[params['domain']][:app]}&client_secret=#{FB[params['domain']][:secret]}&" +
    "fb_exchange_token=#{accessToken}"
  j = JSON.parse response.body
  @long_term_token  = j['access_token']
  @graph            = Koala::Facebook::API.new( accessToken )
  @me               = @graph.get_object( 'me', :fields => 'email' )
  @current_user     = User.where( :email => @me['email'] ).first

  # send the jwt to client
  @jwt_token = encode(user_id: @current_user.id.to_s)

  render json: {
    email: @current_user.email,
    jwt_token: @jwt_token,
    long_term_token: @long_term_token,
    n_unlocks: @current_user.profile.n_unlocks,
  }
end

#testObject



11
12
# File 'app/controllers/ishapi/application_controller.rb', line 11

def test
end