class Fluent::Plugin::GithubActivities::UsersManager

Constants

DEFAULT_LAST_EVENT_TIMESTAMP

Public Class Methods

new(params={}) click to toggle source
# File lib/fluent/plugin/github-activities/users_manager.rb, line 27
def initialize(params={})
  @users = params[:users]
  @pos_storage = params[:pos_storage]
end

Public Instance Methods

generate_initial_requests() click to toggle source
# File lib/fluent/plugin/github-activities/users_manager.rb, line 32
def generate_initial_requests
  @users.collect do |user|
    new_events_request(user)
  end
end
new_events_request(user, options={}) click to toggle source
# File lib/fluent/plugin/github-activities/users_manager.rb, line 38
def new_events_request(user, options={})
  request = {
    type: TYPE_EVENTS,
    user: user,
  }
  response = options[:previous_response]
  if response
    now = options[:now] || Time.now
    interval = response["X-Poll-Interval"].to_i
    time_to_process = now.to_i + interval
    request[:previous_entity_tag] = response["ETag"] ||
                                    options[:previous_entity_tag]
    request[:process_after] = time_to_process
  else
    request[:previous_entity_tag] = options[:previous_entity_tag] if options.key?(:previous_entity_tag)
  end
  request
end
position_for(user) click to toggle source
# File lib/fluent/plugin/github-activities/users_manager.rb, line 57
def position_for(user)
  @pos_storage.get(user)
end
save_position_for(user, params) click to toggle source
# File lib/fluent/plugin/github-activities/users_manager.rb, line 61
def save_position_for(user, params)
  position = @pos_storage.get(user) || {}

  if params[:entity_tag]
    position["entity_tag"] = params[:entity_tag]
  end

  if params[:last_event_timestamp] and
    params[:last_event_timestamp] != DEFAULT_LAST_EVENT_TIMESTAMP
    old_timestamp = position["last_event_timestamp"]
    if old_timestamp.nil? or old_timestamp < params[:last_event_timestamp]
      position["last_event_timestamp"] = params[:last_event_timestamp]
    end
  end

  @pos_storage.put(user, position)
  @pos_storage.save
end