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 = "\n def \#{method}\#{parameters}\n raise ArgumentError, 'Options must be a hash.' unless options.is_a? Hash\n\n sig_options = {\n :method => \"\#{vimeo_method}\",\n :format => \"json\"\n }\n\n \#{ options[:required].map { |r| \"sig_options.merge! :\#{r} => \#{r}\"}.join(\"\\n\") }\n \#{ options[:optional].map { |o| \"sig_options.merge! :\#{o} => options[:\#{o}] unless options[:\#{o}].nil?\" }.join(\"\\n\") }\n\n make_request sig_options, \#{authorized ? \"true\" : \"false\"}\n end\n\n alias \#{camelized_method} \#{method}\n\n method\n\n class_eval method_string\nend\n" |