module Sheetsu::Util
Constants
- SHEETSU_API_URL_BEGINNING
Public Class Methods
append_query_string_to_url(url, options)
click to toggle source
# File lib/sheetsu/util.rb, line 23 def self.append_query_string_to_url(url, options) url + "?#{query_string(options)}" end
default_headers()
click to toggle source
# File lib/sheetsu/util.rb, line 6 def self.default_headers { 'Accept-Encoding' => 'gzip, deflate', 'Accept' => 'application/vnd.sheetsu.3+json', 'Content-Type' => 'application/json', 'User-Agent' => "Sheetsu-Ruby/#{Sheetsu::VERSION}" } end
encoded_column(options)
click to toggle source
# File lib/sheetsu/util.rb, line 27 def self.encoded_column(options) ['/', CGI::escape(options[:column].to_s), '/', CGI::escape(options[:value].to_s)].join('') end
parse_api_url(url)
click to toggle source
# File lib/sheetsu/util.rb, line 15 def self.parse_api_url(url) if url.start_with?(SHEETSU_API_URL_BEGINNING) url else [SHEETSU_API_URL_BEGINNING, url].join('') end end
parse_response(response)
click to toggle source
# File lib/sheetsu/util.rb, line 31 def self.parse_response(response) case response.code.to_i when 200 then JSON.parse(response.body) when 201 then JSON.parse(response.body) when 204 then :ok when 401 then raise Sheetsu::UnauthorizedError when 403 then raise Sheetsu::ForbiddenError when 404 then raise Sheetsu::NotFoundError when 429 then raise Sheetsu::LimitExceedError else raise Sheetsu::SheetsuError.new(nil, response.code, response.body) end end
Private Class Methods
query_string(options)
click to toggle source
# File lib/sheetsu/util.rb, line 46 def self.query_string(options) options.map do |k,v| "#{k}=#{CGI::escape(v.to_s)}" end.join('&') end