rainforest-cli 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3eea3ded8136b1db14a83589961e477828630f43
4
- data.tar.gz: c4ddb62a796a3e979c276fb7433e662042bae7ba
3
+ metadata.gz: d643c76641c2871f0f18ea635ffe868546443721
4
+ data.tar.gz: 073a323ecb28931576a27d1a7f352718920a3e83
5
5
  SHA512:
6
- metadata.gz: f4aee39f29541cd65b8952073f97566708a993f046ef1d03cde128ed66591254a8602a9897f69280a2e6b9085c991c193ecfdebb20299c6485dc60d55e5e6634
7
- data.tar.gz: ad432b0a9c7b73b0be7bb7b50bafec82f7b8c1020a967e61b61a40d91aab491f6054a665ec7bc2a72e40004d8e6d6f00f8e9929a16c853f871ccdfad989539c3
6
+ metadata.gz: 6b612e2ff7c36f3a666aa6ce0e15740c6051a6af936a3f117ccef0b87d056e6e1c242c5cae54571b880f0bbc7b573b7cfeb117f1691f2dbb984a26dd8f333d5a
7
+ data.tar.gz: 74af9041c9d0b69815a33588b819cfaf44ed323cff190224fd68bf94ad57fbd101f7d709ce8c887bfdf288da8ac287fc74a7806a1567c38f2086609e91e8d281
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Rainforest CLI Changelog
2
2
 
3
+ ## 1.12.0 - 6th February 2017
4
+ - Add category column to list of sites when using the `sites` command.
5
+
3
6
  ## 1.11.0 - 4th November 2016
4
7
  - Add `--single-use` flag for CSV uploads. (17a19694a788365beb59e634bd7286c86528484b, @epaulet)
5
8
 
@@ -1,49 +1,53 @@
1
1
  # frozen_string_literal: true
2
+ require 'terminal-table'
3
+
2
4
  class RainforestCli::Resources
3
- Resource = Struct.new(:identifier, :name)
5
+ HUMANIZE_SITE_CATEGORIES = {
6
+ 'device_farm' => 'Device Farm',
7
+ 'android' => 'Android',
8
+ 'ios' => 'iOS',
9
+ 'site' => 'Site',
10
+ }.freeze
4
11
 
5
12
  def initialize(options)
6
13
  @client = RainforestCli::HttpClient.new(token: options.token)
7
14
  end
8
15
 
9
16
  def sites
10
- sites = @client.get('/sites').map { |s| Resource.new(s['id'], s['name']) }
17
+ sites = @client.get('/sites').map do |s|
18
+ category = s['category']
19
+ [s['id'], s['name'], HUMANIZE_SITE_CATEGORIES[category] || category]
20
+ end
11
21
 
12
22
  if sites.empty?
13
23
  logger.info('No sites found on your account.')
14
24
  logger.info('Please visit https://app.rainforestqa.com/settings/sites to create and edit your sites.')
15
25
  else
16
- print_table('Site', sites)
26
+ print_table(['Site ID', 'Site Name', 'Category'], sites)
17
27
  end
18
28
  end
19
29
 
20
30
  def folders
21
- folders = @client.get('/folders?page_size=100').map { |f| Resource.new(f['id'], f['title']) }
31
+ folders = @client.get('/folders?page_size=100').map { |f| f.values_at('id', 'title') }
32
+
22
33
  if folders.empty?
23
34
  logger.info('No folders found on your account.')
24
35
  logger.info('Please visit https://app.rainforestqa.com/folders to create and edit your sites.')
25
36
  else
26
- print_table('Folder', folders)
37
+ print_table(['Folder ID', 'Folder Name'], folders)
27
38
  end
28
39
  end
29
40
 
30
41
  def browsers
31
42
  account = @client.get('/clients')
32
- browsers = account['available_browsers'].map { |b| Resource.new(b['name'], b['description']) }
33
- print_table('Browser', browsers)
43
+ browsers = account['available_browsers'].map { |b| b.values_at('name', 'description') }
44
+ print_table(['Browser ID', 'Browser Name'], browsers)
34
45
  end
35
46
 
36
- def print_table(resource_name, resources)
37
- id_col = "#{resource_name} ID"
38
- longest_id = resources.map { |r| r.identifier.to_s }.max_by(&:length)
39
- col_length = [id_col.length, longest_id.length].max
40
-
41
- table_heading = "#{id_col.rjust(col_length)} | #{resource_name} Name"
42
- puts table_heading
43
- puts '-' * table_heading.length
44
- resources.each do |resource|
45
- puts "#{resource.identifier.to_s.rjust(col_length)} | #{resource.name}"
46
- end
47
+ def print_table(headings, rows)
48
+ table = Terminal::Table.new(headings: headings, rows: rows)
49
+ table.align_column(0, :right)
50
+ puts table
47
51
  end
48
52
 
49
53
  private
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module RainforestCli
3
- VERSION = '1.11.0'
3
+ VERSION = '1.12.0'
4
4
  end
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'rainforest', '~> 2.1', '>= 2.1.0'
27
27
  spec.add_dependency 'http-exceptions', '~> 0.0', '>= 0.0.4'
28
28
  spec.add_dependency 'builder', '~> 3.2'
29
+ spec.add_dependency 'terminal-table', '1.7.3'
29
30
  spec.add_development_dependency 'bundler', '~> 1.3'
30
31
  spec.add_development_dependency 'rake', '~> 10.4', '>= 10.4.2'
31
32
  end
@@ -9,10 +9,8 @@ describe RainforestCli::Resources do
9
9
  end
10
10
 
11
11
  it 'calls the print method with the correct information' do
12
- expect(subject).to receive(:print_table) do |_name, resources|
13
- resource = resources.first
14
- expect(resource.identifier).to eq(expected_id)
15
- expect(resource.name).to eq(expected_name)
12
+ expect(subject).to receive(:print_table) do |_headers, rows|
13
+ expect(rows).to eq(expected_rows)
16
14
  end
17
15
 
18
16
  subject.send(tested_method)
@@ -40,13 +38,18 @@ describe RainforestCli::Resources do
40
38
  context 'with sites in account' do
41
39
  let(:api_response) do
42
40
  [
43
- { 'id' => 123, 'name' => 'The Foo Site' },
44
- { 'id' => 456, 'name'=> 'The Bar Site' },
45
- { 'id' => 789, 'name' => 'The Baz Site' }
41
+ { 'id' => 123, 'name' => 'The Foo Site', 'category' => 'cat A' },
42
+ { 'id' => 456, 'name'=> 'The Bar Site', 'category' => 'cat B' },
43
+ { 'id' => 789, 'name' => 'The Baz Site', 'category' => 'cat C' },
44
+ ]
45
+ end
46
+ let(:expected_rows) do
47
+ [
48
+ [123, 'The Foo Site', 'cat A'],
49
+ [456, 'The Bar Site', 'cat B'],
50
+ [789, 'The Baz Site', 'cat C'],
46
51
  ]
47
52
  end
48
- let(:expected_id) { api_response.first['id'] }
49
- let(:expected_name) { api_response.first['name'] }
50
53
 
51
54
  it_should_behave_like 'a properly formatted resource', :sites
52
55
  end
@@ -75,24 +78,28 @@ describe RainforestCli::Resources do
75
78
  [
76
79
  { 'id' => 123, 'title' => 'The Foo Folder' },
77
80
  { 'id' => 456, 'title'=> 'The Bar Folder' },
78
- { 'id' => 789, 'title' => 'The Baz Folder' }
81
+ { 'id' => 789, 'title' => 'The Baz Folder' },
82
+ ]
83
+ end
84
+ let(:expected_rows) do
85
+ [
86
+ [123, 'The Foo Folder'],
87
+ [456, 'The Bar Folder'],
88
+ [789, 'The Baz Folder'],
79
89
  ]
80
90
  end
81
- let(:expected_id) { api_response.first['id'] }
82
- let(:expected_name) { api_response.first['title'] }
83
91
 
84
92
  it_should_behave_like 'a properly formatted resource', :folders
85
93
 
86
-
87
94
  it 'should make a get request for 100 pages' do
95
+ allow(subject).to receive(:print_table)
96
+
88
97
  expect_any_instance_of(RainforestCli::HttpClient).to receive(:get) do |_obj, message|
89
98
  expect(message).to include('page_size=100')
90
99
  end.and_return(api_response)
91
100
  subject.folders
92
101
  end
93
102
  end
94
-
95
-
96
103
  end
97
104
 
98
105
  describe '#browsers' do
@@ -100,36 +107,18 @@ describe RainforestCli::Resources do
100
107
  [
101
108
  { 'name' => 'chrome', 'description' => 'Chrome' },
102
109
  { 'name' => 'safari', 'description' => 'Safari' },
103
- { 'name' => 'firefox', 'description' => 'Firefox' }
110
+ { 'name' => 'firefox', 'description' => 'Firefox' },
104
111
  ]
105
112
  end
106
113
  let(:api_response) { { 'available_browsers' => api_resources } }
107
- let(:expected_id) { api_resources.first['name'] }
108
- let(:expected_name) { api_resources.first['description'] }
114
+ let(:expected_rows) do
115
+ [
116
+ ['chrome', 'Chrome'],
117
+ ['safari', 'Safari'],
118
+ ['firefox', 'Firefox'],
119
+ ]
120
+ end
109
121
 
110
122
  it_should_behave_like 'a properly formatted resource', :browsers
111
123
  end
112
-
113
- describe '#print_table' do
114
- let(:resource_id) { 123456 }
115
- let(:resource_name) { 'resource name' }
116
- let(:resources) { [ RainforestCli::Resources::Resource.new(resource_id, resource_name) ] }
117
-
118
- it 'prints out the resources' do
119
- expect(subject).to receive(:puts) do |message|
120
- expect(message).to include('Resource ID')
121
- expect(message).to include('Resource Name')
122
- end
123
-
124
- # Stub dashed the line dividing table header and body
125
- expect(subject).to receive(:puts)
126
-
127
- expect(subject).to receive(:puts) do |message|
128
- expect(message).to include(resource_id.to_s)
129
- expect(message).to include(resource_name)
130
- end
131
-
132
- subject.print_table('Resource', resources)
133
- end
134
- end
135
124
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rainforest-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russell Smith
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-04 00:00:00.000000000 Z
12
+ date: 2017-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -133,6 +133,20 @@ dependencies:
133
133
  - - "~>"
134
134
  - !ruby/object:Gem::Version
135
135
  version: '3.2'
136
+ - !ruby/object:Gem::Dependency
137
+ name: terminal-table
138
+ requirement: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '='
141
+ - !ruby/object:Gem::Version
142
+ version: 1.7.3
143
+ type: :runtime
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - '='
148
+ - !ruby/object:Gem::Version
149
+ version: 1.7.3
136
150
  - !ruby/object:Gem::Dependency
137
151
  name: bundler
138
152
  requirement: !ruby/object:Gem::Requirement