Sha256: f7ea65ca55f8ce4d057ff8681c4d44d7fd470b4bb462e19083b7bcb74e98cadb

Contents?: true

Size: 1.56 KB

Versions: 27

Compression:

Stored size: 1.56 KB

Contents

require 'json'
require 'rest_client'

class Product < SourceAdapter
  def initialize(source)
    @base = 'http://rhostore.herokuapp.com/products'
    super(source)
  end

  def query
    parsed=JSON.parse(RestClient.get("#{@base}.json").body)

    @result={}
    if parsed
      parsed.each do |item|
        key = item["product"]["id"].to_s
        @result[key]=item["product"]
      end
    end
  end

    def sync
      # Manipulate @result before it is saved, or save it
      # yourself using the Rhoconnect::Store interface.
      # By default, super is called below which simply saves @result
      super
    end

    def create(create_hash)
      # TODO: Create a new record in your backend data source
      # If your rhodes rhom object contains image/binary data
      # (has the image_uri attribute), then a blob will be provided
      raise "Please provide some code to create a single record in the backend data source using the create_hash"
    end

    def update(update_hash)
      # TODO: Update an existing record in your backend data source
      raise "Please provide some code to update a single record in the backend data source using the update_hash"
    end

    def delete(delete_hash)
      # TODO: write some code here if applicable
      # be sure to have a hash key and value for "object"
      # for now, we'll say that its OK to not have a delete operation
      # raise "Please provide some code to delete a single object in the backend application using the object_id"
    end

    def logoff
      # TODO: Logout from the data source if necessary
    end
  end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
rhoconnect-7.6.0 examples/simple/sources/product.rb
rhoconnect-7.5.1 examples/simple/sources/product.rb
rhoconnect-7.4.1 examples/simple/sources/product.rb
rhoconnect-7.1.17 examples/simple/sources/product.rb
rhoconnect-6.2.0 examples/simple/sources/product.rb
rhoconnect-6.0.11 examples/simple/sources/product.rb
rhoconnect-5.5.18 examples/simple/sources/product.rb
rhoconnect-5.5.17 examples/simple/sources/product.rb
rhoconnect-5.5.15 examples/simple/sources/product.rb
rhoconnect-5.5.0.22 examples/simple/sources/product.rb
rhoconnect-5.5.2 examples/simple/sources/product.rb
rhoconnect-5.5.0.7 examples/simple/sources/product.rb
rhoconnect-5.5.0.3 examples/simple/sources/product.rb
rhoconnect-5.5.0 examples/simple/sources/product.rb
rhoconnect-5.1.1 examples/simple/sources/product.rb
rhoconnect-4.0.4 examples/simple/sources/product.rb
rhoconnect-4.0.3 examples/simple/sources/product.rb
rhoconnect-4.0.2 examples/simple/sources/product.rb
rhoconnect-4.0.1 examples/simple/sources/product.rb
rhoconnect-4.0.0 examples/simple/sources/product.rb