Class: GetResponse::FromFieldsProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/get_response/from_fields_proxy.rb

Overview

Proxy class from all from fields operations.

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ FromFieldsProxy

Returns a new instance of FromFieldsProxy.



6
7
8
# File 'lib/get_response/from_fields_proxy.rb', line 6

def initialize(connection)
  @connection = connection
end

Instance Method Details

#allObject

Fetch all from fields connected with account

returns
FromFields


14
15
16
17
18
19
# File 'lib/get_response/from_fields_proxy.rb', line 14

def all
  from_fields_attrs = @connection.send_request("get_account_from_fields")["result"]
  from_fields_attrs.map do |id, attrs|
    FromField.new(attrs.merge("id" => id))
  end
end

#create(attributes) ⇒ Object

Create new from field connection with account. Method returns new instance of FromField if new from field was saved or raise GetResponseError if not.

returns

FromField



26
27
28
29
# File 'lib/get_response/from_fields_proxy.rb', line 26

def create(attributes)
  add_result = @connection.send_request("add_account_from_field", attributes)["result"]
  FromField.new(attributes.merge("id" => add_result["FROM_FIELD_ID"]))
end

#find(from_field_id) ⇒ FormField

Get single from field. Method can raise GetResponse::GetResponseError exception when form field with passed from_field_id is not found.

Parameters:

  • from_field_id (String)

Returns:

  • (FormField)


37
38
39
40
41
42
43
# File 'lib/get_response/from_fields_proxy.rb', line 37

def find(from_field_id)
  params = {"account_from_field" => from_field_id}
  resp = @connection.send_request("get_account_from_field", params)["result"]
  raise GetResponseError.new "Form field with id '#{from_field_id}' not found." if resp.empty?
  from_field_attrs = resp.values[0].merge("id" => resp.keys.first)
  FromField.new(from_field_attrs)
end