Sha256: d9c0daffa862a3fa8a928832aab5788da819b805d1c2bdc217ef287f6bfe943e
Contents?: true
Size: 1.49 KB
Versions: 2
Compression:
Stored size: 1.49 KB
Contents
module Access class Request include HTTParty def get(path, api_type, options={}, &block) url = set_base(api_type, path) results = self.class.get(url, headers: headers(options[:access_token]), query: options) if should_return_json?(options[:return_json]) hashify_results?(options[:hashify]) ? results.hashify : results else block.call results end end def get_for_filter(path, api_type, filter, options={}, &block) url = set_base(api_type, path) results = self.class.get(url, headers: headers(options[:access_token]), body: filter) if should_return_json?(options[:return_json]) hashify_results?(options[:hashify]) ? results.hashify : results else block.call results end end private def set_base(api_type, path) "https://#{ api_type }#{ Access::Config::DOMAINS[Access.config.api_environment] }.adcrws.com/v1#{path}" end def headers(token_param) raise Access::Error::NoAccessToken if (access_token = token_param || Access.config.access_token).nil? {"Access-Token" => access_token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'} end def should_return_json?(return_json_param) return_json_param == 'true' || (return_json_param != 'false' && Access.config.return_json == 'true') end def hashify_results?(hashify_param) hashify_param == 'true' || (hashify_param != 'false' && Access.config.hashify == 'true') end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
access-2.0.1 | lib/access/request.rb |
access-2.0.0 | lib/access/request.rb |