Permalink
Browse files

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

  • Loading branch information...
2 parents 8c48910 + 250ac63 commit 4f4ea8c3e77913c377c5b6df75f7cdc5c2414735 @gracjan gracjan committed Oct 31, 2011
Showing with 23 additions and 4 deletions.
  1. +23 −4 app.rb
View
27 app.rb
@@ -65,11 +65,21 @@ def creator
signers.sort{ |a,b| b.date <=> a.date }.first
end
+ def delete
+ response = RestClient.post( "#{API[:url]}new_document",
+ 'service' => API[:service],
+ 'password' => API[:password],
+ 'body' => { "document_id" => document_id, }
+ )
+ @@all.delete self
+ end
+
class << self
# This is how we create new petitions.
#
def create title, filedata
+ filedata.gsub! "\n", ""
response = RestClient.post( "#{API[:url]}new_document",
'service' => API[:service],
'password' => API[:password],
@@ -86,18 +96,21 @@ def create title, filedata
puts response
- #scrive_object = response[...]
+ document_id = response['document_id']
#first_signer =
Petition.new({
- #:document_id => scrive_object['document_id'],
+ :document_id => document_id,
:title => title,
+ #:slug => slugify(title),
:pdf => filedata,
#:signers => [first_signer],
})
end
+
+
# Fetch all petitions (documents) from the Scrive API
#
def all
@@ -112,7 +125,8 @@ def fetch_all_petitions
response = RestClient.post( "#{API[:url]}documents",
'service' => API[:service],
'password' => API[:password],
- 'body' => { 'company_id' => '0' }.to_json )
+ #'body' => { 'company_id' => '0' }.to_json )
+ 'body' => {}.to_json )
raise "Could not retreive documents from API!" unless response
@@ -122,7 +136,12 @@ def fetch_all_petitions
petitions ||= []
created = petitions.map do |petition|
- Petition.new(petition) unless find petition['document_id']
+ unless find petition['document_id']
+ Petition.new({
+ :document_id => petition['document_id'],
+ :title => petition['title'],
+ })
+ end
end
end

0 comments on commit 4f4ea8c

Please sign in to comment.