Class: TimelyApp::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/timely-app/client.rb,
lib/timely-app/client/auth.rb,
lib/timely-app/client/roles.rb,
lib/timely-app/client/teams.rb,
lib/timely-app/client/users.rb,
lib/timely-app/client/events.rb,
lib/timely-app/client/labels.rb,
lib/timely-app/client/clients.rb,
lib/timely-app/client/reports.rb,
lib/timely-app/client/accounts.rb,
lib/timely-app/client/projects.rb,
lib/timely-app/client/webhooks.rb,
lib/timely-app/client/forecasts.rb,
lib/timely-app/client/permissions.rb,
lib/timely-app/client/user_capacities.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/timely-app/client.rb', line 15

def initialize(options = {})
  @auth_header = 'Authorization'
  @auth_value = "Bearer #{options[:access_token]}"
  @user_agent = options.fetch(:user_agent) { "timely-app/#{VERSION} ruby/#{RUBY_VERSION}" }

  @host = 'api.timelyapp.com'

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

  @account_id = options[:account_id]
  @verbose = options[:verbose] || !ENV['VERBOSE'].nil? || false
end

Instance Attribute Details

#account_idObject

Returns the value of attribute account_id.



13
14
15
# File 'lib/timely-app/client.rb', line 13

def 
  @account_id
end

Instance Method Details

#create_bulk_events(create) ⇒ Object



18
19
20
# File 'lib/timely-app/client/events.rb', line 18

def create_bulk_events(create)
  post("/1.1/#{}/bulk/events", create: create)
end

#create_client(name:, **params) ⇒ Object



6
7
8
# File 'lib/timely-app/client/clients.rb', line 6

def create_client(name:, **params)
  post("/1.1/#{}/clients", client: params.merge(name: name))
end

#create_event(day:, hours:, minutes:, **params) ⇒ Object



6
7
8
# File 'lib/timely-app/client/events.rb', line 6

def create_event(day:, hours:, minutes:, **params)
  post("/1.1/#{}/events", event: params.merge(day: day, hours: hours, minutes: minutes))
end

#create_forecast(project_id:, **params) ⇒ Object



6
7
8
# File 'lib/timely-app/client/forecasts.rb', line 6

def create_forecast(project_id:, **params)
  post("/1.1/#{}/forecasts", forecast: params.merge(project_id: project_id))
end

#create_label(name:, **params) ⇒ Object



6
7
8
# File 'lib/timely-app/client/labels.rb', line 6

def create_label(name:, **params)
  post("/1.1/#{}/labels", label: params.merge(name: name))
end

#create_project(name:, color:, client_id:, users:, **params) ⇒ Object



6
7
8
# File 'lib/timely-app/client/projects.rb', line 6

def create_project(name:, color:, client_id:, users:, **params)
  post("/1.1/#{}/projects", project: params.merge(name: name, color: color, client_id: client_id, users: users))
end

#create_project_event(project_id:, day:, hours:, minutes:, **params) ⇒ Object



10
11
12
# File 'lib/timely-app/client/events.rb', line 10

def create_project_event(project_id:, day:, hours:, minutes:, **params)
  post("/1.1/#{}/projects/#{project_id}/events", event: params.merge(day: day, hours: hours, minutes: minutes))
end

#create_team(name:, users:, **params) ⇒ Object



6
7
8
# File 'lib/timely-app/client/teams.rb', line 6

def create_team(name:, users:, **params)
  post("/1.1/#{}/teams", team: params.merge(name: name, users: users))
end

#create_user(name:, email:, role_id:, **params) ⇒ Object



6
7
8
# File 'lib/timely-app/client/users.rb', line 6

def create_user(name:, email:, role_id:, **params)
  post("/1.1/#{}/users", user: params.merge(name: name, email: email, role_id: role_id))
end

#create_user_event(user_id:, day:, hours:, minutes:, **params) ⇒ Object



14
15
16
# File 'lib/timely-app/client/events.rb', line 14

def create_user_event(user_id:, day:, hours:, minutes:, **params)
  post("/1.1/#{}/users/#{user_id}/events", event: params.merge(day: day, hours: hours, minutes: minutes))
end

#create_webhook(url:, **params) ⇒ Object



6
7
8
# File 'lib/timely-app/client/webhooks.rb', line 6

def create_webhook(url:, **params)
  post("/1.1/#{}/webhooks", webhook: params.merge(url: url))
end

#delete_bulk_events(delete) ⇒ Object



26
27
28
# File 'lib/timely-app/client/events.rb', line 26

def delete_bulk_events(delete)
  post("/1.1/#{}/bulk/events", delete: delete)
end

#delete_event(id) ⇒ Object



22
23
24
# File 'lib/timely-app/client/events.rb', line 22

def delete_event(id)
  delete("/1.1/#{}/events/#{id}")
end

#delete_forecast(id) ⇒ Object



10
11
12
# File 'lib/timely-app/client/forecasts.rb', line 10

def delete_forecast(id)
  delete("/1.1/#{}/forecasts/#{id}")
end

#delete_label(id) ⇒ Object



10
11
12
# File 'lib/timely-app/client/labels.rb', line 10

def delete_label(id)
  delete("/1.1/#{}/labels/#{id}")
end

#delete_project(id) ⇒ Object



10
11
12
# File 'lib/timely-app/client/projects.rb', line 10

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

#delete_team(id) ⇒ Object



10
11
12
# File 'lib/timely-app/client/teams.rb', line 10

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

#delete_user(id) ⇒ Object



10
11
12
# File 'lib/timely-app/client/users.rb', line 10

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

#delete_webhook(id) ⇒ Object



10
11
12
# File 'lib/timely-app/client/webhooks.rb', line 10

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

#get(path, params = nil) ⇒ Object



29
30
31
# File 'lib/timely-app/client.rb', line 29

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

#get_account(id) ⇒ Object



14
15
16
# File 'lib/timely-app/client/accounts.rb', line 14

def (id)
  get("/1.1/accounts/#{id}")
end

#get_account_activities(account_id, **params) ⇒ Object



10
11
12
# File 'lib/timely-app/client/accounts.rb', line 10

def (, **params)
  get("/1.1/#{}/activities", params)
end

#get_accountsObject



6
7
8
# File 'lib/timely-app/client/accounts.rb', line 6

def get_accounts
  get('/1.1/accounts')
end

#get_child_labels(parent_id) ⇒ Object



14
15
16
# File 'lib/timely-app/client/labels.rb', line 14

def get_child_labels(parent_id)
  get("/1.1/#{}/labels", parent_id: parent_id)
end

#get_client(id) ⇒ Object



14
15
16
# File 'lib/timely-app/client/clients.rb', line 14

def get_client(id)
  get("/1.1/#{}/clients/#{id}")
end

#get_clients(**params) ⇒ Object



10
11
12
# File 'lib/timely-app/client/clients.rb', line 10

def get_clients(**params)
  get('/1.1/accounts', params)
end

#get_current_userObject



22
23
24
# File 'lib/timely-app/client/users.rb', line 22

def get_current_user
  get("/1.1/#{}/users/current")
end

#get_current_user_permissionsObject



6
7
8
# File 'lib/timely-app/client/permissions.rb', line 6

def get_current_user_permissions
  get("/1.1/#{}/users/current/permissions")
end

#get_event(id) ⇒ Object



50
51
52
# File 'lib/timely-app/client/events.rb', line 50

def get_event(id)
  get("/1.1/#{}/events/#{id}")
end

#get_events(**params) ⇒ Object



30
31
32
# File 'lib/timely-app/client/events.rb', line 30

def get_events(**params)
  get("/1.1/#{}/events", params)
end

#get_filter_reports(**params) ⇒ Object



10
11
12
# File 'lib/timely-app/client/reports.rb', line 10

def get_filter_reports(**params)
  post("/1.1/#{}/reports/filter", params)
end

#get_forecasts(**params) ⇒ Object



14
15
16
# File 'lib/timely-app/client/forecasts.rb', line 14

def get_forecasts(**params)
  get("/1.1/#{}/forecasts", params)
end

#get_label(id) ⇒ Object



22
23
24
# File 'lib/timely-app/client/labels.rb', line 22

def get_label(id)
  get("/1.1/#{}/labels/#{id}")
end

#get_labels(**params) ⇒ Object



18
19
20
# File 'lib/timely-app/client/labels.rb', line 18

def get_labels(**params)
  get("/1.1/#{}/labels", params)
end

#get_oauth_authorize_url(client_id:, redirect_uri:) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/timely-app/client/auth.rb', line 6

def get_oauth_authorize_url(client_id:, redirect_uri:)
  host_uri_join(
    "/1.1/oauth/authorize",
    response_type: 'code',
    redirect_uri: redirect_uri,
    client_id: client_id
  )
end

#get_project(id) ⇒ Object



18
19
20
# File 'lib/timely-app/client/projects.rb', line 18

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

#get_project_events(project_id:, **params) ⇒ Object



34
35
36
# File 'lib/timely-app/client/events.rb', line 34

def get_project_events(project_id:, **params)
  get("/1.1/#{}/projects/#{project_id}/events", params)
end

#get_projects(**params) ⇒ Object



14
15
16
# File 'lib/timely-app/client/projects.rb', line 14

def get_projects(**params)
  get("/1.1/#{}/projects", params)
end

#get_reports(**params) ⇒ Object



6
7
8
# File 'lib/timely-app/client/reports.rb', line 6

def get_reports(**params)
  post("/1.1/#{}/reports", params)
end

#get_rolesObject



6
7
8
# File 'lib/timely-app/client/roles.rb', line 6

def get_roles
  get("/1.1/#{}/roles")
end

#get_team(id) ⇒ Object



18
19
20
# File 'lib/timely-app/client/teams.rb', line 18

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

#get_teams(**params) ⇒ Object



14
15
16
# File 'lib/timely-app/client/teams.rb', line 14

def get_teams(**params)
  get("/1.1/#{}/teams", params)
end

#get_user(id) ⇒ Object



18
19
20
# File 'lib/timely-app/client/users.rb', line 18

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

#get_user_capacities(user_id:) ⇒ Object



10
11
12
# File 'lib/timely-app/client/user_capacities.rb', line 10

def get_user_capacities(user_id:)
  get("/1.1/#{}/users/#{user_id}/capacities")
end

#get_user_events(user_id:, **params) ⇒ Object



38
39
40
# File 'lib/timely-app/client/events.rb', line 38

def get_user_events(user_id:, **params)
  get("/1.1/#{}/users/#{user_id}/events", params)
end

#get_user_permissions(user_id:) ⇒ Object



10
11
12
# File 'lib/timely-app/client/permissions.rb', line 10

def get_user_permissions(user_id:)
  get("/1.1/#{}/users/#{user_id}/permissions")
end

#get_users(**params) ⇒ Object



14
15
16
# File 'lib/timely-app/client/users.rb', line 14

def get_users(**params)
  get("/1.1/#{}/users", params)
end

#get_users_capacities(**params) ⇒ Object



6
7
8
# File 'lib/timely-app/client/user_capacities.rb', line 6

def get_users_capacities(**params)
  get("/1.1/#{}/users/capacities", params)
end

#get_webhook(id) ⇒ Object



18
19
20
# File 'lib/timely-app/client/webhooks.rb', line 18

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

#get_webhooks(**params) ⇒ Object



14
15
16
# File 'lib/timely-app/client/webhooks.rb', line 14

def get_webhooks(**params)
  get("/1.1/#{}/webhooks", params)
end

#post_oauth_token(client_id:, client_secret:, code:, redirect_uri:, grant_type: "authorization_code") ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/timely-app/client/auth.rb', line 15

def post_oauth_token(client_id:, client_secret:, code:, redirect_uri:, grant_type: "authorization_code")
  post(
    "/1.1/oauth/token",
    redirect_uri: redirect_uri,
    code: code,
    client_id: client_id,
    client_secret: client_secret,
    grant_type: grant_type
  )
end

#start_event_timer(id) ⇒ Object



54
55
56
# File 'lib/timely-app/client/events.rb', line 54

def start_event_timer(id)
  put("/1.1/#{}/events/#{id}/start")
end

#stop_event_timer(id) ⇒ Object



58
59
60
# File 'lib/timely-app/client/events.rb', line 58

def stop_event_timer(id)
  put("/1.1/#{}/events/#{id}/stop")
end

#update_bulk_events(update) ⇒ Object



66
67
68
# File 'lib/timely-app/client/events.rb', line 66

def update_bulk_events(update)
  post("/1.1/#{}/bulk/events", update: update)
end

#update_client(id, name:, **params) ⇒ Object



18
19
20
# File 'lib/timely-app/client/clients.rb', line 18

def update_client(id, name:, **params)
  put("/1.1/#{}/clients/#{id}", client: params.merge(name: name))
end

#update_event(id, day:, hours:, minutes:, **params) ⇒ Object



62
63
64
# File 'lib/timely-app/client/events.rb', line 62

def update_event(id, day:, hours:, minutes:, **params)
  put("/1.1/#{}/events/#{id}", event: params.merge(day: day, hours: hours, minutes: minutes))
end

#update_forecast(id, project_id:, estimated_minutes:, **params) ⇒ Object



18
19
20
# File 'lib/timely-app/client/forecasts.rb', line 18

def update_forecast(id, project_id:, estimated_minutes:, **params)
  put("/1.1/#{}/forecasts/#{id}", forecast: params.merge(project_id: project_id, estimated_minutes: estimated_minutes))
end

#update_label(id, name:, **params) ⇒ Object



26
27
28
# File 'lib/timely-app/client/labels.rb', line 26

def update_label(id, name:, **params)
  put("/1.1/#{}/labels/#{id}", label: params.merge(name: name))
end

#update_project(id, name:, color:, client_id:, users:, **params) ⇒ Object



22
23
24
# File 'lib/timely-app/client/projects.rb', line 22

def update_project(id, name:, color:, client_id:, users:, **params)
  put("/1.1/#{}/projects/#{id}", project: params.merge(name: name, color: color, client_id: client_id, users: users))
end

#update_project_event(id, project_id:, day:, hours:, minutes:, **params) ⇒ Object



46
47
48
# File 'lib/timely-app/client/events.rb', line 46

def update_project_event(id, project_id:, day:, hours:, minutes:, **params)
  put("/1.1/#{}/projects/#{project_id}/events/#{id}", event: params.merge(day: day, hours: hours, minutes: minutes))
end

#update_team(id, name:, users:, **params) ⇒ Object



22
23
24
# File 'lib/timely-app/client/teams.rb', line 22

def update_team(id, name:, users:, **params)
  put("/1.1/#{}/teams/#{id}", team: params.merge(name: name, users: users))
end

#update_user(id, name:, email:, role_id:, **params) ⇒ Object



26
27
28
# File 'lib/timely-app/client/users.rb', line 26

def update_user(id, name:, email:, role_id:, **params)
  put("/1.1/#{}/users/#{id}", user: params.merge(name: name, email: email, role_id: role_id))
end

#update_user_event(id, user_id:, day:, hours:, minutes:, **params) ⇒ Object



42
43
44
# File 'lib/timely-app/client/events.rb', line 42

def update_user_event(id, user_id:, day:, hours:, minutes:, **params)
  put("/1.1/#{}/users/#{user_id}/events/#{id}", event: params.merge(day: day, hours: hours, minutes: minutes))
end

#update_webhook(id, url:, **params) ⇒ Object



22
23
24
# File 'lib/timely-app/client/webhooks.rb', line 22

def update_webhook(id, url:, **params)
  put("/1.1/#{}/webhooks/#{id}", webhook: params.merge(url: url))
end