hoptoad-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ *.gem
5
+ pkg/*
@@ -0,0 +1,30 @@
1
+ h1. Hoptoad API
2
+
3
+ An unofficial Ruby library for interacting with the "Hoptoad API":http://hoptoadapp.com/pages/api
4
+
5
+ h2. Usage
6
+
7
+ <pre>
8
+ <code>
9
+ Hoptoad.account = 'myaccount'
10
+ Hoptoad.token = 'abcdeghijklmnopqrstuvwxyz'
11
+
12
+ # find an individual error:
13
+ Hoptoad::Error.find(12345)
14
+
15
+ # or get a list of errors using:
16
+ Hoptoad::Error.find(:all)
17
+ Hoptoad::Error.find(:all, :params => { :page => 2 })
18
+ </code>
19
+ </pre>
20
+
21
+
22
+ h2. Requirements
23
+
24
+ * ActiveResource
25
+ * ActiveSupport
26
+
27
+ h2. Acknowledgements
28
+
29
+ * "Hoptoad":http://hoptoadapp.com
30
+ * "Lighthouse-api":http://github.com/Caged/lighthouse-api (inspiration for much of this code)
@@ -0,0 +1,18 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |s|
6
+ s.name = "hoptoad-api"
7
+ s.summary = %Q{An unofficial gem for interacting with the Hoptoad API}
8
+ s.email = "steve.agalloco@gmail.com"
9
+ s.homepage = "http://github.com/spagalloco/hoptoad-api"
10
+ s.description = "An unofficial gem for interacting with the Hoptoad API"
11
+ s.authors = ["Steve Agalloco"]
12
+ s.add_dependency(%q<activesupport>, [">= 2.1.0"])
13
+ s.add_dependency(%q<activeresource>, [">= 2.1.0"])
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 1
3
+ :minor: 0
4
+ :patch: 0
@@ -0,0 +1,52 @@
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 = "1.0.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-04-24}
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
+ "VERSION.yml",
23
+ "hoptoad-api.gemspec",
24
+ "lib/hoptoad-api.rb",
25
+ "test/hoptoad-api.rb"
26
+ ]
27
+ s.homepage = %q{http://github.com/spagalloco/hoptoad-api}
28
+ s.rdoc_options = ["--charset=UTF-8"]
29
+ s.require_paths = ["lib"]
30
+ s.rubygems_version = %q{1.3.5}
31
+ s.summary = %q{An unofficial gem for interacting with the Hoptoad API}
32
+ s.test_files = [
33
+ "test/hoptoad-api.rb"
34
+ ]
35
+
36
+ if s.respond_to? :specification_version then
37
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
41
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.1.0"])
42
+ s.add_runtime_dependency(%q<activeresource>, [">= 2.1.0"])
43
+ else
44
+ s.add_dependency(%q<activesupport>, [">= 2.1.0"])
45
+ s.add_dependency(%q<activeresource>, [">= 2.1.0"])
46
+ end
47
+ else
48
+ s.add_dependency(%q<activesupport>, [">= 2.1.0"])
49
+ s.add_dependency(%q<activeresource>, [">= 2.1.0"])
50
+ end
51
+ end
52
+
@@ -0,0 +1,122 @@
1
+ require 'rubygems'
2
+
3
+ begin
4
+ require 'uri'
5
+ require 'addressable/uri'
6
+
7
+ module URI
8
+ def decode(*args)
9
+ Addressable::URI.decode(*args)
10
+ end
11
+
12
+ def escape(*args)
13
+ Addressable::URI.escape(*args)
14
+ end
15
+
16
+ def parse(*args)
17
+ Addressable::URI.parse(*args)
18
+ end
19
+ end
20
+ rescue LoadError
21
+ puts "Install the Addressable gem to support accounts with subdomains."
22
+ puts "# sudo gem install addressable"
23
+ puts
24
+ end
25
+
26
+ require 'activesupport'
27
+ require 'activeresource'
28
+
29
+ # Ruby lib for working with the Hoptoad API's XML interface.
30
+ # The first thing you need to set is the account name. This is the same
31
+ # as the web address for your account.
32
+ #
33
+ # Hoptoad.account = 'myaccount'
34
+ #
35
+ # Then, you should set the authentication token.
36
+ #
37
+ # Hoptoad.token = 'abcdefg'
38
+ #
39
+ # If no token or authentication info is given, a HoptoadError exception will be raised.
40
+ #
41
+ # For more details, check out the hoptoad docs at http://hoptoadapp.com/pages/api.
42
+ #
43
+ module Hoptoad
44
+ class HoptoadError < StandardError; end
45
+ class << self
46
+ attr_accessor :host_format, :domain_format, :protocol, :port
47
+ attr_reader :account, :token
48
+
49
+ # Sets the account name, and updates all the resources with the new domain.
50
+ def account=(name)
51
+ resources.each do |klass|
52
+ klass.site = klass.site_format % (host_format % [protocol, domain_format % name, ":#{port}"])
53
+ end
54
+ @account = name
55
+ end
56
+
57
+ # Sets the API token for all the resources.
58
+ def token=(value)
59
+ @token = value
60
+ end
61
+
62
+ def resources
63
+ @resources ||= []
64
+ end
65
+ end
66
+
67
+ self.host_format = '%s://%s%s'
68
+ self.domain_format = '%s.hoptoadapp.com'
69
+ self.protocol = 'http'
70
+ self.port = ''
71
+
72
+ class Base < ActiveResource::Base
73
+ def self.inherited(base)
74
+ Hoptoad.resources << base
75
+ class << base
76
+ attr_accessor :site_format
77
+
78
+ def append_auth_token_to_params(*arguments)
79
+ opts = arguments.last.is_a?(Hash) ? arguments.pop : {}
80
+ opts = opts.has_key?(:params) ? opts : opts.merge(:params => {})
81
+ opts[:params] = opts[:params].merge(:auth_token => Hoptoad.token)
82
+ arguments << opts
83
+ arguments
84
+ end
85
+ end
86
+ base.site_format = '%s'
87
+ super
88
+ end
89
+ end
90
+
91
+ # Find errors
92
+ #
93
+ # Errors are paginated. You get 25 at a time.
94
+ # Hoptoad::Error.find(:all)
95
+ # Hoptoad::Error.find(:all, :params => { :page => 2 })
96
+ #
97
+ # find individual error by ID
98
+ # Hoptoad::Error.find(44)
99
+ #
100
+ class Error < Base
101
+
102
+ # find using token
103
+ def self.find(*arguments)
104
+ raise HoptoadError.new('API Token cannot be nil') if Hoptoad.token.blank?
105
+ raise HoptoadError.new('Account cannot be nil') if Hoptoad.account.blank?
106
+
107
+ arguments = append_auth_token_to_params(*arguments)
108
+ super(*arguments)
109
+ end
110
+
111
+ # produces the url on hoptoad's site
112
+ def url
113
+ path = Error.site.to_s
114
+ path << collection_path.gsub!(/^\//,'')
115
+ path.gsub!('.xml','')
116
+ path << '/'
117
+ path << self.id.to_s
118
+ end
119
+
120
+ end
121
+
122
+ end
@@ -0,0 +1,29 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'shoulda'
4
+ require File.join(File.dirname(__FILE__), "..", "lib", "hoptoad-api")
5
+
6
+ class HoptoadTest < Test::Unit::TestCase
7
+
8
+ context "given a Hoptoad account & API key" do
9
+ setup do
10
+ credentials_path = File.join(ENV['HOME'], ".hoptoad.yml")
11
+ credentials = YAML::load_file(credentials_path)
12
+ Hoptoad.account = credentials['account']
13
+ Hoptoad.token = credentials['token']
14
+ end
15
+
16
+ should "find a page of the 30 most recent errors" do
17
+ errors = Hoptoad::Error.find(:all)
18
+ ordered = errors.sort_by(&:most_recent_notice_at).reverse
19
+ assert_equal ordered, errors
20
+ assert_equal 30, errors.size
21
+ end
22
+
23
+ should "have correct collection path" do
24
+ assert_equal "/errors.xml", Hoptoad::Error.collection_path
25
+ end
26
+ end
27
+
28
+ end
29
+
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hoptoad-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Steve Agalloco
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-04-24 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activeresource
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ version:
35
+ description: An unofficial gem for interacting with the Hoptoad API
36
+ email: steve.agalloco@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.textile
43
+ files:
44
+ - .gitignore
45
+ - README.textile
46
+ - Rakefile
47
+ - VERSION.yml
48
+ - hoptoad-api.gemspec
49
+ - lib/hoptoad-api.rb
50
+ - test/hoptoad-api.rb
51
+ has_rdoc: true
52
+ homepage: http://github.com/spagalloco/hoptoad-api
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --charset=UTF-8
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.5
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: An unofficial gem for interacting with the Hoptoad API
79
+ test_files:
80
+ - test/hoptoad-api.rb