jugyo-rubytter 0.2.0
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/History.txt +0 -0
- data/README.rdoc +75 -0
- data/lib/rubytter.rb +134 -0
- data/spec/rubytter_spec.rb +108 -0
- data/spec/spec_helper.rb +4 -0
- metadata +69 -0
data/History.txt
ADDED
|
File without changes
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
= rubytter
|
|
2
|
+
|
|
3
|
+
http://github.com/jugyo/rubytter
|
|
4
|
+
|
|
5
|
+
== DESCRIPTION:
|
|
6
|
+
|
|
7
|
+
Rubytter is simple twitter library.
|
|
8
|
+
|
|
9
|
+
== FEATURES/PROBLEMS:
|
|
10
|
+
|
|
11
|
+
implemented methods:
|
|
12
|
+
|
|
13
|
+
- /direct_messages
|
|
14
|
+
- /direct_messages/destroy/id
|
|
15
|
+
- /direct_messages/new
|
|
16
|
+
- /direct_messages/sent
|
|
17
|
+
- /followers/ids/id
|
|
18
|
+
- /friends/ids/id
|
|
19
|
+
- /friendships/create/id
|
|
20
|
+
- /friendships/destroy/id
|
|
21
|
+
- /friendships/exists
|
|
22
|
+
- /statuses/destroy/id
|
|
23
|
+
- /statuses/followers/id
|
|
24
|
+
- /statuses/friends/id
|
|
25
|
+
- /statuses/friends_timeline
|
|
26
|
+
- /statuses/public_timeline
|
|
27
|
+
- /statuses/replies
|
|
28
|
+
- /statuses/show/id
|
|
29
|
+
- /statuses/update
|
|
30
|
+
- /statuses/user_timeline/id
|
|
31
|
+
- /users/show/id
|
|
32
|
+
|
|
33
|
+
== SYNOPSIS:
|
|
34
|
+
|
|
35
|
+
TODO
|
|
36
|
+
|
|
37
|
+
== REQUIREMENTS:
|
|
38
|
+
|
|
39
|
+
* json
|
|
40
|
+
|
|
41
|
+
== INSTALL:
|
|
42
|
+
|
|
43
|
+
TODO
|
|
44
|
+
|
|
45
|
+
== TODO:
|
|
46
|
+
|
|
47
|
+
- search
|
|
48
|
+
- direct_message
|
|
49
|
+
- follow/leave
|
|
50
|
+
- favorite
|
|
51
|
+
|
|
52
|
+
== LICENSE:
|
|
53
|
+
|
|
54
|
+
(The MIT License)
|
|
55
|
+
|
|
56
|
+
Copyright (c) 2008-2009 jugyo
|
|
57
|
+
|
|
58
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
59
|
+
a copy of this software and associated documentation files (the
|
|
60
|
+
'Software'), to deal in the Software without restriction, including
|
|
61
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
62
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
63
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
64
|
+
the following conditions:
|
|
65
|
+
|
|
66
|
+
The above copyright notice and this permission notice shall be
|
|
67
|
+
included in all copies or substantial portions of the Software.
|
|
68
|
+
|
|
69
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
70
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
71
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
72
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
73
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
74
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
75
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/rubytter.rb
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'net/https'
|
|
4
|
+
require 'cgi'
|
|
5
|
+
|
|
6
|
+
class Rubytter
|
|
7
|
+
APP_NAME = self.to_s
|
|
8
|
+
|
|
9
|
+
def initialize(login, password, options = {})
|
|
10
|
+
@login = login
|
|
11
|
+
@password = password
|
|
12
|
+
@host = options[:host] || 'twitter.com'
|
|
13
|
+
@connection = Connection.new(options)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.api_settings
|
|
17
|
+
# method name path for API http method
|
|
18
|
+
"
|
|
19
|
+
status_update /statuses/update post
|
|
20
|
+
destroy /statuses/destroy/%s delete
|
|
21
|
+
public_timeline /statuses/public_timeline
|
|
22
|
+
friends_timeline /statuses/friends_timeline
|
|
23
|
+
replies /statuses/replies
|
|
24
|
+
user_timeline /statuses/user_timeline/%s
|
|
25
|
+
show /statuses/show/%s
|
|
26
|
+
friends /statuses/friends/%s
|
|
27
|
+
followers /statuses/followers/%s
|
|
28
|
+
user /users/show/%s
|
|
29
|
+
direct_messages /direct_messages
|
|
30
|
+
sent_direct_messages /direct_messages/sent
|
|
31
|
+
send_direct_message /direct_messages/new post
|
|
32
|
+
destroy_direct_message /direct_messages/destroy/%s delete
|
|
33
|
+
create_friendship /friendships/create/%s post
|
|
34
|
+
destroy_friendship /friendships/destroy/%s delete
|
|
35
|
+
friendship_exists /friendships/exists
|
|
36
|
+
followers_ids /followers/ids/%s
|
|
37
|
+
friends_ids /friends/ids/%s
|
|
38
|
+
".strip.split("\n").map{|line| line.strip.split(/\s+/)}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
api_settings.each do |array|
|
|
42
|
+
method, path, http_method = *array
|
|
43
|
+
http_method ||= 'get'
|
|
44
|
+
if /%s$/ =~ path
|
|
45
|
+
eval <<-EOS
|
|
46
|
+
def #{method}(id, params = {})
|
|
47
|
+
#{http_method}('#{path}' % id, params)
|
|
48
|
+
end
|
|
49
|
+
EOS
|
|
50
|
+
else
|
|
51
|
+
eval <<-EOS
|
|
52
|
+
def #{method}(params = {})
|
|
53
|
+
#{http_method}('#{path}', params)
|
|
54
|
+
end
|
|
55
|
+
EOS
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def update(status, params = {})
|
|
60
|
+
status_update(params.merge({:status => status}))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def direct_message(user, text, params = {})
|
|
64
|
+
send_direct_message(params.merge({:user => user, :text => text}))
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# TODO: define some alias for commonly used methods
|
|
68
|
+
|
|
69
|
+
def get(path, params = {})
|
|
70
|
+
path += '.json'
|
|
71
|
+
param_str = '?' + params.to_a.map{|i| i[0].to_s + '=' + CGI.escape(i[1]) }.join('&')
|
|
72
|
+
path = path + param_str unless param_str.empty?
|
|
73
|
+
|
|
74
|
+
req = Net::HTTP::Get.new(path)
|
|
75
|
+
req.add_field('User-Agent', 'Rubytter http://github.com/jugyo/rubytter')
|
|
76
|
+
req.basic_auth(@login, @password)
|
|
77
|
+
res_text = @connection.start(@host) do |http|
|
|
78
|
+
http.request(req).body
|
|
79
|
+
end
|
|
80
|
+
return JSON.parse(res_text)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def post(path, params = {})
|
|
84
|
+
path += '.json'
|
|
85
|
+
param_str = params.to_a.map{|i| i[0].to_s + '=' + CGI.escape(i[1]) }.join('&')
|
|
86
|
+
|
|
87
|
+
req = Net::HTTP::Post.new(path)
|
|
88
|
+
req.add_field('User-Agent', 'Rubytter http://github.com/jugyo/rubytter')
|
|
89
|
+
req.basic_auth(@login, @password)
|
|
90
|
+
@connection.start(@host) do |http|
|
|
91
|
+
http.request(req, param_str).body
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def delete(path, params = {})
|
|
96
|
+
post(path, params)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
class Connection
|
|
100
|
+
attr_reader :protocol, :port, :proxy_uri
|
|
101
|
+
|
|
102
|
+
def initialize(options = {})
|
|
103
|
+
@proxy_host = options[:proxy_host]
|
|
104
|
+
@proxy_port = options[:proxy_port]
|
|
105
|
+
@proxy_user = options[:proxy_user_name]
|
|
106
|
+
@proxy_password = options[:proxy_password]
|
|
107
|
+
@proxy_uri = nil
|
|
108
|
+
@enable_ssl = options[:enable_ssl]
|
|
109
|
+
|
|
110
|
+
if @proxy_host
|
|
111
|
+
@http_class = Net::HTTP::Proxy(@proxy_host, @proxy_port,
|
|
112
|
+
@proxy_user, @proxy_password)
|
|
113
|
+
@proxy_uri = "http://" + @proxy_host + ":" + @proxy_port + "/"
|
|
114
|
+
else
|
|
115
|
+
@http_class = Net::HTTP
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
if @enable_ssl
|
|
119
|
+
@protocol = "https"
|
|
120
|
+
@port = 443
|
|
121
|
+
else
|
|
122
|
+
@protocol = "http"
|
|
123
|
+
@port = 80
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def start(host, port = nil, &block)
|
|
128
|
+
http = @http_class.new(host, port || @port)
|
|
129
|
+
http.use_ssl = @enable_ssl
|
|
130
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
|
|
131
|
+
http.start(&block)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
4
|
+
|
|
5
|
+
class Rubytter
|
|
6
|
+
describe Rubytter do
|
|
7
|
+
before do
|
|
8
|
+
@rubytter = Rubytter.new('test', 'test')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'should receive ...' do
|
|
12
|
+
@rubytter.should_receive(:user_timeline).with(1)
|
|
13
|
+
@rubytter.user_timeline(1)
|
|
14
|
+
@rubytter.should_receive(:friend_timeline)
|
|
15
|
+
@rubytter.friend_timeline
|
|
16
|
+
@rubytter.should_receive(:replies).with({:page => 2})
|
|
17
|
+
@rubytter.replies(:page => 2)
|
|
18
|
+
# more...
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'should get or post' do
|
|
22
|
+
# TODO: split specs
|
|
23
|
+
@rubytter.should_receive(:get).with('/statuses/replies', {})
|
|
24
|
+
@rubytter.replies
|
|
25
|
+
|
|
26
|
+
@rubytter.should_receive(:get).with('/statuses/replies', {:page => 2})
|
|
27
|
+
@rubytter.replies(:page => 2)
|
|
28
|
+
|
|
29
|
+
@rubytter.should_receive(:get).with('/statuses/user_timeline/1', {})
|
|
30
|
+
@rubytter.user_timeline(1)
|
|
31
|
+
|
|
32
|
+
@rubytter.should_receive(:get).with('/users/show/1', {})
|
|
33
|
+
@rubytter.user(1)
|
|
34
|
+
|
|
35
|
+
@rubytter.should_receive(:delete).with('/statuses/destroy/1', {})
|
|
36
|
+
@rubytter.destroy(1)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# direct_messages
|
|
40
|
+
|
|
41
|
+
it 'should respond to direct_messages' do
|
|
42
|
+
@rubytter.should_receive(:get).with('/direct_messages', {})
|
|
43
|
+
@rubytter.direct_messages()
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'should respond to sent_direct_messages' do
|
|
47
|
+
@rubytter.should_receive(:get).with('/direct_messages/sent', {})
|
|
48
|
+
@rubytter.sent_direct_messages()
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'should respond to send_direct_message' do
|
|
52
|
+
@rubytter.should_receive(:post).with('/direct_messages/new', {})
|
|
53
|
+
@rubytter.send_direct_message()
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'should respond to destroy_direct_message' do
|
|
57
|
+
@rubytter.should_receive(:delete).with('/direct_messages/destroy/1', {})
|
|
58
|
+
@rubytter.destroy_direct_message(1)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'should respond to direct_message' do
|
|
62
|
+
@rubytter.should_receive(:post).with('/direct_messages/new', {:user => 'test', :text => 'aaaaaaaaaaaaa'})
|
|
63
|
+
@rubytter.direct_message('test', 'aaaaaaaaaaaaa')
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# statuses
|
|
67
|
+
|
|
68
|
+
it 'should respond to update' do
|
|
69
|
+
@rubytter.should_receive(:post).with('/statuses/update', {:status => 'test'})
|
|
70
|
+
@rubytter.update('test')
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'should respond to status_update' do
|
|
74
|
+
@rubytter.should_receive(:post).with('/statuses/update', {:status => 'test'})
|
|
75
|
+
@rubytter.status_update(:status => 'test')
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# friendship
|
|
79
|
+
|
|
80
|
+
it 'should respond to create_friendship' do
|
|
81
|
+
@rubytter.should_receive(:post).with('/friendships/create/test', {})
|
|
82
|
+
@rubytter.create_friendship('test')
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'should respond to destroy_friendship' do
|
|
86
|
+
@rubytter.should_receive(:delete).with('/friendships/destroy/test', {})
|
|
87
|
+
@rubytter.destroy_friendship('test')
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'should respond to friendship_exists' do
|
|
91
|
+
@rubytter.should_receive(:get).with('/friendships/exists', {:user_a => 'a', :user_b => 'b'})
|
|
92
|
+
@rubytter.friendship_exists(:user_a => 'a', :user_b => 'b')
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Social Graph Methods
|
|
96
|
+
|
|
97
|
+
it 'should respond to followers_ids' do
|
|
98
|
+
@rubytter.should_receive(:get).with('/friends/ids/test', {})
|
|
99
|
+
@rubytter.friends_ids('test')
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'should respond to followers_ids' do
|
|
103
|
+
@rubytter.should_receive(:get).with('/followers/ids/test', {})
|
|
104
|
+
@rubytter.followers_ids('test')
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jugyo-rubytter
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- jugyo
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-02-05 00:00:00 -08:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: json
|
|
17
|
+
version_requirement:
|
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
19
|
+
requirements:
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 1.1.3
|
|
23
|
+
version:
|
|
24
|
+
description: Rubytter is a simple twitter client.
|
|
25
|
+
email: jugyo.org@gmail.com
|
|
26
|
+
executables: []
|
|
27
|
+
|
|
28
|
+
extensions: []
|
|
29
|
+
|
|
30
|
+
extra_rdoc_files:
|
|
31
|
+
- README.rdoc
|
|
32
|
+
- History.txt
|
|
33
|
+
files:
|
|
34
|
+
- lib/rubytter.rb
|
|
35
|
+
- spec/rubytter_spec.rb
|
|
36
|
+
- spec/spec_helper.rb
|
|
37
|
+
- README.rdoc
|
|
38
|
+
- History.txt
|
|
39
|
+
has_rdoc: true
|
|
40
|
+
homepage: http://github.com/jugyo/rubytter
|
|
41
|
+
post_install_message:
|
|
42
|
+
rdoc_options:
|
|
43
|
+
- --main
|
|
44
|
+
- README.rdoc
|
|
45
|
+
- --exclude
|
|
46
|
+
- spec
|
|
47
|
+
require_paths:
|
|
48
|
+
- lib
|
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: "0"
|
|
54
|
+
version:
|
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: "0"
|
|
60
|
+
version:
|
|
61
|
+
requirements: []
|
|
62
|
+
|
|
63
|
+
rubyforge_project: rubytter
|
|
64
|
+
rubygems_version: 1.2.0
|
|
65
|
+
signing_key:
|
|
66
|
+
specification_version: 2
|
|
67
|
+
summary: Simple twitter client.
|
|
68
|
+
test_files: []
|
|
69
|
+
|