lib/hello_sign/resource/base_resource.rb in hellosign-ruby-sdk-3.6.4 vs lib/hello_sign/resource/base_resource.rb in hellosign-ruby-sdk-3.7.0

- old
+ new

@@ -30,20 +30,26 @@ # # @author [hellosign] # class BaseResource + attr_reader :data, :raw_data, :warnings, :headers + # # recursively convert hash data into BaseResource. # # @param hash [Hash] data of the resource # @param key [String] (nil) key of the hash, point to where resource data is. If nil then the hash itself # # @return [HelloSign::Resource::BaseResource] a new BaseResource def initialize(hash, key=nil) - @raw_data = key ? hash[key] : hash - @warnings = hash['warnings'] ? hash['warnings'] : nil + @headers = hash[:headers] + @raw_data = key ? hash[:body][key] : hash + if hash[:body] + @warnings = hash[:body]['warnings'] ? hash[:body]['warnings'] : nil + end + @data = @raw_data.inject({}) do |data, (key, value)| data[key.to_s] = if value.is_a? Hash value = BaseResource.new(value) elsif ((value.is_a? Array) && (value[0].is_a? Hash)) value = value.map {|v| BaseResource.new(v)} @@ -67,25 +73,9 @@ # resource = BaseResource.new :email_address => "me@example.com" # resource.email_address # => "me@example.com" # resource.not_in_hash_keys # => nil def method_missing(method) @data.key?(method.to_s) ? @data[method.to_s] : nil - end - - # - # raw response data from the server in json - # - # @return [type] [description] - def data - @raw_data - end - - # - # shows any warnings returned with the api response, if present - # - # @return [Array<Hash>, nil] Array of warning hashes in format {'warning_msg' => val, 'warning_name' => val} or nil - def warnings - @warnings end end end end