animoto 0.0.0.alpha0 → 0.0.0.alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/animoto/client.rb +33 -9
- data/lib/animoto/resource.rb +4 -8
- data/lib/animoto.rb +1 -1
- metadata +4 -4
data/lib/animoto/client.rb
CHANGED
@@ -27,7 +27,7 @@ require 'animoto/rendering_job'
|
|
27
27
|
|
28
28
|
module Animoto
|
29
29
|
class Client
|
30
|
-
API_ENDPOINT = "
|
30
|
+
API_ENDPOINT = "https://api2-staging.animoto.com/"
|
31
31
|
API_VERSION = 1
|
32
32
|
BASE_CONTENT_TYPE = "application/vnd.animoto"
|
33
33
|
HTTP_METHOD_MAP = {
|
@@ -69,9 +69,6 @@ module Animoto
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
@format = 'json'
|
72
|
-
uri = URI.parse(API_ENDPOINT)
|
73
|
-
@http = Net::HTTP.new uri.host, uri.port
|
74
|
-
# @http.use_ssl = true
|
75
72
|
end
|
76
73
|
|
77
74
|
# Finds a resource by its URL.
|
@@ -130,7 +127,8 @@ module Animoto
|
|
130
127
|
# @param [Hash] options
|
131
128
|
# @return [Hash] deserialized JSON response body
|
132
129
|
def find_request klass, url, options = {}
|
133
|
-
request(:get, URI.parse(url).path, nil, { "Accept" => content_type_of(klass) }, options)
|
130
|
+
# request(:get, URI.parse(url).path, nil, { "Accept" => content_type_of(klass) }, options)
|
131
|
+
request(:get, URI.parse(url), nil, { "Accept" => content_type_of(klass) }, options)
|
134
132
|
end
|
135
133
|
|
136
134
|
# Builds a request requiring a manifest.
|
@@ -140,21 +138,47 @@ module Animoto
|
|
140
138
|
# @param [Hash] options
|
141
139
|
# @return [Hash] deserialized JSON response body
|
142
140
|
def send_manifest manifest, endpoint, options = {}
|
143
|
-
request(:post, endpoint, manifest.to_json, { "Accept" => "application/#{format}", "Content-Type" => content_type_of(manifest) }, options)
|
141
|
+
# request(:post, endpoint, manifest.to_json, { "Accept" => "application/#{format}", "Content-Type" => content_type_of(manifest) }, options)
|
142
|
+
u = URI.parse(API_ENDPOINT)
|
143
|
+
u.path = endpoint
|
144
|
+
request(:post, u, manifest.to_json, { "Accept" => "application/#{format}", "Content-Type" => content_type_of(manifest) }, options)
|
144
145
|
end
|
145
146
|
|
146
147
|
# Makes a request and parses the response.
|
147
148
|
#
|
148
149
|
# @param [Symbol] method which HTTP method to use (should be lowercase, i.e. :get instead of :GET)
|
149
|
-
# @param [
|
150
|
+
# @param [URI] uri a URI object of the request URI
|
150
151
|
# @param [String, nil] body the request body
|
151
152
|
# @param [Hash<String,String>] headers the request headers (will be sent as-is, which means you should
|
152
153
|
# specify "Content-Type" => "..." instead of, say, :content_type => "...")
|
153
154
|
# @param [Hash] options
|
154
155
|
# @return [Hash] deserialized JSON response body
|
155
156
|
def request method, uri, body, headers = {}, options = {}
|
157
|
+
http = Net::HTTP.new uri.host, uri.port
|
158
|
+
http.use_ssl = true
|
159
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
156
160
|
req = build_request method, uri, body, headers, options
|
157
|
-
|
161
|
+
if @debug
|
162
|
+
puts "********************* REQUEST *******************"
|
163
|
+
puts "#{req.method} #{uri.to_s} HTTP/#{http.instance_variable_get(:@curr_http_version)}\r\n"
|
164
|
+
req.each_capitalized { |header, value| puts "#{header}: #{value}\r\n" }
|
165
|
+
puts "\r\n"
|
166
|
+
puts req.body unless req.method == 'GET'
|
167
|
+
end
|
168
|
+
response = http.request(req)
|
169
|
+
if @debug
|
170
|
+
puts "********************* RESPONSE *******************"
|
171
|
+
puts "#{response.code} #{response.message}\r\n"
|
172
|
+
response.each_capitalized { |header, value| puts "#{header}: #{value}\r\n" }
|
173
|
+
puts "\r\n"
|
174
|
+
body = response.body
|
175
|
+
if body.nil? || body.empty?
|
176
|
+
puts "(No content)"
|
177
|
+
else
|
178
|
+
puts body
|
179
|
+
end
|
180
|
+
end
|
181
|
+
read_response response
|
158
182
|
end
|
159
183
|
|
160
184
|
# Builds the request object.
|
@@ -167,7 +191,7 @@ module Animoto
|
|
167
191
|
# @param [Hash] options
|
168
192
|
# @return [Net::HTTPRequest] the request object
|
169
193
|
def build_request method, uri, body, headers, options
|
170
|
-
req = HTTP_METHOD_MAP[method].new uri
|
194
|
+
req = HTTP_METHOD_MAP[method].new uri.path
|
171
195
|
req.body = body
|
172
196
|
req.initialize_http_header headers
|
173
197
|
req.basic_auth key, secret
|
data/lib/animoto/resource.rb
CHANGED
@@ -50,13 +50,12 @@ module Animoto
|
|
50
50
|
self.class.payload_key
|
51
51
|
end
|
52
52
|
|
53
|
-
# @private
|
54
|
-
#
|
55
53
|
# Makes a new instance of this class from a deserialized JSON response body. Note that
|
56
54
|
# it assumes the hash you're passing is structured correctly and does no format checking
|
57
55
|
# at all, so if the hash is not in the "standard envelope", this method will most likely
|
58
56
|
# raise an error.
|
59
57
|
#
|
58
|
+
# @private
|
60
59
|
# @param [Hash] body the deserialized JSON response body
|
61
60
|
# @return [Resource] an instance of this class
|
62
61
|
def self.load body
|
@@ -87,11 +86,10 @@ module Animoto
|
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
|
-
# @private
|
91
|
-
#
|
92
89
|
# Registers an instance in the identity map so that subsequent finds or instantiations
|
93
90
|
# of this resource with the same URL will return the same object.
|
94
91
|
#
|
92
|
+
# @private
|
95
93
|
# @param [Resource] instance the instance to register
|
96
94
|
# @raise [ArgumentError] if the instance isn't of this class
|
97
95
|
def register instance
|
@@ -115,22 +113,20 @@ module Animoto
|
|
115
113
|
instantiate attributes
|
116
114
|
end
|
117
115
|
|
118
|
-
# @private
|
119
|
-
#
|
120
116
|
# Update this instance with new attributes from the response body.
|
121
117
|
#
|
118
|
+
# @private
|
122
119
|
# @param [Hash] body deserialized JSON from a response body
|
123
120
|
# @return [self] this instance, updated
|
124
121
|
def load body = {}
|
125
122
|
instantiate unpack_standard_envelope(body)
|
126
123
|
end
|
127
124
|
|
128
|
-
# @private
|
129
|
-
#
|
130
125
|
# Since Resources can be created a number of different ways, this method does
|
131
126
|
# the actual attribute setting for a Resource, acting much like a public version
|
132
127
|
# of #initialize.
|
133
128
|
#
|
129
|
+
# @private
|
134
130
|
# @param [Hash] attributes hash of attributes for this resource
|
135
131
|
# @return [self] this instance
|
136
132
|
def instantiate attributes = {}
|
data/lib/animoto.rb
CHANGED
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: -1710980557
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 0.0.0.
|
10
|
+
- alpha1
|
11
|
+
version: 0.0.0.alpha1
|
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-08-
|
19
|
+
date: 2010-08-13 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|