lib/stripe_tester.rb in stripe_tester-0.4.0 vs lib/stripe_tester.rb in stripe_tester-0.5.0

- old
+ new

@@ -19,11 +19,11 @@ # replace multiple values for multiple keys in a hash def self.overwrite_attributes(original_data, attributes={}) data = original_data.clone if attributes - attributes.each do |k,v| + indifferent(attributes).each do |k,v| replace_value(data, k, v) end end data end @@ -43,11 +43,11 @@ # deep merge original_attributes with new_attributes def self.merge_attributes(original_attributes, new_attributes={}) original_attributes = original_attributes.clone if new_attributes - new_attributes.each do |key, value| + indifferent(new_attributes).each do |key, value| if value.is_a?(Hash) && original_attributes[key].is_a?(Hash) original_attributes[key] = self.merge_attributes original_attributes[key], value else original_attributes[key] = value end @@ -62,11 +62,11 @@ if post_url # set up request req = Net::HTTP::Post.new(post_url.path) req.content_type = 'application/json' req.body = data.to_json - + req.basic_auth 'stripe', self.basic_authentication_password if !self.basic_authentication_password.nil? http_object = Net::HTTP.new(post_url.hostname, post_url.port) http_object.use_ssl = true if post_url.scheme == 'https' http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE if (!verify_ssl? && http_object.use_ssl?) # send request @@ -91,12 +91,12 @@ gem_root = spec.gem_dir version = StripeTester.stripe_version path = gem_root + "/stripe_webhooks/#{version}/#{callback_type}.yml" if File.exists?(path) - template = Psych.load_file(path) - + template = indifferent(Psych.load_file(path)) + unless attributes.empty? if options[:method] == :merge template = merge_attributes(template, attributes) else template = overwrite_attributes(template, attributes) @@ -123,10 +123,22 @@ def self.remove_url @url = nil end + def self.webhook_password=(webhook_password) + @webhook_password = webhook_password + end + + def self.webhook_password + @webhook_password + end + + def self.basic_authentication_password + @webhook_password || self.webhook_url.password + end + def self.stripe_version=(version) @version = version end def self.stripe_version @@ -137,8 +149,18 @@ @verify_ssl = verify end def self.verify_ssl? !@verify_ssl.nil? ? @verify_ssl : true + end + + private + + def self.indifferent(obj) + if obj.is_a?(Hash) && obj.respond_to?(:with_indifferent_access) + obj.with_indifferent_access + else + obj + end end end