Sha256: 708a70b3be32d60afa29a45f8fee8ca4418f184e31d13e6444500be8a856f02e
Contents?: true
Size: 1.8 KB
Versions: 15
Compression:
Stored size: 1.8 KB
Contents
module EasyPost class Address < Resource attr_accessor :message # Backwards compatibility def self.create(params={}, api_key=nil) url = self.url if params[:verify] || params[:verify_strict] verify = params.delete(:verify) || [] verify_strict = params.delete(:verify_strict) || [] url += "?" verify.each do |verification| url += "verify[]=#{verification}&" end verify_strict.each do |verification| url += "verify_strict[]=#{verification}&" end end response, api_key = EasyPost.request(:post, url, api_key, {address: params}) return Util.convert_to_easypost_object(response, api_key) end def self.create_and_verify(params={}, carrier=nil, api_key=nil) wrapped_params = {} wrapped_params[self.class_name().to_sym] = params wrapped_params[:carrier] = carrier response, api_key = EasyPost.request(:post, url + '/create_and_verify', api_key, wrapped_params) if response.has_key?(:address) if response.has_key?(:message) response[:address][:message] = response[:message] end verified_address = EasyPost::Util::convert_to_easypost_object(response[:address], api_key) return verified_address else raise Error.new("Unable to verify address.") end end def verify(params={}, carrier=nil) begin response, api_key = EasyPost.request(:get, url + '/verify?carrier=' + String(carrier), @api_key, params) rescue raise Error.new("Unable to verify address.") end if response.has_key?(:address) return EasyPost::Util::convert_to_easypost_object(response[:address], api_key) else raise Error.new("Unable to verify address.") end return self end end end
Version data entries
15 entries across 15 versions & 1 rubygems