shelltoad 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog.textile CHANGED
@@ -1,3 +1,9 @@
1
+ h3. 0.3.0
2
+
3
+ * Support ssl in configuration
4
+ * Support project id in configuration
5
+ * Rework with hoptoad-api gem instead of ActiveSupport
6
+
1
7
  h3. 0.2.5
2
8
 
3
9
  * Bugfixes
data/Gemfile CHANGED
@@ -1,11 +1,7 @@
1
1
  source :gemcutter
2
2
 
3
3
  gem "rake"
4
- gem 'activesupport'
5
- # We use some hash extensions -
6
- # #from_xml and #with_indifferent_access from activesupport
7
- # By some unknown reason these extensions require i18n
8
- gem "i18n"
4
+ gem "hoptoad-api"
9
5
 
10
6
  group :development do
11
7
  gem 'jeweler'
data/Gemfile.lock CHANGED
@@ -1,11 +1,16 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activesupport (3.0.5)
4
+ crack (0.1.8)
5
5
  diff-lcs (1.1.2)
6
6
  fakeweb (1.3.0)
7
7
  git (1.2.5)
8
- i18n (0.5.0)
8
+ hashie (0.4.0)
9
+ hoptoad-api (2.3.0)
10
+ hashie (>= 0.2.0)
11
+ httparty (>= 0.5.2)
12
+ httparty (0.6.1)
13
+ crack (= 0.1.8)
9
14
  jeweler (1.5.2)
10
15
  bundler (~> 1.0.0)
11
16
  git (>= 1.2.5)
@@ -25,9 +30,8 @@ PLATFORMS
25
30
  ruby
26
31
 
27
32
  DEPENDENCIES
28
- activesupport
29
33
  fakeweb
30
- i18n
34
+ hoptoad-api
31
35
  jeweler
32
36
  mocha
33
37
  rake
data/Readme.textile CHANGED
@@ -6,8 +6,10 @@ h3. Configuration
6
6
 
7
7
  Create <pre><code>.shelltoadrc</code></pre> file in your project directory
8
8
  with the application name and access key:
9
- <pre><code>project: myapp
10
- key: c285743ecbc285743ecbc285743ecbc285743ecb</code></pre>
9
+ <pre><code>account: myapp
10
+ key: c285743ecbc285743ecbc285743ecbc285743ecb
11
+ secure true # https usage. Default: false
12
+ project_id: 123456 # see errors only under specified proejct. Default: all projects</code></pre>
11
13
 
12
14
  h3. Commands
13
15
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.3.0
@@ -1,12 +1,37 @@
1
1
  require "yaml"
2
+ require "hoptoad-api"
2
3
 
3
4
 
4
5
  class Shelltoad::Configuration
5
6
 
7
+ #
8
+ # Class methods
9
+ #
10
+
11
+ def self.key
12
+ self.instance.key
13
+ end
14
+
15
+ def self.project_id
16
+ self.instance.project_id
17
+ end
18
+
19
+ def self.secure?
20
+ self.instance.secure
21
+ end
22
+
23
+ def self.account
24
+ self.instance.account
25
+ end
26
+
6
27
  def self.instance
7
28
  @instance ||= self.new
8
29
  end
9
30
 
31
+ #
32
+ # API
33
+ #
34
+
10
35
  def initialize
11
36
  if File.exists?(".shelltoadrc")
12
37
  @config = YAML.load(File.new(".shelltoadrc"))
@@ -15,20 +40,23 @@ class Shelltoad::Configuration
15
40
  end
16
41
  end
17
42
 
18
- def self.key
19
- self.instance.key
43
+ def key
44
+ @config["key"] || raise(::Shelltoad::NoApiKey, "key option not specified in .shelltoadrc")
20
45
  end
21
46
 
22
- def self.project
23
- self.instance.project
47
+ def project_id
48
+ @config["project_id"]
24
49
  end
25
50
 
26
- def key
27
- @config && @config["key"] || raise(::Shelltoad::NoApiKey, "key option not specified in .shelltoadrc")
51
+ def account
52
+ (@config["account"] || @config["project"]) || raise(::Shelltoad::BaseException, "account option not specified in .shelltoadrc")
28
53
  end
29
54
 
30
- def project
31
- @config && @config["project"] || raise(::Shelltoad::NoProject, "project option not specified in .shelltoadrc")
55
+ def secure
56
+ @config["secure"] # false by default
32
57
  end
58
+
33
59
  end
34
60
 
61
+ Hoptoad.auth_token = Shelltoad::Configuration.key
62
+ Hoptoad.account = Shelltoad::Configuration.account
@@ -1,127 +1,126 @@
1
- require "active_support/core_ext/hash/conversions"
2
- require "active_support/core_ext/hash/indifferent_access"
3
- require "net/http"
4
1
  require "uri"
5
2
  require "cgi"
3
+ require "hoptoad-api"
6
4
 
7
- class Shelltoad::Error
5
+ class Shelltoad
6
+ class Error
8
7
 
9
- URL = URI.parse("http://#{::Shelltoad::Configuration.project}.hoptoadapp.com")
8
+ URL = URI.parse("#{Configuration.secure? ? "https" : "http"}://#{Configuration.account}.hoptoadapp.com:80")
10
9
 
11
- #
12
- # Class methods
13
- #
14
-
15
- def self.all(*args)
16
- parse(http_get("/errors.xml"))[:groups].map! do |attributes|
17
- self.new(attributes)
10
+ #
11
+ # Class methods
12
+ #
13
+
14
+ def self.all(options = {})
15
+ options[:project_id] ||= Configuration.project_id if Configuration.project_id
16
+ Hoptoad::Error.find(:all, options).map! do |attributes|
17
+ self.new(attributes)
18
+ end
18
19
  end
19
- end
20
20
 
21
- def self.magic_find(id)
22
- error = self.all(:show_resolved => true).find do |error|
23
- error.id.to_s =~ /#{id}$/
21
+ def self.magic_find(id)
22
+ error = id.to_s.size > 5 ? simple_finder(id) : magic_finder(id)
23
+ if block_given?
24
+ return yield(error)
25
+ end
26
+ error
24
27
  end
25
- raise Shelltoad::ErrorNotFound, "Error with id:#{id} not found" unless error
26
- if block_given?
27
- yield(error)
28
+
29
+ def self.magic_finder(id)
30
+ 1.upto(3) do |page|
31
+ self.all(:show_resolved => true, :page => page).each do |error|
32
+ return self.new(error) if error.id.to_s =~ /#{id}$/
33
+ end
34
+ end
35
+ raise ErrorNotFound, "Error with id like *#{id} not found among last 90 errors.\n Try input full id."
28
36
  end
29
- error
30
- end
31
37
 
32
- #
33
- # API
34
- #
35
-
36
- def initialize(attributes)
37
- @attributes = attributes
38
- end
38
+ def self.simple_finder(id)
39
+ attributes = Hoptoad::Error.find(id) || raise(ErrorNotFound, "Error with id #{id} not found under this account.")
40
+ self.new(attributes, true)
41
+ end
39
42
 
40
- def data
41
- @data ||= self.class.parse(self.class.http_get(path('xml')))[:group]
42
- end
43
+ #
44
+ # API
45
+ #
43
46
 
44
- def view
45
- <<-EOI
46
- #{data[:error_message]}
47
- #{data[:backtrace][:line].join("\n")}
48
- EOI
49
- end
47
+ def initialize(attributes, full = false)
48
+ @attributes = attributes
49
+ @data = attributes if full
50
+ end
50
51
 
51
- def commit!
52
- message = <<-EOI.gsub(/`/, "'")
53
- #{url}
52
+ def data
53
+ @data ||= Hoptoad::Error.find(self.id)
54
+ end
54
55
 
55
- #{self.error_message}
56
- EOI
57
- output = `git commit -m "#{message}"`
58
- if $?.success?
59
- resolve!
56
+ def lines
57
+ self.data[:backtrace][:line]
60
58
  end
61
- output
62
- end
63
59
 
64
- def resolve!
65
- return true if self.resolved?
66
- response = Net::HTTP.post_form(
67
- url,
68
- :"group[resolved]" => 1,
69
- :format => "xml",
70
- :_method => :put,
71
- :auth_token => ::Shelltoad::Configuration.key
72
- )
73
- raise "HTTP error: #{response}" unless response.is_a?(Net::HTTPSuccess)
74
- true
75
- end
60
+ def view
61
+ <<-EOI
62
+ #{self.error_message}
63
+ #{self.lines.join("\n")}
64
+ EOI
65
+ end
76
66
 
67
+ def commit!
68
+ message = <<-EOI.gsub(/`/, "'")
69
+ #{url.to_s}
70
+
71
+ #{self.error_message}
72
+ EOI
73
+ output = `git commit -m "#{message}"`
74
+ if $?.success?
75
+ resolve!
76
+ end
77
+ output
78
+ end
77
79
 
78
- def to_s
79
- "[##{self.id}] #{self.rails_env.first} #{self.error_message} #{self.file}:#{self.line_number}"
80
- end
80
+ def resolve!
81
+ return true if self.resolved?
82
+ Hoptoad::Error.put(path("xml"), :body => {:group => {:resolved => 1}})
83
+ true
84
+ end
81
85
 
82
- def id
83
- @attributes[:id]
84
- end
85
86
 
86
- def resolved?
87
- @attributes[:resolved]
88
- end
87
+ def to_s
88
+ "[##{self.id}] #{self.rails_env.first} #{self.error_message} #{self.file}:#{self.line_number}"
89
+ end
89
90
 
90
- def method_missing(meth, *args, &blk)
91
- if attr = @attributes[meth]
92
- attr
93
- else
94
- super(meth, *args, &blk)
91
+ def id
92
+ @attributes[:id]
95
93
  end
96
- end
97
94
 
98
- #
99
- # Implementation
100
- #
101
-
102
- protected
103
- def path(format = nil)
104
- "/errors/#{self.id}" + (format ? ".#{format}" : "")
105
- end
95
+ def resolved?
96
+ @attributes[:resolved]
97
+ end
106
98
 
107
- def url(format = nil)
108
- URI.parse(URL.to_s + path(format))
109
- end
99
+ def [](key)
100
+ @attributes[key] || self.data[key]
101
+ end
110
102
 
111
- def self.http_get(path, params = {})
112
- params[:auth_token] = ::Shelltoad::Configuration.key
113
- query = path + "?" + params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')
114
- @http ||= Net::HTTP.new(URL.host)
115
- response = @http.get(query)
116
- raise Shelltoad::ServiceNotAvailable.new(<<-EOI) unless response.is_a?(Net::HTTPSuccess)
117
- Hoptoad service not available. HTTP response:\n#{response.body}
118
- EOI
119
- return response.body
120
- end
103
+ def method_missing(meth, *args, &blk)
104
+ if attr = @attributes[meth]
105
+ attr
106
+ else
107
+ super(meth, *args, &blk)
108
+ end
109
+ end
110
+
111
+ #
112
+ # Implementation
113
+ #
114
+
115
+ protected
116
+ def path(format = nil)
117
+ "/errors/#{self.id}" + (format ? ".#{format}" : "")
118
+ end
119
+
120
+ def url(format = nil)
121
+ URI.parse(URL.to_s + path(format))
122
+ end
121
123
 
122
- def self.parse(string)
123
- Hash.from_xml(string).with_indifferent_access
124
124
  end
125
125
 
126
126
  end
127
-
data/shelltoad.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{shelltoad}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bogdan Gusiev"]
12
- s.date = %q{2011-04-04}
12
+ s.date = %q{2011-04-06}
13
13
  s.default_executable = %q{shelltoad}
14
14
  s.description = %q{
15
15
  }
@@ -51,19 +51,16 @@ Gem::Specification.new do |s|
51
51
 
52
52
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
53
  s.add_runtime_dependency(%q<rake>, [">= 0"])
54
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
55
- s.add_runtime_dependency(%q<i18n>, [">= 0"])
54
+ s.add_runtime_dependency(%q<hoptoad-api>, [">= 0"])
56
55
  s.add_development_dependency(%q<jeweler>, [">= 0"])
57
56
  else
58
57
  s.add_dependency(%q<rake>, [">= 0"])
59
- s.add_dependency(%q<activesupport>, [">= 0"])
60
- s.add_dependency(%q<i18n>, [">= 0"])
58
+ s.add_dependency(%q<hoptoad-api>, [">= 0"])
61
59
  s.add_dependency(%q<jeweler>, [">= 0"])
62
60
  end
63
61
  else
64
62
  s.add_dependency(%q<rake>, [">= 0"])
65
- s.add_dependency(%q<activesupport>, [">= 0"])
66
- s.add_dependency(%q<i18n>, [">= 0"])
63
+ s.add_dependency(%q<hoptoad-api>, [">= 0"])
67
64
  s.add_dependency(%q<jeweler>, [">= 0"])
68
65
  end
69
66
  end
@@ -8,7 +8,7 @@
8
8
  <resolved type="boolean">false</resolved>
9
9
  <error-class>ActiveRecord::StatementInvalid</error-class>
10
10
  <error-message>ActiveRecord::StatementInvalid: PGError: ERROR: duplicate key value violates unique constraint "index_companies_on_slug" : INSERT INTO "companies" ("slug", "created_at", "title", "updated_at", "external_url", "logo_id", "custom") VALUES('abbott-associates</error-message>
11
- <id type="integer">4023713</id>
11
+ <id type="integer">4040123</id>
12
12
  <lighthouse-ticket-id type="integer" nil="true"></lighthouse-ticket-id>
13
13
  <controller>domU-12-31-39-15-22-AC:14720:critical,high,medium,low</controller>
14
14
  <file>/var/data/www/apps/startwire/shared/bundle/ruby/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract_adapter.rb</file>
@@ -5,7 +5,8 @@ describe Shelltoad do
5
5
 
6
6
  before(:each) do
7
7
  Shelltoad::Configuration.stubs(:key).returns("whatever")
8
- Shelltoad::Configuration.stubs(:project).returns("startdatelabs")
8
+ Shelltoad::Configuration.stubs(:account).returns("startdatelabs")
9
+ Shelltoad::Configuration.stubs(:project_id).returns(14951)
9
10
  Shelltoad::Error.any_instance.stubs(:commit).returns(true)
10
11
  end
11
12
 
@@ -17,23 +18,6 @@ describe Shelltoad do
17
18
  end
18
19
  end
19
20
 
20
- context "when hoptoad service is unavailable" do
21
- before(:each) do
22
- FakeWeb.register_uri(
23
- :any,
24
- %r|http://startdatelabs.hoptoadapp.com/errors.xml|,
25
- :body => "Service Unavailable. Try again later",
26
- :status => 500
27
- )
28
- Shelltoad.run("errors")
29
-
30
-
31
- end
32
-
33
- it "should output the server error" do
34
- TESTOUT.should =~ /^Hoptoad service not available./
35
- end
36
- end
37
21
  end
38
22
 
39
23
  end
data/spec/spec_helper.rb CHANGED
@@ -32,8 +32,8 @@ RSpec.configure do |config|
32
32
  :body => File.new("spec/assets/error.xml").read
33
33
  )
34
34
  FakeWeb.register_uri(
35
- :post,
36
- "http://startdatelabs.hoptoadapp.com/errors/4040123" ,
35
+ :put,
36
+ "http://startdatelabs.hoptoadapp.com/errors/4040123.xml" ,
37
37
  :body => File.read('spec/assets/error.xml')
38
38
  )
39
39
 
@@ -47,3 +47,4 @@ RSpec.configure do |config|
47
47
  end
48
48
 
49
49
 
50
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelltoad
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 5
10
- version: 0.2.5
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bogdan Gusiev
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-04 00:00:00 +03:00
18
+ date: 2011-04-06 00:00:00 +03:00
19
19
  default_executable: shelltoad
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -34,7 +34,7 @@ dependencies:
34
34
  type: :runtime
35
35
  - !ruby/object:Gem::Dependency
36
36
  prerelease: false
37
- name: activesupport
37
+ name: hoptoad-api
38
38
  version_requirements: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
@@ -48,7 +48,7 @@ dependencies:
48
48
  type: :runtime
49
49
  - !ruby/object:Gem::Dependency
50
50
  prerelease: false
51
- name: i18n
51
+ name: jeweler
52
52
  version_requirements: &id003 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
@@ -59,20 +59,6 @@ dependencies:
59
59
  - 0
60
60
  version: "0"
61
61
  requirement: *id003
62
- type: :runtime
63
- - !ruby/object:Gem::Dependency
64
- prerelease: false
65
- name: jeweler
66
- version_requirements: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
75
- requirement: *id004
76
62
  type: :development
77
63
  description: |
78
64