Module: CreateApiMethod
- Included in:
- Vimeo::Advanced::Base
- Defined in:
- lib/vimeo/advanced/base.rb
Instance Method Summary collapse
-
#create_api_method(method, vimeo_method, options = {}) ⇒ Object
Creates a method that calls a Vimeo Method through the Advanced API.
Instance Method Details
#create_api_method(method, vimeo_method, options = {}) ⇒ Object
Creates a method that calls a Vimeo Method through the Advanced API.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vimeo/advanced/base.rb', line 12 def create_api_method(method, vimeo_method, ={}) = { :required => [], :optional => [] }.merge() method = method.to_s camelized_method = camelize(method, false) raise ArgumentError, 'Required parameters must be an array.' unless [:required].is_a? Array raise ArgumentError, 'Optional parameters must be an array.' unless [:optional].is_a? Array required = [:required].map { |r| r.to_s }.join(",") optional = [:optional].map { |o| ":#{o} => nil" }.join(",") = .fetch(:authorized, true) parameters = "(#{required unless required.empty?}#{',' unless required.empty?}options={#{optional}})" method_string = <<-method def #{method}#{parameters} raise ArgumentError, 'Options must be a hash.' unless options.is_a? Hash sig_options = { :method => "#{vimeo_method}", :format => "json" } #{ [:required].map { |r| "sig_options.merge! :#{r} => #{r}"}.join("\n") } #{ [:optional].map { |o| "sig_options.merge! :#{o} => options[:#{o}] unless options[:#{o}].nil?" }.join("\n") } make_request sig_options, #{ ? "true" : "false"} end alias #{camelized_method} #{method} method class_eval method_string end |