1+ using ESI . NET . Models . Contacts ;
2+ using ESI . NET . Models . Fleets ;
3+ using System . Collections . Generic ;
4+ using System . Net ;
5+ using System . Threading . Tasks ;
6+ using static ESI . NET . ApiRequest ;
7+
8+ namespace ESI . NET . Logic
9+ {
10+ public class ContactsLogic
11+ {
12+ private ESIConfig _config ;
13+ private int character_id , corporation_id , alliance_id ;
14+
15+ public ContactsLogic ( ESIConfig config )
16+ {
17+ _config = config ;
18+
19+ if ( _config . AuthorizedCharacter != null )
20+ {
21+ character_id = _config . AuthorizedCharacter . CharacterID ;
22+ corporation_id = _config . AuthorizedCharacter . CorporationID ;
23+ alliance_id = _config . AuthorizedCharacter . CorporationID ;
24+ }
25+ }
26+
27+ /// <summary>
28+ /// /characters/{character_id}/contacts/
29+ /// </summary>
30+ /// <param name="page"></param>
31+ /// <returns></returns>
32+ public async Task < ApiResponse < List < Contact > > > List ( int page = 1 )
33+ => await Execute < List < Contact > > ( _config , RequestSecurity . Authenticated , RequestMethod . GET , $ "/characters/{ character_id } /contacts/", new string [ ]
34+ {
35+ $ "page={ page } "
36+ } ) ;
37+
38+ /// <summary>
39+ /// /corporations/{corporation_id}/contacts/
40+ /// </summary>
41+ /// <param name="page"></param>
42+ /// <returns></returns>
43+ public async Task < ApiResponse < List < Contact > > > ListForCorporation ( int page = 1 )
44+ => await Execute < List < Contact > > ( _config , RequestSecurity . Authenticated , RequestMethod . GET , $ "/corporations/{ corporation_id } /contacts/", new string [ ]
45+ {
46+ $ "page={ page } "
47+ } ) ;
48+
49+ /// <summary>
50+ /// /alliances/{alliance_id}/contacts/
51+ /// </summary>
52+ /// <param name="page"></param>
53+ /// <returns></returns>
54+ public async Task < ApiResponse < List < Contact > > > ListForAlliance ( int page = 1 )
55+ => await Execute < List < Contact > > ( _config , RequestSecurity . Authenticated , RequestMethod . GET , $ "/alliances/{ alliance_id } /contacts/", new string [ ]
56+ {
57+ $ "page={ page } "
58+ } ) ;
59+
60+ /// <summary>
61+ /// /characters/{character_id}/contacts/
62+ /// </summary>
63+ /// <param name="contact_id"></param>
64+ /// <param name="standing"></param>
65+ /// <param name="label_id"></param>
66+ /// <param name="watched"></param>
67+ /// <returns></returns>
68+ public async Task < ApiResponse < int [ ] > > Add ( int contact_id , decimal standing , int ? label_id = null , bool ? watched = null )
69+ {
70+ var body = new int [ ] { contact_id } ;
71+
72+ var parameters = new List < string > ( ) { $ "standing={ standing } " } ;
73+
74+ if ( label_id != null )
75+ parameters . Add ( $ "label_id={ label_id } ") ;
76+
77+ if ( watched != null )
78+ parameters . Add ( $ "watched={ watched } ") ;
79+
80+ var response = await Execute < int [ ] > ( _config , RequestSecurity . Authenticated , RequestMethod . POST , $ "/characters/{ character_id } /contacts/", body : body , parameters : parameters . ToArray ( ) ) ;
81+
82+ if ( response . StatusCode == HttpStatusCode . NoContent )
83+ response . Message = Dictionaries . NoContentMessages [ "POST|/characters/{character_id}/contacts/" ] ;
84+
85+ return response ;
86+ }
87+
88+ /// <summary>
89+ /// /characters/{character_id}/contacts/
90+ /// </summary>
91+ /// <param name="contact_id"></param>
92+ /// <param name="standing"></param>
93+ /// <param name="label_id"></param>
94+ /// <param name="watched"></param>
95+ /// <returns></returns>
96+ public async Task < ApiResponse < string > > Update ( int contact_id , decimal standing , int ? label_id = null , bool ? watched = null )
97+ {
98+ var body = new int [ ] { contact_id } ;
99+
100+ var parameters = new List < string > ( ) { $ "standing={ standing } " } ;
101+
102+ if ( label_id != null )
103+ parameters . Add ( $ "label_id={ label_id } ") ;
104+
105+ if ( watched != null )
106+ parameters . Add ( $ "watched={ watched } ") ;
107+
108+ var response = await Execute < string > ( _config , RequestSecurity . Authenticated , RequestMethod . PUT , $ "/characters/{ character_id } /contacts/", body : body , parameters : parameters . ToArray ( ) ) ;
109+
110+ if ( response . StatusCode == HttpStatusCode . NoContent )
111+ response . Message = Dictionaries . NoContentMessages [ "PUT|/characters/{character_id}/contacts/" ] ;
112+
113+ return response ;
114+ }
115+
116+ /// <summary>
117+ /// /characters/{character_id}/contacts/
118+ /// </summary>
119+ /// <param name="contact_ids"></param>
120+ /// <returns></returns>
121+ public async Task < ApiResponse < string > > Delete ( int [ ] contact_ids )
122+ {
123+ var response = await Execute < string > ( _config , RequestSecurity . Authenticated , RequestMethod . DELETE , $ "/characters/{ character_id } /contacts/", new string [ ]
124+ {
125+ $ "contact_ids={ string . Join ( "," , contact_ids ) } "
126+ } ) ;
127+
128+ if ( response . StatusCode == HttpStatusCode . NoContent )
129+ response . Message = Dictionaries . NoContentMessages [ "DELETE|/characters/{character_id}/contacts/" ] ;
130+
131+ return response ;
132+ }
133+
134+ /// <summary>
135+ /// /characters/{character_id}/contacts/labels/
136+ /// </summary>
137+ /// <returns></returns>
138+ public async Task < ApiResponse < List < Label > > > Labels ( )
139+ => await Execute < List < Label > > ( _config , RequestSecurity . Authenticated , RequestMethod . GET , $ "/characters/{ character_id } /contacts/labels/") ;
140+ }
141+ }
0 commit comments