Latest1.1.0
Homepagehttps://github.com/hooliooo/BFAstral
LicenseMIT
Platformsios 9.3, osx 10.11, tvos 11.0, watchos 4.0, requires ARC
DependenciesAstral, BrightFutures
FrameworksFoundation
Authors

BFAstral is an extension to Astral that uses Futures/Promises to make http networking calls.

BFAstral makes use of the BrightFutures library to flatten the asynchronous calls
associated with networking, making your code base as readable as possible.

CI Status
Version
License
Platform

Requirements

BFAstral requires iOS 9.3 or higher and Swift 3.x

Installation

CocoaPods

  1. Add the following to your Podfile:
pod 'BFAstral'
  1. Integrate your dependencies using frameworks: add use_frameworks! to your Podfile.
  2. Run pod install.

A Simple Example

Here’s an example using the Pokemon API and the implementations of RequestBuilder and BFDispatcher.

Feel free to build and customize your own implementations. Simply adopt the appropriate protocols.

struct PokeAPIConfiguration: RequestConfiguration {

    let scheme: URLScheme = URLScheme.http

    let host: String = "pokeapi.co"

    let basePathComponents: [String] = [
        "api",
        "v2"
    ]

    let baseHeaders: Set<Header> = [
        Header(key: Header.Field.contentType, value: Header.Value.mediaType(MediaType.applicationJSON))
    ]
}
struct PokemonRequest: Request {

    let id: Int

    let configuration: RequestConfiguration = PokeAPIConfiguration()

    let method: HTTPMethod = HTTPMethod.get

    let pathComponents: [String] = [
        "pokemon",
        "(self.id)"
    ]

    let parameters: [String : Any] = [:]

    let headers: Set<Header> = []
}
let queue: DispatchQueue = DispatchQueue(label: "pokeapi", qos: DispatchQoS.utility, attributes: [DispatchQueue.Attributes.concurrent])

let request: Request = PokemonRequest(id: 1)
let dispatcher: BFDispatcher = BFDispatcher()

dispatcher.response(of: request)
    .onSuccess(queue.context) { (response: Response) -> Void in
    // let responseData: Data = response.data
    // Do something with data
    // or
    // let dictionary: [String: Any] = response.json.dictValue
    // Do something with dictionary
    }
    .onFailure(queue.context) { (error: NetworkingError) -> Void in
    // Handle the error
    }
    .onComplete(queue.context) { (result: Result<Data, NetworkingError>) -> Void in
    // Handle the completion of the network request
    // such as clean up of the UI
    }

Latest podspec

{
    "name": "BFAstral",
    "module_name": "BFAstral",
    "version": "1.1.0",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "summary": "An extension to Astral that uses BrightFutures as the abstraction of asynchronous programming",
    "homepage": "https://github.com/hooliooo/BFAstral",
    "authors": {
        "Julio Alorro": "[email protected]"
    },
    "source": {
        "git": "https://github.com/hooliooo/BFAstral.git",
        "tag": "1.1.0"
    },
    "platforms": {
        "ios": "9.3",
        "osx": "10.11",
        "tvos": "11.0",
        "watchos": "4.0"
    },
    "source_files": "Sources/*.swift",
    "requires_arc": true,
    "frameworks": "Foundation",
    "dependencies": {
        "Astral": [],
        "BrightFutures": []
    },
    "swift_version": "4.0"
}

Pin It on Pinterest

Share This