controller
# hits https://github.com/birchbox/birchbox/blob/1d9dd77c1a060de8efdcd04ffd730e04a885e0ed/shop/app/code/local/Birchbox/Reward/controllers/BoxController.php#L10
def share_box
response = current_user.box_history.find(params[:box_id]).share_box(current_user.session_id)
if response["success"]
respond_with current_user.decorate
else
render :json => { :errors => response["message"] }, :status => response["status_code"]
end
end
the model
class Box < Remote::HTTPResource
base_uri File.join(Figaro.env.magento_uri, '/shop/reward/box')
.... other stuff
def share_box(session_id)
response = post("/share", body: {
box_history_id: id
}.to_json, headers: {
'X-Session-Id' => session_id
})
if !response["success"]
Rails.logger.error response.inspect
Rails.logger.error "There was a problem calling the Magento Share Box endpoint: #{response['message']}"
end
return response
end