Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #162 from vimeo/release/2.1.0
Browse files Browse the repository at this point in the history
Release/2.1.0
  • Loading branch information
wilrnh authored Jun 28, 2017
2 parents dc65878 + f505227 commit 4faa513
Show file tree
Hide file tree
Showing 33 changed files with 1,274 additions and 187 deletions.
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ DEPENDENCIES:

EXTERNAL SOURCES:
VimeoNetworking:
:path: ../VimeoNetworking
:path: "../VimeoNetworking"

SPEC CHECKSUMS:
AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67
VimeoNetworking: 17f8d451e4a168044f619315d0cd821669676e67

PODFILE CHECKSUM: a8a935f97d6d50906dbff286cd02db46fdd6f52c
PODFILE CHECKSUM: 1effa997066c11f594672c4411d368973a769d6f

COCOAPODS: 1.1.1
4 changes: 2 additions & 2 deletions Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

228 changes: 114 additions & 114 deletions Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion VimeoNetworking/Sources/AppConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public struct AppConfiguration
let keychainAccessGroup: String?

public let apiVersion: String
public let baseUrl: URL

/**
Create a new `AppConfiguration`
Expand All @@ -49,6 +50,7 @@ public struct AppConfiguration
- parameter keychainService: Identifes your application to the system keychain, defaults to `KeychainServiceVimeo`
- parameter keychainAccessGroup: Access group your application should use for the system keychain, defaults to nil
- parameter apiVersion: API version your requests should use, defaults to `VimeoDefaultAPIVersionString`
- parameter baseUrl: The baseUrl for HTTP requests made using this configuration, defaults to `VimeoBaseURL`

- returns: an initialized AppConfiguration
*/
Expand All @@ -57,13 +59,15 @@ public struct AppConfiguration
scopes: [Scope],
keychainService: String,
keychainAccessGroup: String? = nil,
apiVersion: String = VimeoDefaultAPIVersionString)
apiVersion: String = VimeoDefaultAPIVersionString,
baseUrl: URL = VimeoBaseURL)
{
self.clientIdentifier = clientIdentifier
self.clientSecret = clientSecret
self.scopes = scopes
self.keychainService = keychainService
self.keychainAccessGroup = keychainAccessGroup
self.apiVersion = apiVersion
self.baseUrl = baseUrl
}
}
16 changes: 6 additions & 10 deletions VimeoNetworking/Sources/AuthenticationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ final public class AuthenticationController

- returns: a new `AuthenticationController`
*/
public init(client: VimeoClient)
public init(client: VimeoClient, appConfiguration: AppConfiguration)
{
self.configuration = client.configuration
self.configuration = appConfiguration
self.client = client
self.accountStore = AccountStore(configuration: client.configuration)
self.accountStore = AccountStore(configuration: configuration)

self.authenticatorClient = VimeoClient(appConfiguration: client.configuration)
self.authenticatorClient = VimeoClient(appConfiguration: configuration)
}

// MARK: - Public Saved Accounts
Expand Down Expand Up @@ -194,11 +194,7 @@ final public class AuthenticationController
Constants.ScopeKey: Scope.combine(self.configuration.scopes),
Constants.StateKey: type(of: self).state]

guard let urlString = VimeoBaseURLString?.appendingPathComponent(Constants.CodeGrantAuthorizationPath).absoluteString
else
{
fatalError("Could not make code grant auth URL")
}
let urlString = self.configuration.baseUrl.appendingPathComponent(Constants.CodeGrantAuthorizationPath).absoluteString

var error: NSError?
let urlRequest = VimeoRequestSerializer(appConfiguration: self.configuration).request(withMethod: VimeoClient.Method.GET.rawValue, urlString: urlString, parameters: parameters, error: &error)
Expand Down Expand Up @@ -263,7 +259,7 @@ final public class AuthenticationController
*/
public func accessToken(token: String, completion: @escaping AuthenticationCompletion)
{
let customSessionManager = VimeoSessionManager.defaultSessionManager(accessTokenProvider: {token})
let customSessionManager = VimeoSessionManager.defaultSessionManager(baseUrl: self.configuration.baseUrl, accessTokenProvider: {token})
let adhocClient = VimeoClient(appConfiguration: self.configuration, sessionManager: customSessionManager)
let request = AuthenticationRequest.verifyAccessTokenRequest()

Expand Down
2 changes: 1 addition & 1 deletion VimeoNetworking/Sources/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import Foundation

/// Base URL for the Vimeo API
public let VimeoBaseURLString = URL(string: "https://api.vimeo.com")
public let VimeoBaseURL = URL(string: "https://api.vimeo.com")!

/// Default API version to use for requests
internal let VimeoDefaultAPIVersionString = "3.2"
11 changes: 8 additions & 3 deletions VimeoNetworking/Sources/Models/VIMModelObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ + (NSUInteger)modelVersion

+ (NSDateFormatter *)dateFormatter
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZZ";
static NSDateFormatter *dateFormatter;
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{
dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZZ";
});

return dateFormatter;
}
Expand Down
2 changes: 1 addition & 1 deletion VimeoNetworking/Sources/Models/VIMUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ typedef NS_ENUM(NSInteger, VIMUserAccountType)
- (nullable VIMNotificationsConnection *)notificationsConnection;
- (nullable VIMInteraction *)interactionWithName:(nonnull NSString *)name;

- (BOOL)hasCopyrightMatch;
- (BOOL)isFollowing;
- (BOOL)hasModeratedChannels;

- (nullable NSString *)accountTypeAnalyticsIdentifier;
- (BOOL)hasSameBadgeCount:(nullable VIMUser *)newUser;
Expand Down
12 changes: 6 additions & 6 deletions VimeoNetworking/Sources/Models/VIMUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,18 @@ - (void)formatModifiedTime

#pragma mark - Helpers

- (BOOL)hasCopyrightMatch
{
VIMConnection *connection = [self connectionWithName:VIMConnectionNameViolations];
return (connection && connection.total.intValue > 0);
}

- (BOOL)isFollowing
{
VIMInteraction *interaction = [self interactionWithName:VIMInteractionNameFollow];
return (interaction && interaction.added.boolValue);
}

- (BOOL)hasModeratedChannels
{
VIMConnection *connection = [self connectionWithName:VIMConnectionNameModeratedChannels];
return (connection && connection.total.intValue > 0);
}

- (NSString *)accountTypeAnalyticsIdentifier
{
switch (self.accountType)
Expand Down
2 changes: 0 additions & 2 deletions VimeoNetworking/Sources/Models/VIMVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,10 @@ - (Class)getClassForObjectKey:(NSString *)key
return [VIMVideoPlayRepresentation class];
}

#if TARGET_OS_TV
if ([key isEqualToString:@"badge"])
{
return [VIMBadge class];
}
#endif

if ([key isEqualToString:@"spatial"])
{
Expand Down
2 changes: 1 addition & 1 deletion VimeoNetworking/Sources/Objc_ExceptionCatcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// THE SOFTWARE.
//

#import "ObjC_ExceptionCatcher.h"
#import "Objc_ExceptionCatcher.h"

@implementation ObjC_ExceptionCatcher

Expand Down
9 changes: 3 additions & 6 deletions VimeoNetworking/Sources/Request+Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ public extension Request
/// Generates a unique cache key for a request, taking into account endpoint and parameters
var cacheKey: String
{
var cacheKey = "cached" + self.path

if let description = (self.parameters as? CustomStringConvertible)?.description
{
cacheKey = cacheKey + "." + String(description.hashValue)
}
let url = NSURL(string: self.path)
let urlPath = url?.path ?? ""

var cacheKey = "cached" + urlPath + "." + String(self.path.hashValue)
cacheKey = cacheKey.replacingOccurrences(of: "/", with: ".")

return cacheKey
Expand Down
25 changes: 21 additions & 4 deletions VimeoNetworking/Sources/ResponseCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,22 @@ private protocol Cache
/// Response cache handles the storage of JSON response dictionaries indexed by their associated `Request`. It contains both memory and disk caching functionality
final internal class ResponseCache
{
struct Constant
private struct Constant
{
static let CacheDirectory = "com.vimeo.Caches"
}

/**
Initializer

- parameter cacheDirectory: the directory name where the cache files will be stored. Defaults to com.vimeo.Caches.
*/
init(cacheDirectory: String = Constant.CacheDirectory)
{
self.memoryCache = ResponseMemoryCache()
self.diskCache = ResponseDiskCache(cacheDirectory: cacheDirectory)
}

/**
Stores a response dictionary for a request.

Expand Down Expand Up @@ -109,7 +120,7 @@ final internal class ResponseCache

// MARK: - Memory Cache

private let memoryCache = ResponseMemoryCache()
private let memoryCache: ResponseMemoryCache

private class ResponseMemoryCache: Cache
{
Expand Down Expand Up @@ -140,11 +151,17 @@ final internal class ResponseCache

// MARK: - Disk Cache

private let diskCache = ResponseDiskCache()
private let diskCache: ResponseDiskCache

private class ResponseDiskCache: Cache
{
private let queue = DispatchQueue(label: "com.vimeo.VIMCache.diskQueue", attributes: DispatchQueue.Attributes.concurrent)
private let cacheDirectory: String

init(cacheDirectory: String)
{
self.cacheDirectory = cacheDirectory
}

func setResponseDictionary(_ responseDictionary: VimeoClient.ResponseDictionary, forKey key: String)
{
Expand Down Expand Up @@ -291,7 +308,7 @@ final internal class ResponseCache
}

// We need to create a directory in `../Library/Caches folder`. Otherwise, trying to remove the Apple /Caches folder will always fail. Note that it's noticeable while testing on a device.
return URL(fileURLWithPath: directory).appendingPathComponent(Constant.CacheDirectory, isDirectory: true)
return URL(fileURLWithPath: directory).appendingPathComponent(self.cacheDirectory, isDirectory: true)
}

private func fileURL(forKey key: String) -> URL?
Expand Down
65 changes: 50 additions & 15 deletions VimeoNetworking/Sources/VimeoClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ final public class VimeoClient
// MARK: -

/// Session manager handles the http session data tasks and request/response serialization
private let sessionManager: VimeoSessionManager
fileprivate var sessionManager: VimeoSessionManager? = nil

/// response cache handles all memory and disk caching of response dictionaries
private let responseCache = ResponseCache()
Expand Down Expand Up @@ -119,18 +119,22 @@ final public class VimeoClient
self.init(appConfiguration: appConfiguration, sessionManager: VimeoSessionManager.defaultSessionManager(appConfiguration: appConfiguration))
}

public init(appConfiguration: AppConfiguration, sessionManager: VimeoSessionManager)
public init(appConfiguration: AppConfiguration?, sessionManager: VimeoSessionManager?)
{
self.configuration = appConfiguration
self.sessionManager = sessionManager

VimeoReachability.beginPostingReachabilityChangeNotifications()
if let appConfiguration = appConfiguration,
let sessionManager = sessionManager
{
self.configuration = appConfiguration
self.sessionManager = sessionManager

VimeoReachability.beginPostingReachabilityChangeNotifications()
}
}

// MARK: - Configuration

/// The client's configuration, as set on initialization
public let configuration: AppConfiguration
/// The client's configuration
public fileprivate(set) var configuration: AppConfiguration? = nil

// MARK: - Authentication

Expand All @@ -141,11 +145,11 @@ final public class VimeoClient
{
if let authenticatedAccount = self.currentAccount
{
self.sessionManager.clientDidAuthenticate(with: authenticatedAccount)
self.sessionManager?.clientDidAuthenticate(with: authenticatedAccount)
}
else
{
self.sessionManager.clientDidClearAccount()
self.sessionManager?.clientDidClearAccount()
}

self.notifyObserversAccountChanged(forAccount: self.currentAccount, previousAccount: oldValue)
Expand Down Expand Up @@ -263,15 +267,15 @@ final public class VimeoClient
switch request.method
{
case .GET:
task = self.sessionManager.get(path, parameters: parameters, progress: nil, success: success, failure: failure)
task = self.sessionManager?.get(path, parameters: parameters, progress: nil, success: success, failure: failure)
case .POST:
task = self.sessionManager.post(path, parameters: parameters, progress: nil, success: success, failure: failure)
task = self.sessionManager?.post(path, parameters: parameters, progress: nil, success: success, failure: failure)
case .PUT:
task = self.sessionManager.put(path, parameters: parameters, success: success, failure: failure)
task = self.sessionManager?.put(path, parameters: parameters, success: success, failure: failure)
case .PATCH:
task = self.sessionManager.patch(path, parameters: parameters, success: success, failure: failure)
task = self.sessionManager?.patch(path, parameters: parameters, success: success, failure: failure)
case .DELETE:
task = self.sessionManager.delete(path, parameters: parameters, success: success, failure: failure)
task = self.sessionManager?.delete(path, parameters: parameters, success: success, failure: failure)
}

guard let requestTask = task else
Expand Down Expand Up @@ -482,3 +486,34 @@ final public class VimeoClient
}
}


extension VimeoClient
{
/// Singleton instance for VimeoClient. Applications must call configureSharedClient(withAppConfiguration appConfiguration:)
/// before it can be accessed.
public static var sharedClient: VimeoClient
{
guard let _ = self._sharedClient.configuration,
let _ = self._sharedClient.sessionManager else
{
assertionFailure("VimeoClient.sharedClient must be configured before accessing")
return self._sharedClient
}

return self._sharedClient
}
private static let _sharedClient = VimeoClient(appConfiguration: nil, sessionManager: nil)

/// Configures the singleton sharedClient instance. This function allows applications to provide
/// client specific app configurations at start time.
///
/// - Parameters:
/// - appConfiguration: An AppConfiguration instance
public static func configureSharedClient(withAppConfiguration appConfiguration: AppConfiguration)
{
self._sharedClient.configuration = appConfiguration
self._sharedClient.sessionManager = VimeoSessionManager.defaultSessionManager(appConfiguration: appConfiguration)

VimeoReachability.beginPostingReachabilityChangeNotifications()
}
}
Loading

0 comments on commit 4faa513

Please sign in to comment.