<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>vendor/sync/Store/README.txt</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -162,8 +162,6 @@ class SourcesController &lt; ApplicationController
   # RETURNS:
   #   a hash of the object_values table ID columns as keys and the updated_at times as values
   def createobjects
-    @app=App.find_by_permalink(params[:app_id]) if params[:app_id]
-    @source=Source.find_by_permalink(params[:id]) if params[:id]
     check_access(@source.app)
     objects={}
     @client = Client.find_by_client_id(params[:client_id]) if params[:client_id]</diff>
      <filename>app/controllers/sources_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -222,7 +222,7 @@ module SourcesHelper
             res = nil
             tmp_object = ClientTempObject.find_by_temp_objectid(x.object)
             begin
-              res = eval cmd
+              res = eval(cmd)
               if res and res.is_a?(String) and tmp_object
                 tmp_object.update_attributes(:objectid =&gt; res, :source_id =&gt; id)
               end</diff>
      <filename>app/helpers/sources_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 &lt;h2&gt;Creating Object for Sync &lt;/h2&gt;
 Creates an object with up to five attribute value pairs
-&lt;% form_for :source, :url =&gt; &quot;/apps/#{@source.app.id}/sources/#{@source.id}/createobjects&quot; do |f| %&gt;
+&lt;% form_for :source, :url =&gt; createobjects_source_path(@source) do |f| %&gt;
 &lt;input type=&quot;Submit&quot; value=&quot;Create Object Value&quot;/&gt;&lt;br/&gt;
 &lt;input type=&quot;hidden&quot; name=&quot;attrvals[][object]&quot; value=&quot;temp1&quot;/&gt;
 Attribute Name &lt;input name=&quot;attrvals[][attrib]&quot; value=&quot;&quot;/&gt;&lt;br/&gt;</diff>
      <filename>app/views/sources/newobject.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -201,7 +201,7 @@ describe SourcesController do
 
   describe &quot;responding to createobjects, deleteobjects, updateobjects&quot; do
     it &quot;should createobjects&quot; do
-      Source.should_receive(:find).twice.with(37).and_return(mock_source)
+      Source.should_receive(:find).with(37).and_return(mock_source)
       get :createobjects,:id =&gt; &quot;37&quot;, :attrvals =&gt; [{&quot;object&quot;=&gt;&quot;temp1&quot;,&quot;attrib&quot;=&gt;&quot;name&quot;,&quot;value&quot;=&gt;&quot;rhomobile&quot;}]
       response.should be_redirect
     end</diff>
      <filename>spec/controllers/sources_controller_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,6 @@
 require 'json'
 require 'open-uri'
+
 class Customer &lt; SourceAdapter
   def initialize(source,credential)
     super(source,credential)
@@ -9,6 +10,8 @@ class Customer &lt; SourceAdapter
   end
  
   def query(conditions=nil,limit=nil,offset=nil)
+    # backend for this source adapter implements condtions
+    
     logger = Logger.new('log/store.log', File::WRONLY | File::APPEND)
     logger.debug &quot;query called with conditions=#{conditions} limit=#{limit} and offset=#{offset}&quot;
     
@@ -20,11 +23,11 @@ class Customer &lt; SourceAdapter
     open(url) do |f|
       parsed=JSON.parse(f.read)
     end
-      logger.debug parsed.inspect.to_s
+    
+    logger.debug parsed.inspect.to_s
     @result={}
     
     parsed.each { |item|@result[item[&quot;customer&quot;][&quot;id&quot;].to_s]=item[&quot;customer&quot;] } if parsed
-    
     logger.debug @result.inspect.to_s
     
     @result
@@ -82,7 +85,7 @@ class Customer &lt; SourceAdapter
         open(res['location']+&quot;.json&quot;) do |f|
           parsed=JSON.parse(f.read)
         end
-        return parsed[&quot;customer&quot;][&quot;id&quot;]
+        return parsed[&quot;customer&quot;][&quot;id&quot;] rescue nil
     end
   end
  </diff>
      <filename>vendor/sync/Store/customer.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,104 @@
-require 'rubygems'
-require 'active_resource'
-require 'rho_helper'
-class Product &lt; ActiveResource::Base
-  include RhoHelper
-  self.site = &quot;http://rhostore.heroku.com/&quot;
+require 'json'
+require 'open-uri'
+
+class Product &lt; SourceAdapter
+  def initialize(source,credential)
+    super(source,credential)
+  end
+ 
+  def login
+  end
+ 
+  # backend for this source adapter doesnt implement condtions but limit and offset
+  def query(conditions=nil,limit=nil,offset=nil)
+
+    url=&quot;http://rhostore.heroku.com/products.json&quot;
+    if limit &amp; offset
+      url += &quot;?limit=#{limit}&amp;offset=#{offset}&quot;
+    end
+    
+    parsed=nil
+    open(url) do |f|
+      parsed=JSON.parse(f.read)
+    end
+    
+    Rails.logger.debug parsed.inspect.to_s
+    @result={}
+    
+    parsed.each { |item|@result[item[&quot;product&quot;][&quot;id&quot;].to_s]=item[&quot;product&quot;] } if parsed
+    Rails.logger.debug @result.inspect.to_s
+    
+    @result
+  end
+
+  # ENABLE THIS IF YOU WANT TO TEST BACKGROUND SYNC AKA PAGED QUERY
+  # implemented in terms of query
+  # for testing only we have hardcoded a page size of 10
+  def page(num)
+    Rails.logger.debug &quot;page %d num class is %s&quot; % [num, num.class.to_s]
+    @result = query(nil, 10, num.to_i * 10)
+    return nil if @result.empty? # nil tells rhosync there are no more pages
+  end
+ 
+  def sync
+    # TODO: write code here that converts the data you got back from query into an @result object
+    # where @result is an array of hashes,  each array item representing an object
+    super # this creates object value triples from an @result variable that contains an array of hashes
+  end
+ 
+  def create(name_value_list)
+    attrvals={}
+    name_value_list.each { |nv| attrvals[&quot;product[&quot;+nv[&quot;name&quot;]+&quot;]&quot;]=nv[&quot;value&quot;]} # convert name-value list to hash
+    res = Net::HTTP.post_form(URI.parse(&quot;http://rhostore.heroku.com/products&quot;),attrvals)
+
+    # after create we are redirected to the new record. We need to get the id of that record and return it as part of create
+    # so rhosync can establish connection from its temporary object on the client to this newly created object on the server
+    case res
+      when Net::HTTPRedirection 
+        parsed = {}
+        open(res['location']+&quot;.json&quot;) do |f|
+          parsed=JSON.parse(f.read)
+        end
+        return parsed[&quot;product&quot;][&quot;id&quot;] rescue nil
+    end
+  end
+ 
+  def update(name_value_list) 
+    obj_id = name_value_list.find { |item| item['name'] == 'id' }
+    name_value_list.delete(obj_id)
+
+    params={}     
+    name_value_list.each {|nv|params[nv[&quot;name&quot;]]=nv[&quot;value&quot;]}
+
+    uri = URI.parse('http://rhostore.heroku.com')
+    Net::HTTP.start(uri.host) do |http|
+      request = Net::HTTP::Put.new(uri.path + &quot;/products/#{obj_id['value']}.xml&quot;, {'Content-type' =&gt; 'application/xml'})
+      request.body = xml_template(params)
+      response = http.request(request)
+    end
+  end
+ 
+  def delete(name_value_list)
+    attrvals={}     
+    name_value_list.each {|nv|attrvals[&quot;product[&quot;+nv[&quot;name&quot;]+&quot;]&quot;]=nv[&quot;value&quot;]}
+    http=Net::HTTP.new(&#8216;rhostore.heroku.com&#8217;,80)
+    path=&quot;/products/#{attrvals['id']}&quot;
+    resp=http.delete(path)
+  end
+ 
+  def logoff
+    #TODO: write some code here if applicable
+    # no need to do a raise here
+  end
+  
+  protected
+  # API is expecting us to send XML content
+  def xml_template(params)
+    xml_str = &quot;&lt;product&gt;&quot;
+    params.each do |key,value|
+      xml_str += &quot;&lt;#{key}&gt;#{value}&lt;/#{key}&gt;&quot;
+     end
+     xml_str += &quot;&lt;/product&gt;&quot;
+     xml_str
+   end
 end
\ No newline at end of file</diff>
      <filename>vendor/sync/Store/product.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>vendor/sync/Store/product_adapter.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>71918209a529832cfad7312196aeba2218abb1d0</id>
    </parent>
  </parents>
  <author>
    <name>Vidal Graupera</name>
    <email>vidal@vdggroup.com</email>
  </author>
  <url>http://github.com/rhomobile/rhosync/commit/6aef6cda71e129e9ff5e34379ae7a7de8b2137de</url>
  <id>6aef6cda71e129e9ff5e34379ae7a7de8b2137de</id>
  <committed-date>2009-11-09T13:56:24-08:00</committed-date>
  <authored-date>2009-11-09T13:56:24-08:00</authored-date>
  <message>updated store and product adapters per adam, fixed one test, cleaned up one page and removed a duplicate query for source...</message>
  <tree>102b616b1209a0be01993ecc73790a6854a0d264</tree>
  <committer>
    <name>Vidal Graupera</name>
    <email>vidal@vdggroup.com</email>
  </committer>
</commit>
