Module: ApiModel::ClassMethods
- Included in:
- Base
- Defined in:
- lib/api_model/class_methods.rb
Instance Method Summary collapse
- #cache(path, &block) ⇒ Object
- #cache_id(path, options = {}) ⇒ Object
- #call_api(method, path, options = {}) ⇒ Object
- #get_json(path, params = {}, options = {}) ⇒ Object
- #post_json(path, body = nil, options = {}) ⇒ Object
Instance Method Details
#cache(path, &block) ⇒ Object
28 29 30 31 32 |
# File 'lib/api_model/class_methods.rb', line 28 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 = {}) ⇒ Object
22 23 24 25 26 |
# File 'lib/api_model/class_methods.rb', line 22 def cache_id(path, ={}) return @cache_id if @cache_id p = ([:params] || {}).collect{ |k,v| "#{k}#{v}" }.join("") "#{path}#{p}" end |
#call_api(method, path, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/api_model/class_methods.rb', line 13 def call_api(method, path, ={}) cache cache_id(path, ) do request = HttpRequest.new path: path, method: method, config: api_model_configuration request.builder = .delete(:builder) || api_model_configuration.builder || self request..merge! request.run.build_objects end end |
#get_json(path, params = {}, options = {}) ⇒ Object
4 5 6 |
# File 'lib/api_model/class_methods.rb', line 4 def get_json(path, params={}, ={}) call_api :get, path, .merge(params: params) end |
#post_json(path, body = nil, options = {}) ⇒ Object
8 9 10 11 |
# File 'lib/api_model/class_methods.rb', line 8 def post_json(path, body=nil, ={}) body = body.to_json if body.is_a?(Hash) call_api :post, path, .merge(body: body) end |