backtype 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Adolfo Builes
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.markdown ADDED
@@ -0,0 +1,8 @@
1
+ backtype
2
+ =======
3
+
4
+ BackType is a marketing intelligence company that develops products and services that help companies understand their social impact.
5
+
6
+ This is a simple Ruby gem wrapper for their API.
7
+
8
+ Note that this wrapper doesn't work for the services in beta or paid.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ # Empty Rakefile...
2
+ require 'rspec/core/rake_task'
3
+
4
+ file_list = FileList['spec/*_spec.rb']
5
+
6
+ RSpec::Core::RakeTask.new('spec') do |t|
7
+ t.pattern = file_list
8
+ t.rspec_opts = ["--colour", "--format progress"]
9
+ end
10
+
11
+ desc 'Default: run specs.'
12
+ task :default => 'spec'
13
+
data/lib/backtype.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'backtype/base'
2
+ require 'backtype/error'
3
+
4
+
@@ -0,0 +1,87 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ module Backtype
5
+ BASE_URL = "http://api.backtype.com/"
6
+ DEFAULT_FORMAT = "json"
7
+
8
+ class Base
9
+ def initialize(params = {})
10
+ @api_key = params[:api_key]
11
+ raise NotAPIKeyGiven unless @api_key
12
+ end
13
+
14
+ def comments_search(params = {})
15
+ check_params params, [:q]
16
+ make_request "comments/search", params
17
+ end
18
+
19
+ def comments_by_author_url(params = {})
20
+ check_params params, [:url]
21
+ make_request "url/#{params[:url]}/comments", params
22
+ end
23
+
24
+ def connect(params = {})
25
+ check_params params, [:url]
26
+ make_request "connect", params
27
+ end
28
+
29
+ def connect_stats(params = {})
30
+ check_params params, [:url]
31
+ make_request "comments/connect/stats", params
32
+ end
33
+
34
+ def comments_by_page(params = {})
35
+ check_params params, [:url]
36
+ make_request "post/comments", params
37
+ end
38
+
39
+ def comments_stats_by_page(params = {})
40
+ check_params params, [:url]
41
+ make_request "post/stats", params
42
+ end
43
+
44
+ def stats_by_url(params = {})
45
+ check_params params, [:q]
46
+ make_request "tweetcount", params
47
+ end
48
+
49
+ def user_influencer_score(params = {})
50
+ check_params params, [:user_name]
51
+ make_request "user/influencer_score", params
52
+ end
53
+
54
+ def user_top_sites(params = {})
55
+ check_params params, [:user_name]
56
+ make_request "user/top_sites", params
57
+ end
58
+
59
+ def user_influenced_by(params = {})
60
+ check_params params, [:user_name]
61
+ make_request "user/influenced_by", params
62
+ end
63
+
64
+ def user_influencer_of(params = {})
65
+ check_params params, [:user_name]
66
+ make_request "user/influencer_of", params
67
+ end
68
+
69
+ private
70
+ def check_params (params = {}, required_keys = [])
71
+ required_keys.each do |key|
72
+ message = "You must specified :#{key} in the parameters"
73
+ raise MissingParameters.new(message) unless params.has_key?(key)
74
+ end
75
+ end
76
+
77
+ def make_request(service, params)
78
+ raise NotParametersGiven if params.empty?
79
+ q = params.merge({:key => @api_key })
80
+ format = params.delete(:format) || DEFAULT_FORMAT
81
+ uri = "#{BASE_URL}#{service}.#{format}"
82
+ request = HTTParty::Request.new(Net::HTTP::Get, uri, :query => q)
83
+ response = request.perform
84
+ response.parsed_response
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,16 @@
1
+ module Backtype
2
+ ERRORS = {
3
+ :api_key => {:klass_name => "NotAPIKeyGiven",
4
+ :message => "You must pass an api_key as parameter" },
5
+ :missing_param => {:klass_name => "MissingParameters"}
6
+ }
7
+
8
+ ERRORS.each_value do |error|
9
+ message = error.has_key?(:message) ? "def to_s;\"#{error[:message]}\"end" : ""
10
+ class_eval %{
11
+ class #{error[:klass_name]} < StandardError
12
+ #{message}
13
+ end
14
+ }
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backtype
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Adolfo Builes
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-28 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: vcr
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 1
44
+ segments:
45
+ - 1
46
+ - 5
47
+ - 1
48
+ version: 1.5.1
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: httparty
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 5
60
+ segments:
61
+ - 0
62
+ - 7
63
+ - 3
64
+ version: 0.7.3
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ description: |
68
+ require 'backtype'
69
+
70
+ backtype = Backtype::Base.new(:api_key => 'your_api_key')
71
+ backtype.comments_by_page :url => 'http://www.reddit.com/r/science/comments/8zf9d/holy_crap_i_never_realized_i_was_peeling_a_banana/'
72
+
73
+ email: builes.adolfo@googlemail.com
74
+ executables: []
75
+
76
+ extensions: []
77
+
78
+ extra_rdoc_files: []
79
+
80
+ files:
81
+ - README.markdown
82
+ - Rakefile
83
+ - LICENSE
84
+ - lib/backtype/base.rb
85
+ - lib/backtype/error.rb
86
+ - lib/backtype.rb
87
+ has_rdoc: true
88
+ homepage: http://github.com/abuiles/backtype
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options: []
93
+
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ requirements: []
115
+
116
+ rubyforge_project:
117
+ rubygems_version: 1.4.2
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Ruby gem wrapper for backtype's API.
121
+ test_files: []
122
+