Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit dde52f7

Browse files
author
Andrej Jančič
committed
expand endpoints and add support for params handling
1 parent d413ecc commit dde52f7

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

lib/creatubbles/base_collection.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ def init_objects response
2222
Creatubbles.instantiate_objects_from_response(response, @connection)
2323
end
2424

25+
def handle_params params_hash={}, allowed_params=['query','filter']
26+
params_hash.stringify_keys!.slice!(allowed_params).to_param
27+
end
28+
2529
end

lib/creatubbles/contents.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ class Creatubbles::Contents < Creatubbles::BaseCollection
44

55
define_type_name 'contents'
66

7-
def index params_hash = {"query": nil}
8-
params_hash.stringify_keys!.slice!("query")
9-
init_objects @connection.get("contents?#{params_hash.to_param}")
7+
def index params = {}
8+
init_objects @connection.get("contents?#{handle_params(params)}")
109
end
1110

1211
def recent
@@ -25,4 +24,12 @@ def followed
2524
init_objects @connection.get('contents/followed')
2625
end
2726

27+
def by_user user_id
28+
init_objects @connection.get("users/#{user_id}/contents")
29+
end
30+
31+
def bubbled_by_user user_id
32+
init_objects @connection.get("users/#{user_id}/bubbled_contents")
33+
end
34+
2835
end

lib/creatubbles/creations.rb

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,39 @@ class Creatubbles::Creations < Creatubbles::BaseCollection
44

55
define_type_name 'creations'
66

7-
# TODO update API endpoint
7+
def index params
8+
init_objects @connection.get("creations?handle_params(params)")
9+
end
10+
811
def recent
9-
res = @connection.get("creations")
10-
Creatubbles.instantiate_objects_from_response(res, @connection)
12+
init_objects @connection.get("creations")
13+
end
14+
15+
def from_gallery gallery_id
16+
init_objects @connection.get("galleries/#{gallery_id}/creations")
17+
end
18+
19+
def by_user user_id
20+
init_objects @connection.get("users/#{user_id}/creations")
21+
end
22+
23+
def by_partner_application partner_application_id
24+
init_objects @connection.get("by_partner_application/#{partner_application_id}/creations")
25+
end
26+
27+
def recommended_for_creation creation_id
28+
init_objects @connection.get("creations/#{creation_id}/recommended_creations")
29+
end
30+
31+
def recommended_for_user user_id
32+
init_objects @connection.get("users/#{user_id}/recommended_creations")
1133
end
1234

1335
def create(name: nil, description: nil)
14-
res = @connection.post('creations', :params => { 'name' => name, 'reflection_text' => description })
15-
Creatubbles.instantiate_object_from_response(res, @connection)
36+
init_objects @connection.post('creations', :params => { 'name' => name, 'reflection_text' => description })
1637
end
17-
38+
1839
def find_by_ids(ids)
19-
res = @connection.get("creations?filter[ids]=#{ids.join(',')}")
20-
Creatubbles.instantiate_objects_from_response(res, @connection)
40+
init_objects @connection.get("creations?filter[ids]=#{ids.join(',')}")
2141
end
2242
end

0 commit comments

Comments
 (0)