From 8b4b16039cee28c327748ac0927884ecb89e1666 Mon Sep 17 00:00:00 2001 From: Riccardo Date: Thu, 23 Feb 2017 14:23:24 +0100 Subject: [PATCH 1/2] Use OpenStruct instead of Hash in RingCaptchaVerification data was saved in a Hash, but, this way delegation didn't work. Using OpenStruct delegation works. --- lib/ringcaptcha.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ringcaptcha.rb b/lib/ringcaptcha.rb index bd37d8d..75c84d3 100644 --- a/lib/ringcaptcha.rb +++ b/lib/ringcaptcha.rb @@ -1,6 +1,7 @@ require 'open-uri' require 'net/http' require 'json' +require 'ostruct' module RingCaptcha class RingCaptchaRequestError < StandardError; end @@ -15,15 +16,15 @@ class RingCaptchaVerification end def initialize(json) - @json = json + @json = OpenStruct.new(json) end def valid? - @status == "SUCCESS" + status == "SUCCESS" end def as_json(options={}) - @json.slice(*PUBLIC_METHODS.map(&:to_s)) + @json.to_h.slice(*PUBLIC_METHODS) end end From 6c3fd32cb665802ec9f522c56996b01c1dd493ed Mon Sep 17 00:00:00 2001 From: Riccardo Date: Thu, 23 Feb 2017 14:32:07 +0100 Subject: [PATCH 2/2] Rename RingCaptchaVerification#phone_number to phone --- lib/ringcaptcha.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ringcaptcha.rb b/lib/ringcaptcha.rb index 75c84d3..b927d73 100644 --- a/lib/ringcaptcha.rb +++ b/lib/ringcaptcha.rb @@ -9,7 +9,7 @@ class RingCaptchaRequestError < StandardError; end class RingCaptchaVerification extend Forwardable - PUBLIC_METHODS = [:status, :message, :transaction_id, :phone_number, :geolocation, :phone_type, :carrier_name, :roaming, :risk, :json] + PUBLIC_METHODS = [:status, :message, :transaction_id, :phone, :geolocation, :phone_type, :carrier_name, :roaming, :risk, :json] PUBLIC_METHODS.each do |m| def_delegators :@json, m