class Feedly2fastladder

Constants

VERSION

Public Class Methods

new(token: token) click to toggle source
# File lib/feedly2fastladder.rb, line 7
def initialize(token: token)
  @token = token
end

Public Instance Methods

subs(unread, from_id: 0, limit: 100) click to toggle source
# File lib/feedly2fastladder.rb, line 11
def subs(unread, from_id: 0, limit: 100)
  @is_unread_only = unread
  @unread_counts = unread_counts
  response = conn.get "/v3/subscriptions"
  convert_with_subs response.body
end
touch_all(subscribe_id, entry_id) click to toggle source
# File lib/feedly2fastladder.rb, line 26
def touch_all(subscribe_id, entry_id)
  response = conn.post "/v3/markers" do |req|
    req.headers['Content-Type'] = 'application/json'
    req.body = {
        action: "markAsRead",
        type: "feeds",
        lastReadEntryId: entry_id,
        feedIds: [subscribe_id],
    }.to_json
  end
  response.status == 200
end
unread(subscribe_id) click to toggle source
# File lib/feedly2fastladder.rb, line 18
def unread(subscribe_id)
  response = conn.get "/v3/streams/contents", {
      streamId: subscribe_id.to_s,
      unreadOnly: true
  }
  convert_with_contents response.body
end

Private Instance Methods

conn() click to toggle source
# File lib/feedly2fastladder.rb, line 40
def conn
  conn = Faraday.new url: "https://cloud.feedly.com"
  conn.headers["Authorization"] = "Bearer #{@token}"
  conn
end
convert_with_contents(text) click to toggle source
# File lib/feedly2fastladder.rb, line 62
def convert_with_contents(text)
  contents = JSON.parse(text)
  contents[:subscribe_id] = contents["id"]
  contents[:channel] = {
      title: contents["title"],
      modified_on: contents["updated"],
  }
  contents[:items] = contents["items"].map do |item|
    item[:created_on] = item["published"]
    item[:modified_on] = item["updated"]
    item[:body] = item["content"]["content"] if item["content"]
    item[:link] = item["alternate"][0]["href"] if item["alternate"]
    item
  end
  contents.to_json
end
convert_with_subs(text) click to toggle source
# File lib/feedly2fastladder.rb, line 46
def convert_with_subs(text)
  items = JSON.parse(text).map do |item|
    item[:public] = 1
    item[:rate] = item["sortid"]
    item[:unread_count] = unread_count_by_id item["id"]
    item[:subscribe_id] = item["id"]
    item[:subscribers_count] = item["subscribers"]
    item[:modified_on] = item["updated"]
    item[:folder] = item["categories"][0]["label"]
    item[:link] = item["website"]
    item[:feedlink] = item["id"].sub /\Afeed\//, ''
    item
  end
  items.select {|item| !@is_unread_only or item[:unread_count] > 0}.to_json
end
unread_count_by_id(id) click to toggle source
# File lib/feedly2fastladder.rb, line 84
def unread_count_by_id(id)
  item = @unread_counts.find {|data| data["id"] == id}
  item["count"].to_i || 0
end
unread_counts() click to toggle source
# File lib/feedly2fastladder.rb, line 79
def unread_counts
  response = conn.get "/v3/markers/counts"
  JSON.parse(response.body)["unreadcounts"]
end