Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
ishkawa committed Feb 18, 2015
1 parent 64297f6 commit 3a95c49
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ protocol set for building type safe web API client in Swift.

## Example

### Sending request

```swift
// parameters of request are validated by type system of Swift
let request = GitHub.Request.SearchRepositories(query: "APIKit", sort: .Stars)
Expand All @@ -28,6 +30,54 @@ GitHub.sendRequest(request) { response in
}
```

### Defining request

```swift
// https://developer.github.com/v3/search/#search-repositories
class SearchRepositories: APIKit.Request {
enum Sort: String {
case Stars = "stars"
case Forks = "forks"
case Updated = "updated"
}

enum Order: String {
case Ascending = "asc"
case Descending = "desc"
}

typealias Response = [Repository]

let query: String
let sort: Sort
let order: Order

var URLRequest: NSURLRequest {
return GitHub.URLRequest(.GET, "/search/repositories", ["q": query, "sort": sort.rawValue, "order": order.rawValue])
}

init(query: String, sort: Sort = .Stars, order: Order = .Ascending) {
self.query = query
self.sort = sort
self.order = order
}

func responseFromObject(object: AnyObject) -> Response? {
var repositories = [Repository]()

if let dictionaries = object["items"] as? [NSDictionary] {
for dictionary in dictionaries {
if let repository = Repository(dictionary: dictionary) {
repositories.append(repository)
}
}
}

return repositories
}
}
```

See [GitHub](https://github.com/ishkawa/APIKit/blob/master/DemoApp/GitHub.swift) and [GitHubRequests](https://github.com/ishkawa/APIKit/blob/master/DemoApp/GitHubRequests.swift) for more details.

## License
Expand Down

0 comments on commit 3a95c49

Please sign in to comment.