Class: Api::DataController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Api::DataController
- Defined in:
- app/controllers/api/data_controller.rb
Overview
COPYRIGHT:
Copyright (c) 2005-2010 North Carolina State University
Developed with funding for the National eXtension Initiative.
LICENSE:
BSD(-compatible)
see LICENSE file or view at http://about.extension.org/wiki/LICENSE
Instance Method Summary (collapse)
- - (Object) articlelink
- - (Object) communitymembers
- - (Object) content_titles
- - (Object) publicprofile
Instance Method Details
- (Object) articlelink
10 11 12 13 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/api/data_controller.rb', line 10 def articlelink filteredparams = ParamsFilter.new([{:source_url => :string},{:original_url => :string},:apikey],params) apikey = (filteredparams.apikey.nil? ? ApiKey.systemkey : filteredparams.apikey) ApiKeyEvent.log_event("#{controller_path}/#{action_name}",apikey) if(filteredparams.original_url.nil? and filteredparams.source_url.nil? ) returnhash = {:success => false, :errormessage => 'Not a valid source url'} return render :text => returnhash.to_json end if(filteredparams.original_url) source_url = filteredparams.original_url elsif(filteredparams.source_url) source_url = filteredparams.source_url end begin parsed_uri = URI.parse(URI.unescape(source_url)) rescue returnhash = {:success => false, :errormessage => 'Not a valid source url'} return render :text => returnhash.to_json end if(parsed_uri.class == URI::Generic) find_url = "http://" + parsed_uri.to_s elsif(parsed_uri.class == URI::HTTP or parsed_uri.class == URI::HTTPS) find_url = parsed_uri.to_s else returnhash = {:success => false, :errormessage => 'Not a valid original url'} return render :text => returnhash.to_json end page = Page.find_by_source_url(find_url) if(!page) returnhash = {:success => false, :errormessage => 'Unable to find an page corresponding to the given URL'} return render :text => returnhash.to_json end returnhash = {} returnhash[:title] = page.title returnhash[:link] = page.id_and_link returnhash[:created] = page.source_created_at returnhash[:updated] = page.source_updated_at return render :text => returnhash.to_json end |
- (Object) communitymembers
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/controllers/api/data_controller.rb', line 79 def communitymembers filteredparams = ParamsFilter.new([:community,:apikey],params) apikey = (filteredparams.apikey.nil? ? ApiKey.systemkey : filteredparams.apikey) # TODO: consider doing this automatically in application_controller as a before_filter ApiKeyEvent.log_event("#{controller_path}/#{action_name}",apikey) if(filteredparams.community.nil?) returnhash = {:success => false, :errormessage => 'No such community.'} return render :text => returnhash.to_json end community = filteredparams.community joined = community.joined returnhash = {:success => true, :total_joined => joined.size, :has_public_data => 0, :person_list => {}} joined.each do |u| public_attributes_for_user = u.public_attributes if(public_attributes_for_user) returnhash[:has_public_data] += 1 returnhash[:person_list][u.login] = public_attributes_for_user end end # add in the community information community_info = {} community_info[:name] = community.name community_info[:entrytype] = community.entrytype_to_s if(!community.shortname.blank?) community_info[:shortname] = community.shortname end if(!community.description.blank?) community_info[:description] = community.description end if(community.is_launched?) community_info[:launched] = true community_info[:public_name] = community.public_name community_info[:primary_content_tag_name] = community.primary_content_tag_name community_info[:content_tag_names] = community.content_tag_names end returnhash[:community_info] = community_info return render :text => returnhash.to_json end |
- (Object) content_titles
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'app/controllers/api/data_controller.rb', line 125 def content_titles filteredparams = ParamsFilter.new([:apikey,:content_types,:limit,:tags],params) apikey = (filteredparams.apikey.nil? ? ApiKey.systemkey : filteredparams.apikey) # TODO: consider doing this automatically in application_controller as a before_filter ApiKeyEvent.log_event("#{controller_path}/#{action_name}",apikey) returnhash = {:success => true, :content_titles => [], :version => 1} # empty content types? return error if(filteredparams.content_types.nil?) returnhash = {:success => false, :errormessage => 'Unrecognized content types.'} return render :text => returnhash.to_json end if(filteredparams.limit.nil?) # empty limit? set to default limit = AppConfig.configtable['default_content_limit'] elsif(filteredparams.limit > AppConfig.configtable['max_content_limit']) # limit over? return an error, let's be pedantic returnhash = {:success => false, :errormessage => "Requested limit of #{filteredparams.limit} is greater than the max allowed: #{AppConfig.configtable['max_content_limit']}"} return render :text => returnhash.to_json else limit = filteredparams.limit end # empty tags? - presume "all" if(filteredparams..nil?) = true = ['all'] else tag_operator = filteredparams..taglist_operator = filteredparams. = (.include?('all')) end datatypes = [] filteredparams.content_types.each do |content_type| case content_type when 'faqs' datatypes << 'Faq' when 'articles' datatypes << 'Article' when 'events' datatypes << 'Event' when 'news' datatypes << 'News' end end if() @returnitems = Page.recent_content(:datatypes => datatypes, :limit => limit) else @returnitems = Page.recent_content(:datatypes => datatypes, :content_tags => , :limit => limit, :tag_operator => tag_operator, :within_days => AppConfig.configtable['events_within_days']) end @returnitems.each do |item| entry = {} entry['id'] = item.id_and_link entry['published'] = item.source_created_at.xmlschema entry['updated'] = item.source_updated_at.xmlschema entry['content_type'] = item.datatype.downcase # TODO? categories entry['title'] = item.title entry['href'] = item.id_and_link returnhash[:content_titles] << entry end return render :text => returnhash.to_json end |
- (Object) publicprofile
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/api/data_controller.rb', line 56 def publicprofile filteredparams = ParamsFilter.new([:person,:apikey],params) apikey = (filteredparams.apikey.nil? ? ApiKey.systemkey : filteredparams.apikey) # TODO: consider doing this automatically in application_controller as a before_filter ApiKeyEvent.log_event("#{controller_path}/#{action_name}",apikey) if(filteredparams.person.nil?) returnhash = {:success => false, :errormessage => 'No such user.'} return render :text => returnhash.to_json else @showuser = filteredparams.person end publicattributes = @showuser.public_attributes if(publicattributes.nil?) returnhash = {:success => false, :errormessage => 'No public attributes'} return render :text => returnhash.to_json else returnhash = publicattributes.merge({:success => true}) return render :text => returnhash.to_json end end |