Class: WfhLib
- Inherits:
-
Object
- Object
- WfhLib
- Defined in:
- lib/wfhcli.rb
Instance Attribute Summary collapse
-
#title_colour ⇒ Object
Returns the value of attribute title_colour.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #categories ⇒ Object
- #companies(page = 1) ⇒ Object
- #company(id) ⇒ Object
- #display_categories ⇒ Object
- #display_companies(page) ⇒ Object
- #display_company(company_id) ⇒ Object
- #display_job(job_id) ⇒ Object
- #display_jobs(page, category_id = nil, source_id = nil) ⇒ Object
- #display_sources ⇒ Object
-
#initialize ⇒ WfhLib
constructor
A new instance of WfhLib.
- #job(id) ⇒ Object
- #jobs(page = 1, category_id = nil, source_id = nil) ⇒ Object
- #sources ⇒ Object
Constructor Details
#initialize ⇒ WfhLib
Returns a new instance of WfhLib.
9 10 11 12 13 |
# File 'lib/wfhcli.rb', line 9 def initialize @shell = Thor::Shell::Color.new @title_colour = :magenta @url = 'https://www.wfh.io/api' end |
Instance Attribute Details
#title_colour ⇒ Object
Returns the value of attribute title_colour.
7 8 9 |
# File 'lib/wfhcli.rb', line 7 def title_colour @title_colour end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/wfhcli.rb', line 7 def url @url end |
Instance Method Details
#categories ⇒ Object
15 16 17 |
# File 'lib/wfhcli.rb', line 15 def categories get_json('/categories') end |
#companies(page = 1) ⇒ Object
23 24 25 26 27 |
# File 'lib/wfhcli.rb', line 23 def companies(page=1) uri = "/companies?page=#{page}" get_json(uri) end |
#company(id) ⇒ Object
19 20 21 |
# File 'lib/wfhcli.rb', line 19 def company(id) get_json("/companies/#{id}") end |
#display_categories ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/wfhcli.rb', line 29 def display_categories categories = self.categories if categories.size > 0 content = [] content[0] = %w{ID Name} categories.each do |category| content << [category['id'], category['name']] end generate_table(content) else 'No categories found' end end |
#display_companies(page) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/wfhcli.rb', line 65 def display_companies(page) companies = self.companies(page) if companies.size > 0 content = [] content[0] = %w{ID Name} companies.each do |company| content << [company['id'], company['name']] end generate_table(content) else 'No companies found' end end |
#display_company(company_id) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/wfhcli.rb', line 46 def display_company(company_id) content = [] company = self.company(company_id) content << ['Name', company['name']] content << ['URL', company['url']] unless company['country'].nil? content << ['Headquarters', company['country']['name']] end unless company['twitter'].nil? || company['twitter'].empty? content << ['Twitter', company['twitter']] end unless company['showcase_url'].nil? || company['showcase_url'].empty? content << ['Showcase URL', company['showcase_url']] end return generate_header_and_body(content) end |
#display_job(job_id) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/wfhcli.rb', line 82 def display_job(job_id) content = [] job = self.job(job_id) if job['country'].nil? || job['country'].empty? country = 'Anywhere' else country = job['country']['name'] end title = "#{job['title']} @ #{job['company']['name']} " \ "(#{job['company']['id']})" category = "#{job['category']['name']} (#{job['category']['id']})" posted = format_date(job['created_at'], true) content << ['Title', title] content << ['Category', category] content << ['Posted', posted] content << ['Description', job['description']] content << ['Application Info', job['application_info']] content << ['Country', country] unless job['location'].nil? || job['location'].empty? content << ['Location', job['location']] end content << ['Source', job['source']['name']] return generate_header_and_body(content) end |
#display_jobs(page, category_id = nil, source_id = nil) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/wfhcli.rb', line 111 def display_jobs(page, category_id=nil, source_id=nil) jobs = self.jobs(page, category_id, source_id) if jobs.size > 0 content = [] content[0] = %w{ID Posted Category Company Title} jobs.each do |job| content << [job['id'], format_date(job['created_at']), "#{job['category']['name']} (#{job['category']['id']})", "#{job['company']['name']} (#{job['company']['id']})", truncate(job['title'], 30)] end generate_table(content) else 'No jobs found' end end |
#display_sources ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/wfhcli.rb', line 132 def display_sources categories = self.sources if sources.size > 0 content = [] content[0] = %w{ID Name URL} sources.each do |source| content << [source['id'], source['name'], source['url']] end generate_table(content) else 'No sources found' end end |
#job(id) ⇒ Object
149 150 151 |
# File 'lib/wfhcli.rb', line 149 def job(id) get_json("/jobs/#{id}") end |
#jobs(page = 1, category_id = nil, source_id = nil) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/wfhcli.rb', line 153 def jobs(page=1, category_id=nil, source_id=nil) uri = "/jobs?page=#{page}&" unless category_id.nil? uri = uri + "category_id=#{category_id}&" end unless source_id.nil? uri = uri + "source_id=#{source_id}" end get_json(uri) end |
#sources ⇒ Object
165 166 167 |
# File 'lib/wfhcli.rb', line 165 def sources get_json('/sources') end |