hoptoad-api 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,31 +1,9 @@
1
- require 'rubygems'
2
1
  require 'rake'
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
3
4
 
4
- $LOAD_PATH.unshift 'lib'
5
-
6
- begin
7
- require 'jeweler'
8
- require 'hoptoad-api/version'
9
-
10
- Jeweler::Tasks.new do |gem|
11
- gem.name = "hoptoad-api"
12
- gem.summary = %Q{An unofficial gem for interacting with the Hoptoad API}
13
- gem.email = "steve.agalloco@gmail.com"
14
- gem.homepage = "http://github.com/spagalloco/hoptoad-api"
15
- gem.description = "An unofficial gem for interacting with the Hoptoad API"
16
- gem.authors = ["Steve Agalloco"]
17
- gem.version = Hoptoad::VERSION
18
-
19
- gem.add_dependency(%q<httparty>, [">= 0.5.2"])
20
- gem.add_dependency(%q<hashie>, [">= 0.2.0"])
21
-
22
- gem.add_development_dependency "shoulda", ">= 0"
23
- gem.add_development_dependency "fakeweb", ">= 0"
24
- end
25
- Jeweler::GemcutterTasks.new
26
- rescue LoadError
27
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
28
- end
5
+ $:.unshift 'lib'
6
+ require 'hoptoad-api/version'
29
7
 
30
8
  require 'rake/testtask'
31
9
  Rake::TestTask.new(:test) do |test|
@@ -34,23 +12,13 @@ Rake::TestTask.new(:test) do |test|
34
12
  test.verbose = true
35
13
  end
36
14
 
37
- begin
38
- require 'rcov/rcovtask'
39
- Rcov::RcovTask.new do |test|
40
- test.libs << 'test'
41
- test.pattern = 'test/**/test_*.rb'
42
- test.verbose = true
43
- end
44
- rescue LoadError
45
- task :rcov do
46
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
47
- end
15
+ require 'rcov/rcovtask'
16
+ Rcov::RcovTask.new do |test|
17
+ test.libs << 'test'
18
+ test.pattern = 'test/**/test_*.rb'
19
+ test.verbose = true
48
20
  end
49
21
 
50
- task :test => :check_dependencies
51
-
52
- task :default => :test
53
-
54
22
  require 'rake/rdoctask'
55
23
  Rake::RDocTask.new do |rdoc|
56
24
  version = Hoptoad::VERSION
@@ -60,3 +28,5 @@ Rake::RDocTask.new do |rdoc|
60
28
  rdoc.rdoc_files.include('README*')
61
29
  rdoc.rdoc_files.include('lib/**/*.rb')
62
30
  end
31
+
32
+ task :default => :test
@@ -3,26 +3,20 @@ require 'httparty'
3
3
 
4
4
  module Hoptoad
5
5
  extend self
6
- attr_accessor :secure
6
+ attr_accessor :account, :auth_token, :secure
7
7
 
8
8
  class HoptoadError < StandardError; end
9
9
 
10
- def account=(account)
11
- @account = account
10
+ def configure(options={})
11
+ @account = options[:account] if options.has_key?(:account)
12
+ @auth_token = options[:auth_token] if options.has_key?(:auth_token)
13
+ @secure = options[:secure] if options.has_key?(:secure)
12
14
  end
13
15
 
14
- def account
16
+ def account_path
15
17
  "#{protocol}://#{@account}.hoptoadapp.com"
16
18
  end
17
19
 
18
- def auth_token=(token)
19
- @auth_token = token
20
- end
21
-
22
- def auth_token
23
- @auth_token
24
- end
25
-
26
20
  def protocol
27
21
  secure ? "https" : "http"
28
22
  end
@@ -25,7 +25,7 @@
25
25
  # Hoptoad::Error.find(:all, :params => { :page => 2 })
26
26
  #
27
27
  # find individual error by ID
28
- # Hoptoad::Error.find(44)
28
+ # Hoptoad::Error.find(44)
29
29
  #
30
30
  # Find *all* notices by error_id
31
31
  #
@@ -39,27 +39,27 @@ module Hoptoad
39
39
  class Base
40
40
  include HTTParty
41
41
  format :xml
42
-
42
+
43
43
  private
44
-
44
+
45
45
  def self.setup
46
- base_uri Hoptoad.account
46
+ base_uri Hoptoad.account_path
47
47
  default_params :auth_token => Hoptoad.auth_token
48
-
48
+
49
49
  check_configuration
50
50
  end
51
-
51
+
52
52
  def self.check_configuration
53
53
  raise HoptoadError.new('API Token cannot be nil') if default_options.nil? || default_options[:default_params].nil? || !default_options[:default_params].has_key?(:auth_token)
54
54
  raise HoptoadError.new('Account cannot be nil') unless default_options.has_key?(:base_uri)
55
55
  end
56
-
56
+
57
57
  def self.fetch(path, options)
58
58
  response = get(path, { :query => options })
59
59
  if response.code == 403
60
60
  raise HoptoadError.new('SSL should be enabled - use Hoptoad.secure = true in configuration')
61
61
  end
62
-
62
+
63
63
  Hashie::Mash.new(response)
64
64
  end
65
65
 
@@ -69,7 +69,7 @@ module Hoptoad
69
69
 
70
70
  def self.find(*args)
71
71
  setup
72
-
72
+
73
73
  results = case args.first
74
74
  when Fixnum
75
75
  find_individual(args)
@@ -78,16 +78,16 @@ module Hoptoad
78
78
  else
79
79
  raise HoptoadError.new('Invalid argument')
80
80
  end
81
-
81
+
82
82
  raise HoptoadError.new('No results found.') if results.nil?
83
83
  raise HoptoadError.new(results.errors.error) if results.errors
84
-
84
+
85
85
  results.group || results.groups
86
86
  end
87
87
 
88
88
  def self.update(error, options)
89
89
  setup
90
-
90
+
91
91
  self.class.put(collection_path, options)
92
92
  end
93
93
 
@@ -95,7 +95,7 @@ module Hoptoad
95
95
 
96
96
  def self.find_all(args)
97
97
  options = args.extract_options!
98
-
98
+
99
99
  fetch(collection_path, options)
100
100
  end
101
101
 
@@ -120,19 +120,19 @@ module Hoptoad
120
120
 
121
121
  def self.find(id, error_id, options={})
122
122
  setup
123
-
123
+
124
124
  hash = fetch(find_path(id, error_id), options)
125
-
125
+
126
126
  if hash.errors
127
127
  raise HoptoadError.new(results.errors.error)
128
128
  end
129
-
129
+
130
130
  hash.notice
131
131
  end
132
-
132
+
133
133
  def self.find_all_by_error_id(error_id)
134
134
  setup
135
-
135
+
136
136
  options = {}
137
137
  notices = []
138
138
  page = 1
@@ -143,7 +143,7 @@ module Hoptoad
143
143
  raise HoptoadError.new(results.errors.error)
144
144
  end
145
145
  notice_stubs = hash.notices
146
-
146
+
147
147
  notice_stubs.map do |notice|
148
148
  notices << find(notice.id, error_id)
149
149
  end
@@ -155,12 +155,12 @@ module Hoptoad
155
155
 
156
156
  def self.find_by_error_id(error_id, options={ 'page' => 1})
157
157
  setup
158
-
158
+
159
159
  hash = fetch(all_path(error_id), options)
160
160
  if hash.errors
161
161
  raise HoptoadError.new(results.errors.error)
162
162
  end
163
-
163
+
164
164
  hash.notices
165
165
  end
166
166
 
@@ -1,3 +1,3 @@
1
1
  module Hoptoad
2
- VERSION = '2.1.0'
2
+ VERSION = '2.2.0'
3
3
  end
@@ -2,6 +2,44 @@ require 'test_helper'
2
2
 
3
3
  class HoptoadTest < Test::Unit::TestCase
4
4
 
5
+ context "configuration" do
6
+ setup do
7
+ Hoptoad.account = nil
8
+ Hoptoad.auth_token = nil
9
+ Hoptoad.secure = false
10
+ end
11
+
12
+
13
+ should "allow setting of the account" do
14
+ Hoptoad.account = 'myapp'
15
+ assert_equal Hoptoad.account, 'myapp'
16
+ assert_equal Hoptoad.account_path, 'http://myapp.hoptoadapp.com'
17
+ end
18
+
19
+ should "allow setting of the auth token" do
20
+ Hoptoad.auth_token = '123456'
21
+ assert_equal Hoptoad.auth_token, '123456'
22
+ end
23
+
24
+ should "allow setting of ssl protocol" do
25
+ Hoptoad.secure = true
26
+ assert_equal Hoptoad.protocol, 'https'
27
+ end
28
+
29
+ should "default to standard http" do
30
+ Hoptoad.secure = false
31
+ assert_equal Hoptoad.protocol, 'http'
32
+ end
33
+
34
+ should "should immplement #configure" do
35
+ Hoptoad.configure(:account => 'anapp', :auth_token => 'abcdefg', :secure => true)
36
+ assert_equal Hoptoad.protocol, 'https'
37
+ assert_equal Hoptoad.auth_token, 'abcdefg'
38
+ assert_equal Hoptoad.account, 'anapp'
39
+ assert_equal Hoptoad.account_path, 'https://anapp.hoptoadapp.com'
40
+ end
41
+ end
42
+
5
43
  context "given a Hoptoad account & API key" do
6
44
  setup do
7
45
  Hoptoad.account = 'myapp'
@@ -18,57 +56,57 @@ class HoptoadTest < Test::Unit::TestCase
18
56
  end
19
57
 
20
58
  context "when finding errors" do
21
-
59
+
22
60
  should "find a page of the 30 most recent errors" do
23
61
  errors = Hoptoad::Error.find(:all)
24
62
  ordered = errors.sort_by(&:most_recent_notice_at).reverse
25
63
  assert_equal ordered, errors
26
64
  assert_equal errors.size, 30
27
65
  end
28
-
66
+
29
67
  should "paginate errors" do
30
68
  errors = Hoptoad::Error.find(:all, :page => 2)
31
69
  ordered = errors.sort_by(&:most_recent_notice_at).reverse
32
70
  assert_equal ordered, errors
33
71
  assert_equal errors.size, 2
34
72
  end
35
-
73
+
36
74
  should "find an individual error" do
37
75
  error = Hoptoad::Error.find(1696170)
38
76
  assert_equal error.action, 'index'
39
77
  assert_equal error.id, 1696170
40
78
  end
41
-
79
+
42
80
  end
43
-
81
+
44
82
  context "when finding notices" do
45
-
83
+
46
84
  should "find error notices" do
47
85
  notices = Hoptoad::Notice.find_by_error_id(1696170)
48
86
  assert_equal notices.size, 30
49
87
  assert_equal notices.first.id, 1234
50
88
  end
51
-
89
+
52
90
  should "find all error notices" do
53
91
  notices = Hoptoad::Notice.find_all_by_error_id(1696170)
54
92
  assert_equal notices.size, 42
55
93
  end
56
-
94
+
57
95
  should "find individual notices" do
58
96
  Hoptoad::Notice.find(1234, 1696170)
59
97
  end
60
-
98
+
61
99
  end
62
-
100
+
63
101
  context "when using SSL" do
64
-
102
+
65
103
  should "find an error if account is SSL enabled" do
66
104
  Hoptoad.secure = true
67
105
  Hoptoad.account = "sslapp"
68
106
  error = Hoptoad::Error.find(1696170)
69
107
  assert_equal error.id, 1696170
70
108
  end
71
-
109
+
72
110
  should "raise exception if trying to access SSL enabled account with unsecure connection" do
73
111
  Hoptoad.account = "sslapp"
74
112
  Hoptoad.secure = false
@@ -77,7 +115,7 @@ class HoptoadTest < Test::Unit::TestCase
77
115
  end
78
116
  end
79
117
  end
80
-
118
+
81
119
  end
82
120
 
83
121
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoptoad-api
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 7
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2
7
- - 1
8
+ - 2
8
9
  - 0
9
- version: 2.1.0
10
+ version: 2.2.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Steve Agalloco
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-26 00:00:00 -04:00
18
+ date: 2010-11-06 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: httparty
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 15
27
30
  segments:
28
31
  - 0
29
32
  - 5
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: hashie
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 23
41
46
  segments:
42
47
  - 0
43
48
  - 2
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: shoulda
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 3
55
62
  segments:
56
63
  - 0
57
64
  version: "0"
@@ -61,9 +68,11 @@ dependencies:
61
68
  name: fakeweb
62
69
  prerelease: false
63
70
  requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
64
72
  requirements:
65
73
  - - ">="
66
74
  - !ruby/object:Gem::Version
75
+ hash: 3
67
76
  segments:
68
77
  - 0
69
78
  version: "0"
@@ -75,17 +84,14 @@ executables: []
75
84
 
76
85
  extensions: []
77
86
 
78
- extra_rdoc_files:
79
- - README.textile
87
+ extra_rdoc_files: []
88
+
80
89
  files:
81
- - .gitignore
82
- - README.textile
83
90
  - Rakefile
84
- - hoptoad-api.gemspec
85
- - lib/hoptoad-api.rb
86
91
  - lib/hoptoad-api/client.rb
87
92
  - lib/hoptoad-api/core_extensions.rb
88
93
  - lib/hoptoad-api/version.rb
94
+ - lib/hoptoad-api.rb
89
95
  - test/fixtures/errors.xml
90
96
  - test/fixtures/individual_error.xml
91
97
  - test/fixtures/individual_notice.xml
@@ -94,36 +100,40 @@ files:
94
100
  - test/fixtures/paginated_notices.xml
95
101
  - test/test_helper.rb
96
102
  - test/test_hoptoad-api.rb
103
+ - README.textile
97
104
  has_rdoc: true
98
105
  homepage: http://github.com/spagalloco/hoptoad-api
99
106
  licenses: []
100
107
 
101
108
  post_install_message:
102
- rdoc_options:
103
- - --charset=UTF-8
109
+ rdoc_options: []
110
+
104
111
  require_paths:
105
112
  - lib
106
113
  required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
107
115
  requirements:
108
116
  - - ">="
109
117
  - !ruby/object:Gem::Version
118
+ hash: 3
110
119
  segments:
111
120
  - 0
112
121
  version: "0"
113
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
114
124
  requirements:
115
125
  - - ">="
116
126
  - !ruby/object:Gem::Version
127
+ hash: 3
117
128
  segments:
118
129
  - 0
119
130
  version: "0"
120
131
  requirements: []
121
132
 
122
133
  rubyforge_project:
123
- rubygems_version: 1.3.6
134
+ rubygems_version: 1.3.7
124
135
  signing_key:
125
136
  specification_version: 3
126
- summary: An unofficial gem for interacting with the Hoptoad API
127
- test_files:
128
- - test/test_helper.rb
129
- - test/test_hoptoad-api.rb
137
+ summary: Hoptoad API
138
+ test_files: []
139
+
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- *.gem
5
- pkg/*
@@ -1,68 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{hoptoad-api}
8
- s.version = "2.1.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Steve Agalloco"]
12
- s.date = %q{2010-05-26}
13
- s.description = %q{An unofficial gem for interacting with the Hoptoad API}
14
- s.email = %q{steve.agalloco@gmail.com}
15
- s.extra_rdoc_files = [
16
- "README.textile"
17
- ]
18
- s.files = [
19
- ".gitignore",
20
- "README.textile",
21
- "Rakefile",
22
- "hoptoad-api.gemspec",
23
- "lib/hoptoad-api.rb",
24
- "lib/hoptoad-api/client.rb",
25
- "lib/hoptoad-api/core_extensions.rb",
26
- "lib/hoptoad-api/version.rb",
27
- "test/fixtures/errors.xml",
28
- "test/fixtures/individual_error.xml",
29
- "test/fixtures/individual_notice.xml",
30
- "test/fixtures/notices.xml",
31
- "test/fixtures/paginated_errors.xml",
32
- "test/fixtures/paginated_notices.xml",
33
- "test/test_helper.rb",
34
- "test/test_hoptoad-api.rb"
35
- ]
36
- s.homepage = %q{http://github.com/spagalloco/hoptoad-api}
37
- s.rdoc_options = ["--charset=UTF-8"]
38
- s.require_paths = ["lib"]
39
- s.rubygems_version = %q{1.3.6}
40
- s.summary = %q{An unofficial gem for interacting with the Hoptoad API}
41
- s.test_files = [
42
- "test/test_helper.rb",
43
- "test/test_hoptoad-api.rb"
44
- ]
45
-
46
- if s.respond_to? :specification_version then
47
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
- s.specification_version = 3
49
-
50
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
- s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
52
- s.add_runtime_dependency(%q<hashie>, [">= 0.2.0"])
53
- s.add_development_dependency(%q<shoulda>, [">= 0"])
54
- s.add_development_dependency(%q<fakeweb>, [">= 0"])
55
- else
56
- s.add_dependency(%q<httparty>, [">= 0.5.2"])
57
- s.add_dependency(%q<hashie>, [">= 0.2.0"])
58
- s.add_dependency(%q<shoulda>, [">= 0"])
59
- s.add_dependency(%q<fakeweb>, [">= 0"])
60
- end
61
- else
62
- s.add_dependency(%q<httparty>, [">= 0.5.2"])
63
- s.add_dependency(%q<hashie>, [">= 0.2.0"])
64
- s.add_dependency(%q<shoulda>, [">= 0"])
65
- s.add_dependency(%q<fakeweb>, [">= 0"])
66
- end
67
- end
68
-