jugyo-rubytter 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -40,8 +40,8 @@ update status
40
40
  get friends timeline
41
41
 
42
42
  client = Rubytter.new(user_id, password)
43
- client.friends_timeline().each do |status|
44
- puts "#{status['user']['screen_name']}: #{status['text']}"
43
+ client.friends_timeline.each do |status|
44
+ puts "#{status.user.screen_name}: #{status.text}"
45
45
  end
46
46
 
47
47
  == REQUIREMENTS:
@@ -56,8 +56,6 @@ get friends timeline
56
56
  == TODO:
57
57
 
58
58
  - search
59
- - direct_message
60
- - follow/leave
61
59
  - favorite
62
60
 
63
61
  == LICENSE:
@@ -9,6 +9,6 @@ if ARGV.size < 2
9
9
  end
10
10
 
11
11
  client = Rubytter.new(ARGV[0], ARGV[1])
12
- client.friends_timeline().each do |status|
12
+ client.friends_timeline.each do |status|
13
13
  puts "#{status.user.screen_name}: #{status.text}"
14
14
  end
data/lib/rubytter.rb CHANGED
@@ -100,15 +100,20 @@ class Rubytter
100
100
  def json_to_struct(json)
101
101
  case json
102
102
  when Array
103
- json.map do |i|
104
- if i.is_a?(Hash)
105
- i.to_struct
106
- else
107
- i
103
+ json.map{|i| json_to_struct(i)}
104
+ when Hash
105
+ struct_values = {}
106
+ json.each do |k, v|
107
+ case k
108
+ when String, Symbol
109
+ struct_values[k.to_sym] = json_to_struct(v)
108
110
  end
109
111
  end
110
- when Hash
111
- json.to_struct
112
+ unless struct_values.empty?
113
+ Struct.new(*struct_values.keys).new(*struct_values.values)
114
+ else
115
+ nil
116
+ end
112
117
  else
113
118
  json
114
119
  end
@@ -104,5 +104,29 @@ class Rubytter
104
104
  @rubytter.followers_ids('test')
105
105
  end
106
106
 
107
+ it 'should create struct from json' do
108
+ hash = {
109
+ :a => 'a',
110
+ 'b' => 1,
111
+ 1 => 'a',
112
+ /regex/ => 'regex',
113
+ nil => nil,
114
+ :c => {:a => 1, :b => 2},
115
+ :d => {:a => {:a => 1, :b => 2}, :b => 1},
116
+ :e => [{:a => 1, :b => 2}, {:c => 3}]
117
+ }
118
+ struct = @rubytter.json_to_struct(hash)
119
+ struct.a.should == 'a'
120
+ struct.b.should == 1
121
+ struct.c.a.should == 1
122
+ struct.c.b.should == 2
123
+ struct.d.a.a.should == 1
124
+ struct.e[0].a.should == 1
125
+ struct.e[0].b.should == 2
126
+ struct.e[1].c.should == 3
127
+ lambda {struct.x}.should raise_error(NoMethodError)
128
+ lambda {struct.regex}.should raise_error(NoMethodError)
129
+ end
130
+
107
131
  end
108
132
  end
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.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -13,7 +13,7 @@ date: 2009-02-05 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: json
16
+ name: json_pure
17
17
  version_requirement:
18
18
  version_requirements: !ruby/object:Gem::Requirement
19
19
  requirements: