From 1a7754b3f7133f7a2bc99b986ef66ee86d64a4d6 Mon Sep 17 00:00:00 2001 From: Marcel Jackwerth Date: Tue, 7 Sep 2010 21:04:26 +0200 Subject: [PATCH] also support unauthorized requests for certain methods (like videos.search) --- lib/vimeo/advanced/base.rb | 13 ++++++++++--- lib/vimeo/advanced/video.rb | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/vimeo/advanced/base.rb b/lib/vimeo/advanced/base.rb index a3fb748..a73fd6c 100644 --- a/lib/vimeo/advanced/base.rb +++ b/lib/vimeo/advanced/base.rb @@ -20,6 +20,7 @@ def create_api_method(method, vimeo_method, options={}) required = options[:required].map { |r| r.to_s }.join(",") optional = options[:optional].map { |o| ":#{o} => nil" }.join(",") + authorized = options.fetch(:authorized, true) parameters = "(#{required unless required.blank?}#{',' unless required.blank?}options={#{optional}})" @@ -36,7 +37,7 @@ def #{method}#{parameters} #{ options[:required].map { |r| "sig_options.merge! :#{r} => #{r}"}.join("\n") } #{ options[:optional].map { |o| "sig_options.merge! :#{o} => options[:#{o}] unless options[:#{o}].nil?" }.join("\n") } - make_request sig_options + make_request sig_options, #{authorized ? "true" : "false"} end alias #{camelized_method} #{method} @@ -91,8 +92,14 @@ def get_access_token(oauth_token=nil, oauth_secret=nil, oauth_verifier=nil) private - def make_request(options) - response = Crack::JSON.parse @oauth_consumer.request(:post, "http://vimeo.com/api/rest/v2", get_access_token, {}, options).body + def make_request(options, authorized) + if authorized + raw_response = @oauth_consumer.request(:post, "http://vimeo.com/api/rest/v2", get_access_token, {}, options).body + else + raw_response = @oauth_consumer.request(:post, "http://vimeo.com/api/rest/v2", nil, {}, options).body + end + + response = Crack::JSON.parse(raw_response) validate_response! response response end diff --git a/lib/vimeo/advanced/video.rb b/lib/vimeo/advanced/video.rb index 71cbb6c..e1b4d9c 100644 --- a/lib/vimeo/advanced/video.rb +++ b/lib/vimeo/advanced/video.rb @@ -87,7 +87,8 @@ class Video < Vimeo::Advanced::Base create_api_method :search, "vimeo.videos.search", :required => [:query], - :optional => [:page, :per_page, :full_response, :sort, :user_id] + :optional => [:page, :per_page, :full_response, :sort, :user_id], + :authorized => false create_api_method :set_description, "vimeo.videos.setDescription",