Class: WuParty

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/wuparty.rb

Overview

:startdoc:

Defined Under Namespace

Classes: ConnectionError, Entity, Form, HTTPError, Report, User

Constant Summary collapse

VERSION =
'1.2.3'
ENDPOINT =
'https://%s.wufoo.com/api/v3'
API_VERSION =
'3.0'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account, api_key) ⇒ WuParty

Create a new WuParty object



109
110
111
112
113
# File 'lib/wuparty.rb', line 109

def initialize(, api_key)
  @account = 
  @api_key = api_key
  @field_numbers = {}
end

Class Method Details

.login(integration_key, email, password, account = nil) ⇒ Object

uses the Login API to fetch a user’s API key



97
98
99
100
101
102
103
104
105
106
# File 'lib/wuparty.rb', line 97

def self.(integration_key, email, password,  = nil)
  result = self.post("https://wufoo.com/api/v3/login.json", { :body => { :integrationKey => integration_key, :email => email, :password => password, :subdomain =>  }})
  if result.is_a?(String)
    raise ConnectionError, result
  elsif result['HTTPCode']
    raise HTTPError.new(result['HTTPCode'], result['Text'])
  else
    result
  end
end

Instance Method Details

#add_webhook(form_id, url, metadata = false, handshakeKey = "") ⇒ Object



143
144
145
# File 'lib/wuparty.rb', line 143

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

#delete(method, options = {}) ⇒ Object

:nodoc:



170
171
172
# File 'lib/wuparty.rb', line 170

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

#delete_webhook(form_id, webhook_hash) ⇒ Object



147
148
149
# File 'lib/wuparty.rb', line 147

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

#form(form_id) ⇒ Object

Returns details about the specified form.



137
138
139
140
141
# File 'lib/wuparty.rb', line 137

def form(form_id)
  if f = get("forms/#{form_id}")['Forms']
    Form.new(f.first['Url'], :party => self, :details => f.first)
  end
end

#formsObject

Returns list of forms and details accessible by the user account.



116
117
118
119
120
# File 'lib/wuparty.rb', line 116

def forms
  get(:forms)['Forms'].map do |details|
    Form.new(details['Url'], :party => self, :details => details)
  end
end

#get(method, options = {}) ⇒ Object

:nodoc:



158
159
160
# File 'lib/wuparty.rb', line 158

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

#post(method, options = {}) ⇒ Object

:nodoc:



162
163
164
# File 'lib/wuparty.rb', line 162

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

#put(method, options = {}) ⇒ Object

:nodoc:



166
167
168
# File 'lib/wuparty.rb', line 166

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

#report(report_id) ⇒ Object

Returns details about the specified report.



152
153
154
155
156
# File 'lib/wuparty.rb', line 152

def report(report_id)
  if r = get("reports/#{report_id}")['Reports']
    Report.new(r.first['Url'], :party => self, :details => r.first)
  end
end

#reportsObject

Returns list of reports and details accessible by the user account.



123
124
125
126
127
# File 'lib/wuparty.rb', line 123

def reports
  get(:reports)['Reports'].map do |details|
    Report.new(details['Url'], :party => self, :details => details)
  end
end

#usersObject

Returns list of users and details.



130
131
132
133
134
# File 'lib/wuparty.rb', line 130

def users
  get(:users)['Users'].map do |details|
    User.new(details['Url'], :party => self, :details => details)
  end
end