sfdcutil 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2012 John Rizzo
2
+
3
+ This program is free software: you can redistribute it and/or modify
4
+ it under the terms of the GNU General Public License as published by
5
+ the Free Software Foundation, either version 3 of the License, or
6
+ (at your option) any later version.
7
+
8
+ This program is distributed in the hope that it will be useful,
9
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ GNU General Public License for more details.
12
+
13
+ You should have received a copy of the GNU General Public License
14
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # SFDCUtil
2
+
3
+ SFDCUtil is a set of libraries that I've created to help me perform common tasks for working with salesforce.com
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ $ gem 'sfdcutil'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sfdcutil
18
+
19
+ ## Usage
20
+
21
+ $ sfdcutil -h
22
+ Usage: sfdcutil COMMAND [OPTIONS]
23
+
24
+ Commands
25
+ trust:status - get the status of all instances
26
+
27
+ Options
28
+ -u, --url URL trust URL
29
+ -i, --instance INSTANCE which instance do you want to get the status of
30
+ -v, --[no-]verbose Run verbosely
31
+ -h, --help help
32
+
33
+ Getting a single instance status
34
+
35
+ $ sfdcutil trust:status --instance "NA1"
36
+ Instance Status
37
+ NA1 Instance available
38
+
39
+ Get a status of all instances
40
+
41
+ $ sfdcutil trust:status
42
+ Instance Status
43
+ AP0 (Japan) Instance available
44
+ AP1 (APAC) Instance available
45
+ EU0 (EMEA) Instance available
46
+ EU1 Instance available
47
+ EU2 Instance available
48
+ NA0 (SSL) Instance available
49
+ NA1 Instance available
50
+ NA2 Instance available
51
+ NA3 Instance available
52
+ NA4 Instance available
53
+ NA5 Instance available
54
+ NA6 Instance available
55
+ NA7 Instance available
56
+ NA8 Instance available
57
+ NA9 Instance available
58
+ NA10 Instance available
59
+ NA11 Instance available
60
+ NA12 Instance available
61
+ NA13 Instance available
62
+ NA14 Instance available
63
+ CS0 (TAPP0) Instance available
64
+ CS1 Instance available
65
+ CS2 Instance available
66
+ CS3 Instance available
67
+ CS4 Instance available
68
+ CS5 Instance available
69
+ CS6 Instance available
70
+ CS7 Instance available
71
+ CS8 Instance available
72
+ CS9 Instance available
73
+ CS10 Instance available
74
+ CS11 Instance available
75
+ CS12 Instance available
76
+ CS13 Instance available
77
+ CS14 Instance available
78
+ CS15 Instance available
79
+ CS16 Instance available
80
+ CS17 Instance available
81
+
82
+ ## Contributing
83
+
84
+ 1. Fork it
85
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
86
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
87
+ 4. Push to the branch (`git push origin my-new-feature`)
88
+ 5. Create new Pull Request
89
+
90
+ ## Contact
91
+ I can be reached by sending an email to johnrizzo1 at gmail dot com
92
+
93
+ ## Disclaimer
94
+
95
+ I am currently a Salesforce.com employee. The views expressed are my own and not those of salesforce.com
96
+
97
+ ## TODO
98
+
99
+ 1. Fix the code so that querying a specific POD works properly.
100
+
101
+ ## Versions
102
+
103
+ 0.4 Fixed the script so that it works properly however it is not working when you query for a single org.
104
+ 0.3 Fixed the script so that it now works with the latest site updates and prints out the proper colors for all
105
+ status types.
106
+ 0.2 Partially fixed an issue that occurred after the recent site changes
107
+ 0.1 Initial version
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
8
+ task :test => :spec
data/bin/sfdcutil ADDED
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sfdcutil'
4
+ require 'optparse'
5
+ require 'ostruct'
6
+ require 'pp'
7
+
8
+ class SFDCUtilParser
9
+ def self.parse(args)
10
+ options = OpenStruct.new
11
+ options.verbose = false
12
+ options.url = nil
13
+ options.instance = nil
14
+ script_name = File.basename($0)
15
+
16
+ opts = OptionParser.new do |opts|
17
+ opts.banner = "Usage: " + script_name + " COMMAND [OPTIONS]"
18
+ opts.separator ""
19
+
20
+ opts.separator "Commands"
21
+ opts.separator " trust:status - get the status of all instances"
22
+
23
+ opts.separator ""
24
+ opts.separator "Options"
25
+
26
+ opts.on("-u", "--url URL", "trust URL") do |url|
27
+ options.url = url
28
+ end
29
+
30
+ opts.on("-i", "--instance INSTANCE", "which instance do you want to get the status of") do |instance|
31
+ options.instance = instance
32
+ end
33
+
34
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
35
+ options.verbose = v
36
+ end
37
+
38
+ opts.on("-h", "--help", "help") do
39
+ puts opts
40
+ end
41
+ end
42
+
43
+ opts.parse!(args)
44
+ options.opts = opts
45
+
46
+ options
47
+ end
48
+ end
49
+
50
+ options = SFDCUtilParser.parse(ARGV)
51
+ def colorize(text, color_code)
52
+ "\e[#{color_code}m#{text}\e[0m"
53
+ end
54
+
55
+ RED = 31
56
+ GREEN = 32
57
+ YELLOW = 33
58
+ BLUE = 34
59
+ MAGENTA = 35
60
+
61
+ case ARGV[0]
62
+ when "trust:status"
63
+ if options.url != nil
64
+ trust = SFDCUtil::Trust.new(url)
65
+ else
66
+ trust = SFDCUtil::Trust.new
67
+ end
68
+
69
+ if options.instance != nil
70
+ instances = trust.get_status(options.instance)
71
+ else
72
+ instances = trust.get_all_status
73
+ end
74
+
75
+ puts sprintf("%12s %s", "Instance", "Status")
76
+ instances.each do |instance|
77
+ color = RED
78
+ if instance[:status] == "Instance available"
79
+ color = GREEN
80
+ elsif instance[:status] == "Performance issues"
81
+ puts color = YELLOW
82
+ elsif instance[:status] == "Service disruption"
83
+ puts color = RED
84
+ elsif instance[:status] == "Informational message"
85
+ puts color = BLUE
86
+ elsif instance[:status] == "Status not available"
87
+ puts color = MAGENTA
88
+ end
89
+
90
+ puts colorize(sprintf("[%12s] [%s]" % [instance[:instance], instance[:status]]), color)
91
+ end
92
+ else
93
+ puts options.opts
94
+ end
95
+
@@ -0,0 +1,56 @@
1
+ module SFDCUtil
2
+ class Trust
3
+ require 'open-uri'
4
+ require 'nokogiri'
5
+
6
+ def initialize(url = 'http://trust.salesforce.com/trust/status/')
7
+ @url = url
8
+ @instances = nil
9
+ end
10
+
11
+ def set_url(url)
12
+ unless url == nil
13
+ @url = url
14
+ end
15
+ end
16
+
17
+ def get_all_status()
18
+ gather_data()
19
+ end
20
+
21
+ def get_status(instance_name)
22
+ data = gather_data()
23
+ data.select { |item| item[:instance] == instance_name }
24
+ end
25
+
26
+ private
27
+
28
+ def gather_data(reload=false)
29
+ if @instances != nil &&
30
+ reload != true
31
+ return @instances
32
+ end
33
+
34
+ html_doc = Nokogiri::HTML(open(@url))
35
+
36
+ @instances = Array.new
37
+
38
+ %w(NORTH_AMERICA APAC EMEA SANDBOX).each do |region|
39
+ raw_instances = html_doc.css('#instanceTable_' + region + ' * a[title]')
40
+ raw_status = html_doc.css('#instanceTable_' + region + ' > tbody > tr > td > img')
41
+
42
+ (0..raw_instances.length - 1).each do |x|
43
+ # Yes this is really ugly but I can't figure out why strip doesn't work
44
+ # I think that there is actually a multi-byte character in at [-1]
45
+ instance = raw_instances[x].content[0..-2]
46
+ status = raw_status[x].attribute('title').to_s
47
+
48
+ @instances << {:instance => instance,
49
+ :status => status }
50
+ end
51
+ end
52
+
53
+ @instances
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module SFDCUtil
2
+ VERSION = "0.0.7"
3
+ end
data/lib/sfdcutil.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "sfdcutil/version"
2
+ require "sfdcutil/trust"
3
+
4
+ module SFDCUtil
5
+ # Your code goes here...
6
+ end
data/sfdctrust.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'sfdcutil/version'
4
+ #require File.expand_path('../lib/sfdcutil/version', __FILE__)
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.authors = ["John Rizzo"]
8
+ gem.email = %w(johnrizzo1@gmail.com)
9
+ gem.description = %q{This is a utility for querying the Salesforce.com trust site and printing the instance status.}
10
+ gem.summary = %q{This is a utility for querying the Salesforce.com trust site and printing the instance status.}
11
+ gem.homepage = ""
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "sfdcutil"
17
+ #gem.require_paths = ["sfdcutil"]
18
+ gem.require_paths = %w(lib)
19
+ gem.version = SFDCUtil::VERSION
20
+
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec'
23
+
24
+ gem.add_runtime_dependency 'nokogiri'
25
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe "SFDCUtil::Trust" do
4
+ it "should return all host status by default" do
5
+ tp = SFDCUtil::Trust.new()
6
+ tp.should_not be_nil
7
+ return_data = tp.get_all_status()
8
+ return_data.length.should >= 1
9
+
10
+ #return_data =
11
+ #return_data.should_not be_nil
12
+ end
13
+
14
+ it "should return a single host status" do
15
+ tp = SFDCUtil::Trust.new()
16
+ tp.should_not be_nil
17
+ return_data = tp.get_status("NA1")
18
+ return_data.length.should == 1
19
+ return_data[0][:instance].should == "NA1"
20
+ end
21
+ end
@@ -0,0 +1 @@
1
+ require 'sfdcutil/trust'
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sfdcutil
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Rizzo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: nokogiri
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: This is a utility for querying the Salesforce.com trust site and printing
63
+ the instance status.
64
+ email:
65
+ - johnrizzo1@gmail.com
66
+ executables:
67
+ - sfdcutil
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - .gitignore
72
+ - .idea/.name
73
+ - .idea/.rakeTasks
74
+ - .idea/dictionaries/jrizzo.xml
75
+ - .idea/encodings.xml
76
+ - .idea/inspectionProfiles/Project_Default.xml
77
+ - .idea/inspectionProfiles/profiles_settings.xml
78
+ - .idea/misc.xml
79
+ - .idea/modules.xml
80
+ - .idea/scopes/scope_settings.xml
81
+ - .idea/trust_parser.iml
82
+ - .idea/vcs.xml
83
+ - .idea/workspace.xml
84
+ - .rvmrc
85
+ - COPYING
86
+ - Gemfile
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - bin/sfdcutil
91
+ - lib/sfdcutil.rb
92
+ - lib/sfdcutil/trust.rb
93
+ - lib/sfdcutil/version.rb
94
+ - sfdctrust.gemspec
95
+ - spec/sfdcutil/sfdcutil_trust_spec.rb
96
+ - spec/spec_helper.rb
97
+ homepage: ''
98
+ licenses: []
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.24
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: This is a utility for querying the Salesforce.com trust site and printing
121
+ the instance status.
122
+ test_files:
123
+ - spec/sfdcutil/sfdcutil_trust_spec.rb
124
+ - spec/spec_helper.rb