backtyper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+ gem "httparty", ">= 0.6.0"
3
+
4
+ # Add dependencies to develop your gem here.
5
+ # Include everything needed to run rake, tests, features, etc.
6
+ group :development do
7
+ gem "shoulda", ">= 0"
8
+ gem "bundler", "~> 1.0.0"
9
+ gem "jeweler", "~> 1.5.2"
10
+ gem "rcov", ">= 0"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ crack (0.1.8)
5
+ git (1.2.5)
6
+ httparty (0.7.3)
7
+ crack (= 0.1.8)
8
+ jeweler (1.5.2)
9
+ bundler (~> 1.0.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rake (0.8.7)
13
+ rcov (0.9.9)
14
+ shoulda (2.11.3)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.0.0)
21
+ httparty (>= 0.6.0)
22
+ jeweler (~> 1.5.2)
23
+ rcov
24
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Justin Britten
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
@@ -0,0 +1,75 @@
1
+ # BackType API
2
+
3
+ A simple Ruby wrapper for the [BackType API](http://www.backtype.com/developers).
4
+
5
+ ## Warning, Warning, Warning
6
+
7
+ This is a work-in-progress. The entire BackType API is not yet supported. There is little error handling in place. Tests are non-existent. A gem has not yet been compiled and pushed to a repository.
8
+
9
+ ## Installation
10
+
11
+ To install as a Gem:
12
+
13
+ sudo gem install backtyper
14
+
15
+ ## Authentication
16
+
17
+ Authentication is necessary for all actions.
18
+
19
+ BackTyper.authenticate "api_key"
20
+
21
+ ---
22
+
23
+ ## Tweet examples
24
+
25
+ * Documentation - {BackTyper::Tweets}
26
+
27
+ ---
28
+
29
+ # Authenticate with BackType
30
+ BackTyper.authenticate "ABC123"
31
+
32
+ # Retrieve the number of tweets that link to a particular URL.
33
+ BackTyper::Tweets.count('http://www.google.com')
34
+
35
+ # Retrieve filtered tweets that link to a given URL with both shortened and unshortened links.
36
+ # This returns a subset of Tweets by URL, but it filters tweets linking to a URL for quality.
37
+ # This skips all the tweets that only contain the page title, etc.
38
+ BackTyper::Tweets.good('http://www.google.com')
39
+
40
+ ---
41
+
42
+ ## Comment examples
43
+
44
+ * Documentation - {BackTyper::Comments}
45
+
46
+ ---
47
+
48
+ # Authenticate with BackType
49
+ BackTyper.authenticate "ABC123"
50
+
51
+ # Retrieve all conversations related to a given URL.
52
+ BackTyper::Comments.connect('http://www.google.com')
53
+
54
+ # Retrieve statistics on the conversations related to a given URL.
55
+ BackTyper::Comments.connect_stats('http://www.google.com')
56
+
57
+ ---
58
+
59
+ ## Note on Patches/Pull Requests
60
+
61
+ * Fork the project.
62
+ * Make your feature addition or bug fix.
63
+ * Start a feature/bugfix branch
64
+ * Commit and push until you are happy with your contribution
65
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
66
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
67
+ * Send me a pull request. Bonus points for topic branches.
68
+
69
+ ## Author & Contributors
70
+
71
+ * [Justin Britten](http://www.justinbritten.com)
72
+
73
+ ## Copyright
74
+
75
+ Copyright (c) 2011 Justin Britten. See LICENSE.txt for details.
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "backtyper"
16
+ gem.homepage = "http://github.com/jbritten/backtyper"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{A Ruby wrapper for the BackType API}
19
+ gem.description = %Q{A Ruby wrapper for the BackType API}
20
+ gem.email = "justinbritten@gmail.com"
21
+ gem.authors = ["Justin Britten"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency "httparty", ">= 0.6.0"
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ end
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "backtyper #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/backtyper.gemspec ADDED
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{backtyper}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Justin Britten"]
12
+ s.date = %q{2011-02-16}
13
+ s.description = %q{A Ruby wrapper for the BackType API}
14
+ s.email = %q{justinbritten@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "backtyper.gemspec",
28
+ "lib/backtyper.rb",
29
+ "lib/backtyper/client.rb",
30
+ "lib/backtyper/comments.rb",
31
+ "lib/backtyper/tweets.rb",
32
+ "test/helper.rb",
33
+ "test/test_backtyper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/jbritten/backtyper}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{A Ruby wrapper for the BackType API}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/test_backtyper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<httparty>, [">= 0.6.0"])
51
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
54
+ s.add_development_dependency(%q<rcov>, [">= 0"])
55
+ s.add_runtime_dependency(%q<httparty>, [">= 0.6.0"])
56
+ else
57
+ s.add_dependency(%q<httparty>, [">= 0.6.0"])
58
+ s.add_dependency(%q<shoulda>, [">= 0"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
61
+ s.add_dependency(%q<rcov>, [">= 0"])
62
+ s.add_dependency(%q<httparty>, [">= 0.6.0"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<httparty>, [">= 0.6.0"])
66
+ s.add_dependency(%q<shoulda>, [">= 0"])
67
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
68
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
69
+ s.add_dependency(%q<rcov>, [">= 0"])
70
+ s.add_dependency(%q<httparty>, [">= 0.6.0"])
71
+ end
72
+ end
73
+
@@ -0,0 +1,33 @@
1
+ module BackTyper
2
+
3
+ class Client
4
+
5
+ include HTTParty
6
+ base_uri 'api.backtype.com'
7
+ format :json
8
+
9
+ def self.authenticate(key)
10
+ default_params :key => key
11
+ end
12
+
13
+ protected
14
+
15
+ def self.handle_response(response)
16
+ case response.code.to_i
17
+ when 403 then raise BadApiKeyError
18
+ when 200 then return response
19
+ when 400 then handle_bad_request(response.body)
20
+ else raise "Don't know how to handle code #{response.code.inspect}"
21
+ end
22
+ end
23
+
24
+ def self.handle_bad_request(body)
25
+ case body
26
+ when "No Such Object Exists" then raise NotFoundError
27
+ else raise "Don't know how to handle #{body.inspect}"
28
+ end
29
+ end
30
+
31
+ end # class Client
32
+
33
+ end # module BackTyper
@@ -0,0 +1,38 @@
1
+ module BackTyper
2
+
3
+ class Comments < Client
4
+ #
5
+ # Retrieve excerpts of comments published on a particular page.
6
+ #
7
+ # url = The post url to return comments for
8
+ #
9
+ def self.by_url(url, options={})
10
+ response = get('/post/comments.json', :query => {:url => url}.merge(options))
11
+ handle_response(response)
12
+ end
13
+
14
+ #
15
+ # Retrieve all conversations related to a given URL.
16
+ #
17
+ # url = The URL you want related conversations for
18
+ # sources = Comma delimited list of source titles (native, blog, digg, reddit, yc, friendfeed, twitter) or blog ID.
19
+ # sort = If set to 1, results will be ordered by the date they were found by BackType.
20
+ #
21
+ def self.connect(url, options={})
22
+ response = get('/connect.json', :query => {:url => url}.merge(options))
23
+ handle_response(response)
24
+ end
25
+
26
+ #
27
+ # Retrieve statistics on the conversations related to a given URL.
28
+ #
29
+ # url = The URL you want related conversations for
30
+ #
31
+ def self.connect_stats(url, options={})
32
+ response = get('/comments/connect/stats.json', :query => {:url => url}.merge(options))
33
+ handle_response(response)
34
+ end
35
+
36
+ end # class Comments
37
+
38
+ end # module BackTyper
@@ -0,0 +1,38 @@
1
+ module BackTyper
2
+
3
+ class Tweets < Client
4
+ #
5
+ # Retrieve the number of tweets that link to a particular URL.
6
+ #
7
+ # q = The url to return number of tweets for
8
+ #
9
+ def self.count(q, options={})
10
+ response = get('/tweetcount.json', :query => {:q => q}.merge(options))
11
+ handle_response(response)
12
+ end
13
+
14
+ #
15
+ # Retrieve tweets that link to a given URL, whether the links are shortened or unshortened.
16
+ #
17
+ # q = The url to return number of tweets for
18
+ #
19
+ def self.by_url(q, options={})
20
+ response = get('/tweets/search/links.json', :query => {:q => q}.merge(options))
21
+ handle_response(response)
22
+ end
23
+
24
+ #
25
+ # Retrieve filtered tweets that link to a given URL with both shortened and unshortened links.
26
+ # This returns a subset of Tweets by URL, but it filters tweets linking to a URL for quality.
27
+ # This skips all the tweets that only contain the page title, etc.
28
+ #
29
+ # q = The url to return number of tweets for
30
+ #
31
+ def self.good(q, options={})
32
+ response = get('/goodtweets.json', :query => {:q => q}.merge(options))
33
+ handle_response(response)
34
+ end
35
+
36
+ end # class Tweets
37
+
38
+ end # module BackTyper
data/lib/backtyper.rb ADDED
@@ -0,0 +1,21 @@
1
+ module BackTyper
2
+
3
+ def BackTyper.authenticate(key)
4
+ Client.authenticate(key)
5
+ end
6
+
7
+ class BadApiKeyError < StandardError
8
+ end
9
+
10
+ class NotFoundError < StandardError
11
+ end
12
+
13
+ end # module BackTyper
14
+
15
+ $:.unshift File.dirname(__FILE__)
16
+
17
+ require "httparty"
18
+
19
+ require 'backtyper/client'
20
+ require 'backtyper/tweets'
21
+ require 'backtyper/comments'
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'backtyper'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestBacktyper < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backtyper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Justin Britten
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-16 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 7
28
+ segments:
29
+ - 0
30
+ - 6
31
+ - 0
32
+ version: 0.6.0
33
+ type: :runtime
34
+ name: httparty
35
+ prerelease: false
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ name: shoulda
49
+ prerelease: false
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 23
58
+ segments:
59
+ - 1
60
+ - 0
61
+ - 0
62
+ version: 1.0.0
63
+ type: :development
64
+ name: bundler
65
+ prerelease: false
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ hash: 7
74
+ segments:
75
+ - 1
76
+ - 5
77
+ - 2
78
+ version: 1.5.2
79
+ type: :development
80
+ name: jeweler
81
+ prerelease: false
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ type: :development
94
+ name: rcov
95
+ prerelease: false
96
+ version_requirements: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 7
104
+ segments:
105
+ - 0
106
+ - 6
107
+ - 0
108
+ version: 0.6.0
109
+ type: :runtime
110
+ name: httparty
111
+ prerelease: false
112
+ version_requirements: *id006
113
+ description: A Ruby wrapper for the BackType API
114
+ email: justinbritten@gmail.com
115
+ executables: []
116
+
117
+ extensions: []
118
+
119
+ extra_rdoc_files:
120
+ - LICENSE.txt
121
+ - README.md
122
+ files:
123
+ - .document
124
+ - Gemfile
125
+ - Gemfile.lock
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - VERSION
130
+ - backtyper.gemspec
131
+ - lib/backtyper.rb
132
+ - lib/backtyper/client.rb
133
+ - lib/backtyper/comments.rb
134
+ - lib/backtyper/tweets.rb
135
+ - test/helper.rb
136
+ - test/test_backtyper.rb
137
+ has_rdoc: true
138
+ homepage: http://github.com/jbritten/backtyper
139
+ licenses:
140
+ - MIT
141
+ post_install_message:
142
+ rdoc_options: []
143
+
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ hash: 3
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ hash: 3
161
+ segments:
162
+ - 0
163
+ version: "0"
164
+ requirements: []
165
+
166
+ rubyforge_project:
167
+ rubygems_version: 1.3.7
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: A Ruby wrapper for the BackType API
171
+ test_files:
172
+ - test/helper.rb
173
+ - test/test_backtyper.rb