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 +2 -4
- data/examples/friends_timeline.rb +1 -1
- data/lib/rubytter.rb +12 -7
- data/spec/rubytter_spec.rb +24 -0
- metadata +2 -2
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
|
44
|
-
puts "#{status
|
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:
|
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
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
|
-
|
111
|
-
|
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
|
data/spec/rubytter_spec.rb
CHANGED
@@ -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.
|
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:
|
16
|
+
name: json_pure
|
17
17
|
version_requirement:
|
18
18
|
version_requirements: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|