Class: Caboose::SocialController
Instance Method Summary
collapse
#add_ga_event, #admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_delete, #admin_index, #admin_json, #admin_json_single, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#admin_edit ⇒ Object
12
13
14
15
16
|
# File 'app/controllers/caboose/social_controller.rb', line 12
def admin_edit
return if !user_is_allowed('social', 'edit')
@social_config = @site.social_config
@social_config = SocialConfig.create(:site_id => @site.id) if @social_config.nil?
end
|
#admin_update ⇒ Object
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
44
45
46
47
|
# File 'app/controllers/caboose/social_controller.rb', line 19
def admin_update
return if !user_is_allowed('social', 'edit')
resp = StdClass.new
sc = @site.social_config
sc = SocialConfig.create(:site_id => @site.id) if sc.nil?
save = true
params.each do |name,value|
case name
when 'site_id' then sc.site_id = value
when 'facebook_page_id' then sc.facebook_page_id = value
when 'twitter_username' then sc. = value
when 'instagram_username' then sc.instagram_username = value
when 'youtube_url' then sc.youtube_url = value
when 'pinterest_url' then sc.pinterest_url = value
when 'vimeo_url' then sc.vimeo_url = value
when 'rss_url' then sc. = value
when 'google_plus_url' then sc.google_plus_url = value
when 'linkedin_url' then sc.linkedin_url = value
when 'google_analytics_id' then sc.google_analytics_id = value
when 'google_analytics_id2' then sc.google_analytics_id2 = value
when 'auto_ga_js' then sc.auto_ga_js = value
end
end
resp.success = save && sc.save
render :json => resp
end
|
#admin_update_image ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'app/controllers/caboose/social_controller.rb', line 98
def admin_update_image
return if !user_is_allowed('social', 'edit')
resp = Caboose::StdClass.new
sc = @site.social_config
sc.share_image = params[:share_image]
resp.success = sc.save
resp.attributes = { 'share_image' => { 'value' => sc.share_image.url(:large) }}
render :text => resp.to_json
end
|
#analytics ⇒ Object
8
9
|
# File 'app/controllers/caboose/social_controller.rb', line 8
def analytics
end
|
#authorize_instagram ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/controllers/caboose/social_controller.rb', line 50
def authorize_instagram
code = params[:code]
site_id = params[:state]
site = Site.where(:id => site_id).first
master_site = Site.where(:is_master => true).first
master_domain = master_site ? (master_site.primary_domain ? master_site.primary_domain.domain : 'caboosecms.com') : 'caboosecms.com'
domain = site ? (site.primary_domain ? site.primary_domain.domain : 'www.caboosecms.com') : 'www.caboosecms.com'
resp = HTTParty.post(
'https://api.instagram.com/oauth/access_token',
:body => {
:client_id => 'bac12987b6cb4262a004f3ffc388accc',
:client_secret => 'ede277a5b2df47fe8efcb69a9fac8e07',
:grant_type => 'authorization_code',
:redirect_uri => 'http://' + master_domain + '/api/instagram',
:code => code
}
)
if resp
if resp['code'] && (resp['code'] == 400 || resp['code'] = '400')
redirect_to 'http://' + domain + '/admin/social?instagram=fail'
elsif !resp['access_token'].blank?
sc = SocialConfig.where(:site_id => site_id).first
sc.instagram_access_token = resp['access_token']
sc.instagram_user_id = resp['user']['id']
sc.instagram_username = resp['user']['username']
sc.save
redirect_to 'http://' + domain + '/admin/social?instagram=success'
end
else
redirect_to 'http://' + domain + '/admin/social?instagram=fail'
end
end
|
#deauthorize_instagram ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'app/controllers/caboose/social_controller.rb', line 84
def deauthorize_instagram
resp = StdClass.new
site_id = params[:site_id]
site = Site.where(:id => site_id).first
sc = SocialConfig.where(:site_id => site.id).first
sc.instagram_username = nil
sc.instagram_user_id = nil
sc.instagram_access_token = nil
sc.save
resp.success = true
render :json => resp
end
|