ishapi 0.1.8.46 → 0.1.8.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 170e73546c25909c2cbc434038b19099caa85525
4
- data.tar.gz: 9e1088d6219ae9345a351603eb0c5e88cc97e8a2
3
+ metadata.gz: a20173c671af02b9594c0a9c2e7a99a91f8974fd
4
+ data.tar.gz: 48b52b9fd85cd05fa06a78555c222e0e415a8a77
5
5
  SHA512:
6
- metadata.gz: fb0d57c1ba431351443fa1866675aa359423c8b3a37ae7217cb2effc956c11972889d550696337bd08fb3be9bbc7aacb856916cd22b0a4ba6f88e844d0b8cd72
7
- data.tar.gz: ef07397eadcba06e9bb1b643942b3db2d37eff07cde4ba5a8bda2947396e251e9634e4e99e12bf574e73548d27c83d4b87f508954684b6cb1500c9ea18aeff4e
6
+ metadata.gz: 0fc840115817634f92f8d24cefff80a997253e52bea0aa6e11d88225c02750630b88bb8fec850f48d69a28f3a8070c8aba3b6b02ddab6c62c475ad25f9bf4764
7
+ data.tar.gz: '08b5d09c051b6a9ee6918b255c65d6ed3b4e1bf5c102e8591ad66d936c826da5def20326a3f582eebe664a5f832bd618cc058491f197e2b7d61815604dc94e2f'
@@ -4,71 +4,10 @@ module Ishapi
4
4
  class ApiController < ApplicationController
5
5
 
6
6
  def home
7
- puts! params, 'params'
8
-
7
+ authorize! :welcome_home, Ishapi
9
8
  render :json => { :status => :ok, :message => 'Ishapi::ApiController.home',
10
9
  :n_reports => Report.count, :n_cities => City.count }
11
- authorize! :welcome_home, Ishapi
12
- end
13
-
14
- =begin
15
- before_action :set_article, only: [:show, :edit, :update, :destroy]
16
-
17
- # GET /articles
18
- def index
19
- @articles = Article.all
20
- end
21
-
22
- # GET /articles/1
23
- def show
24
- end
25
-
26
- # GET /articles/new
27
- def new
28
- @article = Article.new
29
- end
30
-
31
- # GET /articles/1/edit
32
- def edit
33
- end
34
-
35
- # POST /articles
36
- def create
37
- @article = Article.new(article_params)
38
-
39
- if @article.save
40
- redirect_to @article, notice: 'Article was successfully created.'
41
- else
42
- render :new
43
- end
44
- end
45
-
46
- # PATCH/PUT /articles/1
47
- def update
48
- if @article.update(article_params)
49
- redirect_to @article, notice: 'Article was successfully updated.'
50
- else
51
- render :edit
52
- end
53
- end
54
-
55
- # DELETE /articles/1
56
- def destroy
57
- @article.destroy
58
- redirect_to articles_url, notice: 'Article was successfully destroyed.'
59
- end
60
-
61
- private
62
- # Use callbacks to share common setup or constraints between actions.
63
- def set_article
64
- @article = Article.find(params[:id])
65
- end
66
-
67
- # Only allow a trusted parameter "white list" through.
68
- def article_params
69
- params.require(:article).permit(:title, :text)
70
10
  end
71
- =end
72
11
 
73
12
  end
74
13
  end
@@ -6,8 +6,54 @@ module Ishapi
6
6
  check_authorization
7
7
  skip_before_action :verify_authenticity_token
8
8
 
9
+ #
10
+ # private
11
+ #
9
12
  private
10
13
 
14
+ def set_profile
15
+ accessToken = request.headers[:accessToken]
16
+ accessToken ||= params[:fb_long_access_token]
17
+ accessToken ||= params[:accessToken] # if (params[:debug] == 'abba' && Rails.env.development?)
18
+
19
+ if accessToken
20
+ begin
21
+ @graph = Koala::Facebook::API.new( accessToken )
22
+ @me = @graph.get_object( 'me', :fields => 'email' )
23
+ @user = User.find_or_create_by :email => @me['email']
24
+ @oauth = Koala::Facebook::OAuth.new( CO_TAILORS_FB_APP_ID, CO_TAILORS_FB_APP_SECRET )
25
+ @long_lived_token = get_long_token( accessToken )
26
+
27
+ begin
28
+ @profile = IshModels::UserProfile.find_by :email => @me['email']
29
+ @profile.update_attributes({ :fb_access_token => @long_lived_token,
30
+ :fb_long_access_token => @long_lived_token })
31
+ rescue Mongoid::Errors::DocumentNotFound
32
+ @profile = IshModels::UserProfile.create :user => @user, :email => @me['email'],
33
+ :fb_access_token => @long_lived_token,
34
+ :fb_long_access_token => @long_lived_token,
35
+ :fb_id => params[:id],
36
+ :name => params[:name],
37
+ :signed_request => params[:signedRequest]
38
+ end
39
+ @current_user = @user
40
+ @current_profile = @profile
41
+ rescue Koala::Facebook::AuthenticationError => e
42
+ render :json => { :status => :not_ok, :errors => "Probably expired token: #{accessToken}" }
43
+ return
44
+ end
45
+ end
46
+ end
47
+
48
+ def get_long_token accessToken
49
+ url = "https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&" +
50
+ "client_id=#{FB_APP_ID}&client_secret=#{FB_APP_SECRET}&fb_exchange_token=#{accessToken}"
51
+ result = HTTParty.get url
52
+ token = JSON.parse result.body
53
+ puts! token['access_token'], "long access token is"
54
+ return token['access_token']
55
+ end
56
+
11
57
  def set_current_ability
12
58
  @current_ability ||= ::Ishapi::Ability.new( current_user )
13
59
  end
@@ -3,32 +3,11 @@ require_dependency "ishapi/application_controller"
3
3
  module Ishapi
4
4
  class UsersController < ApplicationController
5
5
 
6
+ before_action :set_profile, :only => [ :fb_sign_in ]
7
+
6
8
  def fb_sign_in
7
9
  authorize! :fb_sign_in, Ishapi
8
- params.permit!
9
-
10
- access_token = params[:accessToken]
11
- email = params[:email]
12
- name = params[:name]
13
- user = User.where( :email => email ).first
14
-
15
- u = IshModels::UserProfile.find_or_create_by :email => email
16
- u.fb_access_token = access_token
17
- u.name ||= name
18
- u.user ||= user
19
- u.email ||= email
20
- u.user ||= User.create( :email => email, :password => (0..8).map { "#{rand(100)}" }.join("#{rand(100)}") )
21
-
22
- auth = Koala::Facebook::OAuth.new
23
- u.fb_long_access_token = auth.exchange_access_token access_token
24
-
25
- puts! u, 'profile, here'
26
-
27
- if u.save
28
- render :json => { :status => :ok, :profile => u }
29
- else
30
- render :json => { :status => :not_ok, :errors => u.errors.messages }
31
- end
10
+ render :json => { :status => :ok }
32
11
  end
33
12
 
34
13
  def show
@@ -0,0 +1,9 @@
1
+
2
+ # this is for... m3?
3
+
4
+ FB_APP_ID ||= '107960979836752'
5
+ FB_APP_SECRET ||= '5d32afa4f281bcc28a8df092b1b081a9'
6
+
7
+ # this is for... co tailors
8
+ CO_TAILORS_FB_APP_ID ||= '2005729719751456'
9
+ CO_TAILORS_FB_APP_SECRET ||= '7650b1e11ef22318ff5fa33e06b322ee'
data/config/routes.rb CHANGED
@@ -1,6 +1,4 @@
1
-
2
1
  Ishapi::Engine.routes.draw do
3
-
4
2
  root :to => 'api#home'
5
3
  post 'home', :to => 'api#home'
6
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ishapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8.46
4
+ version: 0.1.8.47
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-14 00:00:00.000000000 Z
11
+ date: 2017-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -252,6 +252,7 @@ files:
252
252
  - app/views/ishapi/videos/_show.jbuilder
253
253
  - app/views/ishapi/videos/_show.jbuilder~
254
254
  - app/views/layouts/ishapi/application.html.erb
255
+ - config/initializers/koala.rb
255
256
  - config/routes.rb
256
257
  - lib/ishapi.rb
257
258
  - lib/ishapi/engine.rb