Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'master' of github.com:scrive/petitions

  • Loading branch information...
commit 4f4ea8c3e77913c377c5b6df75f7cdc5c2414735 2 parents 8c48910 + 250ac63
gracjan authored October 31, 2011

Showing 1 changed file with 23 additions and 4 deletions. Show diff stats Hide diff stats

  1. 27  app.rb
27  app.rb
@@ -65,11 +65,21 @@ def creator
65 65
     signers.sort{ |a,b| b.date <=> a.date }.first
66 66
   end
67 67
   
  68
+  def delete
  69
+    response = RestClient.post( "#{API[:url]}new_document",
  70
+                                'service' => API[:service],
  71
+                                'password' => API[:password],
  72
+                                'body' => { "document_id" => document_id, }
  73
+                              )
  74
+    @@all.delete self
  75
+  end
  76
+  
68 77
   class << self
69 78
     
70 79
     # This is how we create new petitions.
71 80
     #
72 81
     def create title, filedata
  82
+      filedata.gsub! "\n", ""
73 83
       response = RestClient.post( "#{API[:url]}new_document",
74 84
                                   'service' => API[:service],
75 85
                                   'password' => API[:password],
@@ -86,18 +96,21 @@ def create title, filedata
86 96
 
87 97
       puts response
88 98
       
89  
-      #scrive_object = response[...]
  99
+      document_id = response['document_id']
90 100
       
91 101
       #first_signer = 
92 102
 
93 103
       Petition.new({
94  
-        #:document_id => scrive_object['document_id'],
  104
+        :document_id => document_id,
95 105
         :title => title,
  106
+        #:slug => slugify(title),
96 107
         :pdf => filedata,
97 108
         #:signers => [first_signer],
98 109
       })
99 110
     end
100 111
 
  112
+    
  113
+
101 114
     # Fetch all petitions (documents) from the Scrive API
102 115
     #
103 116
     def all
@@ -112,7 +125,8 @@ def fetch_all_petitions
112 125
       response = RestClient.post( "#{API[:url]}documents",
113 126
                                   'service' => API[:service],
114 127
                                   'password' => API[:password],
115  
-                                  'body' => { 'company_id' => '0' }.to_json )
  128
+                                  #'body' => { 'company_id' => '0' }.to_json )
  129
+                                  'body' => {}.to_json )
116 130
 
117 131
       raise "Could not retreive documents from API!" unless response
118 132
 
@@ -122,7 +136,12 @@ def fetch_all_petitions
122 136
       petitions ||= []
123 137
 
124 138
       created = petitions.map do |petition|
125  
-        Petition.new(petition) unless find petition['document_id']
  139
+        unless find petition['document_id']
  140
+          Petition.new({
  141
+            :document_id => petition['document_id'],
  142
+            :title => petition['title'],
  143
+          })
  144
+        end
126 145
       end
127 146
     end
128 147
 

0 notes on commit 4f4ea8c

Please sign in to comment.
Something went wrong with that request. Please try again.