Skip to content

Commit

Permalink
Merge pull request #6 from hiringthing/master
Browse files Browse the repository at this point in the history
Added Login API support & Support for Metadata in Webhook calls
  • Loading branch information
seven1m committed Apr 23, 2012
2 parents e9f837f + 9de58bb commit 2a47c43
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
12 changes: 12 additions & 0 deletions README.rdoc
Expand Up @@ -53,12 +53,24 @@ Make sure you have latest version installed (1.0.0 or higher).
# Add a webhook to your Wufoo form.
# Any submission to this form will now post to the given url.
result = form.add_webhook('http://www.postbin.org/zh9iy1')
# Tell the webhook to include metadata in its postback
result = form.add_webhook('http://www.postbin.org/zh9iy1', true)

result = form.delete_webhook(result["WebHookPutResult"]["Hash"])

# Or, directly through wufoo:
result = wufoo.add_webhook(FORM_ID, 'http://www.postbin.org/zh9iy1')
# Tell the webhook to include metadata in its postback
result = wufoo.add_webhook(FORM_ID, 'http://www.postbin.org/zh9iy1', true)

result = wufoo.delete_webhook(FORM_ID, result["WebHookPutResult"]["Hash"])

# You can use the Login API (http://www.wufoo.com/docs/api/v3/login/), like so
result = WuParty.login(myIntegrationKey, users_email, users_password)

# or
result = WuParty.login(myIntegrationKey, users_email, users_password, users_subdomain)

== Feedback

I’d love to hear from you if you have suggestions for improvement, bug fixes, or whatever.
Expand Down
21 changes: 17 additions & 4 deletions lib/wuparty.rb
Expand Up @@ -93,6 +93,19 @@ def initialize(code, message) # :nodoc:
ENDPOINT = 'https://%s.wufoo.com/api/v3'
API_VERSION = '3.0'

# uses the Login API to fetch a user's API key
def self.login(integration_key, email, password, account = nil)
result = self.post("https://wufoo.com/api/v3/login.json", { :body => { :integrationKey => integration_key, :email => email, :password => password, :subdomain => account }})
puts result
if result.is_a?(String)
raise ConnectionError, result
elsif result['HTTPCode']
raise HTTPError.new(result['HTTPCode'], result['Text'])
else
result
end
end

# Create a new WuParty object
def initialize(account, api_key)
@account = account
Expand Down Expand Up @@ -128,8 +141,8 @@ def form(form_id)
end
end

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

def delete_webhook(form_id, webhook_hash)
Expand Down Expand Up @@ -228,8 +241,8 @@ def [](id)
@details[id]
end

def add_webhook(url)
@party.add_webhook(@details["Hash"], url)
def add_webhook(url, metadata = false)
@party.add_webhook(@details["Hash"], url, metadata)
end

def delete_webhook(webhook_id)
Expand Down

0 comments on commit 2a47c43

Please sign in to comment.