1
1
namespace jwl . jira ;
2
2
3
3
using System . Net . Http . Json ;
4
+ using System . Xml . Serialization ;
4
5
using jwl . infra ;
6
+ using jwl . wadl ;
5
7
6
8
// https://interconcept.atlassian.net/wiki/spaces/ICTIME/pages/31686672/API
7
9
// https://interconcept.atlassian.net/wiki/spaces/ICBIZ/pages/34701333/REST+Services
@@ -12,6 +14,20 @@ public class JiraWithICTimePluginApi
12
14
public string UserName { get ; }
13
15
public api . rest . common . JiraUserInfo UserInfo => _vanillaJiraApi . UserInfo ;
14
16
17
+ public string PluginBaseUri { get ; } = "rest/ictime/1.0" ;
18
+ public Lazy < Dictionary < string , wadl . ComposedWadlMethodDefinition > > Endpoints =>
19
+ new Lazy < Dictionary < string , ComposedWadlMethodDefinition > > ( ( ) => this . GetWADL ( ) . Result
20
+ . AsEnumerable ( )
21
+ . Where ( res => ! string . IsNullOrEmpty ( res . Id ) )
22
+ . ToDictionary ( res => res . Id ?? string . Empty )
23
+ ) ;
24
+
25
+ public const string CreateWorkLogMethodName = "createWorklog" ;
26
+ public wadl . ComposedWadlMethodDefinition CreateWorkLogMethodDefinition => Endpoints . Value [ CreateWorkLogMethodName ] ;
27
+
28
+ public const string GetActivityTypesForProjectMethodName = "getActivityTypesForProject" ;
29
+ public wadl . ComposedWadlMethodDefinition GetActivityTypesForProjectMethodDefinition => Endpoints . Value [ GetActivityTypesForProjectMethodName ] ;
30
+
15
31
private readonly HttpClient _httpClient ;
16
32
private readonly VanillaJiraClient _vanillaJiraApi ;
17
33
@@ -91,4 +107,18 @@ public async Task UpdateWorklog(string issueKey, long worklogId, DateOnly day, i
91
107
{
92
108
await _vanillaJiraApi . UpdateWorklog ( issueKey , worklogId , day , timeSpentSeconds , activity , comment ) ;
93
109
}
110
+
111
+ private async Task < WadlApplication > GetWADL ( )
112
+ {
113
+ Uri uri = new Uri ( $ "{ PluginBaseUri } /application.wadl", UriKind . Relative ) ;
114
+ using Stream response = await _httpClient . GetStreamAsync ( uri ) ;
115
+ if ( response == null || response . Length <= 0 )
116
+ throw new HttpRequestException ( $ "Empty content received from ${ uri } ") ;
117
+
118
+ XmlSerializer serializer = new XmlSerializer ( typeof ( WadlApplication ) ) ;
119
+ object resultObj = serializer . Deserialize ( response ) ?? throw new InvalidDataException ( $ "Empty/null content deserialization result") ;
120
+
121
+ WadlApplication result = ( WadlApplication ) resultObj ;
122
+ return result ;
123
+ }
94
124
}
0 commit comments