Extract response exceptions
[smsapi-csharp.git] / README.md
blob107b71d88d8ee17c15c5c8f6d7d9971ee76d9d7b
1 csharp-client
2 ===========
4 SMSAPI C# client may be used by *SMSAPI.pl* and *SMSAPI.com* clients.
6 ## How to pick a service?
8 ### *SMSAPI.IO* (default)
10 ```c#
11 var smsApi = new SMSApi.Api.SMSFactory(client);
12 //or
13 var smsApi = new SMSApi.Api.SMSFactory(client, ProxyAddress.SmsApiIo);
14 ```
16 ### *SMSAPI.PL*
18 ```c#
19 var smsApi = new SMSApi.Api.SMSFactory(client, ProxyAddress.SmsApiPl);
20 ```
22 ### *SMSAPI.COM*
24 ```c#
25 var smsApi = new SMSApi.Api.SMSFactory(client, ProxyAddress.SmsApiCom);
26 ```
29 ### Example
31 ```c#
32 try
34         SMSApi.Api.IClient client = new SMSApi.Api.ClientOAuth("token");
36         var smsApi = new SMSApi.Api.SMSFactory(client);
37         // for SMSAPI.com clients:
38         // var smsApi = new SMSApi.Api.SMSFactory(client, ProxyAddress.SmsApiCom);
40         var result =
41                 smsApi.ActionSend()
42                         .SetText("test message")
43                         .SetTo("0000000000")
44                         .SetSender("Test") //Sender name
45                         .Execute();
47         System.Console.WriteLine("Send: " + result.Count);
49         string[] ids = new string[result.Count];
51         for (int i = 0, l = 0; i < result.List.Count; i++)
52         {
53                 if (!result.List[i].isError())
54                 {
55                         if (!result.List[i].isFinal())
56                         {
57                                 ids[l] = result.List[i].ID;
58                                 l++;
59                         }
60                 }
61         }
63         System.Console.WriteLine("Get:");
64         result =
65                 smsApi.ActionGet()
66                         .Ids(ids)
67                         .Execute();
69         foreach (var status in result.List)
70         {
71                 System.Console.WriteLine("ID: " + status.ID + " Number: " + status.Number + " Points:" + status.Points + " Status:" + status.Status + " IDx: " + status.IDx);
72         }
74 catch (SMSApi.Api.ActionException e)
76         /**
77          * Action error
78          */
79         System.Console.WriteLine(e.Message);
81 catch (SMSApi.Api.ClientException e)
83         /**
84          * Error codes (list available in smsapi docs). Example:
85          * 101  Invalid authorization info
86          * 102  Invalid username or password
87          * 103  Insufficient credits on Your account
88          * 104  No such template
89          * 105  Wrong IP address (for IP filter turned on)
90          * 110  Action not allowed for your account
91          */
92         System.Console.WriteLine(e.Message);
94 catch (SMSApi.Api.HostException e)
96         /* 
97          * Server errors
98          * SMSApi.Api.HostException.E_JSON_DECODE - problem with parsing data
99          */
100         System.Console.WriteLine(e.Message);
102 catch (SMSApi.Api.ProxyException e)
104         // communication problem between client and sever
105         System.Console.WriteLine(e.Message);
109 ## Requirements
111 * C# >= 3.5 + System.Runtime.Serialization, System.ServiceModel.Web
112 * C# >= 4.0
114 ## LICENSE
115 [Apache 2.0 License](https://github.com/smsapi/smsapi-php-client/blob/master/LICENSE)