Class: WufooParty

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

Overview

:startdoc:

Defined Under Namespace

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

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(account, api_key) ⇒ WufooParty

Create a new WufooParty object



97
98
99
100
101
# File 'lib/wufoo_party.rb', line 97

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

Instance Method Details

#form(form_id) ⇒ Object

Returns details about the specified form.



125
126
127
128
129
# File 'lib/wufoo_party.rb', line 125

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.



104
105
106
107
108
# File 'lib/wufoo_party.rb', line 104

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

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

:nodoc:



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/wufoo_party.rb', line 138

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
end

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

:nodoc:



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/wufoo_party.rb', line 151

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
end

#report(report_id) ⇒ Object

Returns details about the specified report.



132
133
134
135
136
# File 'lib/wufoo_party.rb', line 132

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

#reportsObject

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



111
112
113
114
115
# File 'lib/wufoo_party.rb', line 111

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.



118
119
120
121
122
# File 'lib/wufoo_party.rb', line 118

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