-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.rb
51 lines (43 loc) · 1.82 KB
/
cli.rb
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
require 'rubygems'
require 'bundler/setup'
Bundler.require(:default)
require_relative 'cli/refresh_token'
require_relative 'cli/store'
require_relative 'cli/token'
require_relative 'cli/simple_api'
token = Token.new
api = SimpleApi.new(token: token)
# Show who the authorized user is
me = api.me
puts "Authorization:"
puts "\tYou are authorized as #{me["email"]}"
# Create a fake person for the current user
unique_fake_safe_email = me["email"].split("@").join("+#{Time.now.to_i}@")
person = api.create_person(email_address: unique_fake_safe_email)
puts "Person Creation:"
puts "\tPerson #{person["id"]} was created with email #{person["email_address"]}"
puts "\tYou can view this person at #{api.person_url(person["id"])}"
# Update the person's name
updated_person = api.update_person(person["id"], first_name: "Test", last_name: "McTester")
puts "Person Updating:"
puts "\tPerson #{person["id"]} was updated to have a different name."
# Find the person by email
id_lookup_person = api.get_person(person["id"])
email_lookup_person = api.get_person(person["email_address"])
puts "Id and email lookup are the same? #{id_lookup_person == email_lookup_person}"
puts "Person email lookup:"
puts "\tPeople can be looked up by their email address, like #{email_lookup_person["id"]} was just looked up."
# Add the person to the cadence
cadences = api.cadences
puts "Add person to cadence:"
if cadences.any?
added_person = api.add_person_to_cadence(person["id"], cadences[0]["id"])
if added_person["person_id"]
puts "\tPerson #{added_person["person_id"]} added to cadence #{added_person["cadence_id"]}."
puts "\tView this cadence's people at #{api.cadence_people_url(added_person["cadence_id"])}"
else
puts "\tOops, this person could not be added."
end
else
puts "\tYou must create a cadence in app before you can add a person to a cadence"
end