Соединение API Close.io с синтаксической ошибкой Ruby

Мой вопрос касается подключения к API Close.io и, в частности, обновления настраиваемых полей, связанных с лидами — http://developer.close.io/#Leads

В вашей документации указано, что...

custom: чтобы обновить одно настраиваемое поле, не удаляя другие, используйте custom.field_name: updated_value вместо custom: { all: 'fields', listed: 'here' }. Вы также можете отключить одно поле, используя custom.field_name: null.

Но это вызывает некоторые причуды в нашем проекте. Каждое обновление одного поля продолжает удалять остальные.

Итак, вот наш код -

# We're using the close.io gem ( a ruby wrapper ) - https://github.com/taylorbrooks/closeio
# First we get the signed in user's email address 
# and query closeio to pull the appropriate lead associated with it

closeio_lead_id = (Closeio::Lead.where query: "email:['#{current_user.email}']")[0]['id']

#Next we're attempting to update the lead custom field of "kk_referral" with a float
(Closeio::Lead.update closeio_lead_id,
    custom: { kk_referral: Referral.where( :user_id => current_user.id).count.to_f }
    )

# And it works! Yay But then we run the next line to update another custom field... 
# the last action is erased. what the hell?

(Closeio::Lead.update closeio_lead_id,
    custom.kk_blog_posts_submitted: Comment.where( :user_id => current_user.id).count.to_f 
    )

# So we attempted to store the in a variable so we can replicate some of the direction provided in the documentation.
closeio_comment = Comment.where( :user_id => current_user.id).count.to_f
(Closeio::Lead.update closeio_lead_id,
    custom.kk_blog_posts_submitted: closeio_comment 
    )

# And nothing is coming through. AHhhh. Only the original syntax works.

При попытке использовать синтаксис, представленный в документации....

custom.field_name: some_variable_storing_a_float

Я получаю синтаксическую ошибку, связанную с двоеточием после field_name.

И при попытке использовать более дружественный синтаксис Ruby....

custom.field_name => some_variable_storing_a_float 

Я получаю сообщение об ошибке при использовании пользовательской локальной переменной. (Точно читает «NameError: неопределенная локальная переменная или метод `custom’ для main:Object )

Любой совет? Спасибо!


person piratetone    schedule 23.12.2014    source источник


Ответы (1)


Наконец-то разобрался, ребята. Вот синтаксис -

Closeio::Lead.update 'lead_id', 'custom.Field Name' => 'Value'
person piratetone    schedule 29.12.2014