Skip to content

xanbuck/gettyimages-api_dotnet

 
 

Repository files navigation

Getty Images API SDK - .NET

Introduction

This SDK makes using the Getty Images API easy. It handles credential management, makes HTTP requests and is written with a fluent style in mind. The API Documentation is located on Github.

Getting started

Using the Nuget Package

The SDK is published to the public Nuget package repository.

Open the package manager and add the package to your project: Add nuget package reference

Usage

The SDK currently supports:

  • Searching for images
  • Getting image metadata
  • Creating download URLs

Code

The SDK supports async operations, however it can also be used synchonously, such as when running in a console application:

var connect = ConnectSdk.GetConnectSdkWithClientCredentials("my_api_key", "my_api_secret");
var searchResult = connect.Search()
    .Images()
    .Editorial()
    .WithEditorialSegment(EditorialSegment.News)
    .WithPhrase("all vocabulary")
    .WithSortOrder("newest")
    .ExecuteAsync()
    .Result;

foreach (var image in searchResult.images)
{
    Console.WriteLine("Title: {0} \r\nId: {1}", image.title, image.id);
}

Results are returned as dynamic. Visit the API Interactive Documentation to learn more about available parameters and to see what the response object look like.

Building From Source Code

This is only necessary if you would like to contribute to the project. Otherwise, use the Nuget Package

Assumptions

Tests

The API team at Getty Images uses Behavior Driven Development (BDD). We think it's a great way to develop software and want to spread the word. The test project contains scenarios written in the Gherkin language which are bound to code using SpecFlow.

Clone the repository

The Git repository contains a submodule which requires some special handling to get setup properly. This is because we share our scenario files across all our SDKs.

Open a console window (Command Prompt, PowerShell or Bash) and issue the following commands to clone the Git repository:

git clone git@github.com:gettyimages/connect_sdk_csharp.git
pushd connect_sdk_csharp
git submodule update --init

Build using Command Prompt or Powershell

.\build.cmd

Build using Bash

./build.sh

Opening the code in Visual Studio and running tests

Setup environment variables

The tests expect credentials to be stored in environment variables.

  • ConnectSDK_ApiKey: API key assigned when you registered
  • ConnectSDK_ApiSecret: API secret assigned when you registered
  • ConnectSDK_UserName: a Getty Images user. Create one at the Getty Images website.
  • ConnectSDK_UserPassword: Getty Images user's password

Note: If you don't have user account credentials, some of the tests will fail. That's OK!

Once this is complete, you can open the solution in Visual Studio:

  1. Open the ConnectSdk.sln file.
  2. Build the solution.
  3. Tests can be run using:
    • ReSharper Unit Test Explorer
    • NUnit - You may need to install the NUnit Test Adapter
    • Note: Running all tests at once can occasionally result in the error "GettyImages.Connect.OverQpsException : Exception of type 'GettyImages.Connect.OverQpsException' was thrown.". Please run tests individually if you encounter this error and the tests should run properly.

Packages

No packages published

Languages

  • C# 99.0%
  • Shell 1.0%