class Fixer::API
Attributes
current_options[RW]
Public Class Methods
new(options = {}) { |self| ... }
click to toggle source
# File lib/fixer/api.rb, line 21 def initialize(options = {}) apply_options(options) yield(self) if block_given? end
Public Instance Methods
apply_options(options = {})
click to toggle source
# File lib/fixer/api.rb, line 26 def apply_options(options = {}) self.current_options ||= Fixer.options.with_indifferent_access self.current_options = current_options.merge(args_to_options(options)) Configuration.keys.each do |key| send("#{key}=", current_options[key]) end end
args_to_options(args)
click to toggle source
# File lib/fixer/api.rb, line 91 def args_to_options(args) params = if args.is_a?(String) || args.is_a?(Symbol) || args.is_a?(Numeric) {"#{self.class.name.demodulize.downcase.singularize}_id" => args.to_s} elsif args.is_a?(Hash) args end end
base_path()
click to toggle source
# File lib/fixer/api.rb, line 54 def base_path parts = self.class.name.split("::").inject([]){|a, c| if c != 'Fixer' base = c.underscore a << base.tr('_','-') a << current_options["#{base.singularize}_id"] if current_options["#{base.singularize}_id"] end a } parts.join('/') + '/' end
create(params={})
click to toggle source
# File lib/fixer/api.rb, line 76 def create(params={}) self.current_options = current_options.merge(args_to_options(params)) request(:post, base_path, { data: params } ) end
delete(params={})
click to toggle source
# File lib/fixer/api.rb, line 86 def delete(params={}) self.current_options = current_options.merge(args_to_options(params)) request(:delete, base_path) end
get(params={})
click to toggle source
# File lib/fixer/api.rb, line 71 def get(params={}) self.current_options = current_options.merge(args_to_options(params)) request(:get, base_path) end
list(params={})
click to toggle source
# File lib/fixer/api.rb, line 66 def list(params={}) self.current_options = current_options.merge(args_to_options(params)) request(:get, base_path) end
update(params={})
click to toggle source
# File lib/fixer/api.rb, line 81 def update(params={}) self.current_options = current_options.merge(args_to_options(params)) request(:put, base_path, { data: params } ) end