ishapi 0.1.8.114 → 0.1.8.116

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd43d94d4d5bee2b7c5256be58fcb1c3f5f5738d4a50b63820f77521b941da56
4
- data.tar.gz: 4b4d6868efc90c9a382967245e8492c1a24b2fc0fe94f9b39f53ec034dc3df5f
3
+ metadata.gz: 5b55b77299fe0ad600967ee834aaeb25eeb531d4c76402788eee2efcf80443a4
4
+ data.tar.gz: c4409f71ee678ce226678acae816863e69d0c3cddda7a073087dfb3e323c713c
5
5
  SHA512:
6
- metadata.gz: 12f57e6f9aba87accbb8a961e3d955997c21863c28b72330cba006e7321ce8224ed667a313c65a593b28b0bbe899c4020283c20d87097401d3ebe4e081ae098c
7
- data.tar.gz: 9196172b477ef601108da041bf3ac686320e247ada3316963635adb55ba3fe586f74c438fbb492592f7521431f85fc62b82b780dda93fdf41c7d59551247cb38
6
+ metadata.gz: a345c900145cde1c693462f0f8f057d327c4097fb3e844861f897da4e6c5c3ee8900d6d85b952de12bc97ae76b547cf1674f39b37fd6fb286f8367d2f0cbf946
7
+ data.tar.gz: 23a8bc20a8727d2cca598f156a9c37ea50c384f55341e5ef682d030287448fa08c389957144f32adc681c4507f54ad3cb032eecec67c2546587a1889de935f9c
@@ -37,13 +37,35 @@ module Ishapi
37
37
  private
38
38
 
39
39
  def append_long_term_token
40
- puts! 'after action!', @long_term_token
41
-
42
40
  if @long_term_token
43
41
  response.body = JSON.parse(response.body).merge({ long_term_token: @long_term_token }).to_json
44
42
  end
45
43
  end
46
44
 
45
+ ## Hard check by default; craps out if accessToken is missing
46
+ def check_long_term_token soft=false
47
+ accessToken = request.headers[:accessToken]
48
+ accessToken ||= params[:accessToken]
49
+ if accessToken
50
+ @graph = Koala::Facebook::API.new( accessToken )
51
+ @me = @graph.get_object( 'me', :fields => 'email' )
52
+ @current_user = User.where( :email => @me['email'] ).first
53
+ @profile = @current_user.profile
54
+ raise '98& - no profile' unless @profile
55
+ else
56
+ if soft
57
+ return
58
+ else
59
+ raise 'no access token'
60
+ end
61
+ end
62
+ end
63
+ ## Does not crap out if accessToken is missing
64
+ def soft_check_long_term_token
65
+ check_long_term_token soft=true
66
+ # puts! @profile, 'soft_check_long_term_token() profile'
67
+ end
68
+
47
69
  def check_multiprofile provider = 'google'
48
70
  if 'google' == provider
49
71
  # client_secrets = ::Google::APIClient::ClientSecrets.load
@@ -67,7 +89,6 @@ module Ishapi
67
89
  # long-term token
68
90
  #
69
91
  params['domain'] = 'tgm.piousbox.com'
70
- puts! accessToken, 'accessToken'
71
92
  response = HTTParty.get "https://graph.facebook.com/v5.0/oauth/access_token?grant_type=fb_exchange_token&" +
72
93
  "client_id=#{FB[params['domain']][:app]}&client_secret=#{FB[params['domain']][:secret]}&" +
73
94
  "fb_exchange_token=#{accessToken}"
@@ -100,7 +121,8 @@ module Ishapi
100
121
  puts! @current_user, 'current_user'
101
122
  puts! @current_profile, 'current_profile'
102
123
  # byebug
103
-
124
+ else
125
+ puts! 'check_multiprofile(): no access token'
104
126
  end
105
127
 
106
128
  sign_in @current_user, scope: :user
@@ -108,7 +130,7 @@ module Ishapi
108
130
  end
109
131
 
110
132
  # this doesn't generate long-lived token, doesn't update user_profile
111
- # this is only for facebook?
133
+ # this is only for facebook now
112
134
  def check_profile
113
135
  # return check_multiprofile 'google'
114
136
  return check_multiprofile 'facebook'
@@ -190,7 +212,7 @@ module Ishapi
190
212
 
191
213
  def set_current_ability
192
214
  # puts! current_user.email, '#set_current_ability() :: @current_user'
193
- @current_user ||= User.new
215
+ @current_user ||= User.new({ profile: ::IshModels::UserProfile.new })
194
216
  @current_ability ||= ::Ishapi::Ability.new( @current_user )
195
217
  end
196
218
 
@@ -3,6 +3,8 @@ require_dependency "ishapi/application_controller"
3
3
  module Ishapi
4
4
  class GalleriesController < ApplicationController
5
5
 
6
+ before_action :soft_check_long_term_token, only: [ :show ]
7
+
6
8
  def index
7
9
  @galleries = Gallery.all
8
10
  authorize! :index, Gallery
@@ -15,12 +17,20 @@ module Ishapi
15
17
  @galleries = @galleries.where( :site => @site )
16
18
  end
17
19
  @galleries = @galleries.page( params[:galleries_page] ).per( 10 )
18
- byebug
19
20
  end
20
21
 
21
22
  def show
22
23
  @gallery = ::Gallery.unscoped.find_by :galleryname => params[:galleryname]
23
24
  authorize! :show, @gallery
25
+ if @gallery.premium?
26
+ if current_user.profile.has_premium_purchase( @gallery )
27
+ render 'show_premium_unlocked'
28
+ else
29
+ render 'show_premium_locked'
30
+ end
31
+ else
32
+ render 'show'
33
+ end
24
34
  end
25
35
 
26
36
  end
@@ -0,0 +1,64 @@
1
+ require_dependency "ishapi/application_controller"
2
+
3
+ module Ishapi
4
+ class GameuiController < ApplicationController
5
+ before_action :check_long_term_token, except: []
6
+
7
+ def buy_stars
8
+ authorize! :buy_stars, @profile
9
+ puts! @current_user, 'current_user'
10
+ puts! @profile, 'profile'
11
+
12
+ payment = Ish::Payment.new :email => @profile.email, :amount => params[:amount],
13
+ profile: @profile
14
+
15
+ ::Stripe.api_key = STRIPE_SK
16
+ acct = Stripe::Account.create(
17
+ :country => 'US',
18
+ :type => 'custom'
19
+ )
20
+ charge = ::Stripe::Charge.create(
21
+ :amount => params[:amount],
22
+ :currency => 'usd',
23
+ :source => params[:stripeToken],
24
+ :destination => {
25
+ :account => acct,
26
+ }
27
+ )
28
+ puts! charge, 'charge'
29
+ payment.charge = JSON.parse( charge.to_json )
30
+ payment.save
31
+ if payment.persisted?
32
+ # add the star
33
+ @profile.n_stars += 1
34
+ @profile.save
35
+ if !@profile.persisted?
36
+ raise 'could not save profile, somehow'
37
+ end
38
+ else
39
+ puts! payment.errors.messages
40
+ end
41
+
42
+ render json: { status: 'ok', n_stars: @profile.n_stars }
43
+ end
44
+
45
+ ## spend the star
46
+ def do_purchase
47
+ authorize! :do_purchase, ::Gameui
48
+ item = params[:className].constantize.find_by_slug( params[:slug] )
49
+
50
+ raise 'no such item' if !item
51
+ raise 'too little funds' if @profile.n_stars < item.premium_tier
52
+
53
+ ::IshModels::UserProfile.with_session do
54
+ @profile.update_attributes( n_stars: @profile.n_stars - item.premium_tier )
55
+ @purchase = ::Gameui::PremiumPurchase.create! user_profile: @profile, item: item
56
+ end
57
+
58
+ render json: @purchase
59
+ rescue ::Exception => e
60
+ render json: e
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,39 @@
1
+ require_dependency "ishapi/application_controller"
2
+ module Ishapi
3
+ class MapsController < ApplicationController
4
+
5
+ before_action :soft_check_long_term_token, only: [ :show ]
6
+
7
+ def index
8
+ authorize! :index, ::Gameui::Map
9
+ @maps = ::Gameui::Map.all
10
+ end
11
+
12
+ def show
13
+ @map = ::Gameui::Map.find_by slug: params[:slug]
14
+ @markers = @map.markers.where( is_active: true )
15
+
16
+ case @map.ordering_type
17
+ when ::Gameui::Map::ORDERING_TYPE_ALPHABETIC
18
+ @markers = @markers.order_by( name: :asc )
19
+ when ::Gameui::Map::ORDERING_TYPE_CUSTOM
20
+ @markers = @markers.order_by( ordering: :asc )
21
+ end
22
+
23
+ if city = City.where( cityname: @map.slug ).first
24
+ @newsitems = city.newsitems
25
+ @galleries = city.galleries
26
+ @reports = city.reports
27
+ @videos = city.videos
28
+ end
29
+ authorize! :show, @map
30
+ end
31
+
32
+ def show_marker
33
+ @marker = ::Gameui::Marker.find_by slug: params[:slug]
34
+ authorize! :show, @marker
35
+ render json: @marker
36
+ end
37
+
38
+ end
39
+ end
@@ -16,13 +16,14 @@ class Ishapi::Ability
16
16
  can [ :show ], Gallery do |gallery|
17
17
  gallery.user_profile == user.profile
18
18
  end
19
+ can [ :do_purchase ], ::Gameui
19
20
 
20
21
  can [ :update ], ::CoTailors::Address do |address|
21
22
  puts [ user.inspect, address.inspect ], '+++ user in cancancan'
22
23
  true
23
24
  end
24
25
 
25
-
26
+ can [ :buy_stars ], ::IshModels::UserProfile
26
27
 
27
28
  end
28
29
  #
@@ -41,10 +42,15 @@ class Ishapi::Ability
41
42
 
42
43
  can [ :index, :show ], Event
43
44
 
45
+ #
46
+ # G
47
+ #
44
48
  can [ :index ], Gallery
45
49
  can [ :show ], Gallery do |gallery|
46
- gallery.is_public
50
+ gallery.is_public && !gallery.is_trash
47
51
  end
52
+ can [ :index, :show ], ::Gameui::Map
53
+ can [ :show ], ::Gameui::Marker
48
54
 
49
55
  can [ :index ], Report
50
56
  can [ :my_index, :show ], Report do |report|
@@ -1,10 +1,8 @@
1
-
2
1
  #
3
2
  # ishapi / galleries / _show
4
3
  #
5
4
 
6
- json.id gallery.id.to_s
7
- json.name gallery.name
8
- json.galleryname gallery.galleryname
9
-
10
- json.partial! 'ishapi/photos/index', :photos => gallery.photos
5
+ json.id gallery.id.to_s
6
+ json.name gallery.name
7
+ json.galleryname gallery.galleryname
8
+ json.description gallery.description
@@ -1,4 +1,3 @@
1
-
2
1
  #
3
2
  # ishapi / galleries / show
4
3
  #
@@ -6,11 +5,8 @@
6
5
  this_key = [ @gallery, params.permit! ]
7
6
  json.cache! this_key do
8
7
  json.gallery do
9
- json.id @gallery.id.to_s
10
- json.name @gallery.name
11
- json.galleryname @gallery.galleryname
12
- json.description @gallery.descr
13
- json.partial! 'ishapi/photos/index', :photos => @gallery.photos
8
+ json.partial! 'ishapi/galleries/show', gallery: @gallery
9
+ json.partial! 'ishapi/photos/index', :photos => @gallery.photos
14
10
  end
15
11
  end
16
12
 
@@ -0,0 +1,17 @@
1
+ #
2
+ # ishapi / galleries / show_premium_locked
3
+ #
4
+
5
+ this_key = [ @gallery, params.permit! ]
6
+ json.cache! this_key do
7
+ json.gallery do
8
+ json.message "This is premium content - please purchase it to view!"
9
+ json.premium_tier @gallery.premium_tier
10
+ json.is_premium @gallery.is_premium
11
+ json.is_purchased false
12
+
13
+ json.partial! 'ishapi/galleries/show', gallery: @gallery
14
+ json.partial! 'ishapi/photos/index', :photos => [ @gallery.photos[0] ]
15
+ end
16
+ end
17
+
@@ -0,0 +1,17 @@
1
+ #
2
+ # ishapi / galleries / show_premium_unlocked
3
+ #
4
+
5
+ this_key = [ @gallery, params.permit! ]
6
+ json.cache! this_key do
7
+ json.gallery do
8
+ json.message "Thanks for purchasing!"
9
+ json.premium_tier @gallery.premium_tier
10
+ json.is_premium @gallery.is_premium
11
+ json.is_purchased true
12
+
13
+ json.partial! 'ishapi/galleries/show', gallery: @gallery
14
+ json.partial! 'ishapi/photos/index', :photos => @gallery.photos
15
+ end
16
+ end
17
+
@@ -0,0 +1,12 @@
1
+ #
2
+ # ishapi / maps / index
3
+ #
4
+
5
+ json.maps do
6
+ @maps.each do |map|
7
+ json.id map.id.to_s
8
+ json.slug map.slug
9
+ end
10
+ end
11
+
12
+
@@ -0,0 +1,42 @@
1
+ #
2
+ # ishapi / maps / show
3
+ #
4
+
5
+ this_key = [ @map, params.permit! ]
6
+ json.cache! this_key do
7
+ json.map do
8
+ json.id @map.id.to_s
9
+ json.slug @map.slug
10
+ json.parent_slug @map.parent_slug
11
+ json.description @map.description
12
+ json.w @map.w
13
+ json.h @map.h
14
+ json.img_path @map.img_path
15
+ json.updated_at @map.updated_at
16
+
17
+ json.markers do
18
+ json.array! @markers do |marker|
19
+ json.name marker.name
20
+ json.slug marker.slug
21
+ json.x marker.x
22
+ json.y marker.y
23
+ json.w marker.w
24
+ json.h marker.h
25
+ json.img_path marker.img_path
26
+ json.title_img_path marker.title_img_path
27
+ json.item_type marker.item_type
28
+ end
29
+ end
30
+
31
+ if @newsitems
32
+ json.partial! 'ishapi/newsitems/index', :newsitems => @newsitems
33
+ end
34
+
35
+ if @galleries
36
+ json.partial! 'ishapi/galleries/index', galleries: @galleries
37
+ end
38
+
39
+ end
40
+ end
41
+
42
+
@@ -11,13 +11,21 @@ json.newsitems do
11
11
  json.created_at item.created_at
12
12
 
13
13
  if item.gallery
14
- json.item_type 'gallery'
15
- json.name item.gallery.name
16
- json.galleryname item.gallery.galleryname
17
- json.username item.username
14
+ json.item_type 'gallery'
15
+ json.name item.gallery.name
16
+ json.galleryname item.gallery.galleryname
17
+ json.username item.username
18
+
18
19
 
19
20
  json.partial! 'ishapi/application/meta', :item => item.gallery
20
- json.partial! 'ishapi/photos/index', :photos => item.gallery.photos
21
+ if item.gallery.is_premium
22
+ json.premium_tier item.gallery.premium_tier
23
+ json.is_premium item.gallery.premium_tier > 0
24
+ json.is_purchased current_user.profile.has_premium_purchase( item.gallery )
25
+ json.partial! 'ishapi/photos/index', :photos => [ item.gallery.photos[0] ]
26
+ else
27
+ json.partial! 'ishapi/photos/index', :photos => item.gallery.photos
28
+ end
21
29
  end
22
30
 
23
31
  if item.report
@@ -1,6 +1,5 @@
1
-
2
- #
3
1
  #
2
+ # ishapi / newsitems / index
4
3
  #
5
4
 
6
5
  json.partial! 'index', :newsitems => @newsitems
@@ -16,8 +16,8 @@ json.cache! key do
16
16
  end
17
17
 
18
18
  # @TODO: move this to meta
19
- json.created_at @report.created_at.strftime('%Y%m%d')
20
- json.updated_at @report.updated_at.strftime('%Y%m%d')
19
+ json.created_at @report.created_at
20
+ json.updated_at @report.updated_at
21
21
  json.username @report.user_profile.name if @report.user_profile
22
22
  json.cityname @report.city.cityname if @report.city
23
23
  json.tagname @report.tag.name_seo if @report.tag
@@ -6,6 +6,7 @@ json.email @profile.email
6
6
  json.n_reports @profile.reports.count
7
7
  json.n_galleries @profile.galleries.count
8
8
  json.n_videos @profile.videos.count
9
+ json.n_stars @profile.n_stars
9
10
 
10
11
  if @profile.current_city
11
12
  json.current_city @profile.current_city
@@ -5,6 +5,7 @@ json.username @profile.username
5
5
  json.n_reports @profile.reports.count
6
6
  json.n_galleries @profile.galleries.count
7
7
  json.n_videos @profile.videos.count
8
+ json.n_stars @profile.n_stars
8
9
 
9
10
  if @profile.current_city
10
11
  json.current_city @profile.current_city
data/config/routes.rb CHANGED
@@ -15,6 +15,8 @@ Ishapi::Engine.routes.draw do
15
15
  namespace :co_tailors do
16
16
  end
17
17
 
18
+ post 'do_purchase', to: 'gameui#do_purchase'
19
+
18
20
  get 'events/view/:eventname', :to => 'events#show'
19
21
 
20
22
  get 'galleries', :to => 'galleries#index'
@@ -24,15 +26,15 @@ Ishapi::Engine.routes.draw do
24
26
 
25
27
  post 'invoices/search', :to => 'invoices#search'
26
28
 
29
+ get 'maps', to: 'maps#index'
30
+ get 'maps/view/:slug', to: 'maps#show'
31
+ get 'markers/view/:slug', to: 'maps#show_marker'
32
+
27
33
  get 'my/newsitems', to: 'newsitems#index'
28
34
  get 'my/account', to: 'user_profiles#my'
29
35
  namespace :my do
30
- post 'reports', :to => 'reports#index'
36
+ # post 'reports', :to => 'reports#index'
31
37
  get 'reports', :to => 'reports#index'
32
-
33
- # resources :reports
34
- # resources :galleries
35
- # resources :videos
36
38
  end
37
39
 
38
40
  post 'payments', :to => 'payments#create'
@@ -49,11 +51,10 @@ Ishapi::Engine.routes.draw do
49
51
  get 'sites/view/:domain/reports/page/:reports_page', :to => 'reports#index', :constraints => { :domain => /[^\/]+/ }
50
52
  get 'sites/view/:domain/tags', :to => 'tags#index', :constraints => { :domain => /[^\/]+/ }
51
53
 
54
+ post 'stars/buy', to: 'gameui#buy_stars'
55
+
52
56
  get 'tags/view/:tagname', :to => 'tags#show'
53
57
  get 'test', to: 'application#test'
54
-
55
- namespace :tgm do
56
- end
57
58
 
58
59
  post 'users/fb_sign_in', :to => 'users#fb_sign_in'
59
60
  post 'users/profile', :to => 'users#show'
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.114
4
+ version: 0.1.8.116
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-31 00:00:00.000000000 Z
11
+ date: 2020-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -201,7 +201,9 @@ files:
201
201
  - app/controllers/ishapi/cities_controller.rb
202
202
  - app/controllers/ishapi/events_controller.rb
203
203
  - app/controllers/ishapi/galleries_controller.rb
204
+ - app/controllers/ishapi/gameui_controller.rb
204
205
  - app/controllers/ishapi/invoices_controller.rb
206
+ - app/controllers/ishapi/maps_controller.rb
205
207
  - app/controllers/ishapi/measurements_controller.rb
206
208
  - app/controllers/ishapi/my/my_controller.rb
207
209
  - app/controllers/ishapi/my/reports_controller.rb
@@ -223,8 +225,6 @@ files:
223
225
  - app/jobs/ishapi/application_job.rb
224
226
  - app/mailers/ishapi/application_mailer.rb
225
227
  - app/models/ishapi/ability.rb
226
- - app/models/ishapi/application_record.rb
227
- - app/models/ishapi/article.rb
228
228
  - app/views/ishapi/addresses/_show.jbuilder
229
229
  - app/views/ishapi/application/_meta.jbuilder
230
230
  - app/views/ishapi/articles/_form.html.erb
@@ -243,8 +243,11 @@ files:
243
243
  - app/views/ishapi/galleries/_show.jbuilder
244
244
  - app/views/ishapi/galleries/index.jbuilder
245
245
  - app/views/ishapi/galleries/show.jbuilder
246
+ - app/views/ishapi/galleries/show_premium_locked.jbuilder
247
+ - app/views/ishapi/galleries/show_premium_unlocked.jbuilder
248
+ - app/views/ishapi/maps/index.jbuilder
249
+ - app/views/ishapi/maps/show.jbuilder
246
250
  - app/views/ishapi/measurements/_show.jbuilder
247
- - app/views/ishapi/my/reports/index.jbuilder
248
251
  - app/views/ishapi/newsitems/_index.jbuilder
249
252
  - app/views/ishapi/newsitems/index.jbuilder
250
253
  - app/views/ishapi/orders/_item.jbuilder
@@ -270,7 +273,6 @@ files:
270
273
  - app/views/ishapi/videos/_index.jbuilder
271
274
  - app/views/ishapi/videos/_show.jbuilder
272
275
  - app/views/ishapi/videos/index.jbuilder
273
- - app/views/layouts/ishapi/application.html.erb
274
276
  - config/routes.rb
275
277
  - lib/ishapi.rb
276
278
  - lib/ishapi/engine.rb
@@ -1,5 +0,0 @@
1
-
2
- module Ishapi
3
- class ApplicationRecord
4
- end
5
- end
@@ -1,4 +0,0 @@
1
- module Ishapi
2
- class Article < ApplicationRecord
3
- end
4
- end
@@ -1,7 +0,0 @@
1
-
2
- json.reports do
3
- json.array! @reports do |report|
4
- json.id report.id.to_s
5
- json.name report.name
6
- end
7
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Ishapi</title>
5
- <%= stylesheet_link_tag "ishapi/application", media: "all" %>
6
- <%= javascript_include_tag "ishapi/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>