Method: Rdgem.assert_fields

Defined in:
lib/rdgem.rb

.assert_fields(fields, app_key) ⇒ Object

checks in the account if the custom fields are created.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rdgem.rb', line 89

def self.assert_fields(fields, app_key)
		@field_key = []

    query = PIPEDRIVE_API + 'personFields?' + TOKEN + app_key

  	response = HTTParty.get(query)
  	puts "field_key_begin",@field_key

  	if response["success"]
  		#asserts fields
  		fields.each_with_index do |assert, index|
  	response["data"].each do |search|
   			if search['name'] == assert
    			@field_key[index] = search['key']
  				end
  			end
		end
		puts "field_key middle",@field_key

		# create missing fields
		fields.each_with_index do |create, index|
			@field_key[index].blank?
			@field_key[index] = create_field(app_key, create[0])
		end
		puts "field_key end",@field_key
		 
  		#Hash the info
		custom_field = Hash[fields.zip(@field_key.map \
  			{|i| i.include?(',') ? (i.split /, /) : i})] #/
	else
		if response["error"] == "You need to be authorized to make this request."
			return false
		end
	end
	puts "custom_field", custom_field
	return custom_field
end