pupil 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -0
- data/README.md +6 -6
- data/VERSION +1 -1
- data/lib/pupil.rb +2 -1
- data/lib/pupil/search.rb +14 -0
- data/lib/pupil/statuses.rb +18 -6
- data/lib/pupil/stream/base.rb +31 -29
- data/pupil.gemspec +3 -2
- data/spec/pupil_spec.rb +26 -11
- metadata +17 -16
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
0.1.4
|
2
|
+
----------------
|
3
|
+
|
4
|
+
* Rename Search stream method, :filter to :search
|
5
|
+
* Search REST API are supported
|
6
|
+
* Pupil::Stream::Shash is outdated. Instead, use Pupil::Stream::Hash
|
7
|
+
* New class, Pupil::Stream::Array
|
8
|
+
* Pupil#public_timeline are supported
|
9
|
+
|
1
10
|
0.1.3
|
2
11
|
----------------
|
3
12
|
|
data/README.md
CHANGED
@@ -45,10 +45,10 @@ Examples
|
|
45
45
|
pupil.home_timeline :count => 50, :exclude => :replies
|
46
46
|
|
47
47
|
# Follow User
|
48
|
-
pupil.follow :screen_name
|
48
|
+
pupil.follow :screen_name => :twitterapi
|
49
49
|
|
50
50
|
# Update URL on profile
|
51
|
-
pupil.update_profile :url
|
51
|
+
pupil.update_profile :url => "http://oameya.com"
|
52
52
|
|
53
53
|
Using Streaming API
|
54
54
|
|
@@ -71,15 +71,15 @@ Using Streaming API
|
|
71
71
|
|
72
72
|
# Userstream
|
73
73
|
stream.start :userstream do |status|
|
74
|
-
puts status.event #=> Show type of
|
74
|
+
puts status.event #=> Show type of event
|
75
75
|
if status.event == :retweeted
|
76
|
-
puts "#{status.user.screen_name}
|
76
|
+
puts "#{status.user.screen_name}: #{status.text}"
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
# Search stream
|
81
|
-
stream.start :
|
82
|
-
puts "#{status
|
81
|
+
stream.start :search, :track => "#MerryChristmas" do |status|
|
82
|
+
puts "#{status.user.screen_name}: #{status.text}"
|
83
83
|
end
|
84
84
|
|
85
85
|
Making `pupil_key`
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/pupil.rb
CHANGED
data/lib/pupil/search.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
class Pupil
|
2
|
+
# @param [String] keyword Search word
|
3
|
+
# @param [Hash] option
|
4
|
+
# @return [Array] Tweets
|
5
|
+
def search(keyword, option={})
|
6
|
+
response = self.get("http://search.twitter.com/search.json", {:q => keyword}.update(option))
|
7
|
+
statuses = Array.new
|
8
|
+
response["results"].each do |element|
|
9
|
+
status = Status.new element
|
10
|
+
statuses << status
|
11
|
+
end
|
12
|
+
return statuses
|
13
|
+
end
|
14
|
+
end
|
data/lib/pupil/statuses.rb
CHANGED
@@ -9,7 +9,7 @@ class Pupil
|
|
9
9
|
# @option param [Symbol] :include #=> [:rts]
|
10
10
|
# @option param [Symbol] :exclude #=> [:replies]
|
11
11
|
# @option param [Symbol] :contributor_details
|
12
|
-
def home_timeline
|
12
|
+
def home_timeline(param={})
|
13
13
|
response = self.get("/statuses/home_timeline.json", param)
|
14
14
|
statuses = Array.new
|
15
15
|
response.each do |element|
|
@@ -19,9 +19,9 @@ class Pupil
|
|
19
19
|
return statuses
|
20
20
|
end
|
21
21
|
|
22
|
-
# @return [
|
22
|
+
# @return [Array] Mention
|
23
23
|
# @param [Hash] param
|
24
|
-
def mentions
|
24
|
+
def mentions(param={})
|
25
25
|
response = self.get("/statuses/mentions.json", param)
|
26
26
|
statuses = Array.new
|
27
27
|
response.each do |element|
|
@@ -32,7 +32,7 @@ class Pupil
|
|
32
32
|
end
|
33
33
|
|
34
34
|
# Returning user timeline
|
35
|
-
# @return [
|
35
|
+
# @return [Array] timeline
|
36
36
|
# @param [Hash] param
|
37
37
|
# @option param [Fixnum] :user_id The ID of user
|
38
38
|
# @option param [String] :screen_name The Screen name of user
|
@@ -49,7 +49,7 @@ class Pupil
|
|
49
49
|
# twitter.user_timeline(:screen_name => 'o_ame', :exclude => :replies).each do |status|
|
50
50
|
# puts "#{status.user.screen_name}: #{status.text}"
|
51
51
|
# end
|
52
|
-
def user_timeline
|
52
|
+
def user_timeline(param={})
|
53
53
|
response = self.get("/statuses/user_timeline.json", param)
|
54
54
|
statuses = Array.new
|
55
55
|
response.each do |element|
|
@@ -58,8 +58,20 @@ class Pupil
|
|
58
58
|
end
|
59
59
|
return statuses
|
60
60
|
end
|
61
|
+
# Returning public timeline
|
62
|
+
# @return [Array] Timeline
|
63
|
+
# @param [Hash] param
|
64
|
+
def public_timeline(param={})
|
65
|
+
response = self.get("/statuses/public_timeline.json", param)
|
66
|
+
statuses = Array.new
|
67
|
+
response.each do |element|
|
68
|
+
status = Status.new element
|
69
|
+
statuses << status
|
70
|
+
end
|
71
|
+
return statuses
|
72
|
+
end
|
61
73
|
|
62
|
-
def show_status
|
74
|
+
def show_status(status_id)
|
63
75
|
response = @access_token.get("/statuses/show/#{status_id}.json").body
|
64
76
|
return response
|
65
77
|
status = Status.new response
|
data/lib/pupil/stream/base.rb
CHANGED
@@ -4,7 +4,7 @@ class Pupil
|
|
4
4
|
class StreamError < StandardError ; end
|
5
5
|
STREAM_APIS = {
|
6
6
|
:userstream => "https://userstream.twitter.com/2/user.json",
|
7
|
-
:
|
7
|
+
:search => "https://stream.twitter.com/1/statuses/filter.json%s"
|
8
8
|
}
|
9
9
|
|
10
10
|
def initialize key
|
@@ -21,14 +21,14 @@ class Pupil
|
|
21
21
|
key[:access_token_secret]
|
22
22
|
)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# @return [Pupil::Stream::Shash, Pupil::Stream::Status] event variable supported :status, :retweeted, :favorite, :friends and :delete
|
26
26
|
def start(type, param=nil, &block)
|
27
27
|
raise ArgumentError unless block_given?
|
28
|
-
|
28
|
+
|
29
29
|
run_get_stream type, param, &block
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def run_get_stream(type, param=nil, &block)
|
33
33
|
uri = URI.parse(STREAM_APIS[type] % Pupil.param_serializer(param))
|
34
34
|
https = Net::HTTP.new(uri.host, uri.port)
|
@@ -54,7 +54,7 @@ class Pupil
|
|
54
54
|
rescue
|
55
55
|
break
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
event = self.guess_event status
|
59
59
|
block.call event
|
60
60
|
end
|
@@ -66,53 +66,55 @@ class Pupil
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def guess_event status
|
71
71
|
if status["delete"]
|
72
|
-
return
|
72
|
+
return Pupil::Stream::Hash.new(status["delete"]["status"], :delete)
|
73
73
|
elsif status["friends"]
|
74
|
-
return
|
74
|
+
return Pupil::Stream::Array.new(status["friends"], :friends)
|
75
75
|
elsif status["event"] == "favorite"
|
76
|
-
return
|
76
|
+
return Pupil::Stream::Hash.new(status, :favorite)
|
77
77
|
elsif status["retweeted_status"]
|
78
|
-
return Status.new(status, :retweeted)
|
78
|
+
return Pupil::Stream::Status.new(status, :retweeted)
|
79
79
|
elsif status["text"]
|
80
|
-
return Status.new(status)
|
80
|
+
return Pupil::Stream::Status.new(status)
|
81
81
|
else
|
82
|
-
return
|
82
|
+
return Pupil::Stream::Hash.new(status, :unknown)
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
# Stream Status
|
87
87
|
class Status < Pupil::Status
|
88
88
|
attr_reader :event
|
89
89
|
attr_reader :retweeted_status
|
90
|
-
|
91
|
-
def initialize
|
90
|
+
|
91
|
+
def initialize(status, event=nil)
|
92
92
|
super(status)
|
93
93
|
@event = (event)? event : :status
|
94
94
|
@retweeted_status = status["retweeted_status"]
|
95
95
|
end
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
# Stream Hash
|
99
|
-
class
|
99
|
+
class Hash < Hash
|
100
100
|
attr_reader :event
|
101
|
-
|
102
|
-
def initialize event
|
103
|
-
|
101
|
+
|
102
|
+
def initialize(status, event)
|
103
|
+
super()
|
104
|
+
self.update(status)
|
104
105
|
@event = event
|
105
106
|
end
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
107
|
+
end
|
108
|
+
|
109
|
+
# Stream Array
|
110
|
+
class Array < Array
|
111
|
+
attr_reader :event
|
112
|
+
|
113
|
+
def initialize(status, event)
|
114
|
+
super(status)
|
115
|
+
#self.update(status)
|
116
|
+
@event = event
|
113
117
|
end
|
114
|
-
|
115
|
-
alias_method :length, :size
|
116
118
|
end
|
117
119
|
end
|
118
120
|
end
|
data/pupil.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "pupil"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Oame"]
|
12
|
-
s.date = "2011-12-
|
12
|
+
s.date = "2011-12-29"
|
13
13
|
s.description = "The \"Lazy\" Twitter API Library for Ruby 1.9.x. Easy to use."
|
14
14
|
s.email = "oame@oameya.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -65,6 +65,7 @@ Gem::Specification.new do |s|
|
|
65
65
|
"lib/pupil/keygen/base.rb",
|
66
66
|
"lib/pupil/lists.rb",
|
67
67
|
"lib/pupil/schemes.rb",
|
68
|
+
"lib/pupil/search.rb",
|
68
69
|
"lib/pupil/statuses.rb",
|
69
70
|
"lib/pupil/stream.rb",
|
70
71
|
"lib/pupil/stream/base.rb",
|
data/spec/pupil_spec.rb
CHANGED
@@ -6,6 +6,17 @@
|
|
6
6
|
|
7
7
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
8
8
|
|
9
|
+
describe Pupil, "が #verify_credentials を呼ぶ時は" do
|
10
|
+
before do
|
11
|
+
pupil = Pupil.new PUPIL_TESTKEY
|
12
|
+
@vc = pupil.verify_credentials
|
13
|
+
end
|
14
|
+
|
15
|
+
it "Pupil::User型を返すこと" do
|
16
|
+
@vc.class.should == Pupil::User
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
9
20
|
describe Pupil, "が #home_timeline を呼ぶ時は" do
|
10
21
|
before do
|
11
22
|
pupil = Pupil.new PUPIL_TESTKEY
|
@@ -36,17 +47,6 @@ describe Pupil, "が #mentions を呼ぶ時は" do
|
|
36
47
|
end
|
37
48
|
end
|
38
49
|
|
39
|
-
describe Pupil, "が #verify_credentials を呼ぶ時は" do
|
40
|
-
before do
|
41
|
-
pupil = Pupil.new PUPIL_TESTKEY
|
42
|
-
@vc = pupil.verify_credentials
|
43
|
-
end
|
44
|
-
|
45
|
-
it "Pupil::User型を返すこと" do
|
46
|
-
@vc.class.should == Pupil::User
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
50
|
describe Pupil, "が #user_timeline を呼ぶ時は" do
|
51
51
|
before do
|
52
52
|
pupil = Pupil.new PUPIL_TESTKEY
|
@@ -147,4 +147,19 @@ describe Pupil, "が #blocking を呼ぶ時は" do
|
|
147
147
|
it "Array型を返すこと" do
|
148
148
|
@blocking.class.should == Array
|
149
149
|
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe Pupil, "が、 #search を呼ぶ時は" do
|
153
|
+
before do
|
154
|
+
pupil = Pupil.new PUPIL_TESTKEY
|
155
|
+
@search = pupil.search("Twitter", :rpp => 10)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "Array型を返すこと" do
|
159
|
+
@search.class.should == Array
|
160
|
+
end
|
161
|
+
|
162
|
+
it "sizeが10であること" do
|
163
|
+
@search.size.should == 10
|
164
|
+
end
|
150
165
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pupil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-29 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth
|
16
|
-
requirement: &
|
16
|
+
requirement: &70151989267360 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70151989267360
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70151989266380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70151989266380
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70151989265220 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.3.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70151989265220
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: yard
|
49
|
-
requirement: &
|
49
|
+
requirement: &70151989263920 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.6.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70151989263920
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70151989262100 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.0.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70151989262100
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: jeweler
|
71
|
-
requirement: &
|
71
|
+
requirement: &70151989246200 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.6.4
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70151989246200
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rcov
|
82
|
-
requirement: &
|
82
|
+
requirement: &70151989243220 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70151989243220
|
91
91
|
description: The "Lazy" Twitter API Library for Ruby 1.9.x. Easy to use.
|
92
92
|
email: oame@oameya.com
|
93
93
|
executables: []
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- lib/pupil/keygen/base.rb
|
145
145
|
- lib/pupil/lists.rb
|
146
146
|
- lib/pupil/schemes.rb
|
147
|
+
- lib/pupil/search.rb
|
147
148
|
- lib/pupil/statuses.rb
|
148
149
|
- lib/pupil/stream.rb
|
149
150
|
- lib/pupil/stream/base.rb
|