Skip to content

Instantly share code, notes, and snippets.

@richiejd
Created March 30, 2015 20:11
Show Gist options
  • Save richiejd/3195f58d08a0d589073a to your computer and use it in GitHub Desktop.
Save richiejd/3195f58d08a0d589073a to your computer and use it in GitHub Desktop.
Tryin man, I'm tryin

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment