MoyaProvider
open class MoyaProvider<Target> : MoyaProviderType where Target : TargetType
Request provider class. Requests should be made through this class only.
-
Closure that defines the endpoints for the provider.
Declaration
Swift
public typealias EndpointClosure = (Target) -> Endpoint
-
Closure that decides if and what request should be performed.
Declaration
Swift
public typealias RequestResultClosure = (Result<URLRequest, MoyaError>) -> Void
-
Closure that resolves an
Endpoint
into aRequestResult
.Declaration
Swift
public typealias RequestClosure = (Endpoint, @escaping RequestResultClosure) -> Void
-
Closure that decides if/how a request should be stubbed.
Declaration
Swift
public typealias StubClosure = (Target) -> Moya.StubBehavior
-
A closure responsible for mapping a
TargetType
to anEndPoint
.Declaration
Swift
public let endpointClosure: EndpointClosure
-
A closure deciding if and what request should be performed.
Declaration
Swift
public let requestClosure: RequestClosure
-
A closure responsible for determining the stubbing behavior of a request for a given
TargetType
.Declaration
Swift
public let stubClosure: StubClosure
-
Undocumented
Declaration
Swift
public let session: Session
-
A list of plugins. e.g. for logging, network activity indicator or credentials.
Declaration
Swift
public let plugins: [PluginType]
-
Undocumented
Declaration
Swift
public let trackInflights: Bool
-
Undocumented
Declaration
Swift
open internal(set) var inflightRequests: [Endpoint : [Completion]]
-
Initializes a provider.
Declaration
Swift
public init(endpointClosure: @escaping EndpointClosure = MoyaProvider.defaultEndpointMapping, requestClosure: @escaping RequestClosure = MoyaProvider.defaultRequestMapping, stubClosure: @escaping StubClosure = MoyaProvider.neverStub, callbackQueue: DispatchQueue? = nil, session: Session = MoyaProvider<Target>.defaultAlamofireSession(), plugins: [PluginType] = [], trackInflights: Bool = false)
-
Returns an
Endpoint
based on the token, method, and parameters by invoking theendpointClosure
.Declaration
Swift
open func endpoint(_ token: Target) -> Endpoint
-
Designated request-making method. Returns a
Cancellable
token to cancel the request later.Declaration
Swift
@discardableResult open func request(_ target: Target, callbackQueue: DispatchQueue? = .none, progress: ProgressBlock? = .none, completion: @escaping Completion) -> Cancellable
-
When overriding this method, call
notifyPluginsOfImpendingStub
to prepare your request and then use the returnedURLRequest
in thecreateStubFunction
method. Note: this was previously in an extension, however it must be in the original class declaration to allow subclasses to override.Declaration
Swift
@discardableResult open func stubRequest(_ target: Target, request: URLRequest, callbackQueue: DispatchQueue?, completion: @escaping Moya.Completion, endpoint: Endpoint, stubBehavior: Moya.StubBehavior) -> CancellableToken
-
Undocumented
Declaration
Swift
final class func defaultEndpointMapping(for target: Target) -> Endpoint
-
Undocumented
Declaration
Swift
final class func defaultRequestMapping(for endpoint: Endpoint, closure: RequestResultClosure)
-
Undocumented
Declaration
Swift
final class func defaultAlamofireSession() -> Session
-
Performs normal requests.
Declaration
Swift
func requestNormal(_ target: Target, callbackQueue: DispatchQueue?, progress: Moya.ProgressBlock?, completion: @escaping Moya.Completion) -> Cancellable
-
Undocumented
Declaration
Swift
func cancelCompletion(_ completion: Moya.Completion, target: Target)
-
Creates a function which, when called, executes the appropriate stubbing behavior for the given parameters.
Declaration
Swift
final func createStubFunction(_ token: CancellableToken, forTarget target: Target, withCompletion completion: @escaping Moya.Completion, endpoint: Endpoint, plugins: [PluginType], request: URLRequest) -> (() -> Void)
-
Notify all plugins that a stub is about to be performed. You must call this if overriding
stubRequest
.Declaration
Swift
final func notifyPluginsOfImpendingStub(for request: URLRequest, target: Target) -> URLRequest
-
Do not stub.
Declaration
Swift
final class func neverStub(_: Target) -> Moya.StubBehavior
-
Return a response immediately.
Declaration
Swift
final class func immediatelyStub(_: Target) -> Moya.StubBehavior
-
Return a response after a delay.
Declaration
Swift
final class func delayedStub(_ seconds: TimeInterval) -> (Target) -> Moya.StubBehavior