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 : #public } ZnockBase >> at: keyString put: valueString [ self response. ^ builtClient response headers at: keyString put: valueString ] { #category : #accessing } ZnockBase >> baseUrl [ ^ baseUrl ] { #category : #accessing } ZnockBase >> baseUrl: aZnUrl [ baseUrl := aZnUrl ] { #category : #public } ZnockBase >> beOptional [ self request. builtClient beOptional ] { #category : #building } ZnockBase >> closeState: aSymbol [ "self shouldBeImplemented." ] { #category : #building } ZnockBase >> doesNotUnderstand: aMessage [ self forwardedSelectors keysAndValuesDo: [ :handler :candidates | (candidates includes: aMessage selector) ifTrue: [ ^ self perform: handler with: aMessage ] ]. ^ super doesNotUnderstand: aMessage ] { #category : #building } ZnockBase >> forwardedSelectors [ ^ { #handleClientMessage: -> #(addPath: addPathSegment: delete get head host: http https method: options patch path: port: post put #username:password:). #handleResponseCreationMessage: -> #(accepted noContent notModified ok: redirect: #redirect:entity: serverError: serverErrorWithEntity: statusCode: statusLine: unauthorized unauthorized: #unauthorized:entity:). #handleResponseCreationFromRequestMessage: -> #(#badRequest: badRequest:entity: methodNotAllowed: methodNotAllowed:entity:). #handleResponseCreationFromUrlMessage: -> #(#created: created:entity: notFound: notFound:entity: redirect: redirect:entity:). #handleResponseMessage: -> #(addCookie: entity: headers: resetEntity: setLocation: setWWWAuthenticate: statusLine:). #handleResponseHeadersMessage: -> #(addAll: at:add: at:put: at:put:ifPresentMerge:). } asDictionary ] { #category : #building } ZnockBase >> handleClientMessage: aMessage [ self request. ^ aMessage sendTo: builtClient ] { #category : #building } ZnockBase >> handleResponseCreationFromRequestMessage: aMessage [ aMessage argument ifNotNil: [ ^ self handleResponseCreationMessage: aMessage ]. self will: [ :req :res | aMessage argument: req. res customizeFrom: (aMessage sendTo: ZnResponse) ] ] { #category : #building } ZnockBase >> handleResponseCreationFromUrlMessage: aMessage [ aMessage argument ifNotNil: [ ^ self handleResponseCreationMessage: aMessage ]. self will: [ :req :res | aMessage argument: req url. res customizeFrom: (aMessage sendTo: ZnResponse) ] ] { #category : #building } ZnockBase >> handleResponseCreationMessage: aMessage [ ^ self response: (aMessage sendTo: ZnResponse) ] { #category : #building } ZnockBase >> handleResponseHeadersMessage: aMessage [ self response. ^ aMessage sendTo: builtClient response headers ] { #category : #building } ZnockBase >> handleResponseMessage: aMessage [ self response. ^ aMessage sendTo: builtClient response ] { #category : #building } ZnockBase >> newCleanResponse [ ^ ZnResponse statusLine: ZnStatusLine ok ] { #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 >> response: response [ self response ifNotNil: [ self error: 'Response already created' ]. builtClient response: response ] { #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 ] { #category : #public } ZnockBase >> waitFor: aDuration [ self response. builtClient delay: aDuration ] { #category : #public } ZnockBase >> will: aBlock [ self response: self newCleanResponse. builtClient customizeResponseBlock: aBlock ] { #category : #public } ZnockBase >> willError: aString [ self will: [ :req :res | self error: aString ] ]