Sha256: 73bc59f78f91b5d4a253b8cdf94cd0dfae46d8acf9a5347a83af26c2a9e6bcff

Contents?: true

Size: 887 Bytes

Versions: 2

Compression:

Stored size: 887 Bytes

Contents

require 'sinatra/shopify-sinatra-app'

class SinatraApp < Sinatra::Base
  register Sinatra::Shopify

  get '/' do
    # your app's Home page
    shopify_session do |shop_name|
      @shop_name = shop_name
      @products = ShopifyAPI::Product.all(limit: 5)
      erb :home
    end
  end

  private

  def install
    # setup any webhooks or services you need when your app is installed
    shopify_session do |shop_name|
      params = YAML.load(File.read("config/app.yml"))

      # create the uninstall webhook
      uninstall_webhook = ShopifyAPI::Webhook.new(params["uninstall_webhook"])
      unless ShopifyAPI::Webhook.find(:all).include?(uninstall_webhook)
        uninstall_webhook.save
      end
    end
    redirect '/'
  end

  def uninstall
    # remove data for a shop when they uninstall your app
    webhook_session do |shop, params|
      shop.destroy
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shopify-sinatra-app-0.0.3 lib/generator/lib/app.rb
shopify-sinatra-app-0.0.2 lib/generator/lib/app.rb