spagalloco-hoptoad-api 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +13 -0
- data/VERSION.yml +4 -0
- data/lib/hoptoad-api.rb +122 -0
- metadata +56 -0
data/README.textile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
h1. Hoptoad API
|
2
|
+
|
3
|
+
An unofficial Ruby library for interacting with the "Hoptoad API":http://hoptoadapp.com/pages/api
|
4
|
+
|
5
|
+
h2. Requirements
|
6
|
+
|
7
|
+
* ActiveResource
|
8
|
+
* ActiveSupport
|
9
|
+
|
10
|
+
h2. Acknowledgements
|
11
|
+
|
12
|
+
* "Hoptoad":http://hoptoadapp.com
|
13
|
+
* "Lighthouse-api":http://github.com/Caged/lighthouse-api (inspiration for much of this code)
|
data/VERSION.yml
ADDED
data/lib/hoptoad-api.rb
ADDED
@@ -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
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spagalloco-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: 2009-02-26 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: An unofficial gem for interacting with the Hoptoad API
|
17
|
+
email: steve.agalloco@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.textile
|
26
|
+
- VERSION.yml
|
27
|
+
- lib/hoptoad-api.rb
|
28
|
+
has_rdoc: true
|
29
|
+
homepage: http://github.com/spagalloco/hoptoad-api
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options:
|
32
|
+
- --inline-source
|
33
|
+
- --charset=UTF-8
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.2.0
|
52
|
+
signing_key:
|
53
|
+
specification_version: 2
|
54
|
+
summary: An unofficial gem for interacting with the Hoptoad API
|
55
|
+
test_files: []
|
56
|
+
|