rubytter 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -56,6 +56,7 @@ or
56
56
 
57
57
  client = OAuthRubytter.new(access_token)
58
58
 
59
+ It required a 'oauth' library.
59
60
  You must specify valid instance of OAuth::AccessToken as acces_token.
60
61
 
61
62
  === update status:
data/lib/rubytter.rb CHANGED
@@ -9,7 +9,7 @@ require 'rubytter/oauth_rubytter'
9
9
 
10
10
  class Rubytter
11
11
 
12
- VERSION = '0.7.0'
12
+ VERSION = '0.8.0'
13
13
 
14
14
  class APIError < StandardError
15
15
  attr_reader :response
@@ -212,6 +212,25 @@ class Rubytter
212
212
  def method_missing(*args, &block)
213
213
  nil
214
214
  end
215
+
216
+ def to_hash(escape = false)
217
+ hash = {}
218
+ self.members.each do |member|
219
+ value = self[member]
220
+ if value.respond_to?(:to_hash)
221
+ hash[member] = value.to_hash(escape)
222
+ elsif value.is_a?(Array)
223
+ hash[member] = value.map{ |i| i.to_hash(escape) }
224
+ else
225
+ hash[member] = escape && value.is_a?(String) ? CGI.escapeHTML(value) : value
226
+ end
227
+ end
228
+ hash
229
+ end
230
+
231
+ def to_json(escape = false)
232
+ to_hash(escape).to_json
233
+ end
215
234
  end
216
235
  @@structs[keys] = struct
217
236
  end
@@ -193,6 +193,52 @@ class Rubytter
193
193
  struct.regex.should == nil
194
194
  end
195
195
 
196
+ it 'should convert struct to hash' do
197
+ hash = {
198
+ :a => 'a',
199
+ 'b' => 1,
200
+ 1 => 'a',
201
+ /regex/ => 'regex',
202
+ nil => nil,
203
+ :c => {:a => 1, :b => 2},
204
+ :d => {:a => {:a => 1, :b => 2}, :b => 1},
205
+ :e => [{:a => 1, :b => 2}, {:c => '&quot;&lt;&gt;&amp;'}]
206
+ }
207
+ struct = Rubytter.json_to_struct(hash)
208
+ struct.to_hash.should == {"a"=>"a", "b"=>1, "c"=>{"a"=>1, "b"=>2}, "d"=>{"a"=>{"a"=>1, "b"=>2}, "b"=>1}, "e"=>[{"a"=>1, "b"=>2}, {"c"=>"\"<>&"}]}
209
+ end
210
+
211
+ it 'should convert struct to hash with escape as HTML' do
212
+ hash = {
213
+ :e => [{:a => 1, :b => 2}, {:c => '&quot;&lt;&gt;&amp;'}]
214
+ }
215
+ struct = Rubytter.json_to_struct(hash)
216
+ struct.to_hash(true).should == {"e"=>[{"a"=>1, "b"=>2}, {"c"=>"&quot;&lt;&gt;&amp;"}]}
217
+ end
218
+
219
+ it 'should convert struct to json' do
220
+ hash = {
221
+ :a => 'a',
222
+ 'b' => 1,
223
+ 1 => 'a',
224
+ /regex/ => 'regex',
225
+ nil => nil,
226
+ :c => {:a => 1, :b => 2},
227
+ :d => {:a => {:a => 1, :b => 2}, :b => 1},
228
+ :e => [{:a => 1, :b => 2}, {:c => '&quot;&lt;&gt;&amp;'}]
229
+ }
230
+ struct = Rubytter.json_to_struct(hash)
231
+ struct.to_json.should == '{"a":"a","b":1,"c":{"a":1,"b":2},"d":{"a":{"a":1,"b":2},"b":1},"e":[{"a":1,"b":2},{"c":"\"<>&"}]}'
232
+ end
233
+
234
+ it 'should convert struct to json with escape as HTML' do
235
+ hash = {
236
+ :e => [{:a => 1, :b => 2}, {:c => '&quot;&lt;&gt;&amp;'}]
237
+ }
238
+ struct = Rubytter.json_to_struct(hash)
239
+ struct.to_json(true).should == '{"e":[{"a":1,"b":2},{"c":"&quot;&lt;&gt;&amp;"}]}'
240
+ end
241
+
196
242
  it 'should create same structs from same datas' do
197
243
  Rubytter.json_to_struct({:a => 'a'}).should == Rubytter.json_to_struct({:a => 'a'})
198
244
  Rubytter.json_to_struct({:a => 'a', :b => {:c => 'c'}}).should ==
@@ -252,21 +298,21 @@ class Rubytter
252
298
  it 'should post using access_token' do
253
299
  access_token = Object.new
254
300
  rubytter = OAuthRubytter.new(access_token)
255
- access_token.should_receive(:post).with('/statuses/update.json', {:status => 'test'}, {"User-Agent"=>"Rubytter/0.6.6 (http://github.com/jugyo/rubytter)"})
301
+ access_token.should_receive(:post).with('/statuses/update.json', {:status => 'test'}, {"User-Agent"=>"Rubytter/#{Rubytter::VERSION} (http://github.com/jugyo/rubytter)"})
256
302
  rubytter.update('test')
257
303
  end
258
304
 
259
305
  it 'should get using access_token' do
260
306
  access_token = Object.new
261
307
  rubytter = OAuthRubytter.new(access_token)
262
- access_token.should_receive(:get).with('/statuses/friends_timeline.json', {}, {"User-Agent"=>"Rubytter/0.6.6 (http://github.com/jugyo/rubytter)"})
308
+ access_token.should_receive(:get).with('/statuses/friends_timeline.json', {}, {"User-Agent"=>"Rubytter/#{Rubytter::VERSION} (http://github.com/jugyo/rubytter)"})
263
309
  rubytter.friends_timeline
264
310
  end
265
311
 
266
312
  it 'should get with params using access_token' do
267
313
  access_token = Object.new
268
314
  rubytter = OAuthRubytter.new(access_token)
269
- access_token.should_receive(:get).with('/statuses/friends_timeline.json', {:page => 2}, {"User-Agent"=>"Rubytter/0.6.6 (http://github.com/jugyo/rubytter)"})
315
+ access_token.should_receive(:get).with('/statuses/friends_timeline.json', {:page => 2}, {"User-Agent"=>"Rubytter/#{Rubytter::VERSION} (http://github.com/jugyo/rubytter)"})
270
316
  rubytter.friends_timeline(:page => 2)
271
317
  end
272
318
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubytter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-06 00:00:00 +09:00
12
+ date: 2009-06-16 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency