summaryrefslogtreecommitdiff
path: root/lib/sentry/client/projects.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sentry/client/projects.rb')
-rw-r--r--lib/sentry/client/projects.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/sentry/client/projects.rb b/lib/sentry/client/projects.rb
new file mode 100644
index 00000000000..68f8fe0f9c9
--- /dev/null
+++ b/lib/sentry/client/projects.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+module Sentry
+ class Client
+ module Projects
+ def projects
+ projects = get_projects
+
+ handle_mapping_exceptions do
+ map_to_projects(projects)
+ end
+ end
+
+ private
+
+ def get_projects
+ http_get(projects_api_url)[:body]
+ end
+
+ def projects_api_url
+ projects_url = URI(url)
+ projects_url.path = '/api/0/projects/'
+
+ projects_url
+ end
+
+ def map_to_projects(projects)
+ projects.map(&method(:map_to_project))
+ end
+
+ def map_to_project(project)
+ organization = project.fetch('organization')
+
+ Gitlab::ErrorTracking::Project.new(
+ id: project.fetch('id', nil),
+ name: project.fetch('name'),
+ slug: project.fetch('slug'),
+ status: project.dig('status'),
+ organization_name: organization.fetch('name'),
+ organization_id: organization.fetch('id', nil),
+ organization_slug: organization.fetch('slug')
+ )
+ end
+ end
+ end
+end