rsift 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rvmrc +1 -0
- data/Gemfile +6 -0
- data/README.md +5 -0
- data/Rakefile +7 -0
- data/config/keys_example.yml +6 -0
- data/lib/rsift/comment.rb +21 -0
- data/lib/rsift/connection.rb +24 -0
- data/lib/rsift/data.rb +20 -0
- data/lib/rsift/model.rb +9 -0
- data/lib/rsift/stream.rb +21 -0
- data/lib/rsift/version.rb +3 -0
- data/lib/rsift.rb +17 -0
- data/rsift.gemspec +33 -0
- data/test/unit/comment_test.rb +43 -0
- data/test/unit/data_test.rb +31 -0
- data/test/unit/stream_test.rb +74 -0
- metadata +218 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm ruby-1.9.2-p0
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "model"
|
2
|
+
|
3
|
+
module Rsift
|
4
|
+
class Comment < Rsift::Model
|
5
|
+
|
6
|
+
def initialize(url, key, username)
|
7
|
+
@format = "json"
|
8
|
+
@section = "comment"
|
9
|
+
super(url, key, username)
|
10
|
+
end
|
11
|
+
|
12
|
+
def do(verb, opts = {})
|
13
|
+
get("#{@section}/#{verb}.#{@format}?&"+
|
14
|
+
Rsift::escape_options(opts).join("&"))
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(path)
|
18
|
+
@conn.get(path)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "jkl"
|
2
|
+
require "net/http"
|
3
|
+
require "uri"
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module Rsift
|
7
|
+
class Connection
|
8
|
+
|
9
|
+
def initialize(url, key, username)
|
10
|
+
@api_url = url
|
11
|
+
@api_key = key
|
12
|
+
@username = username
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(path)
|
16
|
+
request = "#{@api_url}#{path}#{auth_string}"
|
17
|
+
JSON.parse(Jkl::get_from(request))
|
18
|
+
end
|
19
|
+
|
20
|
+
def auth_string
|
21
|
+
"&username=#{@username}&api_key=#{@api_key}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/rsift/data.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "model"
|
2
|
+
|
3
|
+
module Rsift
|
4
|
+
class Data < Rsift::Model
|
5
|
+
|
6
|
+
def initialize(url, key, username)
|
7
|
+
@format = "json"
|
8
|
+
super(url, key, username)
|
9
|
+
end
|
10
|
+
|
11
|
+
def do(opts = {})
|
12
|
+
get("stream.#{@format}?&"+
|
13
|
+
Rsift::escape_options(opts).join("&"))
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(path)
|
17
|
+
@conn.get(path)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/rsift/model.rb
ADDED
data/lib/rsift/stream.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "model"
|
2
|
+
|
3
|
+
module Rsift
|
4
|
+
class Stream < Rsift::Model
|
5
|
+
|
6
|
+
def initialize(url, key, username)
|
7
|
+
@format = "json"
|
8
|
+
@section = "stream"
|
9
|
+
super(url, key, username)
|
10
|
+
end
|
11
|
+
|
12
|
+
def do(verb, opts = {})
|
13
|
+
get("#{@section}/#{verb}.#{@format}?&"+
|
14
|
+
Rsift::escape_options(opts).join("&"))
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(path)
|
18
|
+
@conn.get(path)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/rsift.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require "rsift/model"
|
5
|
+
require "rsift/connection"
|
6
|
+
require "rsift/stream"
|
7
|
+
require "rsift/comment"
|
8
|
+
require "rsift/data"
|
9
|
+
|
10
|
+
module Rsift
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def escape_options(options)
|
14
|
+
options.map { |k, v| "#{k}=#{CGI::escape(v.to_s)}" }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/rsift.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rsift/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rsift"
|
7
|
+
s.version = Rsift::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Steven Shingler"]
|
10
|
+
s.email = ["shingler@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/sshingler/rsift"
|
12
|
+
s.summary = %q{Ruby wrapper for the Datasift API}
|
13
|
+
s.description = <<-EOF
|
14
|
+
A Ruby client/wrapper gem for the Datasift API.
|
15
|
+
Right now, it just handles data, streams and comments.
|
16
|
+
EOF
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency("rake", "0.8.7")
|
23
|
+
s.add_dependency("json", "1.4.6")
|
24
|
+
s.add_dependency("rest-client", "1.4.2")
|
25
|
+
s.add_dependency("jakal", "0.1.95")
|
26
|
+
s.add_dependency("em-http-request", "0.2.15")
|
27
|
+
s.add_dependency("yajl-ruby", "0.7.8")
|
28
|
+
|
29
|
+
# Test libraries
|
30
|
+
s.add_dependency("test-unit", "1.2.3")
|
31
|
+
s.add_dependency("shoulda", "2.11.3")
|
32
|
+
s.add_dependency("webmock", "1.6.1")
|
33
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "webmock/test_unit"
|
2
|
+
require "test/unit"
|
3
|
+
require "shoulda"
|
4
|
+
require_relative "../../lib/rsift"
|
5
|
+
|
6
|
+
class CommentTest < Test::Unit::TestCase
|
7
|
+
include WebMock::API
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@api_url = YAML::load_file("config/keys.yml")["url"]
|
11
|
+
@api_key = YAML::load_file("config/keys.yml")["api-key"]
|
12
|
+
@username = YAML::load_file("config/keys.yml")["username"]
|
13
|
+
@comment = Rsift::Comment.new(@api_url,@api_key,@username)
|
14
|
+
end
|
15
|
+
|
16
|
+
context "with comments" do
|
17
|
+
setup do
|
18
|
+
body = '{"success":true}'
|
19
|
+
stub_request(:get, /api.datasift.net\/comment/).
|
20
|
+
with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
21
|
+
to_return(:status => 200, :body => body, :headers => {})
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
should "get a comment" do
|
26
|
+
opts = {:stream_id => "1"}
|
27
|
+
response = @comment.do("get",opts)
|
28
|
+
assert_equal true, response["success"]
|
29
|
+
end
|
30
|
+
|
31
|
+
should "create a comment" do
|
32
|
+
opts = {:stream_id => "1", :comment => "test comment"}
|
33
|
+
response = @comment.do("create",opts)
|
34
|
+
assert_equal true, response["success"]
|
35
|
+
end
|
36
|
+
|
37
|
+
should "flag a comment" do
|
38
|
+
opts = {:comment_id => "1"}
|
39
|
+
response = @comment.do("flag",opts)
|
40
|
+
assert_equal true, response["success"]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "webmock/test_unit"
|
2
|
+
require "test/unit"
|
3
|
+
require "shoulda"
|
4
|
+
require_relative "../../lib/rsift"
|
5
|
+
|
6
|
+
class DataTest < Test::Unit::TestCase
|
7
|
+
include WebMock::API
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@api_url = YAML::load_file("config/keys.yml")["url"]
|
11
|
+
@api_key = YAML::load_file("config/keys.yml")["api-key"]
|
12
|
+
@username = YAML::load_file("config/keys.yml")["username"]
|
13
|
+
@data = Rsift::Data.new(@api_url,@api_key,@username)
|
14
|
+
end
|
15
|
+
|
16
|
+
context "with data" do
|
17
|
+
setup do
|
18
|
+
body = '{"success":true}'
|
19
|
+
stub_request(:get, /api.datasift.net\/stream.json/).
|
20
|
+
with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
21
|
+
to_return(:status => 200, :body => body, :headers => {})
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
should "get a comment" do
|
26
|
+
opts = {:stream_identifier => "1", :count => 10}
|
27
|
+
response = @data.do(opts)
|
28
|
+
assert_equal true, response["success"]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "webmock/test_unit"
|
2
|
+
require "test/unit"
|
3
|
+
require "shoulda"
|
4
|
+
require_relative "../../lib/rsift"
|
5
|
+
|
6
|
+
class StreamTest < Test::Unit::TestCase
|
7
|
+
include WebMock::API
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@api_url = YAML::load_file("config/keys.yml")["url"]
|
11
|
+
@api_key = YAML::load_file("config/keys.yml")["api-key"]
|
12
|
+
@username = YAML::load_file("config/keys.yml")["username"]
|
13
|
+
@stream = Rsift::Stream.new(@api_url,@api_key,@username)
|
14
|
+
end
|
15
|
+
|
16
|
+
context "with streams" do
|
17
|
+
setup do
|
18
|
+
body = '{"success":true}'
|
19
|
+
stub_request(:get, /api.datasift.net\/stream/).
|
20
|
+
with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
21
|
+
to_return(:status => 200, :body => body, :headers => {})
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
should "list my streams" do
|
26
|
+
response = @stream.do("my")
|
27
|
+
assert_equal true, response["success"]
|
28
|
+
end
|
29
|
+
|
30
|
+
should "get a stream" do
|
31
|
+
opts = {:stream_id => "1"}
|
32
|
+
response = @stream.do("get", opts)
|
33
|
+
assert_equal true, response["success"]
|
34
|
+
end
|
35
|
+
|
36
|
+
should "create a stream" do
|
37
|
+
opts = {:name => "test stream",
|
38
|
+
:description => "it's a test description",
|
39
|
+
:definition => 'interaction.content contains " London"',
|
40
|
+
:tags => "london, uk"}
|
41
|
+
response = @stream.do("create", opts)
|
42
|
+
assert_equal true, response["success"]
|
43
|
+
end
|
44
|
+
|
45
|
+
should "update a stream " do
|
46
|
+
opts = {:stream_id => "1",
|
47
|
+
:name => "test stream",
|
48
|
+
:description => "it's a test description",
|
49
|
+
:definition => 'interaction.content contains " London"',
|
50
|
+
:add_tags => "tag1",
|
51
|
+
:remove_tage => "tag2"}
|
52
|
+
response = @stream.do("update", opts)
|
53
|
+
assert_equal true, response["success"]
|
54
|
+
end
|
55
|
+
|
56
|
+
should "duplicate a stream" do
|
57
|
+
opts = {:stream_id => "1"}
|
58
|
+
response = @stream.do("duplicate", opts)
|
59
|
+
assert_equal true, response["success"]
|
60
|
+
end
|
61
|
+
|
62
|
+
should "rate a stream" do
|
63
|
+
opts = {:stream_id => "1", :rating => 5}
|
64
|
+
response = @stream.do("rate", opts)
|
65
|
+
assert_equal true, response["success"]
|
66
|
+
end
|
67
|
+
|
68
|
+
should "delete a stream" do
|
69
|
+
opts = {:stream_id => "1"}
|
70
|
+
response = @stream.do("delete", opts)
|
71
|
+
assert_equal true, response["success"]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rsift
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Steven Shingler
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-12-23 00:00:00 +00:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - "="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 8
|
31
|
+
- 7
|
32
|
+
version: 0.8.7
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: json
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - "="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 4
|
46
|
+
- 6
|
47
|
+
version: 1.4.6
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rest-client
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - "="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 1
|
60
|
+
- 4
|
61
|
+
- 2
|
62
|
+
version: 1.4.2
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: jakal
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - "="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
- 1
|
76
|
+
- 95
|
77
|
+
version: 0.1.95
|
78
|
+
type: :runtime
|
79
|
+
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: em-http-request
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - "="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
- 2
|
91
|
+
- 15
|
92
|
+
version: 0.2.15
|
93
|
+
type: :runtime
|
94
|
+
version_requirements: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: yajl-ruby
|
97
|
+
prerelease: false
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - "="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
- 7
|
106
|
+
- 8
|
107
|
+
version: 0.7.8
|
108
|
+
type: :runtime
|
109
|
+
version_requirements: *id006
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: test-unit
|
112
|
+
prerelease: false
|
113
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - "="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
segments:
|
119
|
+
- 1
|
120
|
+
- 2
|
121
|
+
- 3
|
122
|
+
version: 1.2.3
|
123
|
+
type: :runtime
|
124
|
+
version_requirements: *id007
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: shoulda
|
127
|
+
prerelease: false
|
128
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - "="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
segments:
|
134
|
+
- 2
|
135
|
+
- 11
|
136
|
+
- 3
|
137
|
+
version: 2.11.3
|
138
|
+
type: :runtime
|
139
|
+
version_requirements: *id008
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: webmock
|
142
|
+
prerelease: false
|
143
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - "="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
segments:
|
149
|
+
- 1
|
150
|
+
- 6
|
151
|
+
- 1
|
152
|
+
version: 1.6.1
|
153
|
+
type: :runtime
|
154
|
+
version_requirements: *id009
|
155
|
+
description: |
|
156
|
+
A Ruby client/wrapper gem for the Datasift API.
|
157
|
+
Right now, it just handles data, streams and comments.
|
158
|
+
|
159
|
+
email:
|
160
|
+
- shingler@gmail.com
|
161
|
+
executables: []
|
162
|
+
|
163
|
+
extensions: []
|
164
|
+
|
165
|
+
extra_rdoc_files: []
|
166
|
+
|
167
|
+
files:
|
168
|
+
- .gitignore
|
169
|
+
- .rvmrc
|
170
|
+
- Gemfile
|
171
|
+
- README.md
|
172
|
+
- Rakefile
|
173
|
+
- config/keys_example.yml
|
174
|
+
- lib/rsift.rb
|
175
|
+
- lib/rsift/comment.rb
|
176
|
+
- lib/rsift/connection.rb
|
177
|
+
- lib/rsift/data.rb
|
178
|
+
- lib/rsift/model.rb
|
179
|
+
- lib/rsift/stream.rb
|
180
|
+
- lib/rsift/version.rb
|
181
|
+
- rsift.gemspec
|
182
|
+
- test/unit/comment_test.rb
|
183
|
+
- test/unit/data_test.rb
|
184
|
+
- test/unit/stream_test.rb
|
185
|
+
has_rdoc: true
|
186
|
+
homepage: http://github.com/sshingler/rsift
|
187
|
+
licenses: []
|
188
|
+
|
189
|
+
post_install_message:
|
190
|
+
rdoc_options: []
|
191
|
+
|
192
|
+
require_paths:
|
193
|
+
- lib
|
194
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
195
|
+
none: false
|
196
|
+
requirements:
|
197
|
+
- - ">="
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
segments:
|
200
|
+
- 0
|
201
|
+
version: "0"
|
202
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
|
+
none: false
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
segments:
|
208
|
+
- 0
|
209
|
+
version: "0"
|
210
|
+
requirements: []
|
211
|
+
|
212
|
+
rubyforge_project:
|
213
|
+
rubygems_version: 1.3.7
|
214
|
+
signing_key:
|
215
|
+
specification_version: 3
|
216
|
+
summary: Ruby wrapper for the Datasift API
|
217
|
+
test_files: []
|
218
|
+
|