databasedotcom_console 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/bin/dbdc CHANGED
@@ -1,65 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
- require 'rubygems'
3
2
  require 'databasedotcom_console'
4
- require 'irb'
5
-
6
- def supported_ruby
7
- this_ruby = RUBY_VERSION.dup
8
- Gem::Version.new(this_ruby) >= Gem::Version.new("1.9.3")
9
- end
10
-
11
- require 'io/console' if supported_ruby
12
- require 'optparse'
13
-
14
- ### RANDOM UTIL METHOD
15
- def get_creds(opts={})
16
- creds = {}
17
- if opts[:host]
18
- creds[:host] = opts[:host]
19
- else
20
- print "HOST (test.salesforce.com, login.salesforce.com, etc): "
21
- creds[:host] = gets.strip
22
- end
23
- if opts[:un]
24
- creds[:un] = opts[:un]
25
- else
26
- print "USERNAME: "
27
- creds[:un] = gets.strip
28
- end
29
- if opts[:pw]
30
- creds[:pw] = opts[:pw]
31
- else
32
- print "PASSWORD (and security token if necessary): "
33
- creds[:pw] = STDIN.noecho(&:gets) if supported_ruby
34
- creds[:pw] = gets.strip unless supported_ruby
35
- end
36
- creds
37
- end
38
-
39
- options = {}
40
- parser = OptionParser.new do |opts|
41
- opts.banner = "Usage: dbdc [options]"
42
- opts.on("-h","--host HOST","enter the host (login.salesforce.com or test.salesforce.com") do |arg|
43
- options[:host] = arg
44
- end
45
- opts.on("-u","--username USERNAME","your username") do |arg|
46
- options[:un] = arg
47
- end
48
- opts.on("-p","--password PASSWORD","your password") do |arg|
49
- options[:pw] = arg
50
- end
51
- end
52
- parser.parse!
3
+ require 'databasedotcom_console/cli_tools'
53
4
 
54
5
  if ARGV[0] == "exec"
55
6
  path = ARGV[1]
56
7
  ARGV.clear
57
- creds = get_creds(options)
8
+ creds = get_creds
58
9
  @dbdc = DatabasedotcomConsole.new_client(creds[:host], creds[:un], creds[:pw])
59
10
  DatabasedotcomConsole::ScriptRunner.new(path, @dbdc)
60
11
  else
61
12
  begin
62
- creds = get_creds(options)
13
+ creds = get_creds
63
14
  @dbdc = DatabasedotcomConsole.new_client(creds[:host], creds[:un], creds[:pw])
64
15
 
65
16
  def dbdc
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ require 'databasedotcom_console'
3
+ require 'databasedotcom_console/cli_tools'
4
+
5
+ if ARGV[0] == "exec"
6
+ path = ARGV[1]
7
+ ARGV.clear
8
+ creds = get_creds
9
+ @rforce = DatabasedotcomConsole.new_restforce_client(creds[:host], creds[:un], creds[:pw])
10
+ DatabasedotcomConsole::ScriptRunner.new(path, @rforce)
11
+ else
12
+ begin
13
+ creds = get_creds
14
+ @rforce = DatabasedotcomConsole.new_restforce_client(creds[:host], creds[:un], creds[:pw])
15
+ puts "\nWelcome to the Restforce Ruby Console. \nYou you can access your restforce client via the variable: @rforce"
16
+ puts "Check out https://github.com/ejholmes/restforce for complete documentation on how to use the restforce gem\n\n"
17
+ ARGV.clear
18
+ IRB.start
19
+ rescue Exception => e
20
+ puts "ERROR: #{e.message}"
21
+ puts e.backtrace
22
+ puts "\nOh Noes! Looks like an error occurred. Make sure you have correctly entered your salesforce credentials!\n"
23
+ puts "PROTIP: If your org requires a security token, please be sure to concatenate it at the end of your password. \n\n"
24
+ end
25
+ end
@@ -30,10 +30,11 @@ Gem::Specification.new do |gem|
30
30
  gem.homepage = "http://mavens.io/"
31
31
 
32
32
  gem.files = `git ls-files`.split($\)
33
- gem.executables = ["dbdc"]
33
+ gem.executables = ["dbdc", "restforce"]
34
34
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
35
35
  gem.name = "databasedotcom_console"
36
36
  gem.require_paths = ["lib"]
37
37
  gem.add_runtime_dependency "databasedotcom"
38
+ gem.add_runtime_dependency "restforce"
38
39
  gem.version = DatabasedotcomConsole::VERSION
39
40
  end
@@ -1,18 +1,32 @@
1
1
  require "databasedotcom_console/version"
2
2
  require "databasedotcom"
3
+ require "restforce"
4
+
5
+ CLIENT_ID = '3MVG9QDx8IX8nP5RUXIFbi3L4rSVruiBU4O_ozvkJiU0aGZDBxfsF6XDhngJf6Ha2fDNniyDxpt0Gb9Pp.2Tk'
6
+ CLIENT_SECRET = '7712607496533706277'
3
7
 
4
8
  module DatabasedotcomConsole
5
9
  ## Create a new client for use with multiple orgs
6
10
  def self.new_client(host, username, password)
7
11
  client = Databasedotcom::Client.new(
8
- :client_id => '3MVG9QDx8IX8nP5RUXIFbi3L4rSVruiBU4O_ozvkJiU0aGZDBxfsF6XDhngJf6Ha2fDNniyDxpt0Gb9Pp.2Tk',
9
- :client_secret => '7712607496533706277',
12
+ :client_id => CLIENT_ID,
13
+ :client_secret => CLIENT_SECRET,
10
14
  :host => host
11
15
  )
12
16
  client.authenticate(:username => username, :password => password)
13
17
  client
14
18
  end
15
19
 
20
+ def self.new_restforce_client(host, username, password)
21
+ Restforce.new(
22
+ :password => password,
23
+ :username => username,
24
+ :client_id => CLIENT_ID,
25
+ :client_secret => CLIENT_SECRET,
26
+ :host => host
27
+ )
28
+ end
29
+
16
30
  class ScriptRunner
17
31
  def initialize(path, connection)
18
32
  @dbdc = connection
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'databasedotcom_console'
3
+ require 'irb'
4
+
5
+ def supported_ruby
6
+ this_ruby = RUBY_VERSION.dup
7
+ Gem::Version.new(this_ruby) >= Gem::Version.new("1.9.3")
8
+ end
9
+
10
+ # run this once when the file is included.
11
+ require 'io/console' if supported_ruby
12
+ require 'optparse'
13
+ @options = {}
14
+ parser = OptionParser.new do |opts|
15
+ opts.banner = "Usage: <cmd> [options]"
16
+
17
+ opts.on("-h","--host HOST","enter the host (login.salesforce.com or test.salesforce.com") do |arg|
18
+ @options[:host] = arg
19
+ end
20
+
21
+ opts.on("-u","--username USERNAME","your username") do |arg|
22
+ @options[:un] = arg
23
+ end
24
+
25
+ opts.on("-p","--password PASSWORD","your password") do |arg|
26
+ @options[:pw] = arg
27
+ end
28
+ end
29
+ parser.parse!
30
+
31
+ ### UTIL METHOD
32
+ def get_creds
33
+ opts = @options
34
+ creds = {}
35
+
36
+ if opts[:host]
37
+ creds[:host] = opts[:host]
38
+ else
39
+ print "HOST (test.salesforce.com, login.salesforce.com, etc): "
40
+ creds[:host] = gets.strip
41
+ end
42
+
43
+ if opts[:un]
44
+ creds[:un] = opts[:un]
45
+ else
46
+ print "USERNAME: "
47
+ creds[:un] = gets.strip
48
+ end
49
+
50
+ if opts[:pw]
51
+ creds[:pw] = opts[:pw]
52
+ else
53
+ print "PASSWORD (and security token if necessary): "
54
+ creds[:pw] = STDIN.noecho(&:gets) if supported_ruby
55
+ creds[:pw] = gets.strip unless supported_ruby
56
+ end
57
+
58
+ creds
59
+ end
@@ -1,3 +1,3 @@
1
1
  module DatabasedotcomConsole
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -0,0 +1,24 @@
1
+ =begin
2
+ TESTS TO COMPLETE
3
+ - script runner initialize
4
+ - test running the executables
5
+ =end
6
+
7
+ require 'test/unit'
8
+ require './lib/databasedotcom_console'
9
+ class ConsoleStartTest < Test::Unit::TestCase
10
+ ## Creds point to a DE org that exists solely for testing this gem. If you want to hack a DE org that you can obtain for free, I feel sorry for you.
11
+ USERNAME = 'dbdcconsole@dfriedman.com'
12
+ PASSWORD = '321console'
13
+ HOST = 'login.salesforce.com'
14
+ def test_open_dbdc_console
15
+ client = DatabasedotcomConsole.new_client(HOST, USERNAME, PASSWORD)
16
+ assert_equal client.class, Databasedotcom::Client
17
+ end
18
+
19
+ def test_open_restforce_console
20
+ client = DatabasedotcomConsole.new_restforce_client(HOST, USERNAME, PASSWORD)
21
+ assert_equal client.class, Restforce::Client
22
+
23
+ end
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: databasedotcom_console
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-06 00:00:00.000000000 Z
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: databasedotcom
@@ -27,11 +27,28 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: restforce
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: Quickly spin up a ruby console that can talk to your salesforce org.
31
47
  email:
32
48
  - dfriedm3@gmail.com
33
49
  executables:
34
50
  - dbdc
51
+ - restforce
35
52
  extensions: []
36
53
  extra_rdoc_files: []
37
54
  files:
@@ -41,10 +58,12 @@ files:
41
58
  - README.md
42
59
  - Rakefile
43
60
  - bin/dbdc
61
+ - bin/restforce
44
62
  - databasedotcom_console.gemspec
45
63
  - lib/databasedotcom_console.rb
64
+ - lib/databasedotcom_console/cli_tools.rb
46
65
  - lib/databasedotcom_console/version.rb
47
- - test/console_test.rb
66
+ - test/start_console_test.rb
48
67
  homepage: http://mavens.io/
49
68
  licenses: []
50
69
  post_install_message:
@@ -70,4 +89,4 @@ signing_key:
70
89
  specification_version: 3
71
90
  summary: Quickly spin up a ruby console that can talk to your salesforce org.
72
91
  test_files:
73
- - test/console_test.rb
92
+ - test/start_console_test.rb
@@ -1,7 +0,0 @@
1
- # Console Test
2
- require 'databasedotcom_console.rb'
3
-
4
- class TestDatabasedotcomConsole < Test::Unit::TestCase
5
- def open_dbdc_console
6
- end
7
- end