Skip to content

Releases: ishkawa/APIKit

1.0.0 beta3

24 Aug 12:46
Compare
Choose a tag to compare
1.0.0 beta3 Pre-release
Pre-release
  • Support Swift 2 beta 5.
  • Fix URL query encoding issue #59.

1.0.0 beta2

30 Jul 16:38
Compare
Choose a tag to compare
1.0.0 beta2 Pre-release
Pre-release
  • Follow Swift 2 beta 4.

1.0.0 beta1

30 Jun 01:13
Compare
Choose a tag to compare
1.0.0 beta1 Pre-release
Pre-release

Redesign for Swift 2

This release contains significant breaking change.
See the following for how to migrate 0.x to 1.x.

Remove boxing

0.x

let request = SomeRequest()

SomeAPI.sendRequest(request) { result in
    switch result {
    case .Success(let box):
        let response = box.value // response is a T.Response

    case .Faikure(let box):
        let error = box.value    // error is a NSError
    }
}

1.x

let request = SomeRequest()

SomeAPI.sendRequest(request) { result in
    switch result {
    case .Success(let response): // response is a T.Response
    case .Failure(let error):    // error is a NSError
    }
}

Replace URLRequest with method, path and parameters

0.x

struct SearchRepositories: Request {
    var URLRequest: NSURLRequest? {
        return GitHub.URLRequest(
            method: .GET,
            path: "/search/repositories",
            parameters: ["q": query, "sort": sort.rawValue, "order": order.rawValue]
        )
    }

    ...
}

1.x

struct SearchRepositories: GitHubRequest {
    var method: HTTPMethod {
        return .GET
    }

    var path: String {
        return "/search/repositories"
    }

    var parameters: [String: AnyObject] {
        return ["q": query, "sort": sort.rawValue, "order": order.rawValue]
    }

    func configureURLRequest(URLRequest: NSMutableURLRequest) throws -> NSMutableURLRequest {
        // You can add any configurations here
    }

    ...
}

You can omit implementing parameters and configureURLRequest because they have default implementations.

Move properties in API class to Request protocol

In 1.x or later, creating abstract protocol like GitHubRequest is required to provide common configurations
such as baseURL, requestBodyBuilder, responseBodyParser and acceptableStatusCodes.

0.x

class GitHubAPI: API {
    override class var baseURL: NSURL {
        return NSURL(string: "https://api.github.com")!
    }

    override class var requestBodyBuilder: RequestBodyBuilder {
        return .JSON(writingOptions: nil)
    }

    override class var responseBodyParser: ResponseBodyParser {
        return .JSON(readingOptions: nil)
    }

    override class var acceptableStatusCodes: Set<Int> {
        return Set(200..<300)
    }

    override class func responseErrorFromObject(object: AnyObject) -> NSError {
        ...
    }

    ...
}

1.x

protocol GitHubRequest: Request {
    var baseURL: NSURL {
        return NSURL(string: "https://api.github.com")!
    }

    var requestBodyBuilder: RequestBodyBuilder {
        return .JSON(writingOptions: [])
    }

    var responseBodyParser: ResponseBodyParser {
        return .JSON(readingOptions: [])
    }

    var acceptableStatusCodes: Set<Int> {
        return Set(200..<300)
    }

    func errorFromObject(object: AnyObject) -> ErrorType? {
        ...
    }

    ...
}

You can omit implementing requestBodyBuilder, responseBodyParser, acceptableStatusCodes and errorFromObject() because they have default implementations.

Add URLResponse to responseFromObject() and errorFromObject() in Request

0.x

class func responseFromObject(object: AnyObject) -> Response? {
    ...
}
class func responseErrorFromObject(object: AnyObject) -> Response? {
    ...
}

1.x

func responseFromObject(object: AnyObject, URLResponse: NSHTTPURLResponse) -> Response? {
    ...
}
func errorFromObject(object: AnyObject, URLResponse: NSHTTPURLResponse) -> ErrorType? {
    ...
}

Replace Method with HTTPMethod

0.x

public enum Method: String {
    case GET = "GET"
    case POST = "POST"
    ...
}

1.x

public enum HTTPMethod: String {
    case GET = "GET"
    case POST = "POST"
    ...
}

Introdoce APIError

Errors in handler of sendRequest() are now detailed as below:

public enum APIError: ErrorType {
    case ConnectionError(NSError)

    // request error
    case InvalidBaseURL(NSURL)
    case ConfigurationError(ErrorType)
    case RequestBodySerializationError(ErrorType)
    case FailedToCreateURLSessionTask

    // response error
    case UnacceptableStatusCode(Int, ErrorType)
    case ResponseBodyDeserializationError(ErrorType)
    case InvalidResponseStructure(AnyObject)
    case NotHTTPURLResponse(NSURLResponse?)
}

0.8.2

03 Jun 09:18
Compare
Choose a tag to compare
  • Return type of URLRequest(method:path:parameters:requestBodyBuilder) is changed to NSMutableURLRequest. #42

0.8.1

23 May 15:16
Compare
Choose a tag to compare
  • ResponseBodyParser.JSON returns [:] if NSData express empty data. #38

0.8.0

06 May 12:49
Compare
Choose a tag to compare

This release contains 2 large changes

  • class func URLRequest(_:_:_:) is deprecated to improve readability and flexibility.

    • Old: class func URLRequest(_:_:_:)
    • New: class func URLRequest(method:path:parameters:requestBodyBuilder)

    You can use the alternative function like below. The last 2 arguments, parameters and requestBodyBuilder, in new method have default values, so you can omit them.

    var URLRequest: NSURLRequest? {
        return GitHub.URLRequest(
            method: .GET,
            path: "/search/repositories",
            parameters: ["q": query, "sort": sort.rawValue, "order": order.rawValue]
        )
    }
  • LlamaKit is replaced by Result. Interface of Box type is changed due to this dependency replacement.

    • Old: box.unbox
    • New: box.value

0.7.2

05 May 05:30
Compare
Choose a tag to compare
  • Add ad hoc requestBodyBuilder for an individual endpoint. #31

0.7.1

22 Apr 12:49
Compare
Choose a tag to compare
  • API.acceptableStatusCodes is changed to Set<Int>.

0.7.0

17 Apr 16:14
Compare
Choose a tag to compare
  • Swift 1.2 support
  • baseURL, requestBodyBuilder and ResponseBodyParser are changed to class var.
override class var baseURL: NSURL {
    return NSURL(string: "https://api.github.com")!
}

override class var requestBodyBuilder: RequestBodyBuilder {
    return .JSON(writingOptions: nil)
}

override class var responseBodyParser: ResponseBodyParser {
    return .JSON(readingOptions: nil)
}

0.6.0

31 Mar 00:41
Compare
Choose a tag to compare
  • Avoid capturing request object in sendRequest(_:handler:). #20
  • Minor refactoring. #21

Breaking change:

  • Instance method func responseFromObject(_:) is no longer available.
    Use class method class func responseFromObject(_:) instead.