mogo24r 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2009-02-19
2
+
3
+ * 1 minor enhancement:
4
+ * Initial release
@@ -0,0 +1,17 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ example/cui_client.rb
6
+ example/simple_timeline_reader.rb
7
+ example/simple_update.rb
8
+ lib/mogo24r.rb
9
+ lib/mogo24r/timeline_parser.rb
10
+ lib/mogo24r/utils.rb
11
+ script/console
12
+ script/destroy
13
+ script/generate
14
+ spec/mogo24r_spec.rb
15
+ spec/spec.opts
16
+ spec/spec_helper.rb
17
+ tasks/rspec.rake
@@ -0,0 +1,51 @@
1
+ = mogo24r
2
+
3
+ http://mogo24r.rubyforge.org/
4
+
5
+ == DESCRIPTION:
6
+
7
+ mogo24r is mogo2API-library for ruby.
8
+ mogo2 is Japanese micro-blog.
9
+
10
+ == SYNOPSIS:
11
+
12
+ m24r = Mogo24r.new('your@email.com', 'your-api-key')
13
+
14
+ public_timeline = m24r.get_public_timeline
15
+
16
+ user_name = public_timeline.first[:user][:screen_name]
17
+
18
+ message = public_timeline.first[:text]
19
+
20
+ puts "user: #{user_name}"
21
+
22
+ puts "message: #{message}"
23
+
24
+ == INSTALL:
25
+
26
+ sudo gem install -r mogo24r
27
+
28
+ == LICENSE:
29
+
30
+ (The MIT License)
31
+
32
+ Copyright (c) 2009 saronpasu
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining
35
+ a copy of this software and associated documentation files (the
36
+ 'Software'), to deal in the Software without restriction, including
37
+ without limitation the rights to use, copy, modify, merge, publish,
38
+ distribute, sublicense, and/or sell copies of the Software, and to
39
+ permit persons to whom the Software is furnished to do so, subject to
40
+ the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be
43
+ included in all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
46
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
48
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
49
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
50
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
51
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/mogo24r'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('mogo24r', Mogo24r::VERSION) do |p|
7
+ p.developer('saronpasu', 'saronpasu at gmail dot com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
+ p.rubyforge_name = p.name # TODO this is default value
11
+ # p.extra_deps = [
12
+ # ['activesupport','>= 2.0.2'],
13
+ # ]
14
+ p.extra_dev_deps = [
15
+ ['newgem', ">= #{::Newgem::VERSION}"]
16
+ ]
17
+
18
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
19
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
20
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
21
+ p.rsync_args = '-av --delete --ignore-errors'
22
+ end
23
+
24
+ require 'newgem/tasks' # load /tasks/*.rake
25
+ Dir['tasks/**/*.rake'].each { |t| load t }
26
+
27
+ # TODO - want other tests/tasks run by default? Add them to the list
28
+ # task :default => [:spec, :features]
@@ -0,0 +1,94 @@
1
+ #!ruby -Ku
2
+ # -*- encoding: UTF-8 -*-
3
+ #
4
+ # Sample Application.
5
+ # 'mogo2 simple client'
6
+ #
7
+ require 'mogo24r'
8
+ require 'readline'
9
+ require 'optparse'
10
+ require 'kconv' unless RUBY_VERSION.match(/1\.9/)
11
+
12
+ count = 20
13
+ windows_pattern = /mswin(?!ce)|mingw|cygwin|bccwin/
14
+ platform = RUBY_PLATFORM.match(windows_pattern) ? :windows : :other
15
+
16
+ opts = OptionParser.new do |opt|
17
+ opt.program_name= 'simple mogo2 client'
18
+ opt.version= '0.0.1'
19
+ opt.banner= <<EOS
20
+ simple mogo2 client application.
21
+ input your email and API-Key.
22
+ EOS
23
+ opt.on(
24
+ '-c', '--count [COUNT]', Integer,
25
+ 'friends_timeline count[default=20]'
26
+ ){|v|count = v}
27
+ end
28
+
29
+ message = <<EOS
30
+ This application is simple mogo2 client.
31
+ please input your 'email' and 'API-Key'.
32
+
33
+ $ ruby cui_client.rb your@email.com your-api-key
34
+
35
+ EOS
36
+
37
+ args = opts.parse(ARGV)
38
+ if 1 > args.size then
39
+ puts message
40
+ end
41
+ email = args[0]
42
+ api_key = args[1]
43
+
44
+ m24r = Mogo24r.new(email, api_key)
45
+
46
+ help_message = <<EOS
47
+
48
+ 'exit' or 'quit' to exit this application.
49
+ 'help' or invalid-command to this message.
50
+ no-input Enter to get for mogo2 timeline.
51
+ any word input Enter to message update.
52
+
53
+ EOS
54
+
55
+ while buf = Readline.readline('> ', true)
56
+ case buf
57
+ when /^(exit|quit)$/ then
58
+ break
59
+ when '' then
60
+ puts 'get mogo2 timeline... '
61
+ statuses = m24r.get_friends_timeline({:count=>count})
62
+ statuses.each do|status|
63
+ case
64
+ when platform.eql?(:windows) && !RUBY_VERSION.match(/^1\.9/)
65
+ screen_name = status[:user][:screen_name].tosjis
66
+ text = status[:text].tosjis
67
+ when platform.eql?(:windows) && RUBY_VERSION.match(/1\.9/)
68
+ screen_name = status[:user][:screen_name].encode('Shift_JIS')
69
+ text = status[:text].encode('Shift_JIS')
70
+ else
71
+ screen_name = status[:user][:screen_name]
72
+ text = status[:text]
73
+ end
74
+ p "user: #{screen_name}"
75
+ p "mogo: #{text}"
76
+ end
77
+ when /^(help)$/ then
78
+ print help_message
79
+ when /^(\w+)/ then
80
+ puts 'update ... '
81
+ status = buf
82
+ case
83
+ when platform.eql?(:windows), !RUBY_VERSION.match(/^1\.9/)
84
+ status = buf.toutf8
85
+ when platform.eql?(:windows), RUBY_VERSION.match(/^1\.9/)
86
+ status = buf.encode('UTF-8')
87
+ end
88
+ m24r.update(status)
89
+ puts 'update complete'
90
+ else
91
+ print help_message
92
+ end
93
+ end
94
+
@@ -0,0 +1,16 @@
1
+ #!ruby -Ku
2
+ # -*- encoding: UTF-8 -*-
3
+
4
+ require 'mogo24r'
5
+
6
+ email = 'your@email.com'
7
+ api_key = 'your_api_key'
8
+
9
+ m24r = Mogo24r.new(email, api_key)
10
+
11
+ timeline = m24r.get_public_timeline
12
+ timeline.each do |status|
13
+ p 'Name: '+status[:user][:screen_name]
14
+ p 'Mogo: '+status[:text]
15
+ end
16
+
@@ -0,0 +1,12 @@
1
+ #!ruby -Ku
2
+ # -*- encoding: UTF-8 -*-
3
+
4
+ require 'mogo24r'
5
+ email = 'your@email.com'
6
+ api_key = 'your_api_key'
7
+
8
+ m24r = Mogo24r.new(email, api_key)
9
+
10
+ message = 'test from ruby'
11
+ m24r.update(message)
12
+
@@ -0,0 +1,206 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+ require 'mogo24r/utils'
4
+
5
+ =begin rdoc
6
+ mogo24r is mogo2API-library for ruby.
7
+ mogo2 is Japanese micro-blog.
8
+
9
+ see example/*.rb
10
+
11
+ =end
12
+ class Mogo24r
13
+ VERSION = '0.0.1'#:nodoc:
14
+ # HTTP_HEADER 'User-Agent'.
15
+ attr_accessor :user_agent
16
+ # User's Address.
17
+ attr_accessor :email
18
+ # User's API-Key.
19
+ attr_accessor :api_key
20
+ # mogo2-API's BaseAddress.
21
+ BaseAddress = 'http://api.mogo2.jp/'
22
+
23
+ include Utils
24
+
25
+ =begin rdoc
26
+ Description::
27
+ create mogo24r-instance.
28
+
29
+ Params::
30
+ email (your_mogo2@email.address)
31
+ api_key (your_mogo2_api_key)
32
+
33
+ Return::
34
+ Mogo24r-Instance
35
+
36
+ =end
37
+ def initialize(email, api_key)
38
+ @email = email
39
+ @api_key = api_key
40
+ @user_agent = 'mogo24r (http://mogo24r.rubyforge.org)'
41
+ end
42
+
43
+ autoload :TimelineParser, 'mogo24r/timeline_parser.rb'
44
+
45
+ =begin rdoc
46
+ Description::
47
+ access for public-timeline.
48
+
49
+ Params::
50
+ options = {:since_id => 12345}
51
+
52
+ Return::
53
+ [{:id => 12345, ...}, ...]
54
+
55
+ RelatedMethods::
56
+ Mogo24r::Utils#create_uri,
57
+ Mogo24r::Utils#create_request,
58
+ Mogo24r::Utils#http_access,
59
+ Mogo24r::Utils#parse_options,
60
+ Mogo24r::TimelineParser#parse_timeline
61
+
62
+ =end
63
+ def get_public_timeline(options = nil)
64
+ extend TimelineParser
65
+ address = BaseAddress + 'statuses/public_timeline.xml'
66
+ address += parse_options(options) if options
67
+ uri = create_uri(address)
68
+ request = create_request(:get, uri)
69
+ response = http_access(uri, request)
70
+ if response then
71
+ return parse_timeline(response)
72
+ else
73
+ return false
74
+ end
75
+ end
76
+
77
+ =begin rdoc
78
+ Description::
79
+ get you and your friends timeline.
80
+
81
+ Params::
82
+ options = {
83
+ :count => get statuses(Integer max=20),
84
+ :since => get timeline before date(DateTime)
85
+ }
86
+
87
+ Return::
88
+ [{:id => 12345, ...}, ...]
89
+
90
+ RelatedMethods::
91
+ Mogo24r::Utils#create_uri,
92
+ Mogo24r::Utils#create_request,
93
+ Mogo24r::Utils#http_access,
94
+ Mogo24r::Utils#parse_options,
95
+ Mogo24r::TimelineParser#parse_timeline
96
+
97
+ =end
98
+ def get_friends_timeline(options = nil)
99
+ extend TimelineParser
100
+ address = BaseAddress + 'statuses/friends_timeline.xml'
101
+ address += parse_options(options) if options
102
+ uri = create_uri(address)
103
+ request = create_request(:get, uri)
104
+ response = http_access(uri, request)
105
+ if response then
106
+ return parse_timeline(response)
107
+ else
108
+ return false
109
+ end
110
+ end
111
+
112
+ =begin rdoc
113
+ Description::
114
+ get thread timeline.
115
+
116
+ Params::
117
+ thread_id = target thred's id(Integer)
118
+ options = {:since => get timeline before date(DateTime)}
119
+
120
+ Return::
121
+ [{:id => 12345, ...}, ...]
122
+
123
+ RelatedMethods::
124
+ Mogo24r::Utils#create_uri,
125
+ Mogo24r::Utils#create_request,
126
+ Mogo24r::Utils#http_access,
127
+ Mogo24r::Utils#parse_options,
128
+ Mogo24r::TimelineParser#parse_timeline
129
+
130
+ =end
131
+ def get_thread_timeline(thread_id, options = nil)
132
+ extend TimelineParser
133
+ address = BaseAddress +
134
+ 'statuses/thread_timeline/' +
135
+ thread_id + '.xml'
136
+ address += parse_options(options) if options
137
+ uri = crate_uri(address)
138
+ request = create_request(:get, uri)
139
+ response = http_access(uri, request)
140
+ if response then
141
+ return parse_timeline(response)
142
+ else
143
+ return false
144
+ end
145
+ end
146
+
147
+ =begin rdoc
148
+ Description::
149
+ get user's timeline.
150
+
151
+ Params::
152
+ user_id = target user's id(Integer)
153
+ options = {
154
+ :count => get statuses(Integer max=20),
155
+ :since => get timeline before date(DateTime)
156
+ }
157
+
158
+ Return::
159
+ [{:id => 12345, ...}, ...}]
160
+
161
+ RelatedMethods::
162
+ Mogo24r::Utils#create_uri,
163
+ Mogo24r::Utils#create_request,
164
+ Mogo24r::Utils#http_access,
165
+ Mogo24r::Utils#parse_options,
166
+ Mogo24r::TimelineParser#parse_timeline
167
+
168
+ =end
169
+ def get_user_timeline(user_id = nil, options = nil)
170
+ extend TimellineParser
171
+ address = BaseAddress + 'statuses/user_timeline'
172
+ address += user_id.nil? ? '.xml' : "#{user_id}.xml"
173
+ address += parse_options(options) if options
174
+ uri = create_uri(address)
175
+ request = create_request(:get, uri)
176
+ response = http_access(uri, request)
177
+ if response then
178
+ return parse_timeline
179
+ else
180
+ return false
181
+ end
182
+ end
183
+
184
+ =begin rdoc
185
+ Description::
186
+ update status.
187
+
188
+ Params::
189
+ status(String Encoding: UTF-8)
190
+
191
+ RelatedMethods::
192
+ Mogo24r::Utils#create_uri,
193
+ Mogo24r::Utils#create_request,
194
+ Mogo24r::Utils#http_access
195
+
196
+ =end
197
+ def update_status(status)
198
+ uri = create_uri(
199
+ BaseAddress +
200
+ 'statuses/update.xml?status=' +
201
+ status
202
+ )
203
+ request = create_request(:post, uri)
204
+ http_access(uri, request)
205
+ end
206
+ end
@@ -0,0 +1,82 @@
1
+ # -*- encoding: UTF-8 -*-
2
+ require 'rexml/document'
3
+ require 'date'
4
+ require 'uri'
5
+
6
+ class Mogo24r
7
+ # TimelineParser for mogo2-API response.
8
+ module TimelineParser
9
+
10
+ =begin rdoc
11
+ Description::
12
+ parser-method for user-element.
13
+
14
+ Params::
15
+ user (REXML::Element-Instance)
16
+
17
+ Return::
18
+ {:id => 12345, ...}
19
+
20
+ RelatedMethods::
21
+ parse_timeline,
22
+ parse_status
23
+
24
+ =end
25
+ def parse_user(user)
26
+ result = {
27
+ :id => user.elements['id'].text.to_i,
28
+ :screen_name => user.elements['screen_name'].text,
29
+ :description => user.elements['description'].text,
30
+ :profile_image_url => URI.parse(user.elements['profile_image_url'].text)
31
+ }
32
+ return result
33
+ end
34
+
35
+ =begin rdoc
36
+ Description::
37
+ parse-method for status-element.
38
+
39
+ Params::
40
+ status (REXML::Element-Instance)
41
+
42
+ Return::
43
+ {:id => 12345, ...}
44
+
45
+ RelatedMethods::
46
+ parse_timeline
47
+ parse_user
48
+
49
+ =end
50
+ def parse_status(status)
51
+ result = {
52
+ :text => status.elements['text'].text,
53
+ :id => status.elements['id'].text.to_i,
54
+ :res_count => status.elements['res_count'].text.to_i,
55
+ :created_at => DateTime.parse(status.elements['created_at'].text),
56
+ :user => parse_user(status.elements['user'])
57
+ }
58
+ return result
59
+ end
60
+
61
+ =begin rdoc
62
+ Description::
63
+ timeline-parser for mogo2-API.
64
+
65
+ Params::
66
+ text (mogo2-API response)
67
+
68
+ Return::
69
+ [{:id => 12345, ...}]
70
+
71
+ RelatedMethods::
72
+ parse_status
73
+
74
+ =end
75
+ def parse_timeline(text)
76
+ doc = REXML::Document.new(text)
77
+ doc.elements.collect('//statuses/status'){|status|
78
+ parse_status(status)
79
+ }
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,115 @@
1
+ # -*- encoding: UTF-8 -*-
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'time'
5
+
6
+ class Mogo24r
7
+
8
+ =begin rdoc
9
+ Utility Module for Mogo24r.
10
+ This module include URI, Net::HTTP, and Time.
11
+ =end
12
+ module Utils
13
+
14
+ =begin rdoc
15
+ Description::
16
+ create Net::HTTPRequest instance.
17
+
18
+ Params::
19
+ type (:post|:get),
20
+ uri URI-Instance,
21
+ use_basic_auth (booleans)
22
+
23
+ Return::
24
+ Net::HTTPRequest-Instance
25
+
26
+ RelatedMethods::
27
+ create_uri,
28
+ http_access
29
+ =end
30
+ def create_request(type, uri, use_basic_auth = false)
31
+ case type
32
+ when :get
33
+ request = Net::HTTP::Get.new(uri.request_uri)
34
+ when :post
35
+ request = Net::HTTP::Post.new(uri.request_uri)
36
+ end
37
+ request['User-Agent'] = @user_agent
38
+ request.basic_auth @email, @api_key
39
+ return request
40
+ end
41
+
42
+ =begin rdoc
43
+ Description::
44
+ create URI instance.
45
+
46
+ Params::
47
+ url_string
48
+
49
+ Return::
50
+ URI-Instance
51
+
52
+ RelatedMethods::
53
+ parse_options,
54
+ create_request,
55
+ http_access
56
+ =end
57
+ def create_uri(url_string)
58
+ return URI.parse(URI.escape(url_string))
59
+ end
60
+
61
+ =begin rdoc
62
+ Description::
63
+ access to mogo2-API[http://*FIXME*]
64
+
65
+ Params::
66
+ uri (URI-Instance),
67
+ request (Net::HTTPRequest-Instance)
68
+
69
+ Return::
70
+ Responsed XML-Document or false
71
+
72
+ RelatedMethods::
73
+ create_uri,
74
+ create_request
75
+ =end
76
+ def http_access(uri, request)
77
+ Net::HTTP.start(uri.host, uri.port){|http|
78
+ response = http.request(request)
79
+ if RUBY_VERSION.match(/^1\.9\./)
80
+ response.body.force_encoding('UTF-8')
81
+ end
82
+ if response.code == '200'
83
+ return response.body
84
+ else
85
+ return false
86
+ end
87
+ }
88
+ end
89
+
90
+ =begin rdoc
91
+ Description::
92
+ parse option parametors
93
+
94
+ Params::
95
+ options ({:param_name => value, ...})
96
+
97
+ Return::
98
+ parsed-options ('?param_name=value&...')
99
+
100
+ RelatedMethods::
101
+ create_uri
102
+ =end
103
+ def parse_options(options)
104
+ result = ''
105
+ if options[:since]
106
+ options[:since] = Time.parse(options[:since].to_s).httpdate
107
+ end
108
+ options = options.find_all{|option|option.last}
109
+ result = '?' + options.collect{|option|
110
+ option.join('=')
111
+ }.join('&') unless options.empty?
112
+ return result
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/mogo24r.rb'}"
9
+ puts "Loading mogo24r gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,153 @@
1
+ # -*- encoding: UTF-8 -*-
2
+ require File.dirname(__FILE__) + '/spec_helper.rb'
3
+
4
+ describe Mogo24r, ' when first created' do
5
+ before do
6
+ @accessor = Mogo24r.new('sample@email.com', 'api-key')
7
+ end
8
+
9
+ it 'should be have a email' do
10
+ @accessor.email.should be_eql('sample@email.com')
11
+ end
12
+
13
+ it 'should be have a api-key' do
14
+ @accessor.api_key.should be_eql('api-key')
15
+ end
16
+
17
+ it 'should be have a user-agent' do
18
+ @accessor.user_agent.should be_eql('mogo24r (http://mogo24r.rubyforge.org)')
19
+ end
20
+
21
+ after do
22
+ @accessor = nil
23
+ end
24
+ end
25
+
26
+ describe Mogo24r::Utils, " when use" do
27
+ before do
28
+ @accessor = Mogo24r.new('sample@email.com', 'api-key')
29
+ end
30
+
31
+ it 'create_uri should be URI-Instance' do
32
+ @accessor.create_uri(
33
+ Mogo24r::BaseAddress +
34
+ 'statuses/public_timeline.xml'
35
+ ).should be_a_kind_of(URI)
36
+ end
37
+
38
+ it 'create_request with in type :get should be Net::HTTP::Get-Instance' do
39
+ uri = mock(:uri)
40
+ uri.should_receive(:request_uri).and_return('text')
41
+ @accessor.create_request(:get, uri).should be_a_kind_of(Net::HTTP::Get)
42
+ end
43
+
44
+ it 'create_request with in type :post should be Net::HTTP::Post-Instance' do
45
+ uri = mock(:uri)
46
+ uri.should_receive(:request_uri).and_return('text')
47
+ @accessor.create_request(:post, uri).should be_a_kind_of(Net::HTTP::Post)
48
+ end
49
+
50
+ it 'create_request instance should have basic_auth' do
51
+ uri = mock(:uri)
52
+ uri.should_receive(:request_uri).and_return('text')
53
+ request = @accessor.create_request(:get, uri)
54
+ request['Authorization'].should be_eql(
55
+ 'Basic c2FtcGxlQGVtYWlsLmNvbTphcGkta2V5'
56
+ )
57
+ end
58
+
59
+ it 'parse_options and return parsed-options' do
60
+ @accessor.parse_options({:count=>20, :since_id=>123}).should be_eql('?since_id=123&count=20')
61
+ end
62
+
63
+ after do
64
+ @accessor = nil
65
+ end
66
+ end
67
+
68
+ describe Mogo24r::TimelineParser, 'when use' do
69
+ before do
70
+ @accessor = Mogo24r.new('sample@email.com', 'api-key')
71
+ @accessor.extend(Mogo24r::TimelineParser)
72
+ @user = '
73
+ <user>
74
+ <id>123</id>
75
+ <screen_name>saronpasu</screen_name>
76
+ <description>my name is saronpasu</description>
77
+ <profile_image_url>http://mogo2.jp/dummy.jpg</profile_image_url>
78
+ </user>
79
+ '
80
+ @status = "
81
+ <status>
82
+ <text>hoge</text>
83
+ <created_at>Tue Feb 17 05:17:37 +0900 2009</created_at>
84
+ <id>123</id>
85
+ <res_count>0</res_count>
86
+ #{@user}
87
+ </status>
88
+ "
89
+ @timeline = "
90
+ <statuses>
91
+ #{@status}
92
+ </statuses>
93
+ "
94
+ end
95
+
96
+ it 'parse_timeline and return Hash in Array' do
97
+ @accessor.parse_timeline(@timeline).should be_a_kind_of(Array)
98
+ @accessor.parse_timeline(@timeline).first.should be_a_kind_of(Hash)
99
+ end
100
+
101
+ describe 'parse_timeline result' do
102
+ before do
103
+ @result = @accessor.parse_timeline(@timeline)
104
+ end
105
+
106
+ it 'have status id' do
107
+ @result.first.should have_key(:id)
108
+ end
109
+
110
+ it 'have status created_at' do
111
+ @result.first.should have_key(:created_at)
112
+ end
113
+
114
+ it 'have status text' do
115
+ @result.first.should have_key(:text)
116
+ end
117
+
118
+ it 'have status res_count' do
119
+ @result.first.should have_key(:res_count)
120
+ end
121
+
122
+ it 'have user' do
123
+ @result.first.should have_key(:user)
124
+ end
125
+
126
+ it 'have user id' do
127
+ @result.first[:user].should have_key(:id)
128
+ end
129
+
130
+ it 'have user profile_image_url' do
131
+ @result.first[:user].should have_key(:profile_image_url)
132
+ end
133
+
134
+ it 'have user screen_name' do
135
+ @result.first[:user].should have_key(:screen_name)
136
+ end
137
+
138
+ it 'have user description' do
139
+ @result.first[:user].should have_key(:description)
140
+ end
141
+
142
+ after do
143
+ @result = nil
144
+ end
145
+ end
146
+
147
+ after do
148
+ @accessor = nil
149
+ @user = nil
150
+ @status = nil
151
+ @timeline = nil
152
+ end
153
+ end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'mogo24r'
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mogo24r
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - saronpasu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-19 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: newgem
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.0
34
+ version:
35
+ description: mogo24r is mogo2API-library for ruby. mogo2 is Japanese micro-blog.
36
+ email:
37
+ - saronpasu at gmail dot com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - History.txt
44
+ - Manifest.txt
45
+ - README.rdoc
46
+ files:
47
+ - History.txt
48
+ - Manifest.txt
49
+ - README.rdoc
50
+ - Rakefile
51
+ - example/cui_client.rb
52
+ - example/simple_timeline_reader.rb
53
+ - example/simple_update.rb
54
+ - lib/mogo24r.rb
55
+ - lib/mogo24r/timeline_parser.rb
56
+ - lib/mogo24r/utils.rb
57
+ - script/console
58
+ - script/destroy
59
+ - script/generate
60
+ - spec/mogo24r_spec.rb
61
+ - spec/spec.opts
62
+ - spec/spec_helper.rb
63
+ - tasks/rspec.rake
64
+ has_rdoc: true
65
+ homepage: http://mogo24r.rubyforge.org/
66
+ post_install_message: PostInstall.txt
67
+ rdoc_options:
68
+ - --main
69
+ - README.rdoc
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ requirements: []
85
+
86
+ rubyforge_project: mogo24r
87
+ rubygems_version: 1.2.0
88
+ signing_key:
89
+ specification_version: 2
90
+ summary: mogo24r is mogo2API-library for ruby
91
+ test_files: []
92
+