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

Commit 9befbcc

Browse files
author
Michael Reinsch
committed
improve listing creations
1 parent 1b7101e commit 9befbcc

File tree

5 files changed

+82
-3
lines changed

5 files changed

+82
-3
lines changed

bin/ctb_list_creations

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ auth_details = {
1414
password: ENV['CREATUBBLES_PASSWORD']
1515
}
1616

17+
list_for = nil
18+
list_for_id = nil
19+
1720
opt_parser = OptionParser.new do |opt|
1821
opt.banner = "Usage: ctb_list_creators [OPTIONS]"
1922
opt.separator ""
@@ -33,6 +36,20 @@ opt_parser = OptionParser.new do |opt|
3336
auth_details[:password] = password
3437
end
3538

39+
opt.on("--user id","list creations for user id (use 'me' for logged in user)") do |user_id|
40+
list_for = :users
41+
list_for_id = user_id
42+
end
43+
44+
opt.on("--app slug","partner application") do |app_slug|
45+
list_for = :partner_applications
46+
list_for_id = app_slug
47+
end
48+
49+
opt.on("--recent","list recent creations (default)") do
50+
list_for = nil
51+
end
52+
3653
opt.on("-h","--help","help") do
3754
puts opt_parser
3855
exit
@@ -43,8 +60,16 @@ opt_parser.parse!
4360

4461
if auth_details[:username] && auth_details[:password]
4562
client = Creatubbles::Client.new(auth_details)
46-
me = client.users.me
47-
me.creations.each do |creation|
63+
64+
creations =
65+
if list_for
66+
base = client.send(list_for).find(list_for_id)
67+
base.creations
68+
else
69+
client.creations.recent
70+
end
71+
72+
creations.each do |creation|
4873
puts "#{creation.id} - #{creation.name}"
4974
end
5075
else

lib/creatubbles.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,7 @@ def self.instantiate_objects_from_response(response, connection)
4545
require "creatubbles/galleries"
4646
require "creatubbles/user"
4747
require "creatubbles/users"
48+
require "creatubbles/partner_application"
49+
require "creatubbles/partner_applications"
4850

4951
require "creatubbles/client"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require "creatubbles/base_object"
2+
3+
class Creatubbles::PartnerApplication < Creatubbles::BaseObject
4+
5+
define_type_name 'partner_applications'
6+
define_attributes %w[
7+
name
8+
slug
9+
short_url
10+
header_bg
11+
body_bg
12+
owner_name
13+
description
14+
cta_logged_in_label
15+
cta_logged_out_label
16+
reqeust_cta_for_youngsters
17+
cta_for_youngsters_label
18+
cta_href
19+
categories
20+
age
21+
languages
22+
support
23+
developers
24+
platforms
25+
show_other_apps
26+
display_creations_nr
27+
about_card_text
28+
meta_title
29+
meta_description
30+
meta_keywords
31+
meta_og_title
32+
meta_og_description
33+
meta_og_type
34+
meta_og_image
35+
avatar_url
36+
created_at
37+
updated_at
38+
]
39+
40+
# TODO update API endpoint
41+
def creations
42+
res = @connection.get("creations?partner_application_id=#{slug}")
43+
Creatubbles.instantiate_objects_from_response(res, @connection)
44+
end
45+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "creatubbles/base_collection"
2+
3+
class Creatubbles::PartnerApplications < Creatubbles::BaseCollection
4+
5+
define_type_name 'partner_applications'
6+
7+
end

lib/creatubbles/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def creators
2424

2525
# TODO update API endpoint
2626
def creations
27-
res = @connection.get("creations", user_id: id)
27+
res = @connection.get("creations?user_id=#{id}")
2828
Creatubbles.instantiate_objects_from_response(res, @connection)
2929
end
3030
end

0 commit comments

Comments
 (0)