Class: WuParty

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

Defined Under Namespace

Classes: ConnectionError, HTTPError

Constant Summary collapse

API_VERSION =
'3.0'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account, api_key, domain: 'wufoo.com', account_prefix: nil) ⇒ WuParty

Create a new WuParty object



48
49
50
51
52
53
54
# File 'lib/wuparty.rb', line 48

def initialize(, api_key, domain: 'wufoo.com', account_prefix: nil)
  @account = 
  @api_key = api_key
  @domain = domain
  @account_prefix =  || @account
  @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

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/wuparty.rb', line 32

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

Instance Method Details

#add_webhook(form_id, url, metadata = false, handshake_key = '') ⇒ Object



83
84
85
86
87
88
89
90
91
92
# File 'lib/wuparty.rb', line 83

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

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

:nodoc:



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

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

#delete_webhook(form_id, webhook_hash) ⇒ Object



94
95
96
# File 'lib/wuparty.rb', line 94

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.



78
79
80
81
# File 'lib/wuparty.rb', line 78

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

#formsObject

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



57
58
59
60
61
# File 'lib/wuparty.rb', line 57

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

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

:nodoc:



104
105
106
# File 'lib/wuparty.rb', line 104

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

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

:nodoc:



108
109
110
# File 'lib/wuparty.rb', line 108

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

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

:nodoc:



112
113
114
# File 'lib/wuparty.rb', line 112

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

#report(report_id) ⇒ Object

Returns details about the specified report.



99
100
101
102
# File 'lib/wuparty.rb', line 99

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

#reportsObject

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



64
65
66
67
68
# File 'lib/wuparty.rb', line 64

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.



71
72
73
74
75
# File 'lib/wuparty.rb', line 71

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