Class: Api::EntriesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/api/entries_controller.rb

Overview

Controller to access the Feed model.

Instance Method Summary collapse

Instance Method Details

#indexObject

Return all entries for a given feed or folder.

If requesting entries for a feed, the current user must be subscribed. If requesting entries for a folder, it must be owned by the current user.

If the “include_read” parameter has the “true” value, return all entries; otherwise return only read ones. If the “folder_id” parameter has the special value “all”, all entries for all feeds subscribed by the current user will be returned.


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/api/entries_controller.rb', line 41

def index
  @include_read = param_str_to_boolean :include_read, params

  if params[:feed_id].present?
    index_feed
  elsif params[:folder_id].present?
    if params[:folder_id] == Folder::ALL_FOLDERS
      index_all
    else
      index_folder
    end
  else
    Rails.logger.info "User #{current_user.id} - #{current_user.email} requested entries without specifying a folder or feed id, returning a 404"
    head 404
  end
rescue => e
  handle_error e
end

#updateObject

Set an entry state for the current user as read or unread


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/api/entries_controller.rb', line 15

def update
  whole_feed = param_str_to_boolean :whole_feed, entry_params
  whole_folder = param_str_to_boolean :whole_folder, entry_params
  all_entries = param_str_to_boolean :all_entries, entry_params

  @entry = current_user.entries.find entry_params[:id]
  current_user.change_entries_state @entry,
                                    entry_params[:state],
                                    whole_feed: whole_feed,
                                    whole_folder: whole_folder,
                                    all_entries: all_entries
  head :ok
rescue => e
  handle_error e
end