class Everhour2toggl::Everhour

Public Class Methods

new(from:, to:, fields:, apikey:) click to toggle source
# File lib/everhour2toggl/everhour.rb, line 8
def initialize(from:, to:, fields:, apikey:)
  @from = from
  @to =  to
  @fields = fields
  @apikey = apikey
end

Public Instance Methods

export() click to toggle source
# File lib/everhour2toggl/everhour.rb, line 15
def export
  output_path = "everhour_entries"
  file_generator = Everhour2toggl::FileGenerator.new(output: output_path, filename: "#{@from}-#{@to}-#{@fields}.json")
  file_generator.generate(exported_time_str)
end

Private Instance Methods

exported_time_str() click to toggle source
# File lib/everhour2toggl/everhour.rb, line 23
def exported_time_str
  uri = URI.parse("https://api.everhour.com/team/time/export")
  params = {from: @from, to: @to, "fields": @fields}
  uri.query = URI.encode_www_form(params)

  request = Net::HTTP::Get.new(uri)
  request.content_type = "application/json"
  request["X-Api-Key"] = @apikey

  req_options = {
      use_ssl: uri.scheme == "https",
  }

  response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
    http.request(request)
  end
  # response.code
  JSON.pretty_generate(JSON.parse(response.body))
end