Skip to content

Commit

Permalink
format: json option added
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozef Chraplewski committed May 29, 2014
1 parent 6afac57 commit 0c9b820
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/vzaar/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Vzaar
class Connection
include Vzaar::Helper

SERVER = "vzaar.com".freeze
SERVER = "vzaar.com"
attr_reader :application_token, :force_http, :login, :options

def initialize(options)
Expand Down
16 changes: 14 additions & 2 deletions lib/vzaar/request/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Base < Struct.new(:conn, :opts)
include Vzaar::Helper

class << self
[:authenticated, :http_verb, :format].each do |method_name|
[:authenticated, :http_verb].each do |method_name|
define_method(method_name) do |val|
define_method(method_name) do
val.nil? ? self.options[method_name] : val
Expand All @@ -19,6 +19,13 @@ def endpoint(obj=nil, &fn)
def resource(name)
define_method(:resource) { name }
end

def format(f)
define_method(:format) do
# JC: options should always overwrite format param
self.options[:format] ? self.options[:format] : f
end
end
end

authenticated nil
Expand All @@ -27,7 +34,12 @@ def resource(name)

def execute
conn.using_connection(url, user_options) do |res|
return resource_klass.new(Response::Base.new(res).body, res.code)
_res = Response::Base.new(res)
if _res.json?
return _res.body
else
return resource_klass.new(_res.body, res.code)
end
end
end

Expand Down
10 changes: 4 additions & 6 deletions lib/vzaar/request/generate_thumbnail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ class GenerateThumbnail < Video

def xml_body
<<-XML
<?xml version="1.0" encoding="UTF-8"?>
<vzaar-api>
<video>
<thumb_time>#{options[:time]}</thumb_time>
</video>
</vzaar-api>
<?xml version="1.0" encoding="UTF-8"?>#{hash_to_xml(json_body)}
XML
end

def json_body
{ "vzaar-api" => { "video" => { "thumb_time" => options[:time] }}}
end
end
end
end
2 changes: 1 addition & 1 deletion lib/vzaar/request/multipart.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Vzaar
module Request
class Multipart < Struct.new(:path, :file)
CRLF = "\r\n".freeze
CRLF = "\r\n"

def request
req = Net::HTTP::Post.new(path)
Expand Down

0 comments on commit 0c9b820

Please sign in to comment.