Class: Kscript::KkHnJobsUtils
- Inherits:
-
Base
- Object
- Base
- Kscript::KkHnJobsUtils
show all
- Defined in:
- lib/kscript/plugins/kk_hn_jobs_utils.rb
Constant Summary
collapse
- HN_JOBS_API =
'https://hacker-news.firebaseio.com/v0/jobstories.json'
- HN_ITEM_API =
'https://hacker-news.firebaseio.com/v0/item'
Instance Attribute Summary
Attributes inherited from Base
#logger
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#human_output?, inherited, #with_error_handling
Constructor Details
#initialize(*args, **opts) ⇒ KkHnJobsUtils
Returns a new instance of KkHnJobsUtils.
13
14
15
16
|
# File 'lib/kscript/plugins/kk_hn_jobs_utils.rb', line 13
def initialize(*args, **opts)
super
@limit = (args[0] || 10).to_i
end
|
Class Method Details
.arguments ⇒ Object
28
29
30
|
# File 'lib/kscript/plugins/kk_hn_jobs_utils.rb', line 28
def self.arguments
'[limit]'
end
|
.author ⇒ Object
40
41
42
|
# File 'lib/kscript/plugins/kk_hn_jobs_utils.rb', line 40
def self.author
'kk'
end
|
.description ⇒ Object
44
45
46
|
# File 'lib/kscript/plugins/kk_hn_jobs_utils.rb', line 44
def self.description
'Fetch and display latest Hacker News jobs: description and url.'
end
|
.group ⇒ Object
36
37
38
|
# File 'lib/kscript/plugins/kk_hn_jobs_utils.rb', line 36
def self.group
'network'
end
|
.usage ⇒ Object
32
33
34
|
# File 'lib/kscript/plugins/kk_hn_jobs_utils.rb', line 32
def self.usage
'kscript hn_jobs [limit]'
end
|
Instance Method Details
#run(*args, **_opts) ⇒ Object
18
19
20
21
22
23
24
25
26
|
# File 'lib/kscript/plugins/kk_hn_jobs_utils.rb', line 18
def run(*args, **_opts)
with_error_handling do
limit = (args[0] || @limit || 10).to_i
logger.kinfo("Fetching latest #{limit} Hacker News jobs...")
job_ids = fetch_job_ids.first(limit)
jobs = job_ids.map { |id| (fetch_job_item(id)) }
display_jobs(jobs)
end
end
|