|
| 1 | +# Getty Images API Ruby SDK |
| 2 | + |
| 3 | +## This codebase has ben retired as of 2025-04-11 |
| 4 | + |
| 5 | +_The project has been archived and no new releases will be made. That means no |
| 6 | +new features, no security updates and no bug fixes._ |
| 7 | + |
| 8 | +## Introduction |
| 9 | +This SDK makes using the Getty Images [API](http://developers.gettyimages.com) easy. It handles credential management, makes HTTP requests and is written with a fluent style in mind. For more info about the API, see the [Documentation](https://developers.gettyimages.com/api/). |
| 10 | + |
| 11 | +* Search for images and videos from our extensive creative and editorial catalogs. |
| 12 | +* Get image and video metadata. |
| 13 | +* Download files using your Getty Images products (e.g., Editorial subscriptions, Easy Access, Thinkstock Subscriptions, and Image Packs). |
| 14 | +* Custom Request functionality that allows user to call any endpoint. |
| 15 | + |
| 16 | +## Help & Support |
| 17 | + |
| 18 | +* [Getty Images API](http://developers.gettyimages.com/) |
| 19 | +* [Issue Tracker](https://github.com/gettyimages/gettyimages-api_ruby/issues) |
| 20 | + |
| 21 | +## Getting started |
| 22 | + |
| 23 | +### Obtain an API Key |
| 24 | + |
| 25 | +If you don't already have an API key, fill out and submit the [contact form](http://engage.gettyimages.com/api-contact) to be connected to our Sales team. |
| 26 | + |
| 27 | +### Installing the ruby gem package |
| 28 | + |
| 29 | +The SDK is available as a [ruby gem](https://rubygems.org/gems/gettyimages-api) package. Install in your workspace with: |
| 30 | +```sh |
| 31 | +gem install gettyimages-api |
| 32 | +``` |
| 33 | + |
| 34 | +## Examples |
| 35 | + |
| 36 | +### Search for one or more images |
| 37 | + |
| 38 | +```ruby |
| 39 | +require 'gettyimages-api' |
| 40 | + |
| 41 | +api_key = "API Key" |
| 42 | +api_secret = "API Secret" |
| 43 | + |
| 44 | +# create instance of the SDK |
| 45 | +apiClient = ApiClient.new(api_key, api_secret) |
| 46 | +result = apiClient |
| 47 | + .search_images_creative() |
| 48 | + .with_phrase("gorilla") |
| 49 | + .with_fields(["artist", "id", "title"]) |
| 50 | + .with_exclude_nudity("true") |
| 51 | + .with_page(2) |
| 52 | + .with_page_size(5) |
| 53 | + .execute() |
| 54 | + |
| 55 | +result["images"].each do | image | |
| 56 | + puts "Id: #{image["id"]} Title: #{image["title"]}" |
| 57 | +end |
| 58 | +``` |
| 59 | + |
| 60 | +### Get detailed information for one image |
| 61 | + |
| 62 | +```ruby |
| 63 | +require 'gettyimages-api' |
| 64 | + |
| 65 | +api_key = "API Key" |
| 66 | +api_secret = "API Secret" |
| 67 | + |
| 68 | +# create instance of the SDK |
| 69 | +apiClient = ApiClient.new(api_key, api_secret) |
| 70 | +result = apiClient |
| 71 | + .images() |
| 72 | + .with_id("ASSET_ID") |
| 73 | + .execute() |
| 74 | + |
| 75 | +puts result |
| 76 | +``` |
| 77 | + |
| 78 | +### Get detailed information for multiple images |
| 79 | + |
| 80 | +```ruby |
| 81 | +require 'gettyimages-api' |
| 82 | + |
| 83 | +api_key = "API Key" |
| 84 | +api_secret = "API Secret" |
| 85 | + |
| 86 | +# create instance of the SDK |
| 87 | +apiClient = ApiClient.new(api_key, api_secret) |
| 88 | +result = apiClient |
| 89 | + .images() |
| 90 | + .with_ids(["ASSET_ID_1", "ASSET_ID_2"]) |
| 91 | + .execute() |
| 92 | + |
| 93 | +result["images"].each do | image | |
| 94 | + puts image |
| 95 | +end |
| 96 | +``` |
| 97 | + |
| 98 | +### Download an image |
| 99 | + |
| 100 | +```ruby |
| 101 | +require 'gettyimages-api' |
| 102 | + |
| 103 | +api_key = "API Key" |
| 104 | +api_secret = "API Secret" |
| 105 | + |
| 106 | +# create instance of the SDK |
| 107 | +apiClient = ApiClient.new(api_key, api_secret) |
| 108 | +result = apiClient |
| 109 | + .download_images() |
| 110 | + .with_id("ASSET_ID") |
| 111 | + .execute() |
| 112 | + |
| 113 | +puts result["uri"] |
| 114 | +``` |
| 115 | + |
| 116 | +### Make a request using custom parameter and header |
| 117 | + |
| 118 | +```ruby |
| 119 | +apiClient = ApiClient.new(api_key, api_secret) |
| 120 | +result = apiClient |
| 121 | + .search_images_creative() |
| 122 | + .with_phrase("beach") |
| 123 | + .with_custom_parameter("safe_search", "true") |
| 124 | + .with_custom_header("gi-country-code", "CAN") |
| 125 | + .execute() |
| 126 | +``` |
| 127 | + |
| 128 | +### Use the custom request functionality for GET request with query parameters |
| 129 | + |
| 130 | +```ruby |
| 131 | +require 'gettyimages-api' |
| 132 | + |
| 133 | +api_key = "API Key" |
| 134 | +api_secret = "API Secret" |
| 135 | + |
| 136 | +# create instance of the SDK |
| 137 | +apiClient = ApiClient.new(api_key, api_secret) |
| 138 | +result = apiClient |
| 139 | + .custom_request() |
| 140 | + .with_method("GET") |
| 141 | + .with_route("search/images") |
| 142 | + .with_query_parameters({"phrase"=> "cat", "fields"=> ["artist", "id", "title"], "page" => 2}) |
| 143 | + .execute() |
| 144 | + |
| 145 | +result["images"].each do | image | |
| 146 | + puts "Id: #{image["id"]} Title: #{image["title"]}" |
| 147 | +end |
| 148 | +``` |
| 149 | + |
| 150 | +### Use the custom request functionality for POST request with body |
| 151 | + |
| 152 | +```ruby |
| 153 | +require 'gettyimages-api' |
| 154 | + |
| 155 | +api_key = "API Key" |
| 156 | +api_secret = "API Secret" |
| 157 | + |
| 158 | +# create instance of the SDK |
| 159 | +apiClient = ApiClient.new(api_key, api_secret) |
| 160 | +result = apiClient |
| 161 | + .custom_request() |
| 162 | + .with_method("POST") |
| 163 | + .with_route("boards") |
| 164 | + .with_body({"name"=> "Board Name", "description" => "Board Description"}) |
| 165 | + .execute() |
| 166 | + |
| 167 | +puts result["id"] |
| 168 | +``` |
| 169 | +## Running Source Code |
| 170 | +_Source code is only needed if you would like to contribute to the project. Otherwise, use the [ruby gem](https://rubygems.org/gems/gettyimages-api)_ |
| 171 | + |
| 172 | +### Requirements |
| 173 | + |
| 174 | +- Ruby version >= 3.0 |
| 175 | +- [Bundler](http://bundler.io) |
| 176 | + |
| 177 | +Install bundler and all dependencies |
| 178 | + |
| 179 | +```sh |
| 180 | +gem install bundler |
| 181 | +bundle install |
| 182 | +``` |
| 183 | + |
| 184 | +### Unit Tests |
| 185 | + |
| 186 | +To execute all unit tests: |
| 187 | + |
| 188 | +```sh |
| 189 | +rake |
| 190 | +``` |
| 191 | + |
| 192 | +To run one unit test file: |
| 193 | + |
| 194 | +```sh |
| 195 | +ruby unit_tests/FILENAME.rb |
| 196 | +``` |
0 commit comments