class GVIVE::Response
Attributes
cache[RW]
http_response[RW]
Public Class Methods
new(http_response)
click to toggle source
Requires an HTTP::Response Object which is a dependency from the http gem Response
Class @param [HTTP::Response] http_response
# File lib/gvive/response.rb, line 11 def initialize(http_response) @http_response = http_response end
Public Instance Methods
snakecase(str)
click to toggle source
Shamelessly copied from the internet with 1% modifications :) www.rubydoc.info/github/rubyworks/facets/String%3Asnakecase Convert all CamelCased strings to snake_cased @param [String] str @return [String]
# File lib/gvive/response.rb, line 31 def snakecase(str) str.to_s.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr('-', '_'). gsub(/\s/, '_'). gsub(/__+/, '_'). downcase end
success?()
click to toggle source
to_o()
click to toggle source
Convert response data to plain Ruby Objects @return [OpenStruct]
# File lib/gvive/response.rb, line 17 def to_o old_hash = JSON.parse @http_response.body.to_s new_hash = {} old_hash.each do |k,v| new_hash["#{snakecase(k)}"] = v end @cache = OpenStruct.new(new_hash) end