-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
56 lines (49 loc) · 1.6 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
55
56
using ScgApi;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace delete_contact
{
class Program
{
static async Task DeleteContact(String phoneNumber, SessionOptions opts)
{
using (var session = new Session(opts))
{
var res = Contact.Resource(session);
// We have to use List() to search for the phone number.
// There should be at max one iteration of the loop.
foreach (var contact in res.List(new Dictionary<String, String>()
{
{"primary_mdn", phoneNumber }
}))
{
Console.WriteLine("Deleting contact {0} with mdn {1}",
contact.Id, contact.PrimaryMdn);
await res.Delete(contact.Id);
}
}
}
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Usage: delete_contact phone [auth-file] [api-url]");
return;
}
var opts = new SessionOptions();
if (args.Length > 1)
opts.AuthFilePath = args[1];
if (args.Length > 2)
opts.BaseUrl = args[2];
try
{
DeleteContact(args[0], opts).Wait();
}
catch (Exception ex)
{
Console.WriteLine("Failed: {0}", ex.ToString());
}
}
}
}