├── README.md ├── LICENSE └── Gitter.Archiver.cls /README.md: -------------------------------------------------------------------------------- 1 | Cache Gitter Archiver 2 | --------------------- 3 | 4 | A tiny class for InterSystems Caché that downloads all Gitter's room messages to the archive file. 5 | 6 | **Keywords**: InterSystems, Caché, HTTPS, HTTP, Request, Gitter, API. 7 | 8 | Usage 9 | ----- 10 | 11 | 1. Import `Gitter.Archiver.cls` class to Caché. 12 | 3. Run the script in terminal from user with %SYS namespace access: 13 | 14 | ![2016-05-29_230926](https://cloud.githubusercontent.com/assets/4989256/15635854/ab5ba444-25f3-11e6-8578-ac9fb74644aa.png) 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Nikita 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Gitter.Archiver.cls: -------------------------------------------------------------------------------- 1 | /// Archives messages to a file. 2 | Class Gitter.Archiver 3 | { 4 | 5 | /// SSL configuration name used for HTTPS requests. 6 | Parameter SSLConfig = "DefaultSSL"; 7 | 8 | /// Downloads all Gitter's room messages to the archive file. Specify fileName and roomID parameters, 9 | /// or there would be used default values, which download messages from https://gitter.im/springjazzy/GIS_JKH_Integration 10 | ClassMethod Archive(fileName As %String = "C:\chat.txt", roomID As %String = "56ea6f5f85d51f252ab942cd") As %Status 11 | { 12 | new $namespace 13 | zn "%SYS" 14 | do:'##class(Security.SSLConfigs).Exists(..#SSLConfig) ##class(Security.SSLConfigs).Create(..#SSLConfig) 15 | 16 | set LIMIT = 100 // default limit for messages load. Could not be higher. 17 | set file = ##class(%File).%New(fileName) 18 | do file.Open("WSN") 19 | set req = ##class(%Net.HttpRequest).%New() 20 | set req.Server = "api.gitter.im" 21 | set req.Https = 1 22 | set req.SSLConfiguration = ..#SSLConfig 23 | set chat = ##class(%Object).$new() 24 | set beforeId = "" 25 | set mes = 0 26 | do { 27 | do req.SetHeader("Authorization", "Bearer c8de8cdb9a7f13d225a539a6a8165adb43633a37") 28 | do req.SetHeader("Accept", "application/json") 29 | do req.SetHeader("Content-Type", "application/json") 30 | write $system.Status.GetErrorText( 31 | req.Get("/v1/rooms/"_roomID_"/chatMessages?limit="_LIMIT 32 | _$case(beforeId '= "", 1:"&beforeId="_beforeId, :"")) 33 | ) 34 | set obj = ##class(%AbstractObject).$fromJSON(req.HttpResponse.Data) 35 | if (obj.$size() = 0) { continue } 36 | for k=obj.$size()-1:-1:0 { 37 | set message = obj.$get(k) 38 | set mes = mes + 1 39 | do chat.$set(mes, message) 40 | } 41 | write $c(13), "Messages downloaded: ", mes 42 | set beforeId = obj.$get(0).id 43 | } while (obj.$get(LIMIT-1) '= "") // until the last page is reached 44 | write ". Writing to "_fileName_"... " 45 | for k=mes:-1:1 { 46 | set message = chat.$get(k) 47 | do file.WriteLine( 48 | "["_ message.fromUser.displayName_" @ "_message.fromUser.username 49 | _"] ["_$piece($replace(message.sent, "T", " "), ".", 1)_"]:" 50 | ) 51 | do file.WriteLine(message.text) 52 | do file.WriteLine() 53 | } 54 | write "Done." 55 | 56 | quit $$$OK 57 | } 58 | 59 | } 60 | --------------------------------------------------------------------------------