class GitWakaTime::RequestBuilder

Build an array of hash’s (params) that can be iterated over for the wakatime API.

Constants

API_LIMIT
WAKATIME_EPOCH

Public Class Methods

new(start_at, end_at) click to toggle source
# File lib/gitwakatime/request_builder.rb, line 8
def initialize(start_at, end_at)
  @start_at = [start_at.to_date, WAKATIME_EPOCH].max
  @end_at = end_at.to_date
end

Public Instance Methods

call() click to toggle source
# File lib/gitwakatime/request_builder.rb, line 13
def call
  # Always have a date range great than 1 as the num request
  # will be 0/1 otherwise
  num_requests = ((@end_at + 1) - @start_at) / API_LIMIT
  i = 0

  request_params = num_requests.to_f.ceil.times.map do
    params = construct_params(i)
    i += 1
    params
  end
  request_params
end

Private Instance Methods

construct_params(i) click to toggle source
# File lib/gitwakatime/request_builder.rb, line 29
def construct_params(i)
  {
    date: (@start_at.to_date + i).to_date,
    show: 'file,branch,project,time,id'
  }
end