• Stars
    star
    58
  • Rank 516,103 (Top 11 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The Vimeo iOS SDK

VIMNetworking

⚠️⚠️⚠️
This library has been deprecated and will be removed from Github on March 1, 2017. Use VimeoNetworking instead.
⚠️⚠️⚠️

VIMNetworking is an Objective-C library that enables interaction with the Vimeo API. It handles authentication, request submission, and request cancellation. Advanced features include caching and powerful model object parsing.

If you'd like to upload videos check out VimeoUpload.

Setup

CocoaPods

# Add this to your podfile
target 'YourTarget' do
    pod 'VIMNetworking', '{CURRENT_POD_VERSION}'
end

Note that VIMNetworking has dependencies on AFNetworking and VIMObjectMapper. They will be imported as pods.

###Git Submodules

Add VIMNetworking, VIMObjectMapper and AFNetworking (Release 2.5.4) as submodules of your git repository.

git submodule add [email protected]:vimeo/VIMNetworking.git
git submodule add [email protected]:vimeo/VIMObjectMapper.git
git submodule add [email protected]:AFNetworking/AFNetworking.git

Add each submodule's classes to your project / target.

If you're also including VIMUpload in your project / target, note that both VIMUpload and VIMNetworking include the Certificate/digicert-sha2.cer file (this file is used for cert pinning). You'll have to remove one of the digicert-sha2.cer files from your target to avoid a "Multiple build commands for output file..." warning.

Initialization

On app launch, configure VIMSession with your client key, secret, and scope strings. And once initialization is complete, authenticate if necessary.

#import "VIMNetworking.h"

. . .

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    VIMSessionConfiguration *config = [[VIMSessionConfiguration alloc] init];
    config.clientKey = @"your_client_key";
    config.clientSecret = @"your_client_secret";
    config.scope = @"your_scope"; // E.g. "private public upload etc"
    config.keychainService = @"your_service"; 
    config.keychainAccessGroup = @"your_access_group"; // Optional
    
    [VIMSession sharedSession setupWithConfiguration:config];    

    if ([[VIMSession sharedSession].account isAuthenticated] == NO)
    {
        NSLog(@"Authenticate...");
    }
    else
    {
        NSLog(@"Already authenticated!");
    }

    . . .
}

Note that you must specify a value for keychainService and can optionally provide a value for keychainAccessGroup. The role of the latter value is detailed here in the section on Keychain Access Groups.

Authentication

All calls to the Vimeo API must be authenticated. This means that before making requests to the API you must authenticate and obtain an access token. Two authentication methods are provided:

  1. Client credentials grant: This mechanism allows your application to access publicly accessible content on Vimeo.

  2. OAuth authorization code grant: This mechanism allows a Vimeo user to grant permission to your app so that it can access private, user-specific content on their behalf.

Client Credentials Grant

[[VIMSession sharedSession] authenticateWithClientCredentialsGrant:^(NSError *error) {

        if (error == nil)
        {
            NSLog(@"Success!");
        }
        else
        {
            NSLog(@"Failure: %@", error);
        }
        
}];

OAuth Authorization Code Grant

  1. Set up a redirect url scheme:

Navigate to your app target settings > Info > URL Types. Add a new URL Type, and under url scheme enter vimeo{CLIENT_KEY} (ex: if your CLIENT_KEY is 1234, enter vimeo1234). This allows Vimeo to redirect back into your app after authorization.

You also need to add this redirect URL to your app on the Vimeo API site. Under “App Callback URL”, add vimeo{CLIENT_KEY}://auth (for the example above, vimeo1234://auth).

  1. Open the authorization URL in Mobile Safari:
NSURL *URL = [[VIMSession sharedSession].authenticator codeGrantAuthorizationURL];
[[UIApplication sharedApplication] openURL:URL];
  1. Mobile Safari will open and the user will be presented with a webpage asking them to grant access based on the scope that you specified in your VIMSessionConfiguration above.

  2. The user is then redirected back to your application. In your AppDelegate’s URL handling method, pass the URL back to VIMAPIClient to complete the authorization grant:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    [[VIMSession sharedSession] authenticateWithCodeGrantResponseURL:url completionBlock:^(NSError *error) {
        
        if (error == nil)
        {
            NSLog(@"Success!");
        }
        else
        {
            NSLog(@"Failure: %@", error);
        }

    }];
    
    return YES;
}

Requests

With VIMNetworking configured and authenticated, you’re ready to start making requests to the Vimeo API.

JSON Request

[[VIMSession sharedSession].client requestURI:@"/videos/77091919" completionBlock:^(VIMServerResponse *response, NSError *error) {
	
	id JSONObject = response.result;
	NSLog(@"JSONObject: %@", JSONObject);

}];

Model Object Request

VIMRequestDescriptor *descriptor = [[VIMRequestDescriptor alloc] init];
descriptor.urlPath = @"/videos/77091919";
descriptor.modelClass = [VIMVideo class];

[[VIMSession sharedSession].client requestDescriptor:descriptor completionBlock:^(VIMServerResponse *response, NSError *error) {
	
	VIMVideo *video = (VIMVideo *)response.result;
	NSLog(@"VIMVideo object: %@", video);

}];

Collection Request

VIMRequestDescriptor *descriptor = [[VIMRequestDescriptor alloc] init];
descriptor.urlPath = @"/me/videos";
descriptor.modelClass = [VIMVideo class];
descriptor.modelKeyPath = @"data";

[[VIMSession sharedSession].client requestDescriptor:descriptor completionBlock:^(VIMServerResponse *response, NSError *error) {

	NSArray *videos = (NSArray *)response.result; 
	NSLog(@"Array of VIMVideo objects: %@", videos);

}];

Caching Behavior

VIMRequestDescriptor *descriptor = [[VIMRequestDescriptor alloc] init];
descriptor.urlPath = @"/videos/77091919";
descriptor.modelClass = [VIMVideo class];
descriptor.cachePolicy = VIMCachePolicy_NetworkOnly; // Or VIMCachePolicy_LocalOnly etc.
descriptor.shouldCacheResponse = NO; // Defaults to YES

...

// See VIMRequestDescriptor.h/m additional request configuration options

Request Cancellation

id<VIMRequestToken> currentRequest = [[VIMSession sharedSession].client requestURI:@"/videos/77091919" completionBlock:^(VIMServerResponse *response, NSError *error) {

	id JSONObject = response.result;
	NSLog(@"JSONObject: %@", JSONObject);

}];

[[VIMSession sharedSession].client cancelRequest:currentRequest];

// or

[[VIMSession sharedSession].client cancelAllRequests];

Lightweight Use

If you want to use your own OAuth token you can circumvent VIMSession and its authentication mechanisms and make requests like so:

VIMClient *client = [[VIMClient alloc] initWithDefaultBaseURL];
client.requestSerializer = ...

// Where client.requestSerializer is an AFJSONRequestSerializer subclass that sets the following information for each request:
// [serializer setValue:@"application/vnd.vimeo.*+json; version=3.2" forHTTPHeaderField:@"Accept"];
// [serializer setValue:@"Bearer your_oauth_token" forHTTPHeaderField:@"Authorization"];

[client requestURI:@"/videos/77091919" completionBlock:^(VIMServerResponse *response, NSError *error)
{

    id JSONObject = response.result;
    NSLog(@"JSONObject: %@", JSONObject);

}];

Caching

If you'd like to turn on caching for this lighter weight use case:

VIMClient *client = [[VIMClient alloc] initWithDefaultBaseURL];
client.cache = VIMCache *cache = [VIMCache sharedCache];
// Or client.cache = VIMCache *cache = [[VIMCache alloc] initWithName:@"your_cache_name"];

VIMObjectMapper

VIMObjectMapper converts JSON into model objects. If you'd like to use it on its own (by including the raw source in your project, or by including the ObjectMapper subspec, follow the steps below.

Subclass VIMModelObject

Make your custom model object a subclass of VIMModelObject and optionally implement the VIMMappable protocol methods:

#import "VIMModelObject.h"

@class VIMPictureCollection;

@interface VIMUser : VIMModelObject

@property (nonatomic, copy) NSString *name;
@property (nonatomic, strong) VIMPictureCollection *pictureCollection;
@property (nonatomic, strong) NSDictionary *uploadQuota;
@property (nonatomic, strong) NSArray *websites;

@end
#import "VIMUser.h"
#import "VIMPictureCollection.h"
#import "VIMObjectMapper.h"

@implementation VIMUser

#pragma mark - VIMMappable // All methods are optional, implement to specify how the object should be "inflated"

- (NSDictionary *)getObjectMapping
{
return @{@"pictures": @"pictureCollection"};
}

- (Class)getClassForCollectionKey:(NSString *)key
{
if ([key isEqualToString:@"uploadQuota"])
{
return [NSDictionary class];
}

if ([key isEqualToString:@"websites"])
{
return [NSArray class];
}

return nil;
}

- (Class)getClassForObjectKey:(NSString *)key
{
if ([key isEqualToString:@"pictures"])
{
return [VIMPictureCollection class];
}

return nil;
}

- (void)didFinishMapping
{
// Do any post-parsing work you might want to do
}

Get some JSON

{
user = {
name = "Homer Simpson";
pictures = {
uri = "...";
sizes = (...);
};
"upload_quota" = { ... };
websites = ( ... );
};
}

Let VIMObjectMapper go to work

NSDictionary *JSON = ...;

VIMObjectMapper *mapper = [[VIMObjectMapper alloc] init];

[mapper addMappingClass:[VIMUser class] forKeypath:@"user"];

VIMUser *user = [mapper applyMappingToJSON:JSON];

Found an Issue?

Please file it in the git issue tracker.

Want to Contribute?

If you'd like to contribute, please follow our guidelines found in CONTRIBUTING.md.

License

VIMNetworking is available under the MIT license. See the LICENSE file for more info.

Questions?

Tweet at us here: @vimeoapi.

Post on Stackoverflow with the tag vimeo-ios.

Get in touch here.

Interested in working at Vimeo? We're hiring!

More Repositories

1

psalm

A static analysis tool for finding errors in PHP applications
PHP
5,545
star
2

player.js

Interact with and control an embedded Vimeo Player.
JavaScript
1,432
star
3

graph-explorer

A graphite dashboard powered by structured metrics
Python
1,060
star
4

php-mysql-engine

A MySQL engine written in pure PHP
PHP
547
star
5

vimeo.php

Official PHP library for the Vimeo API.
PHP
450
star
6

player-api

Examples for our JavaScript and ActionScript player APIs.
449
star
7

laravel

A Vimeo bridge for Laravel
PHP
397
star
8

stag-java

Speedy Type Adapter Generation
Java
350
star
9

VIMVideoPlayer

Deprecated: Please use [PlayerKit]( https://github.com/vimeo/PlayerKit) instead.
Objective-C
281
star
10

vimeo.js

Official Node.js library for the Vimeo API.
JavaScript
267
star
11

vimeo-oembed-examples

Some examples of how to use our oEmbed endpoint
HTML
237
star
12

vimeo-unity-sdk

Easily stream your Vimeo videos into Unity or record and publish out to Vimeo.
C#
210
star
13

vimeo.py

Official Python library for the Vimeo API.
Python
210
star
14

graphite-influxdb

An influxdb backend for Graphite-web and graphite-api
Python
198
star
15

vimeo-php-lib

Our official PHP library for the Advanced API.
PHP
180
star
16

tailgate

Tailgate is a nodejs app to pipe `tail -F` into websockets. It's a very simple way to have real-time access to your logs.
JavaScript
164
star
17

PlayerKit

Swift
154
star
18

ABLincoln

A library for online experiments.
PHP
152
star
19

py-money

Money class for Python 3
Python
125
star
20

vimeo-networking-java

The Vimeo Java (Android) SDK
Kotlin
121
star
21

vimeo-threejs-player

A plugin for streaming video from Vimeo to WebGL/VR/AR apps
JavaScript
89
star
22

tattletale.js

A utility to send console logs over XHR for server-side processing.
JavaScript
87
star
23

VimeoNetworking

The Vimeo API iOS SDK
Swift
84
star
24

vimeo-depth-player

A WebVR volumetric video renderer that uses color-depth based videos hosted on Vimeo.
JavaScript
83
star
25

aframe-vimeo-component

Stream Vimeo videos into WebVR.
JavaScript
81
star
26

simple-black-box

A simple black-box behavior testing framework
Shell
68
star
27

pentagon

Vault <-> Kubernetes Secrets
Go
60
star
28

libvmod-boltsort

A fast Varnish module for sorting query string parameters.
C
59
star
29

VimeoUpload

The Vimeo iOS Upload SDK
Swift
59
star
30

whisper-to-influxdb

migrate (import) graphite data from whisper to influxdb
Go
58
star
31

smoketcp

Smokeping like tcp connectivity tester, reports to statsd. written in Golang
Go
58
star
32

vimeo-depth-viewer

OpenGL application for viewing depth and color video streams from Intel RealSense cameras
C++
53
star
33

carbon-tagger

native tag-based metrics for graphite/carbon
Go
50
star
34

iris

Vimeo Design System
TypeScript
47
star
35

go-util

Small reusable Go functions.
Go
44
star
36

Blueprint

aka How We Collaborate
42
star
37

graphite-api-influxdb-docker

docker image with graphite-api and graphite-influxdb
Shell
39
star
38

go-magic

Go Bindings for libmagic and an idiomatic API for getting a file's MIME type.
Go
39
star
39

rollup-plugin-bundle-size

A rollup plugin to show the size of the generated bundle(s).
JavaScript
27
star
40

vimeo-maxmsp

Play and manipulate Vimeo videos in Max/MSP and Jitter
Max
24
star
41

dials

Dials is an extensible configuration package for Go.
Go
18
star
42

VIMDeeplink

Simple Objc and Swift wrappers around the Vimeo iOS deeplink API
Swift
17
star
43

openapi

An OpenAPI specification for the Vimeo API.
16
star
44

puppet-diamond

diamond module for puppet
Puppet
15
star
45

nagios-cloudwatch-plugin

AWS CloudWatch check Nagios plugin
Python
14
star
46

elevator

Validate and patch AV1 levels
Rust
13
star
47

puppet-statsd

statsd module for puppet
Puppet
11
star
48

VIMUpload

This library has been deprecated, use VimeoUpload instead
Objective-C
11
star
49

go-hammer

Go
10
star
50

babel-plugin-transform-i18n

A Babel transform plugin to replace strings with their translations.
JavaScript
10
star
51

VIMObjectMapper

An automatic JSON to model object converter
Objective-C
9
star
52

leaderelection

Go
9
star
53

go-clocks

A convenient package providing a Clock abstraction in Go
Go
9
star
54

go-taglog

Based on, and compatible with, the Go standard log package, but also provides additional functionality and features such as tagging.
Go
8
star
55

ios-labs-staffpicks

An iOS Labs sample project
Swift
7
star
56

grouplogger

Go
6
star
57

netstorage

go client for the new Akamai Netstorage http api
Go
6
star
58

zendesk-ticket-history

JavaScript
6
star
59

caps

Go package to read/write popular video caption formats(mostly a port of pycaption)
Go
6
star
60

Uniform

Swift
6
star
61

alog

Another Go Logging Package
Go
5
star
62

vimeo-deeplink-android

A helper library to deep link into the official Vimeo Android App
Java
5
star
63

vimeo-live-player-examples

Example application for using Vimeo Live M3U8 links with third-party players
HTML
5
star
64

graph-explorer-docker

Shell
5
star
65

eslint-config-player

ESLint config for all player team projects.
JavaScript
5
star
66

go-iccjpeg

A small utility package to extract ICC profiles from JPEGs.
Go
4
star
67

graphite-go

Go
4
star
68

go-imgparse

A small go library to efficiently parse the resolution of various image format streams.
Go
4
star
69

go-retry

A small package for doing comprehensive retries.
Go
4
star
70

omnipay-bluesnap

BlueSnap driver for the Omnipay PHP payment processing library
PHP
4
star
71

payment-gateway-logger

PHP
3
star
72

av1stats

An AV1 stream analysis CLI tool
Rust
3
star
73

omnipay-vindicia

Vindicia driver for the Omnipay PHP payment processing library
PHP
3
star
74

genepool

A golang package for building generic workpools in a standardized way
Go
2
star
75

VimeoCommon

1
star
76

k8swatcher

Convenient watching interface for Kubernetes.
Go
1
star
77

policy

1
star