-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli
executable file
·108 lines (74 loc) · 2.23 KB
/
cli
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/home/crisdias/.rbenv/shims/ruby
require 'bundler/setup'
require 'rubygems'
require 'paapi'
require 'pp'
require 'json'
require 'rubygems'
require 'liquid'
require 'babosa'
require 'cloudinary'
require 'yourls'
require 'thor'
require 'nokogiri'
require 'open-uri'
require './src/cli/utils.rb'
require './src/cli/amazon.rb'
require './src/cli/youtube.rb'
require './src/cli/link.rb'
require './src/cli/cloudinary.rb'
require './src/cli/render.rb'
puts "\n" * 15
class CrisCLI < Thor
desc "hello NAME", "say hello to NAME"
def hello(name)
puts "Hello #{name}"
end
### AMAZON
desc "amazon URL", "Cria post a partir de um LIVRO na Amazon"
def amazon(link)
# get ASIN from Amazon link
if link.include? 'amazon.com'
if link =~ /\/dp\//
asin = link.split('/dp/')[1].split('/')[0].split('?')[0]
# elsif link =~ /\/gp\//
# asin = link.split('/gp/')[1].split('/')[1]
else
raise "Link inválido"
end
else
asin = link
end
data = amazon_grabber(asin)
yourls = Yourls::Client.new(ENV['YOURLS_URL'], ENV['YOURLS_TOKEN'], {offset: 0})
data['shorturl'] = yourls.shorten(data['linkto'], title: data['titulo']).short_url
data['cloudinary'] = cloudinary_upload(data)
post_render(data)
end
### YOUTUBE
desc "youtube URL", "Cria post a partir de um vídeo do YouTube"
def youtube(link)
# get ASIN from Amazon link
if (link.include? 'youtube.com') || (link.include? 'youtu.be')
# get youtube thumbnail image url from link
data = youtube_grabber(link)
else
raise "Link inválido"
end
yourls = Yourls::Client.new(ENV['YOURLS_URL'], ENV['YOURLS_TOKEN'], {offset: 0})
data['shorturl'] = yourls.shorten(data['linkto'], title: data['titulo']).short_url
data['cloudinary'] = cloudinary_upload(data)
post_render(data)
end
### LINK
desc "link URL", "Cria post a partir de um link"
def link(link)
data = link_grabber(link)
yourls = Yourls::Client.new(ENV['YOURLS_URL'], ENV['YOURLS_TOKEN'], {offset: 0})
data['shorturl'] = yourls.shorten(data['linkto'], title: data['titulo']).short_url
data['cloudinary'] = cloudinary_upload(data)
post_render(data)
end
end
CrisCLI.start(ARGV)
exit