Skip to content

Commit

Permalink
also support unauthorized requests for certain methods (like videos.s…
Browse files Browse the repository at this point in the history
…earch)
  • Loading branch information
NDMarcel committed Sep 7, 2010
1 parent 9c2397a commit 1a7754b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions lib/vimeo/advanced/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}})"

Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/vimeo/advanced/video.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1a7754b

Please sign in to comment.