Jump to content
Fórum Script Brasil
  • 0

Ruby para PHP


lucasbicalleto

Question

Eii , pessoal alguém sabe me dizer oque isso significa em PHP ? 

 def find_leads(criteria=false)
    #No criteria means search all by default
    if not criteria
      leads = @@intercom.get("/contacts", "")
      if not leads.empty?
        leads['contacts'].each {|contact| puts "EMAIL: #{contact['email']}, NAME: #{contact['name']}", \
                                "USER_ID: #{contact['user_id']}, ID: #{contact['id']}"}
      end
    else
      #Lets use the criteria in different ways to search contacts
        #Check against email
        lead_list = @@intercom.contacts.find_all(:email => criteria)
        #Check if email returned anything
        if lead_list.any?
          lead_list.each {|lead| puts "EMAIL: #{lead.email}, NAME: #{lead.name}", \
                        "USER_ID: #{lead.user_id}, ID: #{lead.id}"}
        else
          begin
            lead = @@intercom.contacts.find(user_id: criteria)
            return lead
          rescue Intercom::ResourceNotFound
            lead = @@intercom.contacts.find(id: criteria)
            return lead
          end
        end
    end
  end

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Primeiro pense no que o script faz. A sintaxe muda um pouco, mas a ideia é compreensível.

Veja que o script, em suma, faz uma requisição http ou uma busca no banco e depois exibe os resultados, fazendo um lop no array

A partir daí você implementa a ideia no PHP

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.1k
    • Total Posts
      652k
×
×
  • Create New...