veeqo / ups-ruby

Gem for accessing the UPS API from Ruby
MIT License
10 stars 31 forks source link

undefined method `[]' for nil:NilClass #18

Open payal-balanceit opened 4 years ago

payal-balanceit commented 4 years ago
server = UPS::Connection.new(test_mode: true)
response = server.rates do |rate_builder|
  rate_builder.add_access_request 'test', 'test', 'test'
  rate_builder.add_shipper company_name: 'Veeqo Limited',    phone_number: '01792 123456',    address_line_1: '11 Wind Street',    city: 'Swansea',    state: 'Wales',    postal_code: 'SA1 1DA',    country: 'GB',    shipper_number: 'test'
  rate_builder.add_ship_from company_name: 'Veeqo Limited',    phone_number: '01792 123456',    address_line_1: '11 Wind Street',    city: 'Swansea',    state: 'Wales',    postal_code: 'SA1 1DA',    country: 'GB',    shipper_number: 'test'  
  rate_builder.add_ship_to company_name: 'Google Inc.',    phone_number: '0207 031 3000',    address_line_1: '1 St Giles High Street',    city: 'London',    state: 'England',    postal_code: 'WC2H 8AG',    country: 'GB'
  rate_builder.add_package weight: '0.5',    unit: 'KGS'
end

(undefined method `[]' for nil:NilClass)

tcd commented 4 years ago

@payal-balanceit Take a look at response.status_description and response.error_description

aiperon commented 3 years ago

I've also experienced this problem.

Error's backtrace leads me to the code: https://github.com/veeqo/ups-ruby/blob/master/lib/ups/builders/organisation_builder.rb#L51 It means organization builder expects attention_name option passed with a non-blank string. It called from add_ship_from and add_ship_to.

@payal-balanceit , as a workaround you can add non-empty attention_name param to add_ship_from and add_ship_to methods

I suppose Veeqo uses these methods with all options filled in production.