From 31e31598e9f03b0da028597f667955a2f623a1ca Mon Sep 17 00:00:00 2001 From: chshapiro Date: Thu, 30 Mar 2017 12:09:09 -0400 Subject: [PATCH] update v3 --- v3.rb | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 7 deletions(-) diff --git a/v3.rb b/v3.rb index aec6a0d..8b8e380 100644 --- a/v3.rb +++ b/v3.rb @@ -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 @@ -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 " " + 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) + 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" + # 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 @@ -97,6 +151,7 @@ def halt_with_error(error, response_body) end if !params[:attributes].nil? + attributes_object = params[:attributes] 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 @@ -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 } @@ -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_") + # 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