Class: Noko::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/noko/client/tags.rb,
lib/noko/client/teams.rb,
lib/noko/client/users.rb,
lib/noko/client/timers.rb,
lib/noko/client/account.rb,
lib/noko/client/entries.rb,
lib/noko/client/expenses.rb,
lib/noko/client/invoices.rb,
lib/noko/client/projects.rb,
lib/noko/client/webhooks.rb,
lib/noko/client/current_user.rb,
lib/noko/client/project_groups.rb,
lib/noko/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/noko/client.rb', line 12

def initialize(options = {})
  if options.key?(:access_token)
    @auth_header, @auth_value = 'Authorization', "token #{options[:access_token]}"
  elsif options.key?(:token)
    @auth_header, @auth_value = 'X-NokoToken', options.fetch(:token)
  elsif !(netrc = load_netrc_credentials).nil?
    @auth_header, @auth_value = 'X-NokoToken', netrc.password
  else
    raise ArgumentError, 'access_token or token required for authentication'
  end

  @user_agent = options.fetch(:user_agent) { "noko/#{Noko::VERSION} ruby/#{RUBY_VERSION}" }

  @host = 'api.nokotime.com'

  @http = Net::HTTP.new(@host, Net::HTTP.https_default_port)

  @http.use_ssl = true
end

Instance Method Details

#add_team_users(id, params) ⇒ Object



28
29
30
# File 'lib/noko/client/teams.rb', line 28

def add_team_users(id, params)
  post("/v2/teams/#{id}/add_users", params)
end

#add_webhook_events(id, attributes) ⇒ Object



18
19
20
# File 'lib/noko/client/webhooks.rb', line 18

def add_webhook_events(id, attributes)
  put("/v2/webhooks/#{id}/add_events", attributes)
end

#archive_project(id) ⇒ Object



36
37
38
# File 'lib/noko/client/projects.rb', line 36

def archive_project(id)
  put("/v2/projects/#{id}/archive")
end

#archive_projects(project_ids) ⇒ Object



44
45
46
# File 'lib/noko/client/projects.rb', line 44

def archive_projects(project_ids)
  put('/v2/projects/archive', project_ids: project_ids)
end

#create_entry(attributes) ⇒ Object



12
13
14
# File 'lib/noko/client/entries.rb', line 12

def create_entry(attributes)
  post('/v2/entries', attributes)
end

#create_expense(attributes) ⇒ Object



12
13
14
# File 'lib/noko/client/expenses.rb', line 12

def create_expense(attributes)
  post('/v2/expenses', attributes)
end

#create_invoice(attributes) ⇒ Object



12
13
14
# File 'lib/noko/client/invoices.rb', line 12

def create_invoice(attributes)
  post('/v2/invoices', attributes)
end

#create_project(attributes) ⇒ Object



12
13
14
# File 'lib/noko/client/projects.rb', line 12

def create_project(attributes)
  post('/v2/projects', attributes)
end

#create_project_group(attributes) ⇒ Object



12
13
14
# File 'lib/noko/client/project_groups.rb', line 12

def create_project_group(attributes)
  post('/v2/project_groups', attributes)
end

#create_tags(names) ⇒ Object



8
9
10
# File 'lib/noko/client/tags.rb', line 8

def create_tags(names)
  post('/v2/tags', names: names)
end

#create_team(attributes) ⇒ Object



12
13
14
# File 'lib/noko/client/teams.rb', line 12

def create_team(attributes)
  post('/v2/teams', attributes)
end

#create_user(attributes) ⇒ Object



20
21
22
# File 'lib/noko/client/users.rb', line 20

def create_user(attributes)
  post('/v2/users', attributes)
end

#create_webhook(attributes) ⇒ Object



10
11
12
# File 'lib/noko/client/webhooks.rb', line 10

def create_webhook(attributes)
  post('/v2/webhooks', attributes)
end

#deactivate_user(id) ⇒ Object



36
37
38
# File 'lib/noko/client/users.rb', line 36

def deactivate_user(id)
  put("/v2/users/#{id}/deactivate")
end

#delete_entry(id) ⇒ Object



20
21
22
# File 'lib/noko/client/entries.rb', line 20

def delete_entry(id)
  delete("/v2/entries/#{id}")
end

#delete_expense(id) ⇒ Object



20
21
22
# File 'lib/noko/client/expenses.rb', line 20

def delete_expense(id)
  delete("/v2/expenses/#{id}")
end

#delete_invoice(id) ⇒ Object



36
37
38
# File 'lib/noko/client/invoices.rb', line 36

def delete_invoice(id)
  delete("/v2/invoices/#{id}")
end

#delete_project(id) ⇒ Object



32
33
34
# File 'lib/noko/client/projects.rb', line 32

def delete_project(id)
  delete("/v2/projects/#{id}")
end

#delete_project_group(id) ⇒ Object



28
29
30
# File 'lib/noko/client/project_groups.rb', line 28

def delete_project_group(id)
  delete("/v2/project_groups/#{id}")
end

#delete_projects(project_ids) ⇒ Object



52
53
54
# File 'lib/noko/client/projects.rb', line 52

def delete_projects(project_ids)
  put('/v2/projects/delete', project_ids: project_ids)
end

#delete_tag(id) ⇒ Object



28
29
30
# File 'lib/noko/client/tags.rb', line 28

def delete_tag(id)
  delete("/v2/tags/#{id}")
end

#delete_tags(tag_ids) ⇒ Object



32
33
34
# File 'lib/noko/client/tags.rb', line 32

def delete_tags(tag_ids)
  put('/v2/tags/delete', tag_ids: tag_ids)
end

#delete_team(id) ⇒ Object



40
41
42
# File 'lib/noko/client/teams.rb', line 40

def delete_team(id)
  delete("/v2/teams/#{id}")
end

#delete_user(id) ⇒ Object



28
29
30
# File 'lib/noko/client/users.rb', line 28

def delete_user(id)
  delete("/v2/users/#{id}")
end

#delete_webhook(id) ⇒ Object



38
39
40
# File 'lib/noko/client/webhooks.rb', line 38

def delete_webhook(id)
  delete("/v2/webhooks/#{id}")
end

#disable_webhook(id) ⇒ Object



30
31
32
# File 'lib/noko/client/webhooks.rb', line 30

def disable_webhook(id)
  put("/v2/webhooks/#{id}/disable")
end

#discard_timer(project_id) ⇒ Object



28
29
30
# File 'lib/noko/client/timers.rb', line 28

def discard_timer(project_id)
  delete("/v2/projects/#{project_id}/timer")
end

#enable_webhook(id) ⇒ Object



34
35
36
# File 'lib/noko/client/webhooks.rb', line 34

def enable_webhook(id)
  put("/v2/webhooks/#{id}/enable")
end

#get(path, params = nil) ⇒ Object



32
33
34
# File 'lib/noko/client.rb', line 32

def get(path, params = nil)
  request(Net::HTTP::Get.new(Noko::Params.join(path, params)))
end

#get_accountObject



4
5
6
# File 'lib/noko/client/account.rb', line 4

def 
  get('/v2/account')
end

#get_current_userObject



4
5
6
# File 'lib/noko/client/current_user.rb', line 4

def get_current_user
  get('/v2/current_user')
end

#get_current_user_entries(params = nil) ⇒ Object



8
9
10
# File 'lib/noko/client/current_user.rb', line 8

def get_current_user_entries(params = nil)
  get('/v2/current_user/entries', params)
end

#get_current_user_expenses(params = nil) ⇒ Object



12
13
14
# File 'lib/noko/client/current_user.rb', line 12

def get_current_user_expenses(params = nil)
  get('/v2/current_user/expenses', params)
end

#get_entries(params = nil) ⇒ Object



4
5
6
# File 'lib/noko/client/entries.rb', line 4

def get_entries(params = nil)
  get('/v2/entries', params)
end

#get_entry(id) ⇒ Object



8
9
10
# File 'lib/noko/client/entries.rb', line 8

def get_entry(id)
  get("/v2/entries/#{id}")
end

#get_expense(id) ⇒ Object



8
9
10
# File 'lib/noko/client/expenses.rb', line 8

def get_expense(id)
  get("/v2/expenses/#{id}")
end

#get_expenses(params = nil) ⇒ Object



4
5
6
# File 'lib/noko/client/expenses.rb', line 4

def get_expenses(params = nil)
  get('/v2/expenses', params)
end

#get_invoice(id) ⇒ Object



8
9
10
# File 'lib/noko/client/invoices.rb', line 8

def get_invoice(id)
  get("/v2/invoices/#{id}")
end

#get_invoice_entries(id, params = nil) ⇒ Object



28
29
30
# File 'lib/noko/client/invoices.rb', line 28

def get_invoice_entries(id, params = nil)
  get("/v2/invoices/#{id}/entries", params)
end

#get_invoice_expenses(id, params = nil) ⇒ Object



32
33
34
# File 'lib/noko/client/invoices.rb', line 32

def get_invoice_expenses(id, params = nil)
  get("/v2/invoices/#{id}/expenses", params)
end

#get_invoices(params = nil) ⇒ Object



4
5
6
# File 'lib/noko/client/invoices.rb', line 4

def get_invoices(params = nil)
  get('/v2/invoices', params)
end

#get_project(id) ⇒ Object



8
9
10
# File 'lib/noko/client/projects.rb', line 8

def get_project(id)
  get("/v2/projects/#{id}")
end

#get_project_entries(id, params = nil) ⇒ Object



16
17
18
# File 'lib/noko/client/projects.rb', line 16

def get_project_entries(id, params = nil)
  get("/v2/projects/#{id}/entries", params)
end

#get_project_expenses(id, params = nil) ⇒ Object



20
21
22
# File 'lib/noko/client/projects.rb', line 20

def get_project_expenses(id, params = nil)
  get("/v2/projects/#{id}/expenses", params)
end

#get_project_group(id) ⇒ Object



8
9
10
# File 'lib/noko/client/project_groups.rb', line 8

def get_project_group(id)
  get("/v2/project_groups/#{id}")
end

#get_project_group_entries(id, params = nil) ⇒ Object



16
17
18
# File 'lib/noko/client/project_groups.rb', line 16

def get_project_group_entries(id, params = nil)
  get("/v2/project_groups/#{id}/entries", params)
end

#get_project_group_projects(id, params = nil) ⇒ Object



20
21
22
# File 'lib/noko/client/project_groups.rb', line 20

def get_project_group_projects(id, params = nil)
  get("/v2/project_groups/#{id}/projects", params)
end

#get_project_groups(params = nil) ⇒ Object



4
5
6
# File 'lib/noko/client/project_groups.rb', line 4

def get_project_groups(params = nil)
  get('/v2/project_groups', params)
end

#get_projects(params = nil) ⇒ Object



4
5
6
# File 'lib/noko/client/projects.rb', line 4

def get_projects(params = nil)
  get('/v2/projects', params)
end

#get_tag(id) ⇒ Object



12
13
14
# File 'lib/noko/client/tags.rb', line 12

def get_tag(id)
  get("/v2/tags/#{id}")
end

#get_tag_entries(id, params = nil) ⇒ Object



16
17
18
# File 'lib/noko/client/tags.rb', line 16

def get_tag_entries(id, params = nil)
  get("/v2/tags/#{id}/entries", params)
end

#get_tags(params = nil) ⇒ Object



4
5
6
# File 'lib/noko/client/tags.rb', line 4

def get_tags(params = nil)
  get('/v2/tags', params)
end

#get_team(id) ⇒ Object



8
9
10
# File 'lib/noko/client/teams.rb', line 8

def get_team(id)
  get("/v2/teams/#{id}")
end

#get_team_entries(id, params = nil) ⇒ Object



20
21
22
# File 'lib/noko/client/teams.rb', line 20

def get_team_entries(id, params = nil)
  get("/v2/teams/#{id}/entries", params)
end

#get_team_users(id, params = nil) ⇒ Object



24
25
26
# File 'lib/noko/client/teams.rb', line 24

def get_team_users(id, params = nil)
  get("/v2/teams/#{id}/users", params)
end

#get_teams(params = nil) ⇒ Object



4
5
6
# File 'lib/noko/client/teams.rb', line 4

def get_teams(params = nil)
  get('/v2/teams', params)
end

#get_timer(project_id) ⇒ Object



8
9
10
# File 'lib/noko/client/timers.rb', line 8

def get_timer(project_id)
  get("/v2/projects/#{project_id}/timer")
end

#get_timers(params = nil) ⇒ Object



4
5
6
# File 'lib/noko/client/timers.rb', line 4

def get_timers(params = nil)
  get('/v2/timers', params)
end

#get_user(id) ⇒ Object



8
9
10
# File 'lib/noko/client/users.rb', line 8

def get_user(id)
  get("/v2/users/#{id}")
end

#get_user_entries(id, params = nil) ⇒ Object



12
13
14
# File 'lib/noko/client/users.rb', line 12

def get_user_entries(id, params = nil)
  get("/v2/users/#{id}/entries", params)
end

#get_user_expenses(id, params = nil) ⇒ Object



16
17
18
# File 'lib/noko/client/users.rb', line 16

def get_user_expenses(id, params = nil)
  get("/v2/users/#{id}/expenses", params)
end

#get_users(params = nil) ⇒ Object



4
5
6
# File 'lib/noko/client/users.rb', line 4

def get_users(params = nil)
  get('/v2/users', params)
end

#get_webhook(id) ⇒ Object



6
7
8
# File 'lib/noko/client/webhooks.rb', line 6

def get_webhook(id)
  get("/v2/webhooks/#{id}")
end

#get_webhooks(params = nil) ⇒ Object



2
3
4
# File 'lib/noko/client/webhooks.rb', line 2

def get_webhooks(params = nil)
  get('/v2/webhooks', params)
end

#log_timer(project_id, attributes = {}) ⇒ Object



24
25
26
# File 'lib/noko/client/timers.rb', line 24

def log_timer(project_id, attributes = {})
  put("/v2/projects/#{project_id}/timer/log", attributes)
end

#mark_entries_approved(params) ⇒ Object



36
37
38
# File 'lib/noko/client/entries.rb', line 36

def mark_entries_approved(params)
  put('/v2/entries/approved', params)
end

#mark_entries_invoiced(params) ⇒ Object



28
29
30
# File 'lib/noko/client/entries.rb', line 28

def mark_entries_invoiced(params)
  put('/v2/entries/marked_as_invoiced', params)
end

#mark_entries_unapproved(params) ⇒ Object



44
45
46
# File 'lib/noko/client/entries.rb', line 44

def mark_entries_unapproved(params)
  put('/v2/entries/unapproved', params)
end

#mark_entry_approved(id, params = nil) ⇒ Object



32
33
34
# File 'lib/noko/client/entries.rb', line 32

def mark_entry_approved(id, params = nil)
  put("/v2/entries/#{id}/approved", params)
end

#mark_entry_invoiced(id, params) ⇒ Object



24
25
26
# File 'lib/noko/client/entries.rb', line 24

def mark_entry_invoiced(id, params)
  put("/v2/entries/#{id}/marked_as_invoiced", params)
end

#mark_entry_unapproved(id) ⇒ Object



40
41
42
# File 'lib/noko/client/entries.rb', line 40

def mark_entry_unapproved(id)
  put("/v2/entries/#{id}/unapproved")
end

#mark_invoice_paid(id) ⇒ Object



20
21
22
# File 'lib/noko/client/invoices.rb', line 20

def mark_invoice_paid(id)
  put("/v2/invoices/#{id}/paid")
end

#mark_invoice_unpaid(id) ⇒ Object



24
25
26
# File 'lib/noko/client/invoices.rb', line 24

def mark_invoice_unpaid(id)
  put("/v2/invoices/#{id}/unpaid")
end

#merge_projects(id, project_id) ⇒ Object



28
29
30
# File 'lib/noko/client/projects.rb', line 28

def merge_projects(id, project_id)
  put("/v2/projects/#{id}/merge", project_id: project_id)
end

#merge_tags(id, tag_id) ⇒ Object



24
25
26
# File 'lib/noko/client/tags.rb', line 24

def merge_tags(id, tag_id)
  put("/v2/tags/#{id}/merge", tag_id: tag_id)
end

#pause_timer(project_id) ⇒ Object



20
21
22
# File 'lib/noko/client/timers.rb', line 20

def pause_timer(project_id)
  put("/v2/projects/#{project_id}/timer/pause")
end

#reactivate_user(id) ⇒ Object



32
33
34
# File 'lib/noko/client/users.rb', line 32

def reactivate_user(id)
  put("/v2/users/#{id}/activate")
end

#remove_all_team_users(id) ⇒ Object



36
37
38
# File 'lib/noko/client/teams.rb', line 36

def remove_all_team_users(id)
  put("/v2/teams/#{id}/remove_all_users")
end

#remove_team_users(id, params) ⇒ Object



32
33
34
# File 'lib/noko/client/teams.rb', line 32

def remove_team_users(id, params)
  put("/v2/teams/#{id}/remove_users", params)
end

#remove_webhook_events(id, attributes) ⇒ Object



22
23
24
# File 'lib/noko/client/webhooks.rb', line 22

def remove_webhook_events(id, attributes)
  put("/v2/webhooks/#{id}/remove_events", attributes)
end

#reroll_webhook_secret(id) ⇒ Object



26
27
28
# File 'lib/noko/client/webhooks.rb', line 26

def reroll_webhook_secret(id)
  put("/v2/webhooks/#{id}/reroll_secret")
end

#start_timer(project_id) ⇒ Object



16
17
18
# File 'lib/noko/client/timers.rb', line 16

def start_timer(project_id)
  put("/v2/projects/#{project_id}/timer/start")
end

#unarchive_project(id) ⇒ Object



40
41
42
# File 'lib/noko/client/projects.rb', line 40

def unarchive_project(id)
  put("/v2/projects/#{id}/unarchive")
end

#unarchive_projects(project_ids) ⇒ Object



48
49
50
# File 'lib/noko/client/projects.rb', line 48

def unarchive_projects(project_ids)
  put('/v2/projects/unarchive', project_ids: project_ids)
end

#update_current_user(attributes) ⇒ Object



16
17
18
# File 'lib/noko/client/current_user.rb', line 16

def update_current_user(attributes)
  put('/v2/current_user', attributes)
end

#update_entry(id, attributes) ⇒ Object



16
17
18
# File 'lib/noko/client/entries.rb', line 16

def update_entry(id, attributes)
  put("/v2/entries/#{id}", attributes)
end

#update_expense(id, attributes) ⇒ Object



16
17
18
# File 'lib/noko/client/expenses.rb', line 16

def update_expense(id, attributes)
  put("/v2/expenses/#{id}", attributes)
end

#update_invoice(id, attributes) ⇒ Object



16
17
18
# File 'lib/noko/client/invoices.rb', line 16

def update_invoice(id, attributes)
  put("/v2/invoices/#{id}", attributes)
end

#update_project(id, attributes) ⇒ Object



24
25
26
# File 'lib/noko/client/projects.rb', line 24

def update_project(id, attributes)
  put("/v2/projects/#{id}", attributes)
end

#update_project_group(id, attributes) ⇒ Object



24
25
26
# File 'lib/noko/client/project_groups.rb', line 24

def update_project_group(id, attributes)
  put("/v2/project_groups/#{id}", attributes)
end

#update_tag(id, attributes) ⇒ Object



20
21
22
# File 'lib/noko/client/tags.rb', line 20

def update_tag(id, attributes)
  put("/v2/tags/#{id}", attributes)
end

#update_team(id, attributes) ⇒ Object



16
17
18
# File 'lib/noko/client/teams.rb', line 16

def update_team(id, attributes)
  put("/v2/teams/#{id}", attributes)
end

#update_timer(project_id, attributes) ⇒ Object



12
13
14
# File 'lib/noko/client/timers.rb', line 12

def update_timer(project_id, attributes)
  put("/v2/projects/#{project_id}/timer", attributes)
end

#update_user(id, attributes) ⇒ Object



24
25
26
# File 'lib/noko/client/users.rb', line 24

def update_user(id, attributes)
  put("/v2/users/#{id}", attributes)
end

#update_webhook(id, attributes) ⇒ Object



14
15
16
# File 'lib/noko/client/webhooks.rb', line 14

def update_webhook(id, attributes)
  put("/v2/webhooks/#{id}", attributes)
end