wfhcli 0.3.0 → 0.3.1

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.
Files changed (4) hide show
  1. data/README.md +53 -0
  2. data/bin/wfhcli +5 -5
  3. data/lib/wfhcli.rb +33 -24
  4. metadata +3 -2
@@ -0,0 +1,53 @@
1
+ # wfhcli
2
+
3
+ wfhcli is a CLI tool to query [WFH.io](https://www.wfh.io)'s JSON API.
4
+
5
+ ## Usage Examples
6
+
7
+ List latest jobs:
8
+
9
+ ```
10
+ wfhcli jobs
11
+ ```
12
+
13
+ The above results are returned paged, with 30 jobs per page. To view additional pages:
14
+
15
+ ```
16
+ wfhcli jobs --page 2
17
+ ```
18
+
19
+ List categories:
20
+
21
+ ```
22
+ wfhcli categories
23
+ ```
24
+
25
+ List jobs by category:
26
+
27
+ ```
28
+ wfhcli jobs --category 3
29
+ ```
30
+
31
+ Show job details:
32
+
33
+ ```
34
+ wfhcli job 994
35
+ ```
36
+
37
+ List companies:
38
+
39
+ ```
40
+ wfhcli companies
41
+ ```
42
+
43
+ Similar to `wfhcli jobs`, you can also page through companies:
44
+
45
+ ```
46
+ wfhcli companies --page 2
47
+ ```
48
+
49
+ Show company details:
50
+
51
+ ```
52
+ wfhcli company 536
53
+ ```
data/bin/wfhcli CHANGED
@@ -9,23 +9,23 @@ class WfhCli < Thor
9
9
  super
10
10
  end
11
11
 
12
- desc "categories", "List categories"
12
+ desc 'categories', 'List categories'
13
13
  def categories
14
14
  @wfh.list_categories
15
15
  end
16
16
 
17
- desc "companies", "List companies"
17
+ desc 'companies', 'List companies'
18
18
  option :page
19
19
  def companies
20
20
  @wfh.list_companies(options[:page])
21
21
  end
22
22
 
23
- desc "company ID", "Show company with ID"
23
+ desc 'company ID', 'Show company with ID'
24
24
  def company(id)
25
25
  @wfh.show_company(id)
26
26
  end
27
27
 
28
- desc "jobs", "List jobs"
28
+ desc 'jobs', 'List jobs'
29
29
  option :category
30
30
  option :page
31
31
  def jobs
@@ -36,7 +36,7 @@ class WfhCli < Thor
36
36
  end
37
37
  end
38
38
 
39
- desc "job ID", "Show job with ID"
39
+ desc 'job ID', 'Show job with ID'
40
40
  def job(id)
41
41
  @wfh.show_job(id)
42
42
  end
@@ -4,11 +4,12 @@ require 'rest-client'
4
4
  require 'thor'
5
5
 
6
6
  class WfhLib
7
- TITLE_COLOUR = :magenta
8
- URL = 'https://www.wfh.io/api'
7
+ attr_accessor :title_colour, :url
9
8
 
10
9
  def initialize
11
10
  @shell = Thor::Shell::Color.new
11
+ @title_colour = :magenta
12
+ @url = 'https://www.wfh.io/api'
12
13
  end
13
14
 
14
15
  # TODO: Make private once we are able to properly test methods which use
@@ -25,8 +26,8 @@ class WfhLib
25
26
  def generate_table(content)
26
27
  cell_widths = Array.new(content[0].size, 0)
27
28
 
28
- # We do cell.to_s.size as cell could be an integer and 8.size == 8, which is
29
- # not what we want.
29
+ # We do cell.to_s.size as cell could be an integer and 8.size == 8,
30
+ # which is not what we want.
30
31
  content.each do |row|
31
32
  row.each_with_index do |cell, index|
32
33
  if cell.to_s.size > cell_widths[index]
@@ -35,24 +36,24 @@ class WfhLib
35
36
  end
36
37
  end
37
38
 
38
- lines = ""
39
+ lines = ''
39
40
 
40
41
  content.each_with_index do |row, row_index|
41
42
  if row_index == 1
42
- lines << "|"
43
+ lines << '|'
43
44
  cell_widths.each do |c|
44
45
  # We use c + 2 to account for the spaces inside each cell
45
- lines << "-" * (c + 2)
46
- lines << "|"
46
+ lines << '-' * (c + 2)
47
+ lines << '|'
47
48
  end
48
49
  lines << "\n"
49
50
  end
50
- lines << "|"
51
+ lines << '|'
51
52
  row.each_with_index do |cell, cell_index|
52
53
  formatted = cell.to_s.ljust(cell_widths[cell_index])
53
54
 
54
55
  if row_index == 0
55
- lines << " #{@shell.set_color(formatted, TITLE_COLOUR)} |"
56
+ lines << " #{@shell.set_color(formatted, @title_colour)} |"
56
57
  else
57
58
  lines << " #{formatted} |"
58
59
  end
@@ -67,7 +68,10 @@ class WfhLib
67
68
  # use this method.
68
69
  def get_json(uri)
69
70
  begin
70
- r = RestClient.get "#{URL}#{uri}", {:accept => :json}
71
+ r = RestClient.get "#{@url}#{uri}", { accept: :json }
72
+ rescue RestClient::ResourceNotFound
73
+ puts "The resource #{uri} was not found"
74
+ exit!
71
75
  rescue => e
72
76
  puts e
73
77
  exit!
@@ -81,7 +85,7 @@ class WfhLib
81
85
 
82
86
  if categories.size > 0
83
87
  content = []
84
- content[0] = ['ID', 'Name']
88
+ content[0] = %w{ID Name}
85
89
 
86
90
  categories.each do |category|
87
91
  content << [category['id'], category['name']]
@@ -101,7 +105,7 @@ class WfhLib
101
105
 
102
106
  if companies.size > 0
103
107
  content = []
104
- content[0] = ['ID', 'Name']
108
+ content[0] = %w{ID Name}
105
109
 
106
110
  companies.each do |company|
107
111
  content << [company['id'], company['name']]
@@ -114,7 +118,7 @@ class WfhLib
114
118
  end
115
119
 
116
120
  def list_jobs(page=nil, category_id=nil)
117
- if category_id == nil
121
+ if category_id.nil?
118
122
  uri = '/jobs'
119
123
  uri = uri + "?page=#{page}" if page
120
124
  else
@@ -126,7 +130,7 @@ class WfhLib
126
130
 
127
131
  if jobs.size > 0
128
132
  content = []
129
- content[0] = ['ID', 'Posted', 'Category', 'Company', 'Title']
133
+ content[0] = %w{ID Posted Category Company Title}
130
134
 
131
135
  jobs.each do |job|
132
136
  content << [job['id'],
@@ -145,7 +149,7 @@ class WfhLib
145
149
  # TODO: Make private once we are able to properly test methods which use
146
150
  # use this method.
147
151
  def generate_header_and_body(title, body)
148
- "#{@shell.set_color(title, TITLE_COLOUR)}\n#{body}"
152
+ "#{@shell.set_color(title, @title_colour)}\n#{body}"
149
153
  end
150
154
 
151
155
  def show_company(company_id)
@@ -156,29 +160,34 @@ class WfhLib
156
160
  unless company['country'].nil?
157
161
  puts generate_header_and_body('Headquarters', company['country']['name'])
158
162
  end
159
- unless company['twitter'].nil? or company['twitter'].empty?
163
+ unless company['twitter'].nil? || company['twitter'].empty?
160
164
  puts generate_header_and_body('Twitter', company['twitter'])
161
165
  end
162
- unless company['showcase_url'].nil? or company['showcase_url'].empty?
166
+ unless company['showcase_url'].nil? || company['showcase_url'].empty?
163
167
  puts generate_header_and_body('Showcase URL', company['showcase_url'])
164
168
  end
165
169
  end
166
170
 
167
171
  def show_job(job_id)
168
172
  job = get_json("/jobs/#{job_id}")
169
- if job['country'].nil? or job['country'].empty?
173
+ if job['country'].nil? || job['country'].empty?
170
174
  country = 'Anywhere'
171
175
  else
172
176
  country = job['country']['name']
173
177
  end
174
178
 
175
- puts generate_header_and_body('Title', "#{job['title']} @ #{job['company']['name']}")
176
- puts generate_header_and_body('Category', "#{job['category']['name']} (#{job['category']['id']})")
177
- puts generate_header_and_body('Posted', format_date(job['created_at'], inc_time=true))
179
+ title = "#{job['title']} @ #{job['company']['name']} " \
180
+ "(#{job['company']['id']})"
181
+ category = "#{job['category']['name']} (#{job['category']['id']})"
182
+ posted = format_date(job['created_at'], true)
183
+
184
+ puts generate_header_and_body('Title', title)
185
+ puts generate_header_and_body('Category', category)
186
+ puts generate_header_and_body('Posted', posted)
178
187
  puts generate_header_and_body('Description', job['description'])
179
188
  puts generate_header_and_body('Application Info', job['application_info'])
180
189
  puts generate_header_and_body('Country', country)
181
- unless job['location'].nil? or job['location'].empty?
190
+ unless job['location'].nil? || job['location'].empty?
182
191
  puts generate_header_and_body('Location', job['location'])
183
192
  end
184
193
  end
@@ -187,7 +196,7 @@ class WfhLib
187
196
  # use this method.
188
197
  def truncate(str, len)
189
198
  if str.size > len
190
- str[0..(len-4)] + "..."
199
+ str[0..(len - 4)] + '...'
191
200
  else
192
201
  str
193
202
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wfhcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-03 00:00:00.000000000 Z
12
+ date: 2015-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -50,6 +50,7 @@ executables:
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
+ - README.md
53
54
  - lib/wfhcli.rb
54
55
  - bin/wfhcli
55
56
  homepage: https://github.com/wfhio/wfhcli