diff --git a/repository/Fossil/FossilRepo.class.st b/repository/Fossil/FossilRepo.class.st index 7366155..c43e296 100644 --- a/repository/Fossil/FossilRepo.class.st +++ b/repository/Fossil/FossilRepo.class.st @@ -2,6 +2,11 @@ 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, @@ -13,24 +18,58 @@ Class { #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 jsonDataFor: relativeFilePath) = self ifTrue: [ + (self jsonWikiDataFor: relativeFilePath) = self ifTrue: [ self inform: 'WARNING! Key not found, verify the file name you are looking in this repository'. ^ self ]. - ^ (((self jsonDataFor: relativeFilePath) at: 'payload') at: 'checkins') + ^ (((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 wikiRoot addPathSegment: anUrlSegment); + 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 | @@ -39,6 +78,13 @@ FossilRepo >> jsonStringFor: 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 @@ -56,9 +102,32 @@ 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 jsonDataFor: 'list') + ^ NeoJSONReader fromString: (self jsonWikiDataFor: 'list') +] + +{ #category : #authentication } +FossilRepo >> rawCapabilities [ + ^ NeoJSONReader fromString: (self jsonDataFor: 'cap') ] { #category : #accessing } @@ -71,6 +140,11 @@ FossilRepo >> remote: anUrlString [ remote := anUrlString asUrl ] +{ #category : #authentication } +FossilRepo >> whoAmI [ + ^ NeoJSONReader fromString: (self jsonDataFor: 'whoami') +] + { #category : #wiki } FossilRepo >> wikiRoot [ ^ self jsonRoot addPathSegment: 'wiki' @@ -78,5 +152,5 @@ FossilRepo >> wikiRoot [ { #category : #wiki } FossilRepo >> wikiTimeline [ - ^ NeoJSONReader fromString: (self jsonDataFor: 'timeline') + ^ NeoJSONReader fromString: (self jsonWikiDataFor: 'timeline') ]