animoto 0.0.0.alpha4 → 0.0.0.alpha5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/animoto/client.rb +13 -5
- data/lib/animoto.rb +1 -1
- data/spec/animoto/client_spec.rb +1 -1
- metadata +4 -4
data/lib/animoto/client.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'uri'
|
3
|
+
require 'logger'
|
3
4
|
|
4
5
|
require 'animoto/errors'
|
5
6
|
require 'animoto/content_type'
|
@@ -32,7 +33,7 @@ module Animoto
|
|
32
33
|
API_VERSION = 1
|
33
34
|
BASE_CONTENT_TYPE = "application/vnd.animoto"
|
34
35
|
|
35
|
-
attr_accessor :key, :secret, :endpoint
|
36
|
+
attr_accessor :key, :secret, :endpoint, :logger
|
36
37
|
attr_reader :http_engine, :response_parser
|
37
38
|
|
38
39
|
# Creates a new Client object which handles credentials, versioning, making requests, and
|
@@ -49,9 +50,10 @@ module Animoto
|
|
49
50
|
# @raise [ArgumentError] if no credentials are supplied
|
50
51
|
def initialize *args
|
51
52
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
52
|
-
@key
|
53
|
-
@secret
|
53
|
+
@key = args[0]
|
54
|
+
@secret = args[1]
|
54
55
|
@endpoint = options[:endpoint]
|
56
|
+
@logger = options[:logger] || ::Logger.new(STDOUT)
|
55
57
|
configure_from_rc_file
|
56
58
|
@endpoint ||= API_ENDPOINT
|
57
59
|
__send__ :http_engine=, options[:http_engine] || :net_http
|
@@ -221,17 +223,23 @@ module Animoto
|
|
221
223
|
def request method, url, body, headers = {}, options = {}
|
222
224
|
error = catch(:fail) do
|
223
225
|
options = { :username => @key, :password => @secret }.merge(options)
|
226
|
+
@logger.info "Sending request to #{url.inspect} with body #{body.inspect}"
|
224
227
|
response = http_engine.request(method, url, body, headers, options)
|
228
|
+
@logger.info "Received response #{response.inspect}"
|
225
229
|
return response_parser.parse(response)
|
226
230
|
end
|
227
231
|
if error
|
228
232
|
errors = response_parser.parse(error)['response']['status']['errors']
|
229
|
-
|
233
|
+
err_string = errors.collect { |e| e['message'] }.join(', ')
|
234
|
+
@logger.error "Error response from server: #{err_string}"
|
235
|
+
raise Animoto::Error.new(err_string)
|
230
236
|
else
|
237
|
+
@logger.error "Error sending request to #{url.inspect}"
|
231
238
|
raise Animoto::Error
|
232
239
|
end
|
233
240
|
rescue NoMethodError => e
|
234
|
-
|
241
|
+
@logger.error e.inspect
|
242
|
+
raise Animoto::Error.new("Invalid response (#{e.inspect})")
|
235
243
|
end
|
236
244
|
|
237
245
|
# Creates the full content type string given a Resource class or instance
|
data/lib/animoto.rb
CHANGED
data/spec/animoto/client_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
3
3
|
|
4
4
|
describe Animoto::Client do
|
5
5
|
def client options = {}
|
6
|
-
@client ||= Animoto::Client.new "joe", "secret", options
|
6
|
+
@client ||= Animoto::Client.new "joe", "secret", options.merge(:logger => ::Logger.new('/dev/null'))
|
7
7
|
end
|
8
8
|
|
9
9
|
def object
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: animoto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: -
|
4
|
+
hash: -1710980401
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 0.0.0.
|
10
|
+
- alpha5
|
11
|
+
version: 0.0.0.alpha5
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Animoto
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-09-
|
19
|
+
date: 2010-09-09 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|