jugyo-rubytter 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/rubytter.rb +19 -6
  2. data/spec/rubytter_spec.rb +10 -4
  3. metadata +1 -1
data/lib/rubytter.rb CHANGED
@@ -16,7 +16,7 @@ class Rubytter
16
16
  end
17
17
  end
18
18
 
19
- VERSION = '0.6.3'
19
+ VERSION = '0.6.5'
20
20
 
21
21
  attr_reader :login
22
22
  attr_accessor :host, :header
@@ -125,16 +125,16 @@ class Rubytter
125
125
  json_data = http_request("search.#{@host}", req)
126
126
  self.class.json_to_struct(
127
127
  json_data['results'].map do |result|
128
- search_result_to_struct(result)
128
+ self.class.search_result_to_hash(result)
129
129
  end
130
130
  )
131
131
  end
132
132
 
133
- def search_result_to_struct(json)
133
+ def self.search_result_to_hash(json)
134
134
  {
135
135
  'id' => json['id'],
136
136
  'text' => json['text'],
137
- 'source' => CGI.unescapeHTML(json['source']),
137
+ 'source' => json['source'],
138
138
  'created_at' => json['created_at'],
139
139
  'in_reply_to_user_id' => json['to_usre_id'],
140
140
  'in_reply_to_screen_name' => json['to_usre'],
@@ -184,12 +184,17 @@ class Rubytter
184
184
  end
185
185
  end
186
186
  unless struct_values.empty?
187
- Struct.new(*struct_values.keys).new(*struct_values.values)
187
+ get_struct(struct_values.keys).new(*struct_values.values)
188
188
  else
189
189
  nil
190
190
  end
191
191
  else
192
- json
192
+ case json
193
+ when String
194
+ CGI.unescapeHTML(json)
195
+ else
196
+ json
197
+ end
193
198
  end
194
199
  end
195
200
 
@@ -197,4 +202,12 @@ class Rubytter
197
202
  raise ArgumentError, 'Argument must be a Hash object' unless hash.is_a?(Hash)
198
203
  hash.to_a.map{|i| i[0].to_s + '=' + CGI.escape(i[1].to_s) }.join('&')
199
204
  end
205
+
206
+ def self.get_struct(keys)
207
+ @@structs ||= {}
208
+ unless @@structs.has_key?(keys)
209
+ @@structs[keys] = Struct.new(*keys)
210
+ end
211
+ @@structs[keys]
212
+ end
200
213
  end
@@ -178,7 +178,7 @@ class Rubytter
178
178
  nil => nil,
179
179
  :c => {:a => 1, :b => 2},
180
180
  :d => {:a => {:a => 1, :b => 2}, :b => 1},
181
- :e => [{:a => 1, :b => 2}, {:c => 3}]
181
+ :e => [{:a => 1, :b => 2}, {:c => '"<>&'}]
182
182
  }
183
183
  struct = Rubytter.json_to_struct(hash)
184
184
  struct.a.should == 'a'
@@ -188,11 +188,17 @@ class Rubytter
188
188
  struct.d.a.a.should == 1
189
189
  struct.e[0].a.should == 1
190
190
  struct.e[0].b.should == 2
191
- struct.e[1].c.should == 3
191
+ struct.e[1].c.should == '"<>&'
192
192
  lambda {struct.x}.should raise_error(NoMethodError)
193
193
  lambda {struct.regex}.should raise_error(NoMethodError)
194
194
  end
195
195
 
196
+ it 'should create same structs from same datas' do
197
+ Rubytter.json_to_struct({:a => 'a'}).should == Rubytter.json_to_struct({:a => 'a'})
198
+ Rubytter.json_to_struct({:a => 'a', :b => {:c => 'c'}}).should ==
199
+ Rubytter.json_to_struct({:a => 'a', :b => {:c => 'c'}})
200
+ end
201
+
196
202
  it 'should be set app_name' do
197
203
  rubytter = Rubytter.new('test', 'teat', :app_name => "Foo")
198
204
  rubytter.should_receive(:__update_status).with({:status => 'test', :source => "Foo"})
@@ -212,11 +218,11 @@ class Rubytter
212
218
  'profile_image_url' => 'http://s3.amazonaws.com/twitter_production/profile_images/63467667/megane2_normal.png'
213
219
  }
214
220
  rubytter = Rubytter.new('test', 'teat')
215
- result = rubytter.search_result_to_struct(json_data)
221
+ result = Rubytter.search_result_to_hash(json_data)
216
222
  result['id'].should == '123'
217
223
  result['text'].should == 'foo foo bar bar'
218
224
  result['created_at'].should == 'Sat, 21 Mar 2009 09:48:20 +0000'
219
- result['source'].should == "<a href=\"http:\\/\\/twitter.com\\/\">web<\\/a>"
225
+ result['source'].should == '&lt;a href=&quot;http:\/\/twitter.com\/&quot;&gt;web&lt;\/a&gt;'
220
226
  result['in_reply_to_user_id'].should == '20660692'
221
227
  result['in_reply_to_screen_name'].should == 'jugyo_test'
222
228
  result['user']['id'].should == '3748631'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jugyo-rubytter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo