Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve initialization #12

Open
kanet77 opened this issue Jan 14, 2016 · 0 comments
Open

Improve initialization #12

kanet77 opened this issue Jan 14, 2016 · 0 comments
Assignees

Comments

@kanet77
Copy link
Owner

kanet77 commented Jan 14, 2016

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 kanet77 self-assigned this Jan 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant