Class: Animoto::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/animoto/client.rb

Constant Summary collapse

API_ENDPOINT =

The default endpoint where requests go.

"https://platform-sandbox.animoto.com/"
API_VERSION =

The version of the Animoto API this client targets.

1
BASE_CONTENT_TYPE =

The common prefix all vendor-specific Animoto content types share.

"application/vnd.animoto"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Client

Creates a new Client object which handles credentials, versioning, making requests, and parsing responses.

If you have your key and secret in ~/.animotorc or /etc/.animotorc, those credentials will be read from those files (in that order) whenever you make a new Client if you don’t specify them explicitly. You can also specify the endpoint (staging, sandbox, etc.) in the rc file. The default endpoint will be used if one isn’t specified.

Parameters:

  • key (String)

    the API key for your account

  • secret (String)

    the secret key for your account

Raises:

  • (ArgumentError)

    if no credentials are supplied



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/animoto/client.rb', line 111

def initialize *args
  options = args.last.is_a?(Hash) ? args.pop : {}
  @key      = args[0]
  @secret   = args[1]
  @endpoint = options[:endpoint]
  @logger   = options[:logger] || ::Logger.new(STDOUT)
  configure_from_rc_file
  @endpoint ||= API_ENDPOINT
  self.http_engine = options[:http_engine] || :net_http
  self.response_parser= options[:response_parser] || :json
end

Instance Attribute Details

#endpointString

The base URL where all requests will be sent.

Returns:

  • (String)


60
61
62
# File 'lib/animoto/client.rb', line 60

def endpoint
  @endpoint
end

#http_engineHTTPEngines::Base #http_engine=(engine) ⇒ HTTPEngines::Base

The engine to handle HTTP requests.

Overloads:

  • #http_engineHTTPEngines::Base

    Returns the HTTP engine.

    Returns:

  • #http_engine=(engine) ⇒ HTTPEngines::Base

    Sets the HTTP engine.

    Parameters:

    • engine (HTTPEngines::Base, Symbol, Class)

      you may pass a HTTPEngine instance to use, or the symbolic name of an adapter to use, or a Class whose instances respond to #request and return a String of the response body

    Returns:

    Raises:

    • (ArgumentError)

      if given a class without the correct interface

    See Also:

Returns:



81
82
83
# File 'lib/animoto/client.rb', line 81

def http_engine
  @http_engine
end

#keyString

Your API key.

Returns:

  • (String)


52
53
54
# File 'lib/animoto/client.rb', line 52

def key
  @key
end

#loggerLogger

A logger.

Returns:

  • (Logger)


64
65
66
# File 'lib/animoto/client.rb', line 64

def logger
  @logger
end

#response_parserResponseParsers::Base #response_parser=(parser) ⇒ ResponseParsers::Base

The engine to handle parsing XML or JSON responses.

Overloads:

Returns:



97
98
99
# File 'lib/animoto/client.rb', line 97

def response_parser
  @response_parser
end

#secretString

Your API secret.

Returns:

  • (String)


56
57
58
# File 'lib/animoto/client.rb', line 56

def secret
  @secret
end

Instance Method Details

#bundle!(manifest, options = {}) ⇒ Jobs::StoryboardBundling

Sends a request to bundle a storyboard.

Parameters:

Returns:

  • (Jobs::StoryboardBundling)

    a job to monitor the status of the storyboard bundling



195
196
197
# File 'lib/animoto/client.rb', line 195

def bundle! manifest, options = {}
  Resources::Jobs::StoryboardBundling.load(send_manifest(manifest, Resources::Jobs::StoryboardBundling.endpoint, options))
end

#delete!(resource, options = {}) ⇒ Boolean

Delete a resource. May not supported for all types of resources.

Parameters:

  • resource (Resources::Base)

    to delete

  • options (Hash{Symbol=>Object}) (defaults to: {})

Returns:

  • (Boolean)

    true if deletion was successful



223
224
225
# File 'lib/animoto/client.rb', line 223

def delete! resource, options = {}
  request(:delete, resource.url, nil)
end

#direct!(manifest, options = {}) ⇒ Jobs::Directing

Sends a request to start directing a storyboard.

Parameters:

  • manifest (Manifests::Directing)

    the manifest to direct

  • options (Hash{Symbol=>Object}) (defaults to: {})

Returns:

  • (Jobs::Directing)

    a job to monitor the status of the directing



168
169
170
# File 'lib/animoto/client.rb', line 168

def direct! manifest, options = {}
  Resources::Jobs::Directing.load(send_manifest(manifest, Resources::Jobs::Directing.endpoint, options))
end

#direct_and_render!(manifest, options = {}) ⇒ Jobs::DirectingAndRendering

Sends a request to start directing and rendering a video.

Parameters:

Returns:

  • (Jobs::DirectingAndRendering)

    a job to monitor the status of the directing and rendering



186
187
188
# File 'lib/animoto/client.rb', line 186

def direct_and_render! manifest, options = {}
  Resources::Jobs::DirectingAndRendering.load(send_manifest(manifest, Resources::Jobs::DirectingAndRendering.endpoint, options))
end

#find(klass, url, options = {}) ⇒ Resources::Base

Finds a resource by its URL.

Parameters:

  • klass (Class)

    the resource class you’re finding

  • url (String)

    the URL of the resource you want

  • options (Hash{Symbol=>Object}) (defaults to: {})

Returns:



159
160
161
# File 'lib/animoto/client.rb', line 159

def find klass, url, options = {}
  klass.load(find_request(klass, url, options))
end

#reload!(resource, options = {}) ⇒ Resources::Base

Update a resource with the latest attributes. Useful to update the state of a Job to see if it’s ready if you are not using HTTP callbacks.

Parameters:

  • resource (Resources::Base)

    the resource to update

  • options (Hash{Symbol=>Object}) (defaults to: {})

Returns:



214
215
216
# File 'lib/animoto/client.rb', line 214

def reload! resource, options = {}
  resource.load(find_request(resource.class, resource.url, options))
end

#render!(manifest, options = {}) ⇒ Jobs::Rendering

Sends a request to start rendering a video.

Parameters:

  • manifest (Manifests::Rendering)

    the manifest to render

  • options (Hash{Symbol=>Object}) (defaults to: {})

Returns:

  • (Jobs::Rendering)

    a job to monitor the status of the rendering



177
178
179
# File 'lib/animoto/client.rb', line 177

def render! manifest, options = {}
  Resources::Jobs::Rendering.load(send_manifest(manifest, Resources::Jobs::Rendering.endpoint, options))
end

#unbundle!(manifest, options = {}) ⇒ Jobs::StoryboardUnbundling

Sends a request to unbundle a storyboard.

Parameters:

Returns:

  • (Jobs::StoryboardUnbundling)

    a job to monitor the status of the storyboard unbundling



204
205
206
# File 'lib/animoto/client.rb', line 204

def unbundle! manifest, options = {}
  Resources::Jobs::StoryboardUnbundling.load(send_manifest(manifest, Resources::Jobs::StoryboardUnbundling.endpoint, options))
end