Skip to content

Commit

Permalink
Merge pull request #67 from inaka/v2.0.1
Browse files Browse the repository at this point in the history
V2.0.1
  • Loading branch information
agerace authored Jun 23, 2016
2 parents 989740b + e8a3c13 commit 8d2f67e
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 20 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ All notable changes to this project will be documented in this file. `Jayme` a

### 2.x Releases

- `2.0.x` Releases - [2.0.0](#200)
- `2.0.x` Releases - [2.0.0](#200) | [2.0.1](#201)

### 1.x Releases

- `1.0.x` Releases - [1.0.1](#101) | [1.0.2](#102) | [1.0.3](#103) | [1.0.4](#104)

---

## 2.0.1

- `create(...)` function in `CRUDRepository` no longer attaches the `:id` parameter in its `POST` URL. (Issue [#63](https://github.com/inaka/Jayme/issues/63))
- Results from repositories are now returned on the main thread. (Issue [#55](https://github.com/inaka/Jayme/issues/55))
- Added `PATCH` verb in `HTTPMethodName` enumeration. (Issue [#57](https://github.com/inaka/Jayme/issues/57))

## 2.0.0

#### Repository related changes
Expand Down
3 changes: 3 additions & 0 deletions Documentation/Jayme 2.0 Migration Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ They are listed below:
- `self.parseDataAsDictionary(…)``DataParser().dictionaryFromData(…)`
- `self.parseEntitiesFromArray(…)``EntityParser().entitiesFromDictionaries(…)`
- `self.parseEntityFromDictionary(…)``EntityParser().entityFromDictionary(…)`
- Results from Repositories using `NSURLBackend` (ex `ServerBackend`) are now returned on the main thread, instead of on a background thread.
- This will not break your existing code, but it's strongly recommended that you remove any possible `dispatch_async(dispatch_get_main_queue()) { ... }` call that you could have performed within your ViewControllers when getting results back from any repository. These calls are unnecessary now.


---

Expand Down
4 changes: 1 addition & 3 deletions Example/UserDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ class UserDetailViewController: UIViewController {
switch result {
case .Success(let posts):
self.posts = posts
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}
self.tableView.reloadData()
case .Failure(let error):
self.showAlertControllerForError(error)
}
Expand Down
4 changes: 1 addition & 3 deletions Example/UsersViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class UsersViewController: UIViewController {
switch result {
case .Success(let users):
self.users = users
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}
self.tableView.reloadData()
case .Failure(let error):
self.showAlertControllerForError(error)
}
Expand Down
2 changes: 1 addition & 1 deletion Jayme.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = "Jayme"
s.version = "2.0.0"
s.version = "2.0.1"
s.summary = "Abstraction layer that eases RESTful interconnections in Swift"
s.description = <<-DESC
What's the best place to put your entities business logic code? What's the best place to put your networking code? Jayme answers those two existencial questions by defining a straightforward and extendable architecture based on Repositories and Backends. It provides a neat API to deal with REST communication, leaving your ViewControllers out of that business by abstracting all that logic, thereby allowing them to focus on what they should do rather than on how they should connect to services.
Expand Down
2 changes: 1 addition & 1 deletion Jayme/CRUDRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public extension CRUDRepository {

/// Creates the entity in the repository. Returns a `Future` with the created entity or a `JaymeError`
public func create(entity: EntityType) -> Future<EntityType, JaymeError> {
let path = self.pathForID(entity.id)
let path = self.name
return self.backend.futureForPath(path, method: .POST, parameters: entity.dictionaryValue)
.andThen { DataParser().dictionaryFromData($0.0) }
.andThen { EntityParser().entityFromDictionary($0) }
Expand Down
5 changes: 5 additions & 0 deletions Jayme/HTTPHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ import Foundation
public struct HTTPHeader {
public let field: String
public let value: String

public init(field: String, value: String) {
self.field = field
self.value = value
}
}
2 changes: 1 addition & 1 deletion Jayme/HTTPMethodName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ import Foundation

/// Discrete enumeration of possible HTTP methods
public enum HTTPMethodName: String {
case POST, GET, PUT, DELETE
case POST, GET, PUT, PATCH, DELETE
}
16 changes: 9 additions & 7 deletions Jayme/NSURLSessionBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ public class NSURLSessionBackend: Backend {
let task = self.session.dataTaskWithRequest(request) { data, response, error in
let response: FullHTTPResponse = (data, response, error)
let result = self.responseParser.parseResponse(response)
switch result {
case .Success(let maybeData, let pageInfo):
Logger.sharedLogger.log("Jayme: Response #\(requestNumber) | Success")
completion(.Success(maybeData, pageInfo))
case .Failure(let error):
Logger.sharedLogger.log("Jayme: Response #\(requestNumber) | Failure, error: \(error)")
completion(.Failure(error))
dispatch_async(dispatch_get_main_queue()) {
switch result {
case .Success(let maybeData, let pageInfo):
Logger.sharedLogger.log("Jayme: Response #\(requestNumber) | Success")
completion(.Success(maybeData, pageInfo))
case .Failure(let error):
Logger.sharedLogger.log("Jayme: Response #\(requestNumber) | Failure, error: \(error)")
completion(.Failure(error))
}
}
}
task.resume()
Expand Down
9 changes: 7 additions & 2 deletions Jayme/NSURLSessionBackendConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ import Foundation
/// Structure used for holding relevant information that NSURLSessionBackend needs in order to work.
public struct NSURLSessionBackendConfiguration {

let basePath: Path
let httpHeaders: [HTTPHeader]
public let basePath: Path
public let httpHeaders: [HTTPHeader]

public static var defaultConfiguration = NSURLSessionBackendConfiguration(basePath: "http://localhost:8080",
httpHeaders: NSURLSessionBackendConfiguration.defaultHTTPHeaders)

public init(basePath: Path, httpHeaders: [HTTPHeader]) {
self.basePath = basePath
self.httpHeaders = httpHeaders
}

// MARK: - Private

private static var defaultHTTPHeaders = [HTTPHeader(field: "Accept", value: "application/json"),
Expand Down
2 changes: 1 addition & 1 deletion JaymeTests/CRUDRepositoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension CRUDRepositoryTests {
func testCreateCall() {
let document = TestDocument(id: "123", name: "a")
self.repository.create(document)
XCTAssertEqual(self.backend.path, "documents/123")
XCTAssertEqual(self.backend.path, "documents")
XCTAssertEqual(self.backend.method, .POST)
guard let
id = self.backend.parameters?["id"] as? String,
Expand Down

0 comments on commit 8d2f67e

Please sign in to comment.