From b2881b82f4c9a93d71bda2056ae24a5aac7fba22 Mon Sep 17 00:00:00 2001 From: noglows Date: Tue, 19 Jan 2016 16:20:10 -0800 Subject: [PATCH 01/20] Working UPS and USPS rates --- Gemfile | 1 + Gemfile.lock | 5 +++++ app/controllers/packages_controller.rb | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/Gemfile b/Gemfile index dd75501..cb5797e 100644 --- a/Gemfile +++ b/Gemfile @@ -41,6 +41,7 @@ group :development, :test do gem 'pry' gem 'simplecov' gem 'factory_girl_rails' + gem 'dotenv-rails' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 6f100cb..811a2ac 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,6 +65,10 @@ GEM debug_inspector (0.0.2) diff-lcs (1.2.5) docile (1.1.5) + dotenv (2.1.0) + dotenv-rails (2.1.0) + dotenv (= 2.1.0) + railties (>= 4.0, < 5.1) erubis (2.7.0) execjs (2.6.0) factory_girl (4.5.0) @@ -196,6 +200,7 @@ DEPENDENCIES binding_of_caller byebug coffee-rails (~> 4.1.0) + dotenv-rails factory_girl_rails jbuilder (~> 2.0) jquery-rails diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index d240f22..eda740c 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -11,5 +11,24 @@ def rates province: 'ON', city: 'Ottawa', postal_code: 'K1P 1J1') + + # Verified USPS works + usps = ActiveShipping::USPS.new(login: ENV["USPS_USERNAME"], password: ENV["USPS_PASSWORD"]) + response = usps.find_rates(origin, destination, package) + usps_rates = response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]} + + # Verified UPS works + ups = ActiveShipping::UPS.new(login: ENV["UPS_ACCOUNT_NAME"], password: ENV["UPS_ACCOUNT_PASSWORD"], key: ENV["UPS_ACCESS_KEY"]) + response = ups.find_rates(origin, destination, package) + ups_rates = response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]} + + all_rates = { ups: ups_rates, usps: usps_rates } + render :json => all_rates.as_json + + # fedex = ActiveShipping::FedEx.new(login: ENV["FEDEX_ACCOUNT_NAME"], password: ENV["FEDEX_ACCOUNT_PASSWORD"], key: ENV["FEDEX_TEST_KEY"], account: ENV["FEDEX_TEST_ACCOUNT_NUMBER"]) + # response = fedex.find_rates(origin, destination, package) + # fedex_rates = response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]} + + end end From d343e07608c5d91412aefe5073aa2150939c89a3 Mon Sep 17 00:00:00 2001 From: Katherine Defliese Date: Tue, 19 Jan 2016 16:34:13 -0800 Subject: [PATCH 02/20] started trying to make params work --- app/controllers/packages_controller.rb | 5 ++++- config/routes.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index eda740c..c14fea0 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -1,7 +1,10 @@ class PackagesController < ApplicationController def rates - package = ActiveShipping::Package.new(100, [10, 20, 30], :units => :metric) + weight = params[:order_item][:product][:weight] + + # "order_item":{"product":{"weight": "500"}} + package = ActiveShipping::Package.new(weight, [10, 20, 30], :units => :metric) origin = ActiveShipping::Location.new(country: 'US', state: 'CA', city: 'Beverly Hills', diff --git a/config/routes.rb b/config/routes.rb index c87acde..bd06124 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do get 'rates' => 'packages#rates' - + get 'rates/:params' => 'packages#rates' # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". From 64013de54ad742c80253cb79b253775163130eb9 Mon Sep 17 00:00:00 2001 From: Katherine Defliese Date: Tue, 19 Jan 2016 17:01:48 -0800 Subject: [PATCH 03/20] trying to curl to create a destination address --- app/controllers/packages_controller.rb | 27 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index c14fea0..1cdc29e 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -1,20 +1,13 @@ class PackagesController < ApplicationController def rates - weight = params[:order_item][:product][:weight] - - # "order_item":{"product":{"weight": "500"}} - package = ActiveShipping::Package.new(weight, [10, 20, 30], :units => :metric) + package = create_package origin = ActiveShipping::Location.new(country: 'US', state: 'CA', city: 'Beverly Hills', zip: '90210') - destination = ActiveShipping::Location.new(country: 'CA', - province: 'ON', - city: 'Ottawa', - postal_code: 'K1P 1J1') - + destination = create_destination # Verified USPS works usps = ActiveShipping::USPS.new(login: ENV["USPS_USERNAME"], password: ENV["USPS_PASSWORD"]) response = usps.find_rates(origin, destination, package) @@ -32,6 +25,22 @@ def rates # response = fedex.find_rates(origin, destination, package) # fedex_rates = response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]} + end + + private + def create_package + @package = ActiveShipping::Package.new(100, [10, 20, 30], :units => :metric) end + + def create_destination + @destination = ActiveShipping::Location.new(country: params[:destination_address][:country], + state: params[:destination_address][:state], + city: params[:destination_address][:city], + zip: params[:destination_address][:zip]) + end + + # "product[name]=Responsive Web Design with HTML5 and CSS3&product[sku]=1849693188&product[publisher]=Packt Publishing (April 10, 2012)" + # "destination_address[country]=US&destination_address[state]=WA&destination_address[city]=Seattle&destination_address[98112]" + end From 2346ea210f04e9b71da598f96e06aa1481b7f325 Mon Sep 17 00:00:00 2001 From: noglows Date: Wed, 20 Jan 2016 13:42:29 -0800 Subject: [PATCH 04/20] Working create_destination method --- app/controllers/packages_controller.rb | 9 ++++++--- config/routes.rb | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index 1cdc29e..be506f1 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -1,13 +1,15 @@ class PackagesController < ApplicationController - + skip_before_action :verify_authenticity_token + def rates + binding.pry package = create_package origin = ActiveShipping::Location.new(country: 'US', state: 'CA', city: 'Beverly Hills', zip: '90210') - destination = create_destination + destination = create_destination(params) # Verified USPS works usps = ActiveShipping::USPS.new(login: ENV["USPS_USERNAME"], password: ENV["USPS_PASSWORD"]) response = usps.find_rates(origin, destination, package) @@ -33,11 +35,12 @@ def create_package @package = ActiveShipping::Package.new(100, [10, 20, 30], :units => :metric) end - def create_destination + def create_destination(params) @destination = ActiveShipping::Location.new(country: params[:destination_address][:country], state: params[:destination_address][:state], city: params[:destination_address][:city], zip: params[:destination_address][:zip]) + end # "product[name]=Responsive Web Design with HTML5 and CSS3&product[sku]=1849693188&product[publisher]=Packt Publishing (April 10, 2012)" diff --git a/config/routes.rb b/config/routes.rb index bd06124..0b7c97d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do - get 'rates' => 'packages#rates' - get 'rates/:params' => 'packages#rates' + post 'rates' => 'packages#rates' + post 'rates/:params' => 'packages#rates' # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". From 2c795bfea11646d2fb84bba4b0fc7b0bcd844168 Mon Sep 17 00:00:00 2001 From: noglows Date: Wed, 20 Jan 2016 13:50:44 -0800 Subject: [PATCH 05/20] Working create_origin method --- app/controllers/packages_controller.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index be506f1..78f73f8 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -1,13 +1,13 @@ class PackagesController < ApplicationController skip_before_action :verify_authenticity_token - + def rates - binding.pry package = create_package - origin = ActiveShipping::Location.new(country: 'US', - state: 'CA', - city: 'Beverly Hills', - zip: '90210') + origin = create_origin(params) + # origin = ActiveShipping::Location.new(country: 'US', + # state: 'CA', + # city: 'Beverly Hills', + # zip: '90210') destination = create_destination(params) # Verified USPS works @@ -40,10 +40,12 @@ def create_destination(params) state: params[:destination_address][:state], city: params[:destination_address][:city], zip: params[:destination_address][:zip]) - end - # "product[name]=Responsive Web Design with HTML5 and CSS3&product[sku]=1849693188&product[publisher]=Packt Publishing (April 10, 2012)" - # "destination_address[country]=US&destination_address[state]=WA&destination_address[city]=Seattle&destination_address[98112]" - + def create_origin(params) + @origin = ActiveShipping::Location.new(country: params[:origin_address][:country], + state: params[:origin_address][:state], + city: params[:origin_address][:city], + zip: params[:origin_address][:zip]) + end end From a272a2ae57ec93e7174eef463c08bb4bf368120b Mon Sep 17 00:00:00 2001 From: noglows Date: Wed, 20 Jan 2016 13:55:37 -0800 Subject: [PATCH 06/20] Working create_package method --- app/controllers/packages_controller.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index 78f73f8..0dcd67e 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -2,14 +2,10 @@ class PackagesController < ApplicationController skip_before_action :verify_authenticity_token def rates - package = create_package + package = create_package(params) origin = create_origin(params) - # origin = ActiveShipping::Location.new(country: 'US', - # state: 'CA', - # city: 'Beverly Hills', - # zip: '90210') - destination = create_destination(params) + # Verified USPS works usps = ActiveShipping::USPS.new(login: ENV["USPS_USERNAME"], password: ENV["USPS_PASSWORD"]) response = usps.find_rates(origin, destination, package) @@ -31,8 +27,8 @@ def rates private - def create_package - @package = ActiveShipping::Package.new(100, [10, 20, 30], :units => :metric) + def create_package(params) + @package = ActiveShipping::Package.new(params[:package][:weight].to_i, [params[:package][:length].to_i, params[:package][:width].to_i, params[:package][:height].to_i], :units => params[:package][:units]) end def create_destination(params) From 188caffe5bc6276bc5e3283e69dfb9f3f4fac6be Mon Sep 17 00:00:00 2001 From: Katherine Defliese Date: Wed, 20 Jan 2016 14:01:49 -0800 Subject: [PATCH 07/20] changed route to get and got rid of helper spec --- config/routes.rb | 4 +- coverage/.last_run.json | 2 +- coverage/.resultset.json | 44 +++- coverage/index.html | 308 ++++++++++++++++++++++++--- spec/helpers/packages_helper_spec.rb | 2 +- 5 files changed, 327 insertions(+), 33 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 0b7c97d..3cac19d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do - post 'rates' => 'packages#rates' - post 'rates/:params' => 'packages#rates' + get 'rates' => 'packages#rates' + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/coverage/.last_run.json b/coverage/.last_run.json index 3cb5e70..006cd12 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "covered_percent": 100.0 + "covered_percent": 52.0 } } diff --git a/coverage/.resultset.json b/coverage/.resultset.json index 746be54..c0b630a 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -11,9 +11,51 @@ ], "/Users/katherinedefliese/Documents/Ada_homework/project-forks/shipping-service/app/controllers/packages_controller.rb": [ 1, + 1, + null, + 1, + 7, + 0, + 0, + null, + null, + 0, + 0, + 0, + null, + null, + 0, + 0, + 0, + null, + 0, + 0, + null, + null, + null, + null, + null, + null, null, 1, null, + 1, + 7, + null, + null, + 1, + 0, + null, + null, + null, + null, + null, + 1, + 0, + null, + null, + null, + null, null ], "/Users/katherinedefliese/Documents/Ada_homework/project-forks/shipping-service/app/controllers/application_controller.rb": [ @@ -24,6 +66,6 @@ null ] }, - "timestamp": 1453243290 + "timestamp": 1453326997 } } diff --git a/coverage/index.html b/coverage/index.html index ad227ca..77712ae 100644 --- a/coverage/index.html +++ b/coverage/index.html @@ -5,7 +5,7 @@ - + @@ -14,14 +14,14 @@ loading