Skip to content

Commit

Permalink
support for non gem
Browse files Browse the repository at this point in the history
  • Loading branch information
jalemieux committed May 9, 2014
1 parent a2e530a commit 915f1aa
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, '[email protected]'
leads = client.get_leads :email, '[email protected]'
# 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
Expand Down
32 changes: 20 additions & 12 deletions examples/update_lead.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,15 +21,20 @@
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?('=')
print "#{__FILE__} <lead_email> <key1=value2> <key2=value2> ...\n e.g.: #{__FILE__} [email protected] [email protected] CS-EmailNames=Production\n\n"
exit 1
end

email = ARGV.shift
attr_v = ARGV.shift
values = {}
ARGV.each do |pair|
k, v = pair.split('=')
Expand All @@ -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


Expand Down
8 changes: 4 additions & 4 deletions lib/mkto_rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions lib/mkto_rest/lead.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file modified pkg/mkto_rest-0.2.0.gem
Binary file not shown.
4 changes: 2 additions & 2 deletions spec/mkto_rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]', id: 1} )
Expand Down

0 comments on commit 915f1aa

Please sign in to comment.