diff --git a/README.md b/README.md index 0e528bb..c996692 100644 --- a/README.md +++ b/README.md @@ -52,11 +52,11 @@ fetch a lead and update one of its value: updating a lead, using id, email, etc. new_values = { 'Firstname' => 'Jeanne' } - lead = client.get_leads :email, 'jane@scorp.com' + leads = client.get_leads :email, 'jane@scorp.com' # update using id - lead.update(new_values, :id) + leads.first.update(new_values, :id) # update using email - lead.update(new_values, :email) + leads.first.update(new_values, :email) ## Set up diff --git a/examples/update_lead.rb b/examples/update_lead.rb index 86b8d8a..bc51993 100644 --- a/examples/update_lead.rb +++ b/examples/update_lead.rb @@ -1,4 +1,7 @@ -require 'mkto_rest' +$:.unshift(File.expand_path('../../lib/', __FILE__)) +require_relative '../lib/mkto_rest' +# or require 'mkto_gem' if you installed the gem + require 'yaml' =begin @@ -18,7 +21,12 @@ if File.exists? config_path config = YAML::load_file(config_path) else - print "Set your hostname, client id and key in #{config_path}\n\n in this format\n#{{ hostname: '', client_id: '', client_secret: '' }.to_yaml}\n\n" + print <<-EOF +"Set your hostname, client id and key in #{config_path} in this format: + +#{{ hostname: '', client_id: '', client_secret: '' }.to_yaml} + +EOF exit 1 end if ARGV.size < 2 or ARGV[0].include?('=') @@ -26,7 +34,7 @@ exit 1 end -email = ARGV.shift +attr_v = ARGV.shift values = {} ARGV.each do |pair| k, v = pair.split('=') @@ -35,23 +43,23 @@ -client = MktoRest::Client.new(config[:hostname], config[:client_id], config[:client_secret]) +client = MktoRest::Client.new(host: config[:hostname], client_id: config[:client_id], client_secret: config[:client_secret]) #client.debug = true #verbose output, helps debugging client.authenticate - # find leads, updated fields. -client.get_leads :email, email do |lead| - p "found lead #{lead.id}!" - p "#{lead.to_s}" - p lead.update values +leads = client.get_leads :email, attr_v + +leads.each do |l| + p "found lead: #{l.to_s}" + p l.update values end -client.get_leads :email, email do |lead| - p "found lead #{lead.id}!" - p "#{lead.to_s}" +# using a block +leads = client.get_leads :email, attr_v do |lead| + p "found lead #{lead.to_s}" end diff --git a/lib/mkto_rest.rb b/lib/mkto_rest.rb index 988c279..53176b8 100644 --- a/lib/mkto_rest.rb +++ b/lib/mkto_rest.rb @@ -6,10 +6,10 @@ module MktoRest class Client attr_reader :host, :client_id, :client_secret, :token, :expires_in,:valid_until, :token_type, :scope, :last_request_id - def initialize(host, client_id, client_secret) - @host = host - @client_id = client_id - @client_secret = client_secret + def initialize(options = {}) + @host = options[:host] + @client_id = options[:client_id] + @client_secret = options[:client_secret] @options = {} end diff --git a/lib/mkto_rest/lead.rb b/lib/mkto_rest/lead.rb index d6193de..111f21f 100644 --- a/lib/mkto_rest/lead.rb +++ b/lib/mkto_rest/lead.rb @@ -26,8 +26,7 @@ def update(args, attr = :id) end def to_s - #@vars.collect { |k| "#{k} => #{self.send(k)}" }.join(", ") - @vars.to_s + @vars.map { |k| "#{k} => #{self.send(k)}" }.join(", ") end end diff --git a/pkg/mkto_rest-0.2.0.gem b/pkg/mkto_rest-0.2.0.gem index 5e03c96..e9bb0f7 100644 Binary files a/pkg/mkto_rest-0.2.0.gem and b/pkg/mkto_rest-0.2.0.gem differ diff --git a/spec/mkto_rest_spec.rb b/spec/mkto_rest_spec.rb index 41272e0..f8ed668 100644 --- a/spec/mkto_rest_spec.rb +++ b/spec/mkto_rest_spec.rb @@ -11,8 +11,8 @@ @hostname = 'dummy.mktorest.com' @token = 'token' - @client = MktoRest::Client.new(@hostname, @client_id, @client_key) - @authenticated_client = MktoRest::Client.new(@hostname, @client_id, @client_key) + @client = MktoRest::Client.new(host: @hostname, client_id: @client_id, client_secret: @client_key) + @authenticated_client = MktoRest::Client.new(host: @hostname,client_id: @client_id, client_secret: @client_key) @authenticated_client.__auth(@token) @lead1 = MktoRest::Lead.new(@authenticated_client, { name: 'john', email: 'john@acme.com', id: 1} )