|
@@ -0,0 +1,116 @@
|
|
|
+Class {
|
|
|
+ #name : #ZnockBase,
|
|
|
+ #superclass : #Object,
|
|
|
+ #instVars : [
|
|
|
+ 'owner',
|
|
|
+ 'state',
|
|
|
+ 'builtClient',
|
|
|
+ 'baseUrl'
|
|
|
+ ],
|
|
|
+ #category : #Znock
|
|
|
+}
|
|
|
+
|
|
|
+{ #category : #'instance creation' }
|
|
|
+ZnockBase class >> in: aZnock url: aZnUrl [
|
|
|
+ ^ super new
|
|
|
+ baseUrl: aZnUrl;
|
|
|
+ owner: aZnock;
|
|
|
+ yourself
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #accessing }
|
|
|
+ZnockBase >> baseUrl [
|
|
|
+ ^ baseUrl
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #accessing }
|
|
|
+ZnockBase >> baseUrl: aZnUrl [
|
|
|
+ baseUrl := aZnUrl
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #building }
|
|
|
+ZnockBase >> clientSelectors [
|
|
|
+ ^ #(addPath: addPathSegment: delete get head host: http https method: options patch path: port: post put username:password:)
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #building }
|
|
|
+ZnockBase >> closeState: aSymbol [
|
|
|
+ "self shouldBeImplemented."
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #building }
|
|
|
+ZnockBase >> doesNotUnderstand: aMessage [
|
|
|
+ (self clientSelectors includes: aMessage selector) ifTrue: [
|
|
|
+ self request.
|
|
|
+ ^ aMessage sendTo: builtClient ].
|
|
|
+ (self responseCreationSelectors includes: aMessage selector) ifTrue: [
|
|
|
+ self response ifNotNil: [ self error: 'Response already created' ].
|
|
|
+ ^ builtClient response: (aMessage sendTo: ZnResponse) ].
|
|
|
+ (self responseSelectors includes: aMessage selector) ifTrue: [
|
|
|
+ self response.
|
|
|
+ ^ aMessage sendTo: builtClient response ].
|
|
|
+ ^ super doesNotUnderstand: aMessage
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #building }
|
|
|
+ZnockBase >> openState: aSymbol [
|
|
|
+ aSymbol == #request ifTrue: [
|
|
|
+ builtClient := ZnockExpectation new.
|
|
|
+ builtClient url: baseUrl.
|
|
|
+ builtClient request url scheme: baseUrl scheme ].
|
|
|
+ aSymbol == #response ifTrue: [ self owner addExpectation: builtClient ]
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #accessing }
|
|
|
+ZnockBase >> owner [
|
|
|
+ ^ owner
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #accessing }
|
|
|
+ZnockBase >> owner: anObject [
|
|
|
+ owner := anObject
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #building }
|
|
|
+ZnockBase >> request [
|
|
|
+ self state: #request.
|
|
|
+ ^ builtClient
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #building }
|
|
|
+ZnockBase >> resetState [
|
|
|
+ self state: nil
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #building }
|
|
|
+ZnockBase >> response [
|
|
|
+ self state: #response.
|
|
|
+ ^ builtClient response
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #building }
|
|
|
+ZnockBase >> responseCreationSelectors [
|
|
|
+ ^ #(accepted noContent notModified ok: redirect: redirect:entity: serverError: serverErrorWithEntity: statusCode: statusLine: unauthorized unauthorized: unauthorized:entity:)
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #building }
|
|
|
+ZnockBase >> responseSelectors [
|
|
|
+ ^ #(addCookie: entity: headers: resetEntity: setLocation: setWWWAuthenticate: statusLine:)
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #building }
|
|
|
+ZnockBase >> state: aSymbol [
|
|
|
+ state == aSymbol ifTrue: [ ^ self ].
|
|
|
+ self closeState: state.
|
|
|
+ state := aSymbol.
|
|
|
+ self openState: state
|
|
|
+]
|
|
|
+
|
|
|
+{ #category : #public }
|
|
|
+ZnockBase >> url: anObject [
|
|
|
+ | scheme |
|
|
|
+ self request.
|
|
|
+ scheme := builtClient request url scheme.
|
|
|
+ builtClient url: anObject.
|
|
|
+ builtClient request url scheme: scheme
|
|
|
+]
|