-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.rb
69 lines (53 loc) · 1.73 KB
/
controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require_relative 'cass'
class Controller
@@db = Cass.new
# User actions
def self.create_user(firstname, lastname, username, password)
@@db.save_user(firstname, lastname, username, password)
end
def self.remove_user(username)
@@db.remove_user(username)
end
def self.get_user(username)
@@db.get_user_by_username(username)
end
# Friend actions
def self.get_friends(username)
@@db.get_friends(username)
end
def self.get_followers(username)
@@db.get_followers(username)
end
def self.add_friend(username, friend_username)
@@db.add_friend(username, friend_username)
end
def self.remove_friend(username, friend_username)
@@db.remove_friend(username, friend_username)
end
# Activity retrieval
def self.get_user_tweets(username, paging_state, direction)
# Check edge case where returning to first page
if direction == "previous" && paging_state[-3] == nil
return @@db.get_usertweets(username, paging_state, "new_query")
end
@@db.get_usertweets(username, paging_state, direction)
end
def self.get_activity_feed(username, paging_state, direction)
# Check edge case where returning to first page
if direction == "previous" && paging_state[-3] == nil
return @@db.get_timeline(username, paging_state, "new_query")
end
@@db.get_timeline(username, paging_state, direction)
end
# Tweets
def self.create_new_tweet(username, tweet)
generator = Cassandra::Uuid::Generator.new
tweet_id = generator.uuid
@@db.save_tweet(tweet_id, username, tweet)
end
def self.remove_tweet(username, tweet_id, time)
tweet_id = Cassandra::Uuid.new(tweet_id)
time = Cassandra::TimeUuid.new(time)
@@db.remove_tweet(tweet_id, username, time)
end
end