class RdsPdrive::Integrator
Attributes
leads[R]
token[R]
Public Class Methods
new(email, password)
click to toggle source
# File lib/rds_pdrive/integrator.rb, line 8 def initialize(email, password) @email = email @password = password @url = "https://api.pipedrive.com/v1/" authenticate @leads = [] end
Public Instance Methods
add_lead(lead)
click to toggle source
# File lib/rds_pdrive/integrator.rb, line 32 def add_lead(lead) uri = URI.parse("#{@url}persons?api_token=#{@token}") response = Net::HTTP.post_form(uri, {"name" => lead.full_name, "email" => lead.email, "phone" => lead.phone, "company_id" => @company_id}) objeto_json = JSON.parse(response.body) end
find_by_name(name)
click to toggle source
# File lib/rds_pdrive/integrator.rb, line 38 def find_by_name(name) get_all_leads @leads.select { |l| l.name == name} end
get_all_leads()
click to toggle source
# File lib/rds_pdrive/integrator.rb, line 16 def get_all_leads uri = URI.parse("#{@url}persons?api_token=#{@token}") response = Net::HTTP.get(uri) objeto_json = JSON.parse(response) data = objeto_json['data'] @leads = [] if data data.each do |d| lead = Lead.new(d['name'], "", d['email'][0]['value'], "", d['phone'][0]['value']) @leads << lead end end @leads end
Private Instance Methods
authenticate()
click to toggle source
# File lib/rds_pdrive/integrator.rb, line 44 def authenticate uri = URI.parse(@url+"authorizations") response = Net::HTTP.post_form(uri, {"email" => @email, "password" => @password}) objeto_json = JSON.parse(response.body) if objeto_json['success'] == true @token = objeto_json['data'][0]['api_token'] @user_id = objeto_json['data'][0]['user_id'] @company_id = objeto_json['data'][0]['company_id'] end end