Wassruby 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/wassruby.rb CHANGED
@@ -1,182 +1,10 @@
1
- #
2
- #= Simple Wassr Client
3
- #Authors:: Takuya Mannami
4
- #Version:: 0.0.3
5
- #License:: MIT License
6
- #
7
- #==Wassruby use simplejson.rb
8
- #WebOS Goodies (http://webos-goodies.jp/archives/51071565.html)
9
- #
10
- #Simple JSON parser & builde(http://rubyforge.org/snippet/detail.php?type=snippet&id=148)
1
+ #$:.unshift(File.dirname(__FILE__)) unless
2
+ # $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
11
3
 
12
- require 'open-uri'
13
- require 'net/http'
14
- require 'cgi'
15
- require 'simplejson'
16
-
17
- module WWW
18
- class Wassr
19
- VERSION = '0.0.3'
20
- WASSR = "api.wassr.jp"
21
-
22
- WASSR_API_URI = {
23
- :UPDATE => "/statuses/update.json?status=",
24
- :USER_TIMELINE => "/statuses/user_timeline.json?id=",
25
- :FRIENDS_TIMELINE => "/statuses/friends_timeline.json?id=",
26
- :PUBLIC_TIMELINE => "/statuses/public_timeline.json",
27
- :FOOTMARK => "/footmark/recent.json",
28
- :SHOW => "/statuses/show.json?id=",
29
- :FRIENDS => "/statuses/friends.json",
30
- :FOLLOWERS => "/statuses/followers.json",
31
- }
32
-
33
- ###
34
- #login id
35
- attr_accessor :VERSION
36
- attr_accessor :login_id
37
- #password
38
- attr_accessor :password
39
- #post message
40
- attr_accessor :message
41
- ###
42
-
43
- ###
44
- #friend id or user id
45
- attr_accessor :user_id
46
- ###
47
-
48
- #wassr = WWW::Wassr.new('LOGIN_ID', 'PASSWORD')
49
- def initialize(login_id, password)
50
- ###
51
- @login_id = login_id
52
- @password = password
53
- ###
54
-
55
- ###
56
- @message = nil
57
- @escape_message = nil
58
- @user_id = nil
59
- ###
60
-
61
- ###
62
- @http_obj = Net::HTTP.new(WASSR,80)
63
- #using simplejson.rb
64
- @jp_obj = JsonParser.new
65
- ###
66
- end
67
-
68
- #
69
- #WWW::Wassr.start('LOGIN_ID', 'PASSWORD') {|wassr|
70
- #}
71
- #
72
- def Wassr.start(login_id, password)
73
- if block_given?
74
- yield self.new(login_id, password)
75
- end
76
- end
77
-
78
-
79
- #------------------------------------------------------
80
- def json_parse(response_body) # :nodoc:
81
- return @jp_obj.parse(response_body)
82
- end
83
-
84
- def get_http_response_body(uri) #:nodoc:
85
- res = @http_obj.get(uri)
86
- return res.body
87
- end
88
-
89
- def get_val(uri) # :nodoc:
90
- res_body = get_http_response_body(uri)
91
- json_parse(res_body)
92
- end
93
-
94
- #wasssr.message = 'test'
95
- #
96
- #wassr.post_message # => send message 'test'
97
- def post_message
98
- @escape_message = escape(@message)
99
- req = Net::HTTP::Post.new(WASSR_API_URI[:UPDATE]+"#{@escape_message}")
100
- req.basic_auth @login_id, @password
101
- res = @http_obj.request(req)
102
- return res
103
- end
104
-
105
- #wassr.user_id = 'FRIEND_ID'
106
- #
107
- #wassr.get_friends_timeline.each {|v|
108
- # puts v["user_login_id"]
109
- # puts v["text"]
110
- #}
111
- def get_friends_timeline
112
- get_val(WASSR_API_URI[:FRIENDS_TIMELINE]+"#{@user_id.to_s}")
113
- end
114
-
115
- #wassr.get_public_timeline.each {|v|
116
- # puts v[0]["user_login_id"]
117
- # puts v[0]["text"]
118
- #}
119
- def get_public_timeline
120
- get_val(WASSR_API_URI[:PUBLIC_TIMELINE])
121
- end
122
-
123
- #wassr.user_id = "foo"
124
- #
125
- #wassr.get_user_timeline.each {|v|
126
- # puts v["user_login_id"]
127
- # puts v["text"]
128
- #}
129
- def get_user_timeline
130
- get_val(WASSR_API_URI[:USER_TIMELINE]+"#{@user_id.to_s}")
131
- end
132
-
133
- #
134
- #wassr.user_id = "foo"
135
- #
136
- #wassr.get_show.each {|v|
137
- # puts v["user_login_id"]
138
- # puts v["text"]
139
- #}
140
- def get_show
141
- get_val(WASSR_API_URI[:SHOW]+"#{@user_id.to_s}")
142
- end
143
-
144
- #wassr.get_friends.each{|v|
145
- # puts v["name"]
146
- # puts v["screen_name"]
147
- #}
148
- def get_friends
149
- req = Net::HTTP::Get.new(WASSR_API_URI[:FRIENDS])
150
- req.basic_auth @login_id, @password
151
- res = @http_obj.request(req)
152
- json_parse(res.body)
153
- end
154
-
155
- #wassr.get_followers{|v|
156
- # puts v["name"]
157
- # puts v["screen_name"]
158
- #}
159
- def get_followers
160
- req = Net::HTTP::Get.new(WASSR_API_URI[:FOLLOWERS])
161
- req.basic_auth @login_id, @password
162
- res = @http_obj.request(req)
163
- json_parse(res.body)
164
- end
165
-
166
- #wassr.get_footmark.each {|v|
167
- # puts v["nick"]
168
- # puts v["login_id"]
169
- #}
170
- def get_footmark
171
- req = Net::HTTP::Get.new(WASSR_API_URI[:FOOTMARK])
172
- req.basic_auth @login_id, @password
173
- json_parse(@http_obj.request(req).body)
174
- end
175
-
176
- #------------------------------------------------------
177
-
178
- def escape(str) # :nodoc:
179
- return CGI.escape(str)
4
+ require 'www/wassruby'
5
+ require 'www/simplejson'
6
+
7
+ module WWW
8
+ class Wassr
180
9
  end
181
- end
182
- end
10
+ end
@@ -0,0 +1,182 @@
1
+ #
2
+ #= Simple Wassr Client
3
+ #Authors:: Takuya Mannami
4
+ #Version:: 0.0.3
5
+ #License:: MIT License
6
+ #
7
+ #==Wassruby use simplejson.rb
8
+ #WebOS Goodies (http://webos-goodies.jp/archives/51071565.html)
9
+ #
10
+ #Simple JSON parser & builde(http://rubyforge.org/snippet/detail.php?type=snippet&id=148)
11
+
12
+ require 'open-uri'
13
+ require 'net/http'
14
+ require 'cgi'
15
+ #require 'simplejson'
16
+
17
+ module WWW
18
+ class Wassr
19
+ VERSION = '0.0.4'
20
+ WASSR = "api.wassr.jp"
21
+
22
+ WASSR_API_URI = {
23
+ :UPDATE => "/statuses/update.json?status=",
24
+ :USER_TIMELINE => "/statuses/user_timeline.json?id=",
25
+ :FRIENDS_TIMELINE => "/statuses/friends_timeline.json?id=",
26
+ :PUBLIC_TIMELINE => "/statuses/public_timeline.json",
27
+ :FOOTMARK => "/footmark/recent.json",
28
+ :SHOW => "/statuses/show.json?id=",
29
+ :FRIENDS => "/statuses/friends.json",
30
+ :FOLLOWERS => "/statuses/followers.json",
31
+ }
32
+
33
+ ###
34
+ #login id
35
+ attr_accessor :VERSION
36
+ attr_accessor :login_id
37
+ #password
38
+ attr_accessor :password
39
+ #post message
40
+ attr_accessor :message
41
+ ###
42
+
43
+ ###
44
+ #friend id or user id
45
+ attr_accessor :user_id
46
+ ###
47
+
48
+ #wassr = WWW::Wassr.new('LOGIN_ID', 'PASSWORD')
49
+ def initialize(login_id, password)
50
+ ###
51
+ @login_id = login_id
52
+ @password = password
53
+ ###
54
+
55
+ ###
56
+ @message = nil
57
+ @escape_message = nil
58
+ @user_id = nil
59
+ ###
60
+
61
+ ###
62
+ @http_obj = Net::HTTP.new(WASSR,80)
63
+ #using simplejson.rb
64
+ @jp_obj = JsonParser.new
65
+ ###
66
+ end
67
+
68
+ #
69
+ #WWW::Wassr.start('LOGIN_ID', 'PASSWORD') {|wassr|
70
+ #}
71
+ #
72
+ def Wassr.start(login_id, password)
73
+ if block_given?
74
+ yield self.new(login_id, password)
75
+ end
76
+ end
77
+
78
+
79
+ #------------------------------------------------------
80
+ def json_parse(response_body) # :nodoc:
81
+ return @jp_obj.parse(response_body)
82
+ end
83
+
84
+ def get_http_response_body(uri) #:nodoc:
85
+ res = @http_obj.get(uri)
86
+ return res.body
87
+ end
88
+
89
+ def get_val(uri) # :nodoc:
90
+ res_body = get_http_response_body(uri)
91
+ json_parse(res_body)
92
+ end
93
+
94
+ #wasssr.message = 'test'
95
+ #
96
+ #wassr.post_message # => send message 'test'
97
+ def post_message
98
+ @escape_message = escape(@message)
99
+ req = Net::HTTP::Post.new(WASSR_API_URI[:UPDATE]+"#{@escape_message}")
100
+ req.basic_auth @login_id, @password
101
+ res = @http_obj.request(req)
102
+ return res
103
+ end
104
+
105
+ #wassr.user_id = 'FRIEND_ID'
106
+ #
107
+ #wassr.get_friends_timeline.each {|v|
108
+ # puts v["user_login_id"]
109
+ # puts v["text"]
110
+ #}
111
+ def get_friends_timeline
112
+ get_val(WASSR_API_URI[:FRIENDS_TIMELINE]+"#{@user_id.to_s}")
113
+ end
114
+
115
+ #wassr.get_public_timeline.each {|v|
116
+ # puts v[0]["user_login_id"]
117
+ # puts v[0]["text"]
118
+ #}
119
+ def get_public_timeline
120
+ get_val(WASSR_API_URI[:PUBLIC_TIMELINE])
121
+ end
122
+
123
+ #wassr.user_id = "foo"
124
+ #
125
+ #wassr.get_user_timeline.each {|v|
126
+ # puts v["user_login_id"]
127
+ # puts v["text"]
128
+ #}
129
+ def get_user_timeline
130
+ get_val(WASSR_API_URI[:USER_TIMELINE]+"#{@user_id.to_s}")
131
+ end
132
+
133
+ #
134
+ #wassr.user_id = "foo"
135
+ #
136
+ #wassr.get_show.each {|v|
137
+ # puts v["user_login_id"]
138
+ # puts v["text"]
139
+ #}
140
+ def get_show
141
+ get_val(WASSR_API_URI[:SHOW]+"#{@user_id.to_s}")
142
+ end
143
+
144
+ #wassr.get_friends.each{|v|
145
+ # puts v["name"]
146
+ # puts v["screen_name"]
147
+ #}
148
+ def get_friends
149
+ req = Net::HTTP::Get.new(WASSR_API_URI[:FRIENDS])
150
+ req.basic_auth @login_id, @password
151
+ res = @http_obj.request(req)
152
+ json_parse(res.body)
153
+ end
154
+
155
+ #wassr.get_followers{|v|
156
+ # puts v["name"]
157
+ # puts v["screen_name"]
158
+ #}
159
+ def get_followers
160
+ req = Net::HTTP::Get.new(WASSR_API_URI[:FOLLOWERS])
161
+ req.basic_auth @login_id, @password
162
+ res = @http_obj.request(req)
163
+ json_parse(res.body)
164
+ end
165
+
166
+ #wassr.get_footmark.each {|v|
167
+ # puts v["nick"]
168
+ # puts v["login_id"]
169
+ #}
170
+ def get_footmark
171
+ req = Net::HTTP::Get.new(WASSR_API_URI[:FOOTMARK])
172
+ req.basic_auth @login_id, @password
173
+ json_parse(@http_obj.request(req).body)
174
+ end
175
+
176
+ #------------------------------------------------------
177
+
178
+ def escape(str) # :nodoc:
179
+ return CGI.escape(str)
180
+ end
181
+ end
182
+ end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Wassruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takuya Mannami
8
- autorequire:
8
+ autorequire: wassruby
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
@@ -22,9 +22,9 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README.txt
24
24
  files:
25
- - lib/simplejson.rb
26
25
  - lib/wassruby.rb
27
- - wassruby.rb
26
+ - lib/www/simplejson.rb
27
+ - lib/www/wassruby.rb
28
28
  - README.txt
29
29
  has_rdoc: true
30
30
  homepage: http://wassruby.rubyforge.org/
data/wassruby.rb DELETED
@@ -1,5 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
- require 'lib/wassruby'
5
-
File without changes