-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunify_api.rb
More file actions
85 lines (67 loc) · 2.23 KB
/
Copy pathunify_api.rb
File metadata and controls
85 lines (67 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# frozen_string_literal: true
require 'time'
require 'bundleup'
api_key = ENV.fetch('BUNDLEUP_API_KEY', nil)
connection_id = ENV.fetch('BUNDLEUP_CONNECTION_ID', nil)
abort 'BUNDLEUP_API_KEY is required' if api_key.nil? || api_key.empty?
abort 'BUNDLEUP_CONNECTION_ID is required for unify example' if connection_id.nil? || connection_id.empty?
ticketing = BundleUp::Unify::Ticketing.new(api_key, connection_id)
client = BundleUp::Client.new(api_key)
unify = client.unify(connection_id)
puts 'Unify API example'
begin
users = unify.chat.users(limit: 10)
puts "Chat users: #{users['data']&.length || 0}"
rescue StandardError => e
warn "Failed to fetch chat users: #{e.message}"
end
begin
channels = unify.chat.channels(limit: 10)
puts "Chat channels: #{channels['data']&.length || 0}"
channel = channels['data']&.first
if channel
messages = unify.chat.messages(channel['id'], limit: 10)
puts "Messages in #{channel['name']}: #{messages['data']&.length || 0}"
end
rescue StandardError => e
warn "Failed to fetch chat channels: #{e.message}"
end
begin
repos = unify.git.repos(limit: 10)
puts "Git repos: #{repos['data']&.length || 0}"
rescue StandardError => e
warn "Failed to fetch git repos: #{e.message}"
end
begin
tickets = ticketing.tickets(limit: 10)
puts "Ticketing tickets: #{tickets['data']&.length || 0}"
first = tickets['data']&.first
if first
ticket = ticketing.ticket(first['id'])
puts "Ticket #{ticket['data']['id']}: #{ticket['data']['title']}"
end
rescue StandardError => e
warn "Failed to fetch tickets: #{e.message}"
end
begin
companies = unify.crm.companies(limit: 10)
puts "CRM companies: #{companies['data']&.length || 0}"
rescue StandardError => e
warn "Failed to fetch CRM companies: #{e.message}"
end
begin
files = unify.drive.files(limit: 10)
puts "Drive files: #{files['data']&.length || 0}"
rescue StandardError => e
warn "Failed to fetch Drive files: #{e.message}"
end
begin
events = unify.calendar.events(
starts_after: Time.now.utc.iso8601,
starts_before: (Time.now.utc + (7 * 24 * 60 * 60)).iso8601,
limit: 10
)
puts "Calendar events: #{events['data']&.length || 0}"
rescue StandardError => e
warn "Failed to fetch Calendar events: #{e.message}"
end