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

update v3 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
72 changes: 65 additions & 7 deletions v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
require 'sinatra/cross_origin'
require 'multi_json'
require 'newrelic_rpm'
require 'active_support/hash_with_indifferent_access'
require 'active_support/core_ext/hash'
require 'json'

class StubApi < Sinatra::Base
register Sinatra::CrossOrigin
Expand Down Expand Up @@ -37,11 +40,62 @@ def halt_with_error(error, response_body)
"the stub api is up!"
end

post '/v3/data/' do
post '/api/v2/data/?' do
puts " "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use logger instead of puts statements?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or are the behaviorally different for some reason?)

puts "v2 data sent?!"
puts " "
puts " "
puts " "
puts " "
body_read = request.body.read
puts "headers"
puts JSON.pretty_generate(request.env)
puts "body"
puts JSON.pretty_generate(MultiJson.decode(body_read))

response_body = {}
params = MultiJson.decode(request.body.read)
params = HashWithIndifferentAccess.new(params)
response_body[:heh] = "v2 whyyy"

puts "response"
puts JSON.pretty_generate(response_body)
response_body.to_json
end

post '/v3/feedback/?' do
puts " "
puts "FEEDBACK REQUEST START"
puts " "
puts " "
puts " "
puts " "
body_read = request.body.read
# puts "headers"
# puts JSON.pretty_generate(request.env)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove or uncomment this?

puts "body"
puts JSON.pretty_generate(MultiJson.decode(body_read))

response_body = {}
response_body[:heh] = "test feedback i guess"

puts "response"
puts JSON.pretty_generate(response_body)
response_body.to_json
end

post '/v3/data/?' do
puts " "
puts "REQUEST START"
puts " "
puts " "
body_read = request.body.read
# puts "headers"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same note about commented out logging here

# puts JSON.pretty_generate(request.env)
puts "body"
puts JSON.pretty_generate(MultiJson.decode(body_read))

response_body = {}
params = MultiJson.decode(body_read)
params = HashWithIndifferentAccess.new(params)
if params[:time].nil?
halt_with_error("time must not be nil", response_body)
end
Expand Down Expand Up @@ -97,6 +151,7 @@ def halt_with_error(error, response_body)
end

if !params[:attributes].nil?
attributes_object = params[:attributes]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line appears to be irrelevant/cruft?

params[:attributes].each do |attributes_object|
logger.info("Received attributes for user #{attributes_object[:user_id]} with custom #{attributes_object[:custom].inspect}, push_token #{attributes_object[:push_token]}, first_name #{attributes_object[:first_name]}, last_name #{attributes_object[:last_name]}, email #{attributes_object[:email]}, dob #{attributes_object[:dob]}, country #{attributes_object[:country]}, home_city #{attributes_object[:home_city]}, bio #{attributes_object[:bio]}, gender #{attributes_object[:gender]}, phone #{attributes_object[:phone]}, email_subscribe #{attributes_object[:email_subscribe]}, push_subscribe #{attributes_object[:push_subscribe]}, image_url #{attributes_object[:image_url]}, facebook #{attributes_object[:facebook]}, twitter #{attributes_object[:twitter]}, foursquare #{attributes_object[:foursquare]}, foursquare_access_token #{attributes_object[:foursquare_access_token]}")
end
Expand Down Expand Up @@ -251,6 +306,7 @@ def halt_with_error(error, response_body)
"uri" => "http://google.com",
"message_close" => "AUTO_DISMISS",
"icon" => "\uf042",
"type" => "FULL",
"icon_color" => 4294901760
}

Expand Down Expand Up @@ -291,11 +347,13 @@ def halt_with_error(error, response_body)
end
end

if params[:api_key].starts_with?("sleep_")
sleep_time = params[:api_key][6..-1].to_i
sleep sleep_time
end
# if params[:api_key].starts_with?("sleep_")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we leave this code in?

# sleep_time = params[:api_key][6..-1].to_i
# sleep sleep_time
# end

puts "response"
puts JSON.pretty_generate(response_body)
response_body.to_json
end
end