module Atomsphere::Action::ClassMethods
Public Class Methods
included(base)
click to toggle source
# File lib/atomsphere/action.rb, line 7 def self.included base end
new(params={})
click to toggle source
# File lib/atomsphere/action.rb, line 10 def initialize params={} set_params params validate! end
Public Instance Methods
fields()
click to toggle source
# File lib/atomsphere/action.rb, line 15 def fields %w(required one_of optional).map do |m| self.class.class_variable_get :"@@#{m}" end.flatten end
run()
click to toggle source
# File lib/atomsphere/action.rb, line 21 def run @api_response ||= api_client.send(*[ api_method, action, api_method.eql?(:get) ? nil : request ].compact) @response ||= @api_response.to_hash self end
Private Instance Methods
action()
click to toggle source
# File lib/atomsphere/action.rb, line 37 def action if self.class.class_variable_defined? :@@action self.class.class_variable_get :@@action else self.class.name.split('::').last.lower_camelcase end end
api_client()
click to toggle source
# File lib/atomsphere/action.rb, line 57 def api_client Api::Client.new end
api_method()
click to toggle source
# File lib/atomsphere/action.rb, line 45 def api_method if self.class.class_variable_defined? :@@api_method self.class.class_variable_get :@@api_method else :post end end
set_params(params)
click to toggle source
# File lib/atomsphere/action.rb, line 53 def set_params params fields.each{ |f| send(:"#{f}=", params[f]) } end
validate!()
click to toggle source
# File lib/atomsphere/action.rb, line 61 def validate! required.each do |f| raise ArgumentError, "#{f} is required" unless send(:"#{f}") end one_of.each do |fs| unless fs.map{ |f| send(:"#{f}") }.compact.size == 1 raise ArgumentError, "requires one of: #{fs.join(', ')}" end end end