Class: Umami::Client
- Inherits:
-
Object
- Object
- Umami::Client
- Defined in:
- lib/umami/client.rb
Overview
The Client class provides methods to interact with the Umami API.
Instance Attribute Summary collapse
-
#request_timeout ⇒ Object
readonly
Returns the value of attribute request_timeout.
-
#uri_base ⇒ Object
readonly
Returns the value of attribute uri_base.
Instance Method Summary collapse
-
#add_team_user(team_id, user_id, role) ⇒ Hash
Add a user to a team.
-
#cloud? ⇒ Boolean
Check if the client is configured for Umami Cloud.
-
#create_team(name) ⇒ Hash
Create a new team.
-
#create_user(username, password, role) ⇒ Hash
Create a new user.
-
#create_website(params = {}) ⇒ Hash
Create a new website.
-
#delete_team(team_id) ⇒ String
Delete a team.
-
#delete_team_user(team_id, user_id) ⇒ String
Remove a user from a team.
-
#delete_user(user_id) ⇒ String
Delete a user.
-
#delete_website(website_id) ⇒ String
Delete a website.
-
#event_data_events(website_id, params = {}) ⇒ Array<Hash>
Get event data events.
-
#event_data_fields(website_id, params = {}) ⇒ Array<Hash>
Get event data fields.
-
#event_data_stats(website_id, params = {}) ⇒ Array<Hash>
Get event data stats.
-
#initialize(options = {}) ⇒ Client
constructor
Initialize a new Umami API client.
-
#join_team(access_code) ⇒ Hash
Join a team.
-
#reset_website(website_id) ⇒ String
Reset a website's data.
-
#self_hosted? ⇒ Boolean
Check if the client is configured for a self-hosted Umami instance.
-
#send_event(payload) ⇒ Hash
Send an event.
-
#team(team_id) ⇒ Hash
Get a team by ID.
-
#team_user(team_id, user_id) ⇒ Hash
Get a user in a team.
-
#team_users(team_id, params = {}) ⇒ Array<Hash>
Get all users in a team.
-
#team_websites(team_id, params = {}) ⇒ Array<Hash>
Get all websites for a team.
-
#teams(params = {}) ⇒ Array<Hash>
Get all teams.
-
#update_team(team_id, params = {}) ⇒ Hash
Update a team.
-
#update_team_user(team_id, user_id, role) ⇒ String
Update a user's role in a team.
-
#update_user(user_id, params = {}) ⇒ Hash
Update a user.
-
#update_website(website_id, params = {}) ⇒ Hash
Update a website.
-
#user(user_id) ⇒ Hash
Get a user by ID.
-
#user_teams(user_id, params = {}) ⇒ Array<Hash>
Get all teams for a user.
-
#user_websites(user_id, params = {}) ⇒ Array<Hash>
Get all websites for a user.
-
#users ⇒ Array<Hash>
Get all users (admin access required).
-
#verify_token ⇒ Hash
Verify the authentication token.
-
#website(id) ⇒ Hash
Get a website by ID.
-
#website_active_visitors(id) ⇒ Hash
Get active visitors for a website.
-
#website_events(id, params = {}) ⇒ Array<Hash>
Get website events.
-
#website_metrics(id, params = {}) ⇒ Array<Hash>
Get website metrics.
-
#website_pageviews(id, params = {}) ⇒ Hash
Get website pageviews.
-
#website_stats(id, params = {}) ⇒ Hash
Get website statistics.
-
#websites(params = {}) ⇒ Array<Hash>
Get all websites.
Constructor Details
#initialize(options = {}) ⇒ Client
Initialize a new Umami API client
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/umami/client.rb', line 19 def initialize( = {}) @config = [:config] || Umami.configuration @uri_base = [:uri_base] || @config.uri_base @request_timeout = [:request_timeout] || @config.request_timeout @access_token = [:access_token] || @config.access_token @username = [:username] || @config.username @password = [:password] || @config.password authenticate if @access_token.nil? end |
Instance Attribute Details
#request_timeout ⇒ Object (readonly)
Returns the value of attribute request_timeout.
9 10 11 |
# File 'lib/umami/client.rb', line 9 def request_timeout @request_timeout end |
#uri_base ⇒ Object (readonly)
Returns the value of attribute uri_base.
9 10 11 |
# File 'lib/umami/client.rb', line 9 def uri_base @uri_base end |
Instance Method Details
#add_team_user(team_id, user_id, role) ⇒ Hash
Add a user to a team
241 242 243 |
# File 'lib/umami/client.rb', line 241 def add_team_user(team_id, user_id, role) post("/api/teams/#{team_id}/users", { userId: user_id, role: role }) end |
#cloud? ⇒ Boolean
Check if the client is configured for Umami Cloud
35 36 37 |
# File 'lib/umami/client.rb', line 35 def cloud? @uri_base == Umami::Configuration::UMAMI_CLOUD_URL end |
#create_team(name) ⇒ Hash
Create a new team
164 165 166 |
# File 'lib/umami/client.rb', line 164 def create_team(name) post("/api/teams", { name: name }) end |
#create_user(username, password, role) ⇒ Hash
Create a new user
86 87 88 |
# File 'lib/umami/client.rb', line 86 def create_user(username, password, role) post("/api/users", { username: username, password: password, role: role }) end |
#create_website(params = {}) ⇒ Hash
Create a new website
314 315 316 |
# File 'lib/umami/client.rb', line 314 def create_website(params = {}) post("/api/websites", params) end |
#delete_team(team_id) ⇒ String
Delete a team
216 217 218 |
# File 'lib/umami/client.rb', line 216 def delete_team(team_id) delete("/api/teams/#{team_id}") end |
#delete_team_user(team_id, user_id) ⇒ String
Remove a user from a team
272 273 274 |
# File 'lib/umami/client.rb', line 272 def delete_team_user(team_id, user_id) delete("/api/teams/#{team_id}/users/#{user_id}") end |
#delete_user(user_id) ⇒ String
Delete a user
125 126 127 |
# File 'lib/umami/client.rb', line 125 def delete_user(user_id) delete("/api/users/#{user_id}") end |
#delete_website(website_id) ⇒ String
Delete a website
345 346 347 |
# File 'lib/umami/client.rb', line 345 def delete_website(website_id) delete("/api/websites/#{website_id}") end |
#event_data_events(website_id, params = {}) ⇒ Array<Hash>
Get event data events
465 466 467 |
# File 'lib/umami/client.rb', line 465 def event_data_events(website_id, params = {}) get("/api/event-data/events", params.merge(websiteId: website_id)) end |
#event_data_fields(website_id, params = {}) ⇒ Array<Hash>
Get event data fields
480 481 482 |
# File 'lib/umami/client.rb', line 480 def event_data_fields(website_id, params = {}) get("/api/event-data/fields", params.merge(websiteId: website_id)) end |
#event_data_stats(website_id, params = {}) ⇒ Array<Hash>
Get event data stats
492 493 494 |
# File 'lib/umami/client.rb', line 492 def event_data_stats(website_id, params = {}) get("/api/event-data/stats", params.merge(websiteId: website_id)) end |
#join_team(access_code) ⇒ Hash
Join a team
186 187 188 |
# File 'lib/umami/client.rb', line 186 def join_team(access_code) post("/api/teams/join", { accessCode: access_code }) end |
#reset_website(website_id) ⇒ String
Reset a website's data
354 355 356 |
# File 'lib/umami/client.rb', line 354 def reset_website(website_id) post("/api/websites/#{website_id}/reset") end |
#self_hosted? ⇒ Boolean
Check if the client is configured for a self-hosted Umami instance
42 43 44 |
# File 'lib/umami/client.rb', line 42 def self_hosted? !cloud? end |
#send_event(payload) ⇒ Hash
Send an event
512 513 514 |
# File 'lib/umami/client.rb', line 512 def send_event(payload) post("/api/send", { type: "event", payload: payload }) end |
#team(team_id) ⇒ Hash
Get a team by ID
195 196 197 |
# File 'lib/umami/client.rb', line 195 def team(team_id) get("/api/teams/#{team_id}") end |
#team_user(team_id, user_id) ⇒ Hash
Get a user in a team
251 252 253 |
# File 'lib/umami/client.rb', line 251 def team_user(team_id, user_id) get("/api/teams/#{team_id}/users/#{user_id}") end |
#team_users(team_id, params = {}) ⇒ Array<Hash>
Get all users in a team
230 231 232 |
# File 'lib/umami/client.rb', line 230 def team_users(team_id, params = {}) get("/api/teams/#{team_id}/users", params) end |
#team_websites(team_id, params = {}) ⇒ Array<Hash>
Get all websites for a team
286 287 288 |
# File 'lib/umami/client.rb', line 286 def team_websites(team_id, params = {}) get("/api/teams/#{team_id}/websites", params) end |
#teams(params = {}) ⇒ Array<Hash>
Get all teams
177 178 179 |
# File 'lib/umami/client.rb', line 177 def teams(params = {}) get("/api/teams", params) end |
#update_team(team_id, params = {}) ⇒ Hash
Update a team
207 208 209 |
# File 'lib/umami/client.rb', line 207 def update_team(team_id, params = {}) post("/api/teams/#{team_id}", params) end |
#update_team_user(team_id, user_id, role) ⇒ String
Update a user's role in a team
262 263 264 |
# File 'lib/umami/client.rb', line 262 def update_team_user(team_id, user_id, role) post("/api/teams/#{team_id}/users/#{user_id}", { role: role }) end |
#update_user(user_id, params = {}) ⇒ Hash
Update a user
116 117 118 |
# File 'lib/umami/client.rb', line 116 def update_user(user_id, params = {}) post("/api/users/#{user_id}", params) end |
#update_website(website_id, params = {}) ⇒ Hash
Update a website
336 337 338 |
# File 'lib/umami/client.rb', line 336 def update_website(website_id, params = {}) post("/api/websites/#{website_id}", params) end |
#user(user_id) ⇒ Hash
Get a user by ID
103 104 105 |
# File 'lib/umami/client.rb', line 103 def user(user_id) get("/api/users/#{user_id}") end |
#user_teams(user_id, params = {}) ⇒ Array<Hash>
Get all teams for a user
153 154 155 |
# File 'lib/umami/client.rb', line 153 def user_teams(user_id, params = {}) get("/api/users/#{user_id}/teams", params) end |
#user_websites(user_id, params = {}) ⇒ Array<Hash>
Get all websites for a user
139 140 141 |
# File 'lib/umami/client.rb', line 139 def user_websites(user_id, params = {}) get("/api/users/#{user_id}/websites", params) end |
#users ⇒ Array<Hash>
Get all users (admin access required)
94 95 96 |
# File 'lib/umami/client.rb', line 94 def users get("/api/admin/users") end |
#verify_token ⇒ Hash
Verify the authentication token
50 51 52 |
# File 'lib/umami/client.rb', line 50 def verify_token get("/api/auth/verify") end |
#website(id) ⇒ Hash
Get a website by ID
323 324 325 |
# File 'lib/umami/client.rb', line 323 def website(id) get("/api/websites/#{id}") end |
#website_active_visitors(id) ⇒ Hash
Get active visitors for a website
388 389 390 |
# File 'lib/umami/client.rb', line 388 def website_active_visitors(id) get("/api/websites/#{id}/active") end |
#website_events(id, params = {}) ⇒ Array<Hash>
Get website events
403 404 405 |
# File 'lib/umami/client.rb', line 403 def website_events(id, params = {}) get("/api/websites/#{id}/events", params) end |
#website_metrics(id, params = {}) ⇒ Array<Hash>
Get website metrics
452 453 454 |
# File 'lib/umami/client.rb', line 452 def website_metrics(id, params = {}) get("/api/websites/#{id}/metrics", params) end |
#website_pageviews(id, params = {}) ⇒ Hash
Get website pageviews
426 427 428 |
# File 'lib/umami/client.rb', line 426 def website_pageviews(id, params = {}) get("/api/websites/#{id}/pageviews", params) end |
#website_stats(id, params = {}) ⇒ Hash
Get website statistics
379 380 381 |
# File 'lib/umami/client.rb', line 379 def website_stats(id, params = {}) get("/api/websites/#{id}/stats", params) end |
#websites(params = {}) ⇒ Array<Hash>
Get all websites
301 302 303 |
# File 'lib/umami/client.rb', line 301 def websites(params = {}) get("/api/websites", params) end |