-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
54 lines (44 loc) · 1.45 KB
/
Program.cs
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
using ScgApi;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace update_contact
{
class Program
{
static async Task UpdateContact(String id, String newName, SessionOptions opts)
{
using (var session = new Session(opts))
{
var res = Contact.Resource(session);
var contact = await res.Get(id);
string oldName = contact.FirstName;
contact.FirstName = newName;
await res.Update(contact.Id, contact);
Console.WriteLine("Updated the name for contact {0} from {1} to {2}",
contact.Id, oldName, contact.FirstName);
}
}
static void Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("Usage: update_contact contact-id new-first-name [auth-file] [api-url]");
return;
}
var opts = new SessionOptions();
if (args.Length > 2)
opts.AuthFilePath = args[2];
if (args.Length > 3)
opts.BaseUrl = args[3];
try
{
UpdateContact(args[0], args[1], opts).Wait();
}
catch (Exception ex)
{
Console.WriteLine("Failed: {0}", ex.ToString());
}
}
}
}