Skip to content

Commit

Permalink
Updated to version 1.0.4 Fixed rate limit validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrián Bouza Correa committed Jun 7, 2018
1 parent d869d10 commit b0c209e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# UNSPLASHER SDK
![build](https://img.shields.io/badge/build-passing-green.svg) ![platform](https://img.shields.io/badge/platform-iOS%209.0%2B-lightgrey.svg) ![platform](https://img.shields.io/badge/xcode-9.0%2B-lightgrey.svg) ![swift version](https://img.shields.io/badge/swift-4.1-orange.svg) ![cocoapods](https://img.shields.io/badge/pod-v1.0.3-blue.svg)

![build](https://img.shields.io/badge/build-passing-green.svg)
![platform](https://img.shields.io/badge/platform-iOS%209.0%2B-lightgrey.svg)
![platform](https://img.shields.io/badge/xcode-9.0%2B-lightgrey.svg)
![swift version](https://img.shields.io/badge/swift-4.1-orange.svg)
[![cocoapods](https://img.shields.io/cocoapods/v/UnsplasherSDK.svg?style=flat)](https://cocoapods.org/pods/UnsplasherSDK)
[![license](https://img.shields.io/cocoapods/l/KeyboardSwift.svg?style=flat)](https://cocoapods.org/pods/KeyboardSwift)

An Unsplash API client written in Swift. It supports user authentication, likes, manage collections and every feature of the [official API](https://unsplash.com/documentation).

Expand Down
2 changes: 1 addition & 1 deletion Unsplasher/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.3</string>
<string>1.0.4</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
8 changes: 4 additions & 4 deletions Unsplasher/Unsplash/Requests/Requests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,17 @@ extension Unsplash {
completion(.failure(UnsplashError.credentialsError))
return
}
if let remaining = self.rateLimitRemaining, let limit = self.rateLimit, remaining <= 0 {
completion(.failure(UnsplashError.rateLimitError(limit)))
return
}
Alamofire.request(url, method: method, parameters: parameters, encoding: URLEncoding.queryString, headers: includeHeaders ? headers(authenticationNeeded: isAuthenticated) : nil)
.validate(statusCode: 200..<300)
.responseJSON { (response) in
if let rateString = response.response?.allHeaderFields["x-ratelimit-limit"] as? String,
let rateRemainingString = response.response?.allHeaderFields["x-ratelimit-remaining"] as? String {
self.rateLimit = UInt32(rateString)
self.rateLimitRemaining = UInt32(rateRemainingString)
if let remaining = self.rateLimitRemaining, let limit = self.rateLimit, remaining <= 0 {
completion(.failure(UnsplashError.rateLimitError(limit)))
return
}
}
if let linkString = response.response?.allHeaderFields["Link"] as? String {
self.retrieveLinks(from: linkString)
Expand Down

0 comments on commit b0c209e

Please sign in to comment.