Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jnkd/master - finished project #15

Open
wants to merge 21 commits into
base: jnkd/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
Expand Down Expand Up @@ -33,6 +33,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc
# gem 'capistrano-rails', group: :development

gem 'active_shipping'
gem 'pg'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand All @@ -41,6 +42,8 @@ group :development, :test do
gem 'pry'
gem 'simplecov'
gem 'factory_girl_rails'
gem 'dotenv-rails'

end

group :development do
Expand All @@ -49,6 +52,7 @@ group :development do

gem 'better_errors'
gem 'binding_of_caller'
gem 'sqlite3'

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -94,6 +98,7 @@ GEM
multi_json (1.11.2)
nokogiri (1.6.7.1)
mini_portile2 (~> 2.0.0.rc2)
pg (0.18.4)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
Expand Down Expand Up @@ -196,9 +201,11 @@ DEPENDENCIES
binding_of_caller
byebug
coffee-rails (~> 4.1.0)
dotenv-rails
factory_girl_rails
jbuilder (~> 2.0)
jquery-rails
pg
pry
rails (= 4.2.5)
rspec-rails (~> 3.0)
Expand Down
43 changes: 33 additions & 10 deletions app/controllers/packages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
class PackagesController < ApplicationController

def rates
package = ActiveShipping::Package.new(100, [10, 20, 30], :units => :metric)
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')
if params["package"]["width"].to_i == 0 || params["package"]["height"].to_i == 0 || params["package"]["length"].to_i == 0 || params["package"]["weight"].to_i == 0
return render :json => ["Incorrect or missing parameters for package"], :status => :bad_request
end

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])


begin
origin = ActiveShipping::Location.new(params[:origin])
rescue
return render :json => ["Incorrect or missing parameters for origin address"], :status => :bad_request
end

begin
destination = ActiveShipping::Location.new(params[:destination])
rescue
return render :json => ["Incorrect or missing parameters for destination address"], :status => :bad_request
end

begin
usps = ActiveShipping::USPS.new(login: ENV["USPS_USERNAME"], password: ENV["USPS_PASSWORD"])
usps_response = usps.find_rates(origin, destination, package)
usps_rates = usps_response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]}

ups = ActiveShipping::UPS.new(login: ENV["UPS_ACCOUNT_NAME"], password: ENV["UPS_ACCOUNT_PASSWORD"], key: ENV["UPS_ACCESS_KEY"])
ups_response = ups.find_rates(origin, destination, package)
ups_rates = ups_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
rescue
return render :json => "There has been an error", :status => :no_content
end
end
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Rails.application.routes.draw do

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".

Expand Down
2 changes: 1 addition & 1 deletion coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"result": {
"covered_percent": 100.0
"covered_percent": 96.0
}
}
43 changes: 38 additions & 5 deletions coverage/.resultset.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,62 @@
{
"RSpec": {
"coverage": {
"/Users/katherinedefliese/Documents/Ada_homework/project-forks/shipping-service/app/helpers/application_helper.rb": [
"/Users/jessica/Documents/Ada/project-forks/shipping_service_project/shipping-service/app/helpers/application_helper.rb": [
1,
null
],
"/Users/katherinedefliese/Documents/Ada_homework/project-forks/shipping-service/app/helpers/packages_helper.rb": [
"/Users/jessica/Documents/Ada/project-forks/shipping_service_project/shipping-service/app/helpers/packages_helper.rb": [
1,
null
],
"/Users/katherinedefliese/Documents/Ada_homework/project-forks/shipping-service/app/controllers/packages_controller.rb": [
"/Users/jessica/Documents/Ada/project-forks/shipping_service_project/shipping-service/app/controllers/packages_controller.rb": [
1,
null,
1,
6,
1,
null,
null,
5,
null,
null,
5,
5,
null,
1,
null,
null,
4,
4,
null,
1,
null,
null,
3,
3,
3,
36,
null,
3,
3,
21,
null,
3,
3,
null,
0,
null,
null,
null
],
"/Users/katherinedefliese/Documents/Ada_homework/project-forks/shipping-service/app/controllers/application_controller.rb": [
"/Users/jessica/Documents/Ada/project-forks/shipping_service_project/shipping-service/app/controllers/application_controller.rb": [
1,
null,
null,
1,
null
]
},
"timestamp": 1453243290
"timestamp": 1453502619
}
}
Loading