Skip to content

Commit 7527db1

Browse files
author
julianfoo
committed
WIP: Refactor Expansions object
1 parent a0e1992 commit 7527db1

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

lib/tweetkit/response.rb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def extract_and_save_meta
3939
end
4040

4141
def extract_and_save_expansions
42-
@expansions = @response['includes']
42+
@expansions = Expansions.new(@response['includes'])
4343
end
4444

4545
def extract_and_save_options(**options)
@@ -186,7 +186,33 @@ def initialize(expansions)
186186
@places = expansions['places']
187187
@polls = expansions['polls']
188188
@tweets = expansions['tweets']
189-
@users = expansions['users']
189+
@users = Users.new(expansions['users'])
190+
end
191+
192+
class Tweets
193+
attr_accessor :tweets
194+
195+
def initialize(tweets)
196+
@tweets = tweets.collect { |tweet| Tweet.new(tweet) }
197+
end
198+
end
199+
200+
class Users
201+
attr_accessor :users
202+
203+
def initialize(users)
204+
@users = users.collect { |user| User.new(user) }
205+
end
206+
207+
class User
208+
attr_accessor :id, :name, :username
209+
210+
def initialize(user)
211+
@id = user['id']
212+
@name = user['name']
213+
@username = user['username']
214+
end
215+
end
190216
end
191217
end
192218

0 commit comments

Comments
 (0)