Example code for creating Child and Caregiver Profile Data
require 'json'
require 'faraday'
require 'addressable'
class ASQMiddleware < Faraday::Middleware
def initialize(app, options)
@app = app
@token = options[:token]
end
def call(env)
env[:request_headers]["Accept"] = "application/json"
env[:request_headers]["X-Auth-Token"] = @token
@app.call(env)
end
end
connection = Faraday.new(:url => "http://localhost") do |conn|
# Note that this token must be for a program
conn.use ASQMiddleware, :token => "0c8d74ead059792c1373381b22c7ae1f"
conn.adapter Faraday.default_adapter
end
response = connection.post("/api/child_profiles") do |req|
req.headers["Content-Type"] = "application/json"
req.body = {
"child_profile" => {
"alternate_id" => "alternate id",
"first_name" => "Billy",
"middle_name" => "The",
"last_name" => "Kid",
"dob" => "2010-02-28",
"weeks_premature" => 2,
"gender" => true,
"primary_home_language" => "Spanish",
"secondary_home_language" => "Korean",
"address1" => "123 Main St.",
"address2" => "Building 3",
"address3" => "Unit 7",
"city" => "Exampleton",
"county" => "Orange",
"state" => "California",
"country" => "United States",
"zip" => "12345",
"phone" => "555-123-4567",
"date_of_admission_to_monitoring_program" => "2010-05-28",
"birth_weight_pounds" => 9,
"birth_weight_ounces" => 3,
"ethnicity" => "Asian,Hispanic or Latino",
"custom_fields" => {
"hair_color" => "Brown"
}
}
}.to_json
end
raise "error" unless response.success?
location = response.headers["Location"]
response = connection.get(location)
raise "error" unless response.success?
child_profile = JSON.parse(response.body)
require 'json'
require 'faraday'
class ASQMiddleware < Faraday::Middleware
def initialize(app, options)
@app = app
@token = options[:token]
end
def call(env)
env[:request_headers]["Accept"] = "application/json"
env[:request_headers]["X-Auth-Token"] = @token
@app.call(env)
end
end
connection = Faraday.new(:url => "http://localhost") do |conn|
# Note that this token must be for a program
conn.use ASQMiddleware, :token => "0c8d74ead059792c1373381b22c7ae1f"
conn.adapter Faraday.default_adapter
end
response = connection.post("/api/caregiver_profiles") do |req|
req.headers["Content-Type"] = "application/json"
req.body = {
"caregiver_profile" => {
"prefix" => "Ms.",
"first_name" => "Sally",
"middle_name" => "Ann",
"last_name" => "Struthers",
"relationship_to_child" => "Child care provider",
"email" => "[email protected]",
"phone" => "555-123-4567",
"alternate_phone" => "555-987-6543",
"address1" => "123 Main St.",
"address2" => "Ste. 100",
"address3" => "Building 4",
"city" => "Towson",
"county" => "Baltimore County",
"state" => "MD",
"zip" => "21200",
"country" => "USA",
"primary_home_language" => "Korean",
"secondary_home_language" => "English",
"custom_fields" => {
"hair_color" => "Brown"
}
}
}.to_json
end
raise "error" unless response.success?
location = response.headers["Location"]
response = connection.get(location)
raise "error" unless response.success?
caregiver_profile = JSON.parse(response.body)