Module: GdataHelper
- Included in:
- DocumentController, EvidenceController
- Defined in:
- app/helpers/gdata_helper.rb
Overview
Helper methods defined here can be accessed in any controller or view in the application
Instance Method Summary (collapse)
- - (Object) accepted_gfolder(cycle)
-
- (Object) auth_gdocs
Check if this is a redirect from Google Docs with an auth token.
-
- (Object) cycle_gfolder(cycle)
Full path of the folder that contains.
-
- (Object) gdocs_by_title(docs)
Transform a list of docs to a map by title.
-
- (Object) get_gdata(key, opts = {})
Generic method to get gdocs or gfolders.
-
- (Object) get_gdata_client(opts = {})
Obtain an API client object.
-
- (Object) get_gdocs(opts = {})
Get a list of gdocs from the api.
-
- (Object) get_gfolders(opts = {})
Get a list of gdocs folders from the api.
- - (Object) new_client
- - (Object) new_evidence_gfolder(cycle)
- - (Object) system_gfolder(cycle, system = nil)
Instance Method Details
- (Object) accepted_gfolder(cycle)
111 112 113 |
# File 'app/helpers/gdata_helper.rb', line 111 def accepted_gfolder(cycle) "CMS/#{cycle.slug}/Accepted" end |
- (Object) auth_gdocs
Check if this is a redirect from Google Docs with an auth token.
If so, memoize the token and redirect to real destination.
Returns true if the current request is not from gdocs and the request can continue normally.
19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/gdata_helper.rb', line 19 def auth_gdocs() if params[:token] client = Gdoc::Client.new session[:gtoken] = client.set_token(params[:token], true) redirect_to "#{request.scheme}://#{request.host_with_port}#{request.path}" return false end return true end |
- (Object) cycle_gfolder(cycle)
Full path of the folder that contains
103 104 105 |
# File 'app/helpers/gdata_helper.rb', line 103 def cycle_gfolder(cycle) "CMS/#{cycle.slug}" end |
- (Object) gdocs_by_title(docs)
Transform a list of docs to a map by title
5 6 7 8 9 10 11 |
# File 'app/helpers/gdata_helper.rb', line 5 def gdocs_by_title(docs) by_title = {} docs.values.each do |doc| by_title[doc.full_title] = doc end by_title end |
- (Object) get_gdata(key, opts = {})
Generic method to get gdocs or gfolders.
There is a cache, which can be bypassed with opts[:refresh] or params[:r]
Returns nil if we had to issue a redirect to authenticate the user to gdocs.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/gdata_helper.rb', line 48 def get_gdata(key, opts = {}) if params[:r] || opts[:refresh] session[key] = {} else session[key] ||= {} end if session[key][opts[:folder]] return session[key][opts[:folder]] end client = get_gdata_client(opts) return nil if client.nil? docs = yield(client) session[key][opts[:folder]] = docs end |
- (Object) get_gdata_client(opts = {})
Obtain an API client object.
Returns nil if we had to issue a redirect to authenticate the user to gdocs.
This works inside an AJAX request.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/helpers/gdata_helper.rb', line 73 def get_gdata_client(opts = {}) client = new_client if params[:token] session[:gtoken] = client.set_token(params[:token], true) redirect_to "#{request.scheme}://#{request.host_with_port}#{request.path}" return nil elsif session[:gtoken].nil? if opts[:ajax] next_url = opts[:retry_url] auth_url = client.authsub(next_url) @redirect_url = auth_url render :partial => 'base/ajax_redirect' else next_url = "#{request.scheme}://#{request.host_with_port}#{request.path}" redirect_to client.authsub(next_url) end return nil end client.set_token session[:gtoken] client end |
- (Object) get_gdocs(opts = {})
Get a list of gdocs from the api
30 31 32 33 34 |
# File 'app/helpers/gdata_helper.rb', line 30 def get_gdocs(opts = {}) get_gdata('gdocs', opts) do |client| client.get_docs(opts) end end |
- (Object) get_gfolders(opts = {})
Get a list of gdocs folders from the api
37 38 39 40 41 |
# File 'app/helpers/gdata_helper.rb', line 37 def get_gfolders(opts = {}) get_gdata('gfolders', opts) do |client| client.get_folders(opts) end end |
- (Object) new_client
98 99 100 |
# File 'app/helpers/gdata_helper.rb', line 98 def new_client Gdoc::Client.new end |
- (Object) new_evidence_gfolder(cycle)
115 116 117 |
# File 'app/helpers/gdata_helper.rb', line 115 def new_evidence_gfolder(cycle) "CMS/#{cycle.slug}/New Evidence" end |
- (Object) system_gfolder(cycle, system = nil)
107 108 109 |
# File 'app/helpers/gdata_helper.rb', line 107 def system_gfolder(cycle, system = nil) system ? "CMS/#{cycle.slug}/Systems/#{system.slug}" : "CMS/#{cycle.slug}/Systems" end |