module ApiModel::ClassMethods
Public Instance Methods
attribute_synonym(primary_method_name, *alternate_names)
click to toggle source
# File lib/api_model/class_methods.rb, line 8 def attribute_synonym(primary_method_name, *alternate_names) alternate_names.each do |alternate_name| alias_method "#{alternate_name}=".to_sym, "#{primary_method_name}=".to_sym attribute_synonyms[alternate_name] = primary_method_name end end
attribute_synonyms()
click to toggle source
# File lib/api_model/class_methods.rb, line 4 def attribute_synonyms @attribute_synonyms ||= {} end
cache(path, &block)
click to toggle source
# File lib/api_model/class_methods.rb, line 50 def cache(path, &block) api_model_configuration.cache_strategy.new(path, api_model_configuration.cache_settings).cache do block.call end end
cache_id(path, options={})
click to toggle source
# File lib/api_model/class_methods.rb, line 45 def cache_id(path, options={}) p = (options[:params] || {}).collect{ |k,v| "#{k}#{v}" }.join("") "#{path}#{p}" end
call_api(method, path, options={})
click to toggle source
# File lib/api_model/class_methods.rb, line 36 def call_api(method, path, options={}) cache options.delete(:cache_id) || cache_id(path, options) do request = HttpRequest.new path: path, method: method, config: api_model_configuration request.builder = options.delete(:builder) || api_model_configuration.builder || self request.options.deep_merge! options request.run.build_objects end end
call_api_with_json(method, path, body=nil, options={})
click to toggle source
# File lib/api_model/class_methods.rb, line 31 def call_api_with_json(method, path, body=nil, options={}) body = body.to_json if body.is_a?(Hash) call_api method, path, options.merge(body: body) end
get_json(path, params={}, options={})
click to toggle source
# File lib/api_model/class_methods.rb, line 19 def get_json(path, params={}, options={}) call_api :get, path, options.merge(params: params) end
post_json(path, body=nil, options={})
click to toggle source
# File lib/api_model/class_methods.rb, line 23 def post_json(path, body=nil, options={}) call_api_with_json :post, path, body, options end
put_json(path, body=nil, options={})
click to toggle source
# File lib/api_model/class_methods.rb, line 27 def put_json(path, body=nil, options={}) call_api_with_json :put, path, body, options end
real_attribute_name_for(name)
click to toggle source
# File lib/api_model/class_methods.rb, line 15 def real_attribute_name_for(name) attribute_synonyms[name] || name end