Skip to content

Commit

Permalink
Merge pull request #3 from GrooveStomp/master
Browse files Browse the repository at this point in the history
Add and remove webhooks from Wufoo forms.
  • Loading branch information
seven1m committed May 13, 2011
2 parents 4724ac3 + 9fce0ae commit 73a01ee
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions lib/wuparty.rb
Expand Up @@ -128,6 +128,14 @@ def form(form_id)
end
end

def add_webhook(form_id, url)
put("forms/#{form_id}/webhooks", :body => {'url' => url})
end

def delete_webhook(form_id, webhook_hash)
delete("forms/#{form_id}/webhooks/#{webhook_hash}")
end

# Returns details about the specified report.
def report(report_id)
if r = get("reports/#{report_id}")['Reports']
Expand All @@ -136,29 +144,19 @@ def report(report_id)
end

def get(method, options={}) # :nodoc:
options.merge!(:basic_auth => {:username => @api_key})
url = "#{base_url}/#{method}.json"
result = self.class.get(url, options)
if result.is_a?(String)
raise ConnectionError, result
elsif result['HTTPCode']
raise HTTPError.new(result['HTTPCode'], result['Text'])
else
result
end
handle_http_verb(:get, method, options)
end

def post(method, options={}) # :nodoc:
options.merge!(:basic_auth => {:username => @api_key})
url = "#{base_url}/#{method}.json"
result = self.class.post(url, options)
if result.is_a?(String)
raise ConnectionError, result
elsif result['HTTPCode']
raise HTTPError.new(result['HTTPCode'], result['Text'])
else
result
end
handle_http_verb(:post, method, options)
end

def put(method, options={}) # :nodoc:
handle_http_verb(:put, method, options)
end

def delete(method, options={}) # :nodoc:
handle_http_verb(:delete, method, options)
end

private
Expand All @@ -167,6 +165,19 @@ def base_url
ENDPOINT % @account
end

def handle_http_verb(verb, action, options={})
options.merge!(:basic_auth => {:username => @api_key})
url = "#{base_url}/#{action}.json"
result = self.class.send(verb, url, options)
if result.is_a?(String)
raise ConnectionError, result
elsif result['HTTPCode']
raise HTTPError.new(result['HTTPCode'], result['Text'])
else
result
end
end

public

# ----------
Expand Down

0 comments on commit 73a01ee

Please sign in to comment.