Fossil/repository/Fossil/FossilRepo.class.st

157 lines
3.9 KiB
Smalltalk
Raw Normal View History

"
I model a fossil repository. For details about fossil see:
http://fossil-scm.org/
2017-06-09 07:42:57 +00:00
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
}
2017-06-09 07:42:57 +00:00
{ #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)"
2017-06-09 07:42:57 +00:00
(self jsonWikiDataFor: relativeFilePath) = self ifTrue: [
self inform:
'WARNING! Key not found, verify the file name you are looking in this repository'.
^ self ].
2017-06-09 07:42:57 +00:00
^ (((self jsonWikiDataFor: relativeFilePath) at: 'payload') at: 'checkins')
]
{ #category : #wiki }
2017-06-09 07:42:57 +00:00
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
2017-06-09 07:42:57 +00:00
get: (self jsonRoot addPathSegment: anUrlSegment);
contents.
]
2017-06-09 07:42:57 +00:00
{ #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.
]
2017-06-09 07:42:57 +00:00
{ #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
]
2017-06-09 07:42:57 +00:00
{ #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 [
2017-06-09 07:42:57 +00:00
^ 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
]
2017-06-09 07:42:57 +00:00
{ #category : #authentication }
FossilRepo >> whoAmI [
^ NeoJSONReader fromString: (self jsonDataFor: 'whoami')
]
{ #category : #wiki }
FossilRepo >> wikiRoot [
^ self jsonRoot addPathSegment: 'wiki'
]
{ #category : #wiki }
FossilRepo >> wikiTimeline [
2017-06-09 07:42:57 +00:00
^ NeoJSONReader fromString: (self jsonWikiDataFor: 'timeline')
]