lib/easypost/address.rb in easypost-4.1.2 vs lib/easypost/address.rb in easypost-4.2.0
- old
+ new
@@ -4,42 +4,32 @@
class EasyPost::Address < EasyPost::Resource
attr_accessor :message # Backwards compatibility
# Create an Address.
def self.create(params = {}, api_key = nil)
- url = self.url
-
address = params.reject { |k, _| [:verify, :verify_strict].include?(k) }
- if params[:verify] || params[:verify_strict]
- verify = params[:verify] || []
- verify_strict = params[:verify_strict] || []
+ wrapped_params = { address: address }
- url += '?'
- verify.each do |verification|
- url += "verify[]=#{verification}&"
- end
- verify_strict.each do |verification|
- url += "verify_strict[]=#{verification}&"
- end
+ if params[:verify]
+ wrapped_params[:verify] = params[:verify]
end
- response = EasyPost.make_request(:post, url, api_key, { address: address })
+ if params[:verify_strict]
+ wrapped_params[:verify_strict] = params[:verify_strict]
+ end
+
+ response = EasyPost.make_request(:post, url, api_key, wrapped_params)
EasyPost::Util.convert_to_easypost_object(response, api_key)
end
# Create and verify an Address in one call.
- def self.create_and_verify(params = {}, carrier = nil, api_key = nil)
+ def self.create_and_verify(params = {}, api_key = nil)
wrapped_params = {}
wrapped_params[class_name.to_sym] = params
- wrapped_params[:carrier] = carrier
response = EasyPost.make_request(:post, "#{url}/create_and_verify", api_key, wrapped_params)
raise EasyPost::Error.new('Unable to verify address.') unless response.key?('address')
-
- if response.key?('message')
- response['address']['message'] = response['message']
- end
EasyPost::Util.convert_to_easypost_object(response['address'], api_key)
end
# Verify an Address.