lard 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/lard +160 -58
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb8adc7d1714d35d1dbf4407d142a7344dc46d4be2d0f2cf5a6ea7c0b064b683
|
4
|
+
data.tar.gz: 0b68c1d08cc99264b70e77e2f087044e5a6459c4865fb28209eb915dbbd07b73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34d871021eab9850c6c5c4a16e5c39e18367bd6674c7fa7faa413219044c088ce63f73ed68fbeb5567d33ea15bbd453f67928f025d6b905a2d250b8dae99af84
|
7
|
+
data.tar.gz: 325d73f06dfff40b8617cfbdbc71d3e55895e1c5f01800c8b9aaf070f56af462db7d59f325e678edd3a4c2afd8b89358f3e192267281ab325ef74d2020c516ce
|
data/bin/lard
CHANGED
@@ -29,53 +29,37 @@ $options = {
|
|
29
29
|
}
|
30
30
|
$folders = []
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
puts get('user')
|
32
|
+
module LardHTTP
|
33
|
+
def get(endpoint, params = nil)
|
34
|
+
query = { query: params }
|
35
|
+
opts = $options.merge query
|
36
|
+
res = self.class.get "#{prefix}#{endpoint}", opts
|
37
|
+
parse_response res
|
39
38
|
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
$folders.each do |folder|
|
48
|
-
print_folder_name folder
|
49
|
-
end
|
40
|
+
def post(endpoint, args = {})
|
41
|
+
opts = { body: args.to_json, headers: {"Content-Type" => "application/json"} }
|
42
|
+
opts[:headers].merge! $options[:headers]
|
43
|
+
res = self.class.post "#{prefix}#{endpoint}", opts
|
44
|
+
parse_response res
|
50
45
|
end
|
51
46
|
|
52
|
-
|
53
|
-
|
54
|
-
folder = get_folder_by_name name
|
55
|
-
raise "No such folder" unless folder
|
56
|
-
|
57
|
-
print_folder_name folder
|
58
|
-
|
59
|
-
bookmarks = fetch_bookmarks folder[:id]
|
60
|
-
bookmarks.each do |bookmark|
|
61
|
-
print_bookmark bookmark
|
62
|
-
end
|
47
|
+
def parse_response(res)
|
48
|
+
JSON.parse res.body, symbolize_names: true
|
63
49
|
end
|
64
50
|
|
65
|
-
|
51
|
+
def raw_get(url)
|
52
|
+
JSON.parse self.class.get(url, $options).body, symbolize_names: true
|
53
|
+
end
|
66
54
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
unless
|
73
|
-
|
74
|
-
|
75
|
-
print Paint["##{tag[:name]}", tag[:color]]
|
76
|
-
print " "
|
77
|
-
end
|
78
|
-
puts " "
|
55
|
+
def prefix
|
56
|
+
'https://larder.io/api/1/@me/'
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_folder_by_name(name)
|
60
|
+
fetch_folders unless $folders.length > 0
|
61
|
+
$folders.find do |folder|
|
62
|
+
folder[:name] == name
|
79
63
|
end
|
80
64
|
end
|
81
65
|
|
@@ -84,8 +68,19 @@ class Lard < Thor
|
|
84
68
|
puts ":\t#{folder[:links]} links"
|
85
69
|
end
|
86
70
|
|
71
|
+
def fetch_tags
|
72
|
+
res = get 'tags', { limit: 100 }
|
73
|
+
tags = res[:results] || []
|
74
|
+
|
75
|
+
while res[:next] != nil
|
76
|
+
res = raw_get res[:next]
|
77
|
+
tags.push *res[:results]
|
78
|
+
end
|
79
|
+
|
80
|
+
tags
|
81
|
+
end
|
82
|
+
|
87
83
|
def fetch_bookmarks(folder_id)
|
88
|
-
# TODO: Verify pagination logic
|
89
84
|
res = get "folders/#{folder_id}", { limit: 100 }
|
90
85
|
bookmarks = res[:results] || []
|
91
86
|
|
@@ -98,39 +93,146 @@ class Lard < Thor
|
|
98
93
|
end
|
99
94
|
|
100
95
|
def fetch_folders
|
101
|
-
|
102
|
-
res = get 'folders'
|
96
|
+
res = get 'folders', { limit: 100 }
|
103
97
|
$folders = res[:results]
|
104
98
|
|
105
99
|
while res[:next] != nil
|
106
|
-
|
107
|
-
res = get 'folders', params
|
100
|
+
res = raw_get res[:next]
|
108
101
|
$folders.push *res[:results]
|
109
102
|
end
|
110
103
|
|
111
104
|
# TODO: Cache these folders
|
112
105
|
end
|
106
|
+
|
107
|
+
def print_bookmark(bookmark)
|
108
|
+
puts Paint["#{bookmark[:title]}", :bright]
|
109
|
+
puts " #{bookmark[:description]}" if bookmark[:description]
|
110
|
+
puts " #{bookmark[:url]}"
|
111
|
+
|
112
|
+
unless bookmark[:tags].empty?
|
113
|
+
print " "
|
114
|
+
bookmark[:tags].each do |tag|
|
115
|
+
print Paint["##{tag[:name]}", tag[:color]]
|
116
|
+
print " "
|
117
|
+
end
|
118
|
+
puts " "
|
119
|
+
end
|
120
|
+
end
|
113
121
|
|
114
|
-
def
|
115
|
-
|
116
|
-
|
117
|
-
|
122
|
+
def print_tag(tag)
|
123
|
+
puts Paint["##{tag[:name]}", tag[:color]]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
class Bookmark < Thor
|
128
|
+
include LardHTTP
|
129
|
+
include HTTParty
|
130
|
+
maintain_method_across_redirects
|
131
|
+
|
132
|
+
desc 'new <FOLDER> <TITLE> <LINK> [tags...]', 'Creates a new bookmark'
|
133
|
+
option :description, :aliases => :d
|
134
|
+
def new(folder, title, link, *tags)
|
135
|
+
f = get_folder_by_name folder
|
136
|
+
raise "No such folder" unless f
|
137
|
+
parent = f[:id]
|
138
|
+
|
139
|
+
res = post 'links/add', {
|
140
|
+
"title" => title,
|
141
|
+
"url" => link,
|
142
|
+
"parent" => parent,
|
143
|
+
"description" => options[:description],
|
144
|
+
"tags" => tags
|
145
|
+
}
|
146
|
+
unless res[:error]
|
147
|
+
print_bookmark res
|
148
|
+
else
|
149
|
+
# TODO: Test this
|
150
|
+
raise "Unable to add bookmark"
|
118
151
|
end
|
119
152
|
end
|
120
153
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
154
|
+
# Note that this uses the same endpoint as 'new'
|
155
|
+
# simply for the purpose of looking up bookmarks
|
156
|
+
# by the link and not proprietary ID
|
157
|
+
#desc 'edit <LINK> [tags...]', 'Edits an existing bookmark'
|
158
|
+
#option :title, :aliases => :t
|
159
|
+
#option :folder, :aliases => :f
|
160
|
+
#option :description, :aliases => :d
|
161
|
+
#def edit(link, *tags)
|
162
|
+
# f = get_folder_by_name options[:folder]
|
163
|
+
# raise "No such folder" unless f
|
164
|
+
# parent = f[:id]
|
165
|
+
|
166
|
+
# res = post 'links/add', {
|
167
|
+
# "title" => options[:title],
|
168
|
+
# "url" => link,
|
169
|
+
# "parent" => parent,
|
170
|
+
# "description" => options[:description],
|
171
|
+
# "tags" => tags
|
172
|
+
# }
|
173
|
+
# unless res[:error]
|
174
|
+
# print_bookmark res
|
175
|
+
# else
|
176
|
+
# # TODO: Test this
|
177
|
+
# raise "Unable to add bookmark"
|
178
|
+
# end
|
179
|
+
#end
|
180
|
+
end
|
181
|
+
|
182
|
+
class Lard < Thor
|
183
|
+
include LardHTTP
|
184
|
+
include HTTParty
|
185
|
+
maintain_method_across_redirects
|
186
|
+
|
187
|
+
desc "bookmark <COMMAND>", "Manage individual bookmarks"
|
188
|
+
subcommand "bookmark", Bookmark
|
189
|
+
|
190
|
+
desc 'user', 'Prints information about the logged-in user'
|
191
|
+
def user
|
192
|
+
puts get('user')
|
126
193
|
end
|
127
194
|
|
128
|
-
|
129
|
-
|
195
|
+
desc 'folders', 'Lists all bookmark folders'
|
196
|
+
def folders
|
197
|
+
if $folders == []
|
198
|
+
fetch_folders
|
199
|
+
end
|
200
|
+
|
201
|
+
$folders.each do |folder|
|
202
|
+
print_folder_name folder
|
203
|
+
end
|
130
204
|
end
|
131
205
|
|
132
|
-
|
133
|
-
|
206
|
+
desc 'folder <NAME>', 'Lists all bookmarks in a given folder'
|
207
|
+
def folder(name)
|
208
|
+
folder = get_folder_by_name name
|
209
|
+
raise "No such folder" unless folder
|
210
|
+
|
211
|
+
print_folder_name folder
|
212
|
+
|
213
|
+
bookmarks = fetch_bookmarks folder[:id]
|
214
|
+
bookmarks.each do |bookmark|
|
215
|
+
print_bookmark bookmark
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
desc 'tags', 'Lists all tags'
|
220
|
+
def tags
|
221
|
+
tags = fetch_tags
|
222
|
+
tags.each do |tag|
|
223
|
+
print_tag tag
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
desc 'search <QUERY>', 'Search for bookmarks'
|
228
|
+
def search(*args)
|
229
|
+
query = args.join ' '
|
230
|
+
res = get 'search', { q: query }
|
231
|
+
raise "No results for query #{query}" unless res[:results].length > 0
|
232
|
+
bookmarks = res[:results]
|
233
|
+
bookmarks.each do |b|
|
234
|
+
print_bookmark b
|
235
|
+
end
|
134
236
|
end
|
135
237
|
end
|
136
238
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hawkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|