otter-rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +9 -0
- data/lib/otter-rb.rb +28 -0
- data/lib/otter/author.rb +45 -0
- data/lib/otter/base.rb +19 -0
- data/lib/otter/connection.rb +93 -0
- data/lib/otter/count.rb +25 -0
- data/lib/otter/error.rb +22 -0
- data/lib/otter/link.rb +37 -0
- data/lib/otter/post.rb +39 -0
- data/lib/otter/response.rb +47 -0
- data/lib/otter/tag.rb +13 -0
- data/lib/otter/topic.rb +13 -0
- data/lib/otter/trackback.rb +29 -0
- data/lib/otter/urlinfo.rb +34 -0
- data/spec/spec_helper.rb +8 -0
- metadata +109 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jeff Smick
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/lib/otter-rb.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
%w[
|
2
|
+
em-http
|
3
|
+
yajl
|
4
|
+
|
5
|
+
otter/connection
|
6
|
+
otter/response
|
7
|
+
otter/error
|
8
|
+
|
9
|
+
otter/base
|
10
|
+
otter/author
|
11
|
+
otter/post
|
12
|
+
otter/link
|
13
|
+
otter/count
|
14
|
+
otter/tag
|
15
|
+
otter/trackback
|
16
|
+
otter/topic
|
17
|
+
otter/urlinfo
|
18
|
+
].each { |r| require r }
|
19
|
+
|
20
|
+
module Otter
|
21
|
+
|
22
|
+
def self.connect(identifier, &block)
|
23
|
+
EM.run {
|
24
|
+
yield Connection.new(identifier)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/otter/author.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# "name" : "Barack Obama",
|
2
|
+
# "url" : "http://twitter.com/barackobama",
|
3
|
+
# "type" : "twitter",
|
4
|
+
# "nick" : "barackobama",
|
5
|
+
# "description" : "44th President of the United States",
|
6
|
+
# "topsy_author_url" : "http://topsy.com/twitter/barackobama",
|
7
|
+
# "influence_level" : "5"
|
8
|
+
module Otter
|
9
|
+
|
10
|
+
class Author < Base
|
11
|
+
|
12
|
+
def name
|
13
|
+
self.data['name']
|
14
|
+
end
|
15
|
+
|
16
|
+
def type
|
17
|
+
self.data['type']
|
18
|
+
end
|
19
|
+
|
20
|
+
def nick
|
21
|
+
self.data['nick']
|
22
|
+
end
|
23
|
+
|
24
|
+
def description
|
25
|
+
self.data['description']
|
26
|
+
end
|
27
|
+
|
28
|
+
def topsy_author_url
|
29
|
+
self.data['topsy_author_url']
|
30
|
+
end
|
31
|
+
|
32
|
+
def influence_level
|
33
|
+
self.data['influence_level']
|
34
|
+
end
|
35
|
+
|
36
|
+
def topsy_author_url
|
37
|
+
self.data['topsy_author_url']
|
38
|
+
end
|
39
|
+
|
40
|
+
def photo_url
|
41
|
+
self.data['photo_url']
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/lib/otter/base.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Otter
|
2
|
+
|
3
|
+
class Base
|
4
|
+
attr_reader :data
|
5
|
+
|
6
|
+
def self.create(data)
|
7
|
+
if data['list'].is_a?(Array)
|
8
|
+
data['list'].map { |d| self.new(d) }
|
9
|
+
else
|
10
|
+
self.new(data)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(data)
|
15
|
+
@data = data
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Otter
|
2
|
+
|
3
|
+
class Connection
|
4
|
+
def initialize(identifier)
|
5
|
+
@identifier = identifier
|
6
|
+
end
|
7
|
+
|
8
|
+
def authorinfo(username, &block)
|
9
|
+
self.request('authorinfo', {:url => "http://twitter.com/#{username}"}, Author, block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def authorsearch(query, window = 'a', page = nil, perpage = nil, &block)
|
13
|
+
self.request('authorsearch', {:q => query, :window => window}, Author, block, page, perpage)
|
14
|
+
end
|
15
|
+
|
16
|
+
def linkposts(url, contains = nil, page = nil, perpage = nil, &block)
|
17
|
+
self.request('linkposts', {:url => url, :contains => contains}, Post, block, page, perpage)
|
18
|
+
end
|
19
|
+
|
20
|
+
def linkpostcount(url, contains = nil, &block)
|
21
|
+
self.request('linkpostcount', {:url => url, :contains => contains}, Base, lambda { |response, base|
|
22
|
+
if response.is_a?(Error)
|
23
|
+
block.call response
|
24
|
+
else
|
25
|
+
block.call response, Integer(base.data['contains']), Integer(base.data['all'])
|
26
|
+
end
|
27
|
+
})
|
28
|
+
end
|
29
|
+
|
30
|
+
def profilesearch(query, page = nil, perpage = nil, &block)
|
31
|
+
self.request('profilesearch', {:q => query}, Author, block, page, perpage)
|
32
|
+
end
|
33
|
+
|
34
|
+
def related(url, page = nil, perpage = nil, &block)
|
35
|
+
self.request('related', {:url => url}, Link, block, page, perpage)
|
36
|
+
end
|
37
|
+
|
38
|
+
def search(query, window = 'a', page = nil, perpage = nil, &block)
|
39
|
+
self.request('search', {:q => query, :window => window}, Link, block, page, perpage)
|
40
|
+
end
|
41
|
+
|
42
|
+
def searchcount(query, &block)
|
43
|
+
self.request('searchcount', {:q => query}, Count, block)
|
44
|
+
end
|
45
|
+
|
46
|
+
def stats(url, contains = nil, &block)
|
47
|
+
self.request('stats', {:url => url, :contains => contains}, Base, lambda { |response, base|
|
48
|
+
if response.is_a?(Error)
|
49
|
+
block.call response
|
50
|
+
else
|
51
|
+
block.call( response,
|
52
|
+
base.data['topsy_trackback_url'],
|
53
|
+
Integer(base.data['contains']),
|
54
|
+
Integer(base.data['influential']),
|
55
|
+
Integer(base.data['all']))
|
56
|
+
end
|
57
|
+
})
|
58
|
+
end
|
59
|
+
|
60
|
+
def tags(url, page = nil, perpage = nil, &block)
|
61
|
+
self.request('tags', {:url => url}, Tag, block, page, perpage)
|
62
|
+
end
|
63
|
+
|
64
|
+
def trackbacks(url, contains = nil, infonly = nil, page = nil, perpage = nil, &block)
|
65
|
+
self.request('trackbacks', {:url => url, :contains => contains, :infonly => infonly}, Trackback, block, page, perpage)
|
66
|
+
end
|
67
|
+
|
68
|
+
def trending(page = nil, perpage = nil, &block)
|
69
|
+
self.request('trending', nil, Topic, block, page, perpage)
|
70
|
+
end
|
71
|
+
|
72
|
+
def urlinfo(url, &block)
|
73
|
+
self.request('urlinfo', {:url => url}, UrlInfo, block)
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
def request(url, params, klass, callback, page = nil, perpage = nil)
|
78
|
+
params[:page] = page if page
|
79
|
+
params[:perpage] = perpage if perpage
|
80
|
+
|
81
|
+
http = EM::HttpRequest.new("http://otter.topsy.com/#{url}.json", {'X-Topsy-UA' => @identifier}).get :query => params
|
82
|
+
http.callback {
|
83
|
+
body = Yajl::Parser.new.parse(http.response)['response']
|
84
|
+
callback.call(Response.new(http.response_header, body), klass.create(body))
|
85
|
+
}
|
86
|
+
|
87
|
+
http.errback {
|
88
|
+
callback.call(Error.new(http.status))
|
89
|
+
}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
data/lib/otter/count.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Otter
|
2
|
+
|
3
|
+
class Count < Base
|
4
|
+
def hour
|
5
|
+
Integer(self.data['h'])
|
6
|
+
end
|
7
|
+
|
8
|
+
def day
|
9
|
+
Integer(self.data['d'])
|
10
|
+
end
|
11
|
+
|
12
|
+
def week
|
13
|
+
Integer(self.data['w'])
|
14
|
+
end
|
15
|
+
|
16
|
+
def month
|
17
|
+
Integer(self.data['m'])
|
18
|
+
end
|
19
|
+
|
20
|
+
def all
|
21
|
+
Integer(self.data['a'])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/otter/error.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Otter
|
2
|
+
|
3
|
+
class Error
|
4
|
+
attr_reader :code
|
5
|
+
|
6
|
+
def initialize(code)
|
7
|
+
@code = code.to_i
|
8
|
+
end
|
9
|
+
|
10
|
+
def message
|
11
|
+
case self.code
|
12
|
+
when 400 then 'Parameter Check Failed'
|
13
|
+
when 403 then 'Forbidden'
|
14
|
+
when 404 then 'Action Not Supported'
|
15
|
+
when 500 then 'Unexpected Internal Error'
|
16
|
+
when 503 then 'Temporarily Unavailable'
|
17
|
+
else 'Unkown'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/otter/link.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Otter
|
2
|
+
|
3
|
+
class Link < Base
|
4
|
+
def topsy_trackback_url
|
5
|
+
self.data['topsy_trackback_url']
|
6
|
+
end
|
7
|
+
|
8
|
+
def url
|
9
|
+
self.data['url']
|
10
|
+
end
|
11
|
+
|
12
|
+
def title
|
13
|
+
self.data['title']
|
14
|
+
end
|
15
|
+
|
16
|
+
def trackback_total
|
17
|
+
self.data['trackback_total']
|
18
|
+
end
|
19
|
+
|
20
|
+
def hits
|
21
|
+
Integer(self.data['hits'])
|
22
|
+
end
|
23
|
+
|
24
|
+
def content
|
25
|
+
self.data['content']
|
26
|
+
end
|
27
|
+
|
28
|
+
def score
|
29
|
+
Float(self.data['score'])
|
30
|
+
end
|
31
|
+
|
32
|
+
def highlight
|
33
|
+
self.data['highlight']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/otter/post.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Otter
|
2
|
+
|
3
|
+
class Post < Base
|
4
|
+
def permalink_url
|
5
|
+
self.data['permalink_url']
|
6
|
+
end
|
7
|
+
|
8
|
+
def target
|
9
|
+
@target ||= Target.new(self.data['target'])
|
10
|
+
end
|
11
|
+
|
12
|
+
def date
|
13
|
+
Time.at(Integer(self.data['date']))
|
14
|
+
end
|
15
|
+
|
16
|
+
def content
|
17
|
+
self.data['content']
|
18
|
+
end
|
19
|
+
|
20
|
+
def date_alpha
|
21
|
+
self.data['date_alpha']
|
22
|
+
end
|
23
|
+
|
24
|
+
class Target < Base
|
25
|
+
def topsy_trackback_url
|
26
|
+
self.data['topsy_trackback_url']
|
27
|
+
end
|
28
|
+
|
29
|
+
def url
|
30
|
+
self.data['url']
|
31
|
+
end
|
32
|
+
|
33
|
+
def trackback_total
|
34
|
+
Integer(self.data['trackback_total'])
|
35
|
+
end
|
36
|
+
end # Target
|
37
|
+
end # Post
|
38
|
+
|
39
|
+
end # Otter
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Otter
|
2
|
+
|
3
|
+
class Response
|
4
|
+
attr_reader :headers,
|
5
|
+
:response
|
6
|
+
|
7
|
+
def initialize(headers, response) # :nodoc:
|
8
|
+
@headers = headers
|
9
|
+
@response = response
|
10
|
+
end
|
11
|
+
|
12
|
+
# Total credits that can be allocated.
|
13
|
+
def rate_limit
|
14
|
+
Integer(self.headers['X_RATELIMIT_LIMIT'])
|
15
|
+
end
|
16
|
+
|
17
|
+
# Total credits available.
|
18
|
+
def rate_remaining
|
19
|
+
Integer(self.headers['X_RATELIMIT_REMAINING'])
|
20
|
+
end
|
21
|
+
|
22
|
+
# Time when the credits will be reset.
|
23
|
+
def rate_reset
|
24
|
+
Time.at(Integer(self.headers['X_RATELIMIT_RESET']))
|
25
|
+
end
|
26
|
+
|
27
|
+
# Total number of results
|
28
|
+
def total
|
29
|
+
Integer(self.response['page'])
|
30
|
+
end
|
31
|
+
|
32
|
+
# Current page
|
33
|
+
def page
|
34
|
+
Integer(self.response['total'])
|
35
|
+
end
|
36
|
+
|
37
|
+
# Number of results per page
|
38
|
+
def perpage
|
39
|
+
Integer(self.response['perpage'])
|
40
|
+
end
|
41
|
+
|
42
|
+
def window
|
43
|
+
self.response['window']
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/lib/otter/tag.rb
ADDED
data/lib/otter/topic.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Otter
|
2
|
+
|
3
|
+
class Trackback < Base
|
4
|
+
def permalink_url
|
5
|
+
self.data['permalink_url']
|
6
|
+
end
|
7
|
+
|
8
|
+
def date
|
9
|
+
Time.at(Integer(self.data['date']))
|
10
|
+
end
|
11
|
+
|
12
|
+
def content
|
13
|
+
self.data['content']
|
14
|
+
end
|
15
|
+
|
16
|
+
def type
|
17
|
+
self.data['type']
|
18
|
+
end
|
19
|
+
|
20
|
+
def date_alpha
|
21
|
+
self.data['date_alpha']
|
22
|
+
end
|
23
|
+
|
24
|
+
def author
|
25
|
+
@author ||= Author.new(self.data['author'])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Otter
|
2
|
+
|
3
|
+
class UrlInfo < Base
|
4
|
+
def topsy_trackback_url
|
5
|
+
self.data['topsy_trackback_url']
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
def oneforty
|
10
|
+
self.data['oneforty']
|
11
|
+
end
|
12
|
+
|
13
|
+
def url
|
14
|
+
self.data['url']
|
15
|
+
end
|
16
|
+
|
17
|
+
def title
|
18
|
+
self.data['title']
|
19
|
+
end
|
20
|
+
|
21
|
+
def trackback_total
|
22
|
+
Integer(self.data['trackback_total'])
|
23
|
+
end
|
24
|
+
|
25
|
+
def description
|
26
|
+
self.data['description']
|
27
|
+
end
|
28
|
+
|
29
|
+
def description_attribution
|
30
|
+
self.data['description_attribution']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: otter-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Smick
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-08 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: em-http-request
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yajl-ruby
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: minitest
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: yard
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
description: An EventMachine based library for the Topsy Otter API.
|
56
|
+
email: sprsquish@gmail.com
|
57
|
+
executables: []
|
58
|
+
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files:
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
files:
|
65
|
+
- lib/otter-rb.rb
|
66
|
+
- lib/otter/author.rb
|
67
|
+
- lib/otter/base.rb
|
68
|
+
- lib/otter/connection.rb
|
69
|
+
- lib/otter/count.rb
|
70
|
+
- lib/otter/error.rb
|
71
|
+
- lib/otter/link.rb
|
72
|
+
- lib/otter/post.rb
|
73
|
+
- lib/otter/response.rb
|
74
|
+
- lib/otter/tag.rb
|
75
|
+
- lib/otter/topic.rb
|
76
|
+
- lib/otter/trackback.rb
|
77
|
+
- lib/otter/urlinfo.rb
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
has_rdoc: true
|
81
|
+
homepage: http://github.com/sprsquish/collecta-rb
|
82
|
+
licenses: []
|
83
|
+
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options:
|
86
|
+
- --charset=UTF-8
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
version:
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.3.5
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: An EventMachine based library for the Topsy Otter API.
|
108
|
+
test_files:
|
109
|
+
- spec/spec_helper.rb
|