togglv8 icon indicating copy to clipboard operation
togglv8 copied to clipboard

Improve initialization

Open kanet77 opened this issue 8 years ago • 0 comments

Background

Use of TogglV8::API#initialize() is convoluted. It supports three authentication alternatives:

toggl = TogglV8::API.new() # with API token in ~/.toggl
toggl = TogglV8::API.new(api_token)
toggl = TogglV8::API.new(username, password)

Problems

The source code is not clear on how it can be used.

def initialize(username=nil, password=API_TOKEN, opts={})
  1. Passing an API token as username with no corresponding password is unexpected.
  2. The no-argument option is perhaps too magical.
  3. It is only possible to pass a value for opts with the username/password authentication (or by explicitly passing "api_token" as the second parameter.

Solution

  • Separate the three types of authentication and require one to be called explicitly.
  • Provide the credentials and create the connection after new(), not during.
  • Consider allowing other options in opts (e.g. enable debugging) or remove it entirely and replace with explicit method calls

kanet77 avatar Jan 14 '16 08:01 kanet77