" I model a fossil repository. For details about fossil see: http://fossil-scm.org/ The protocols are named following Smalltalk conventions, but also after the Fossil JSON API documentation at [1] [1] https://docs.google.com/document/d/1fXViveNhDbiXgCuE7QDXQOKeFzf2qNUkBEgiUvoqFN4/view " Class { #name : #FossilRepo, #superclass : #Object, #instVars : [ 'local', 'remote' ], #category : #Fossil } { #category : #authentication } FossilRepo >> authTokenFor: anUserName withPassword: passwordString [ ^ ((self loginAs: anUserName withPassword: passwordString) at: 'payload') at: 'authToken' ] { #category : #authentication } FossilRepo >> capabilities [ | payload name permissions | payload := self rawCapabilities at: 'payload'. name := payload at: 'name'. permissions := ((payload at: 'permissionFlags') select: [ :item | item value ]) keys. ^ Dictionary new at: 'name' put: name; at: 'permissions' put: permissions; yourself. ] { #category : #querying } FossilRepo >> checkinsFor: relativeFilePath [ "I get all histotical checkins information for a full file name, wich includes relative path in the repository (i.e: 'Doc/Es/Tutoriales/tutorial.ston' or 'index.html's)" (self jsonWikiDataFor: relativeFilePath) = self ifTrue: [ self inform: 'WARNING! Key not found, verify the file name you are looking in this repository'. ^ self ]. ^ (((self jsonWikiDataFor: relativeFilePath) at: 'payload') at: 'checkins') ] { #category : #wiki } FossilRepo >> createPage: pageName [ ^ NeoJSONReader fromString: (self jsonWikiDataFor: 'create/', pageName) ] { #category : #wiki } FossilRepo >> fetchPage: pageName [ ^ NeoJSONReader fromString: (self jsonWikiDataFor: 'get/', pageName) ] { #category : #utility } FossilRepo >> jsonDataFor: anUrlSegment [ ^ ZnClient new get: (self jsonRoot addPathSegment: anUrlSegment); contents. ] { #category : #utility } FossilRepo >> jsonRoot [ "I define the root of the JSON API for all repo querying and modifiying operations" ^ self remote addPathSegment: 'json'. ] { #category : #querying } FossilRepo >> jsonStringFor: aFileName [ | queryForJSONData | queryForJSONData := self remote addPathSegments: #('json' 'finfo'). queryForJSONData queryAt: 'name' put: aFileName. ^ (ZnEasy get: queryForJSONData) contents. ] { #category : #wiki } FossilRepo >> jsonWikiDataFor: anUrlSegment [ ^ ZnClient new get: (self wikiRoot addPathSegment: anUrlSegment); contents. ] { #category : #querying } FossilRepo >> lastHashNumberFor: aFileName [ "I'm useful to see if local versions of files are updated to the last versions of the online repository" ^ (self checkinsFor: aFileName) first at: 'uuid' ] { #category : #accessing } FossilRepo >> local [ ^ local ] { #category : #accessing } FossilRepo >> local: aLocalFilePath [ local := aLocalFilePath ] { #category : #authentication } FossilRepo >> loginAs: anUserName withPassword: password [ | jsonData | jsonData := ZnClient new url: (self loginUrlWithName: anUserName andPassword: password); get; contents. ^ NeoJSONReader fromString: jsonData ] { #category : #authentication } FossilRepo >> loginUrlWithName: aUser andPassword: passwd [ ^ self jsonRoot addPathSegment: 'login'; queryAt: 'name' put: aUser; queryAt: 'password' put: passwd. ] { #category : #wiki } FossilRepo >> pageList [ ^ NeoJSONReader fromString: (self jsonWikiDataFor: 'list') ] { #category : #authentication } FossilRepo >> rawCapabilities [ ^ NeoJSONReader fromString: (self jsonDataFor: 'cap') ] { #category : #accessing } FossilRepo >> remote [ ^ remote ] { #category : #accessing } FossilRepo >> remote: anUrlString [ remote := anUrlString asUrl ] { #category : #authentication } FossilRepo >> whoAmI [ ^ NeoJSONReader fromString: (self jsonDataFor: 'whoami') ] { #category : #wiki } FossilRepo >> wikiRoot [ ^ self jsonRoot addPathSegment: 'wiki' ] { #category : #wiki } FossilRepo >> wikiTimeline [ ^ NeoJSONReader fromString: (self jsonWikiDataFor: 'timeline') ]