Module: Sheetsu::Util
- Defined in:
- lib/sheetsu/util.rb
Class Method Summary collapse
- .append_query_string_to_url(url, options) ⇒ Object
- .default_headers ⇒ Object
- .encoded_column(options) ⇒ Object
- .parse_api_url(url) ⇒ Object
- .parse_response(response) ⇒ Object
Class Method Details
.append_query_string_to_url(url, options) ⇒ Object
23 24 25 |
# File 'lib/sheetsu/util.rb', line 23 def self.append_query_string_to_url(url, ) url + "?#{query_string()}" end |
.default_headers ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/sheetsu/util.rb', line 10 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) ⇒ Object
27 28 29 |
# File 'lib/sheetsu/util.rb', line 27 def self.encoded_column() ['/', CGI::escape([:column].to_s), '/', CGI::escape([:value].to_s)].join('') end |
.parse_api_url(url) ⇒ Object
19 20 21 |
# File 'lib/sheetsu/util.rb', line 19 def self.parse_api_url(url) [@sheetsu_api_url, url].join('') end |
.parse_response(response) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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 |