cheetah-renoter 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/README +22 -0
- data/lib/renoter.rb +107 -0
- metadata +64 -0
data/README
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Renoter Gem
|
|
2
|
+
--------------------------------
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
|
|
6
|
+
require 'renoter'
|
|
7
|
+
|
|
8
|
+
r = Renoter.new
|
|
9
|
+
public_timeline = r.public_timeline # Last 20 statuses
|
|
10
|
+
|
|
11
|
+
if(r.login('user', 'password'))
|
|
12
|
+
r.update_status 'Hello from ruby!'
|
|
13
|
+
print 'OK!'
|
|
14
|
+
else
|
|
15
|
+
print 'Login failed'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
friends_timeline = r.friends_timeline('5') # Last 5 freinds statuses
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
For more functionality see documentation.
|
data/lib/renoter.rb
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
# This is a small wrapper for http://renoter.com API
|
|
6
|
+
# Author:: cheetah (mailto:thcheetah@gmail.com)
|
|
7
|
+
|
|
8
|
+
class Renoter
|
|
9
|
+
|
|
10
|
+
# Authentication, used in some other methods.
|
|
11
|
+
# Returns true if success, else returns false.
|
|
12
|
+
def login(user, pass)
|
|
13
|
+
api_url = 'http://renoter.com/account/verify_credentials.json'
|
|
14
|
+
url = URI.parse(api_url)
|
|
15
|
+
request = Net::HTTP::Get.new(api_url)
|
|
16
|
+
request.basic_auth(user, pass)
|
|
17
|
+
response = Net::HTTP.new(url.host, url.port).start {|http| http.request(request) }
|
|
18
|
+
if response.class == Net::HTTPOK
|
|
19
|
+
@username = user
|
|
20
|
+
@password = pass
|
|
21
|
+
return true
|
|
22
|
+
end
|
|
23
|
+
false
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Retrieves public timeline, the last 20 statuses.
|
|
27
|
+
# Returns JSON-decoded object, which contains statuses or errors.
|
|
28
|
+
def public_timeline()
|
|
29
|
+
api_url = 'http://renoter.com/statuses/public_timeline.json'
|
|
30
|
+
url = URI.parse(api_url)
|
|
31
|
+
request = Net::HTTP::Get.new(api_url)
|
|
32
|
+
response = Net::HTTP.new(url.host, url.port).start {|http| http.request(request) }
|
|
33
|
+
JSON.parse response.body
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Retrieves friends timeline, specified for authorized user.
|
|
37
|
+
# Returns JSON-decoded object, which contains statuses or errors.
|
|
38
|
+
# Requires authentication.
|
|
39
|
+
def friends_timeline(count = 20)
|
|
40
|
+
return 'at first you must been logged in' if !@username and !@password
|
|
41
|
+
|
|
42
|
+
api_url = 'http://renoter.com/statuses/friends_timeline.json?count=' + count.to_s
|
|
43
|
+
url = URI.parse(api_url)
|
|
44
|
+
request = Net::HTTP::Get.new(api_url)
|
|
45
|
+
request.basic_auth(@username, @password)
|
|
46
|
+
response = Net::HTTP.new(url.host, url.port).start {|http| http.request(request) }
|
|
47
|
+
JSON.parse response.body
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Retrieves timeline, for passed in params user.
|
|
51
|
+
# Returns JSON-decoded object, which contains statuses or errors.
|
|
52
|
+
def user_timeline(login, count = 20)
|
|
53
|
+
api_url = 'http://renoter.com/statuses/user_timeline.json?login=' + login.to_s + '&count=' + count.to_s
|
|
54
|
+
url = URI.parse(api_url)
|
|
55
|
+
request = Net::HTTP::Get.new(api_url)
|
|
56
|
+
request.basic_auth(@username, @password) if @username and @password
|
|
57
|
+
response = Net::HTTP.new(url.host, url.port).start {|http| http.request(request) }
|
|
58
|
+
JSON.parse response.body
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Retrieves status with passed in params id.
|
|
62
|
+
# Returns JSON-decoded object, which contains status or errors.
|
|
63
|
+
def show_status(id)
|
|
64
|
+
return 'id must be not nil.' if id.nil?
|
|
65
|
+
|
|
66
|
+
api_url = 'http://renoter.com/statuses/show/' + id.to_s + '.json'
|
|
67
|
+
url = URI.parse(api_url)
|
|
68
|
+
request = Net::HTTP::Get.new(api_url)
|
|
69
|
+
request.basic_auth(@username, @password) if @username and @password
|
|
70
|
+
response = Net::HTTP.new(url.host, url.port).start {|http| http.request(request) }
|
|
71
|
+
JSON.parse response.body
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Post a new status.
|
|
75
|
+
# Returns JSON-decoded object, which contains new status or errors.
|
|
76
|
+
# Requires authentication.
|
|
77
|
+
def update_status(status, reply_id = nil)
|
|
78
|
+
return 'status must been less than 140 characters.' if status.length > 140
|
|
79
|
+
return 'status must have at least one character.' if status.length < 1
|
|
80
|
+
return 'at first you must been logged in' if !@username and !@password
|
|
81
|
+
|
|
82
|
+
api_url = 'http://renoter.com/statuses/update.json'
|
|
83
|
+
url = URI.parse(api_url)
|
|
84
|
+
request = Net::HTTP::Post.new(url.path)
|
|
85
|
+
request.basic_auth(@username, @password)
|
|
86
|
+
request.set_form_data({'status'=> status, 'in_reply_to_status_id' => reply_id})
|
|
87
|
+
response = Net::HTTP.new(url.host, url.port).start {|http| http.request(request) }
|
|
88
|
+
JSON.parse response.body
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Removes status with passed in params id.
|
|
92
|
+
# Returns JSON-decoded object, which contains removed status or errors.
|
|
93
|
+
# Requires authentication.
|
|
94
|
+
def delete_status(id)
|
|
95
|
+
return 'id must be not nil.' if id.nil?
|
|
96
|
+
return 'at first you must been logged in' if !@username and !@password
|
|
97
|
+
|
|
98
|
+
api_url = 'http://renoter.com/statuses/destroy/' + id.to_s + '.json'
|
|
99
|
+
url = URI.parse(api_url)
|
|
100
|
+
request = Net::HTTP::Post.new(url.path)
|
|
101
|
+
request.basic_auth(@username, @password) if @username and @password
|
|
102
|
+
request.set_form_data({ 'id'=> id }, ';')
|
|
103
|
+
response = Net::HTTP.new(url.host, url.port).start {|http| http.request(request) }
|
|
104
|
+
JSON.parse response.body
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cheetah-renoter
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- cheetah
|
|
8
|
+
autorequire: renoter
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-04-08 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: json
|
|
17
|
+
type: :runtime
|
|
18
|
+
version_requirement:
|
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: 1.1.4
|
|
24
|
+
version:
|
|
25
|
+
description: Some simple methods in Renoter class to interact with http://renoter.com
|
|
26
|
+
email: thcheetah@gmail.com
|
|
27
|
+
executables: []
|
|
28
|
+
|
|
29
|
+
extensions: []
|
|
30
|
+
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
|
|
33
|
+
files:
|
|
34
|
+
- README
|
|
35
|
+
- lib/renoter.rb
|
|
36
|
+
has_rdoc: true
|
|
37
|
+
homepage: http://github.com/cheetah/renoter
|
|
38
|
+
post_install_message:
|
|
39
|
+
rdoc_options:
|
|
40
|
+
- --inline-source
|
|
41
|
+
- --charset=UTF-8
|
|
42
|
+
require_paths:
|
|
43
|
+
- lib
|
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: "0"
|
|
49
|
+
version:
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: "0"
|
|
55
|
+
version:
|
|
56
|
+
requirements: []
|
|
57
|
+
|
|
58
|
+
rubyforge_project:
|
|
59
|
+
rubygems_version: 1.2.0
|
|
60
|
+
signing_key:
|
|
61
|
+
specification_version: 2
|
|
62
|
+
summary: Renoter API ruby wrapper.
|
|
63
|
+
test_files: []
|
|
64
|
+
|