turksatkablo_cli 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b19ab32c3aae669255dfdf8167dfd170b2c615f0
4
- data.tar.gz: 7b6fa7332994494a2a18dfa0516d66dcd93e7e55
3
+ metadata.gz: c16ccc2720b2adada0e6ebb8b07bde9083099335
4
+ data.tar.gz: 9faedcc8bbdab7e2c53fe957f7162f6031d089ed
5
5
  SHA512:
6
- metadata.gz: 706d9059ccddc262168fae94f222897c680112daefde5d868a00e7ad37dd3c14b2fca65491e957f4d602c1b38b67dfbe6e2e4cd4a74900073fe17d769b8c9f75
7
- data.tar.gz: c7bfac791558500ea4f8039949ee0e2554e4ef131d5d38066d806da93aaf12c80f0a119192342db31a85c912f48edb454d87407a0d0af638a2605c1fcaaf213c
6
+ metadata.gz: 8bab11273ca37becbdee3231195baf6662079f5e621f5d1a0896cae08a87104a0d775ed1f6b2849069e9a3b194ec340db57352831600ef76f0eb389347014aeb
7
+ data.tar.gz: eac5c80f567648e29bc7efa55a4f870bc9ff591c90662d270e4aa00b9d7c0a6ec306a321ef60508a8ca29a9dd0a69760d4d9f1c01f17192eab0ee9fdfb856ea1
data/README.md CHANGED
@@ -32,16 +32,19 @@ Verify the `turksatkablo` command is in your path by running it. You should see
32
32
  $ turksatkablo
33
33
  Commands:
34
34
  turksatkablo anlikborc # Anlık borç - kısa kodu b
35
+ turksatkablo fatura TARIH # Fatura göster ÖRN: 12.2017, ÖRN: 12.2017 pdf - kısa kodu f
36
+ turksatkablo faturaliste # Fatura listesi - kısa kodu fl
35
37
  turksatkablo help [COMMAND] # Describe available commands or one specific command
36
38
  turksatkablo hizmet # Mevcut hizmetler - kısa kodu h
37
39
  turksatkablo kampanya # Kampanya bilgileri - kısa kodu ka
38
40
  turksatkablo kota # Kalan kota - kısa kodu k
39
- turksatkablo kotadetay # Son 3 ayın günlük takibi v.s
41
+ turksatkablo kotadetay # Son 3 ay kota kullanım - kısa kodu kd
40
42
  turksatkablo musterino # Müşteri no - kısa kodu mn
41
43
  turksatkablo ozet # Hizmetler genel durum - kısa kodu o
42
44
  ```
43
45
 
44
46
  ## Changelog
47
+ + 0.3.0 – Add `Code coverage`, `Windows 10` support and `fatura TARIH`, `faturaliste`, `kotadetay donem` commands.
45
48
  + 0.2.0 – Add `RSpec` and `environment` tests, required `ruby` version updated (2.2.0 >=), `nokogiri` version updated (has a known critical severity security vulnerability in version range < 1.8.1)
46
49
  + 0.1.4 – Fix retry_authenticate and authenticated? methods (login details could not be saved after the retry_authenticate method)
47
50
  + 0.1.3 – Modernize multiple classes, add `ozet`, `hizmetler`, `musterino`, `kampanya`, `anlikborc` commands
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ rescue LoadError
8
+ # no rspec available
9
+ end
@@ -3,20 +3,16 @@ require 'turksatkablo_cli/base'
3
3
  require 'turksatkablo_cli/online_operations/agent'
4
4
  require 'turksatkablo_cli/online_operations/auth'
5
5
  require "init/poltergeist"
6
-
6
+ require 'turksatkablo_cli/online_operations/commands/quota'
7
7
 
8
8
  module TurksatkabloCli
9
9
  class << self
10
- include TurksatkabloCli::OnlineOperations::Helpers
11
10
  def main
12
- add_commands
13
-
14
- if internet_connection? == false
11
+ if !TurksatkabloCli::OnlineOperations::Helpers.internet_connection?
15
12
  abort 'İnternet bağlantınızı kontrol ediniz!'
16
13
  # Check your internet connection!
17
14
  end
18
15
 
19
-
20
16
  require 'turksatkablo_cli/online_operations/cli'
21
17
 
22
18
  TurksatkabloCli::OnlineOperations::Cli.start(ARGV)
@@ -3,7 +3,8 @@ require 'thor'
3
3
  module TurksatkabloCli
4
4
  module OnlineOperations
5
5
  class Base < Thor
6
-
6
+ include Helpers
7
+ include Thor::Actions
7
8
 
8
9
  # exit with return code 1 in case of a error
9
10
  def self.exit_on_failure?
@@ -18,7 +18,7 @@ module TurksatkabloCli
18
18
  end
19
19
 
20
20
  def has_logged_in?
21
- agent.has_logged_in
21
+ self.has_logged_in
22
22
  end
23
23
 
24
24
  def authenticated?
@@ -126,14 +126,14 @@ module TurksatkabloCli
126
126
  private
127
127
  def set_login_data(auth)
128
128
  if auth.login_data.kind_of?(Hash) && !has_login_data?
129
- agent.username = auth.login_data[:username]
130
- agent.password = auth.login_data[:password]
131
- agent.radio_btn_value = auth.login_data[:radio_btn_value]
129
+ self.username = auth.login_data[:username]
130
+ self.password = auth.login_data[:password]
131
+ self.radio_btn_value = auth.login_data[:radio_btn_value]
132
132
  end
133
133
  end
134
134
 
135
135
  def has_login_data?
136
- if agent.username.nil? || agent.password.nil? || agent.radio_btn_value.nil?
136
+ if self.username.nil? || self.password.nil? || self.radio_btn_value.nil?
137
137
  false
138
138
  else
139
139
  true
@@ -1,128 +1,214 @@
1
1
  require 'terminal-table'
2
-
2
+ require 'launchy'
3
+ require 'tmpdir'
4
+ require 'securerandom'
3
5
 
4
6
  module TurksatkabloCli
5
7
  module OnlineOperations
6
8
  class Cli < Base
7
- include TurksatkabloCli::OnlineOperations::Helpers
8
- include Thor::Actions
9
-
10
9
  # check_unknown_options!
11
10
 
12
11
 
13
12
  def initialize(*)
14
- @session = agent.session
15
- super
16
- end
17
-
18
- desc "ozet", "Hizmetler genel durum - kısa kodu o"
19
- def ozet
20
- if agent.authenticated?
21
- invoke :kota
22
- invoke :musterino
23
- invoke :anlikborc
24
- end
25
- end
26
- map "o" => "ozet"
27
-
28
- desc "kota", "Kalan kota - kısa kodu k"
29
- def kota
30
- if agent.authenticated?
31
- @session.find(:css, "div.circle-container div.toplam p").all("span, sub").map(&:text).each { |val| puts val }
32
- end
33
- end
34
- map "k" => "kota"
35
-
36
- desc "musterino", "Müşteri no - kısa kodu mn"
37
- def musterino
38
- if agent.authenticated?
39
- puts @session.find(:css, "div.musteri div.musteri-id").text
40
-
41
- end
42
- end
43
- map "mn" => "musterino"
44
-
45
- desc "hizmet", "Mevcut hizmetler - kısa kodu h"
46
- def hizmet
47
- if agent.authenticated?
48
- visit_status = @session.visit(Enums::SERVICE_OPERATIONS_URL)
49
- if visit_status["status"] == 'success' && @session.current_url == Enums::SERVICE_OPERATIONS_URL
50
-
51
- # TODO: REFACTOR table helper
52
-
53
- rows = []
54
- services_td_list = @session.all(:css, 'table#hizmetTable tr td:nth-child(-n+4)').map(&:text)
55
-
56
- if services_td_list.size > 0
57
- (0..services_td_list.size).step(4) do |n|
58
- rows << services_td_list[n...n+4]
59
- end
60
-
61
- table = Terminal::Table.new :headings => [Enums::HIZMET, Enums::HIZMET_TURU, Enums::HIZMET_DURUMU, Enums::TARIFE_TIPI], :rows => rows
62
- puts table
63
- else
64
- puts "Mevcut bir hizmetiniz bulunmamaktadır."
65
- end
66
-
13
+ @session = agent.session
14
+ super
15
+ end
16
+
17
+ desc "ozet", "Hizmetler genel durum - kısa kodu o"
18
+ def ozet
19
+ if agent.authenticated?
20
+ invoke :kota
21
+ invoke :musterino
22
+ invoke :anlikborc
23
+ end
24
+ end
25
+ map "o" => "ozet"
26
+
27
+ desc "kota", "Kalan kota - kısa kodu k"
28
+ def kota
29
+ if agent.authenticated?
30
+ @session.find(:css, "div.circle-container div.toplam p").all("span, sub").map(&:text).each { |val| puts val }
31
+ end
32
+ end
33
+ map "k" => "kota"
34
+
35
+ desc "musterino", "Müşteri no - kısa kodu mn"
36
+ def musterino
37
+ if agent.authenticated?
38
+ puts @session.find(:css, "div.musteri div.musteri-id").text
39
+
40
+ end
41
+ end
42
+ map "mn" => "musterino"
43
+
44
+ desc "hizmet", "Mevcut hizmetler - kısa kodu h"
45
+ def hizmet
46
+ if agent.authenticated?
47
+ visit_status = @session.visit(Enums::SERVICE_OPERATIONS_URL)
48
+ if visit_status["status"] == 'success' && @session.current_url == Enums::SERVICE_OPERATIONS_URL
49
+
50
+ # TODO: REFACTOR table helper
51
+
52
+ rows = []
53
+ services_td_list = @session.all(:css, 'table#hizmetTable tr td:nth-child(-n+4)').map(&:text)
54
+
55
+ if services_td_list.size > 0
56
+ (0..services_td_list.size).step(4) do |n|
57
+ rows << services_td_list[n...n+4]
58
+ end
59
+
60
+ table = Terminal::Table.new :headings => [Enums::HIZMET, Enums::HIZMET_TURU, Enums::HIZMET_DURUMU, Enums::TARIFE_TIPI], :rows => rows
61
+ puts table
62
+ else
63
+ puts "Mevcut bir hizmetiniz bulunmamaktadır."
64
+ end
65
+
66
+ else
67
+ puts "Hizmet İşlemleri menüsüne şuan ulaşılamıyor."
68
+ end
69
+
70
+ end
71
+ end
72
+ map "h" => "hizmet"
73
+
74
+ desc "kampanya", "Kampanya bilgileri - kısa kodu ka"
75
+ def kampanya
76
+ if agent.authenticated?
77
+ visit_status = @session.visit(Enums::CAMPAIGN_INFO_URL)
78
+ if visit_status["status"] == 'success' && @session.current_url == Enums::CAMPAIGN_INFO_URL
79
+
80
+ # TODO: REFACTOR table helper
81
+ rows = []
82
+ campaigns_td_list = @session.all(:css, 'table.table tr td').map(&:text)
83
+
84
+ if campaigns_td_list.size > 0
85
+ (0..campaigns_td_list.size).step(4) do |n|
86
+ rows << campaigns_td_list[n...n+4]
87
+ end
88
+
89
+ table = Terminal::Table.new :headings => [Enums::HIZMET_ID, Enums::KAMPANYA_ADI, Enums::TAAHHUT_BAS_TRH, Enums::TAAHHUT_BIT_TRH], :rows => rows
90
+ puts table
91
+ else
92
+ puts "Mevcut bir kampanyanız bulunmamaktadır."
93
+ end
94
+
95
+ else
96
+ puts "Kampanya Bilgileri menüsüne şuan ulaşılamıyor."
97
+ end
98
+
99
+ end
100
+ end
101
+ map "ka" => "kampanya"
102
+
103
+ desc "anlikborc", "Anlık borç - kısa kodu b"
104
+ def anlikborc
105
+ if agent.authenticated?
106
+ visit_status = @session.visit(Enums::INSTANT_DEBT_URL)
107
+ if visit_status["status"] == 'success' && @session.current_url == Enums::INSTANT_DEBT_URL
108
+ @session.find(:css, "div.anlik-borc").all("p, h1, small").map(&:text).each { |val| puts val }
67
109
  else
68
- puts "Hizmet İşlemleri menüsüne şuan ulaşılamıyor."
69
- end
70
-
71
- end
72
- end
73
- map "h" => "hizmet"
74
-
75
- desc "kampanya", "Kampanya bilgileri - kısa kodu ka"
76
- def kampanya
77
- if agent.authenticated?
78
- visit_status = @session.visit(Enums::CAMPAIGN_INFO_URL)
79
- if visit_status["status"] == 'success' && @session.current_url == Enums::CAMPAIGN_INFO_URL
80
-
81
- # TODO: REFACTOR table helper
82
- rows = []
83
- campaigns_td_list = @session.all(:css, 'table.table tr td').map(&:text)
84
-
85
- if campaigns_td_list.size > 0
86
- (0..campaigns_td_list.size).step(4) do |n|
87
- rows << campaigns_td_list[n...n+4]
88
- end
89
-
90
- table = Terminal::Table.new :headings => [Enums::HIZMET_ID, Enums::KAMPANYA_ADI, Enums::TAAHHUT_BAS_TRH, Enums::TAAHHUT_BIT_TRH], :rows => rows
91
- puts table
92
- else
93
- puts "Mevcut bir kampanyanız bulunmamaktadır."
94
- end
110
+ puts "Anlık Borç menüsüne şuan ulaşılamıyor."
111
+ end
112
+ end
113
+ end
114
+ map "b" => "anlikborc"
115
+
116
+ desc "fatura TARIH", "Fatura göster ÖRN: 12.2017, ÖRN: 12.2017 pdf - kısa kodu f"
117
+ def fatura(tarih, pdf=nil)
118
+ if agent.authenticated?
119
+ visit_status = @session.visit(Enums::INVOICES_URL)
120
+ if visit_status["status"] == 'success' && @session.current_url == Enums::INVOICES_URL
121
+ temp = Dir.tmpdir()
122
+ invoice_file_path = temp + '/' + SecureRandom.uuid + '.html'
123
+
124
+ begin
125
+ if pdf
126
+ link_element = @session.find('tr', text: tarih).find('a:last-child')
127
+ if link_element[:id] != nil && link_element[:id] == "PDFYok"
128
+ puts "Fatura PDF'iniz ayın 13'ünden sonra oluşacaktır."
129
+ else
130
+ visit_url = link_element[:href]
131
+ Launchy.open(visit_url)
132
+ puts "Faturanız varsayılan internet tarayıcınızda açıldı, kontrol ediniz!"
133
+ end
134
+
135
+ else
136
+ op_button_count = @session.find('tr', text: tarih).all('a').size
137
+
138
+ link_css_selector = 'a:first-child'
139
+ if op_button_count != nil
140
+ if op_button_count == 3
141
+ link_css_selector = 'a:nth-child(2)'
142
+ end
143
+ end
144
+
145
+ fatura_url = @session.find('tr', text: tarih).find(link_css_selector)[:onclick]
146
+ if fatura_url != nil
147
+ first_single_quote_ix = fatura_url.index('\'')
148
+ second_single_quote_ix = fatura_url.index('\'', first_single_quote_ix+1)
149
+
150
+ fatura_url = fatura_url[first_single_quote_ix+1..second_single_quote_ix-1]
151
+ visit_url = Enums::BASE_URL + fatura_url
152
+
153
+ @session.visit(visit_url)
154
+ File.open( "#{invoice_file_path}", "w+" ) { |f| f.write @session.html }
155
+ Launchy.open("#{invoice_file_path}")
156
+ puts 'Faturanız varsayılan internet tarayıcınızda açıldı, kontrol ediniz!'
157
+ else
158
+ puts "Mevcut bir faturanız bulunmamaktadır."
159
+ end
160
+
161
+ end
162
+ rescue Exception => e
163
+ puts 'Bir hata oluştu, mevcut bir faturanız bulunmamaktadır, fatura görüntüleme'
164
+ end
165
+ else
166
+ puts "Fatura Bilgileri menüsüne şuan ulaşılamıyor."
167
+ end
168
+
169
+ end
170
+ end
171
+ map "f" => "fatura"
172
+
173
+ desc "faturaliste", "Fatura listesi - kısa kodu fl"
174
+ def faturaliste
175
+ if agent.authenticated?
176
+ visit_status = @session.visit(Enums::INVOICES_URL)
177
+ if visit_status["status"] == 'success' && @session.current_url == Enums::INVOICES_URL
178
+
179
+ # TODO: REFACTOR table helper
180
+ rows = []
181
+
182
+ invoices_td_list = @session.all(:css, 'div.panel-default table.table tr td:nth-child(-n+5)').map(&:text)
183
+
184
+ if invoices_td_list.size > 0
185
+ (0..invoices_td_list.size).step(5) do |n|
186
+ rows << invoices_td_list[n...n+5]
187
+ end
188
+
189
+ table = Terminal::Table.new :headings => [Enums::AD_SOYAD, Enums::SON_ODEME_TRH, Enums::FATURA_TUTARI, Enums::GECIKME_BEDELI, Enums::TOPLAM_TUTAR], :rows => rows.reverse
190
+ puts table
191
+ else
192
+ puts "Mevcut bir faturanız bulunmamaktadır."
193
+ end
95
194
 
96
- else
97
- puts "Kampanya Bilgileri menüsüne şuan ulaşılamıyor."
98
- end
99
-
100
- end
101
- end
102
- map "ka" => "kampanya"
103
-
104
- desc "anlikborc", "Anlık borç - kısa kodu b"
105
- def anlikborc
106
- if agent.authenticated?
107
- visit_status = @session.visit(Enums::INSTANT_DEBT_URL)
108
- if visit_status["status"] == 'success' && @session.current_url == Enums::INSTANT_DEBT_URL
109
- @session.find(:css, "div.anlik-borc").all("p, h1, small").map(&:text).each { |val| puts val }
110
195
  else
111
- puts "Anlık Borç menüsüne şuan ulaşılamıyor."
112
- end
113
- end
114
- end
115
- map "b" => "anlikborc"
196
+ puts "Fatura Bilgileri menüsüne şuan ulaşılamıyor."
197
+ end
198
+
199
+ end
200
+ end
201
+ map "fl" => "faturaliste"
116
202
 
117
- # default_task :ozet
203
+ # default_task :ozet
118
204
 
119
205
 
120
- desc "kotadetay", "Son 3 ayın günlük takibi v.s"
121
- subcommand 'kotadetay', Commands::Quota
122
- map "kd" => "kotadetay"
206
+ desc "kotadetay", "Son 3 ay kota kullanım - kısa kodu kd"#son 3 ayın günlük takibi v.s"
207
+ subcommand 'kotadetay', Commands::Quota
208
+ map "kd" => "kotadetay"
123
209
 
124
210
 
125
- end
126
- end
211
+ end
212
+ end
127
213
  end
128
214
 
@@ -3,9 +3,39 @@ module TurksatkabloCli
3
3
  module Commands
4
4
  class Quota < Base
5
5
 
6
- desc "donem", "Dönem takibi"
6
+ def initialize(*)
7
+ @session = agent.session
8
+ super
9
+ end
10
+
11
+ desc "donem", "Kota Dönem takibi - kısa kodu d"
7
12
  def donem
13
+ if agent.authenticated?
14
+ visit_status = @session.visit(Enums::QUOTA_PERIOD)
15
+ if visit_status["status"] == 'success' && @session.current_url == Enums::QUOTA_PERIOD
16
+
17
+ # TODO: REFACTOR table helper
18
+ rows = []
19
+
20
+ periods_td_list = @session.all(:css, 'div.panel-default table.table tr td:nth-child(-n+4)').map(&:text)
21
+
22
+ if periods_td_list.size > 0
23
+ (0..periods_td_list.size).step(4) do |n|
24
+ rows << periods_td_list[n...n+4]
25
+ end
26
+
27
+ table = Terminal::Table.new :headings => [Enums::HIZMET_ID, Enums::DONEM, Enums::DOWNLOAD_KULLANIM, Enums::UPLOAD_KULLANIM], :rows => rows
28
+ puts table
29
+ else
30
+ puts "Mevcut bir faturanız bulunmamaktadır."
31
+ end
32
+
33
+ else
34
+ puts "Kota dönem takibi menüsüne şuan ulaşılamıyor."
35
+ end
36
+ end
8
37
  end
38
+ map "d" => "donem"
9
39
 
10
40
  end
11
41
  end
@@ -10,6 +10,8 @@ module TurksatkabloCli
10
10
  define :SERVICE_OPERATIONS_URL, "https://online.turksatkablo.com.tr/MusteriHizmetleri.aspx#Hizmet-Islemleri"
11
11
  define :CAMPAIGN_INFO_URL, "https://online.turksatkablo.com.tr/KampanyaBilgileri.aspx#Hizmet-Islemleri"
12
12
  define :INSTANT_DEBT_URL, "https://online.turksatkablo.com.tr/AnlikBorc.aspx#Fatura-Islemleri"
13
+ define :INVOICES_URL, "https://online.turksatkablo.com.tr/Faturalar.aspx"
14
+ define :QUOTA_PERIOD, "https://online.turksatkablo.com.tr/MusteriKotaDonem.aspx#Hizmet-Islemleri"
13
15
 
14
16
 
15
17
  define :HIZMET, "HİZMET"
@@ -23,6 +25,18 @@ module TurksatkabloCli
23
25
  define :TAAHHUT_BAS_TRH, "TAAHHÜT BAŞLANGIÇ TARİHİ"
24
26
  define :TAAHHUT_BIT_TRH, "TAAHHÜT BİTİŞ TARİHİ"
25
27
 
28
+
29
+ define :AD_SOYAD, "AD SOYAD"
30
+ define :SON_ODEME_TRH, "SON ÖDEME TARİHİ"
31
+ define :FATURA_TUTARI, "FATURA TUTARI(TL)"
32
+ define :GECIKME_BEDELI, "GECİKME BEDELİ(TL)"
33
+ define :TOPLAM_TUTAR, "TOPLAM TUTAR(TL)"
34
+
35
+ define :DONEM, "DÖNEM"
36
+ define :DOWNLOAD_KULLANIM, "DOWNLOAD KULLANIM"
37
+ define :UPLOAD_KULLANIM, "UPLOAD KULLANIM"
38
+
39
+
26
40
  define :PHANTOM_JS_REQUIRED, "turksatkablo_cli requires phantomjs https://github.com/rokumatsumoto/turksatkablo_cli#setup"
27
41
  end
28
42
  end
@@ -1,67 +1,62 @@
1
- require 'open3'
2
1
  require 'net/ping'
3
2
 
4
3
  module TurksatkabloCli
5
4
  module OnlineOperations
6
5
  module Helpers
6
+ extend self
7
7
 
8
- def internet_connection?
8
+ def internet_connection?(host = "8.8.8.8")
9
9
  begin
10
- Net::Ping::External.new("8.8.8.8").ping?
10
+ Net::Ping::External.new(host).ping?
11
11
  rescue
12
- false
12
+ nil
13
13
  end
14
14
  end
15
15
 
16
- def add_commands
17
-
18
- begin
19
- Dir[File.expand_path(File.join('../..','online_operations', 'commands', '*.rb'), __FILE__)].each do |file|
20
- require file
21
- end
22
- rescue Exception => e
23
- end
16
+ def require_all(_dir)
17
+ Dir[File.join(_dir, "**/*.rb")].each do |file|
18
+ require file
19
+ end
20
+ end
24
21
 
22
+ def agent
23
+ unless $agent
24
+ $agent = TurksatkabloCli::OnlineOperations::Agent.new
25
25
  end
26
+ $agent
27
+ end
26
28
 
27
- def agent
28
- unless $agent
29
- $agent = TurksatkabloCli::OnlineOperations::Agent.new
30
- end
31
- $agent
32
- end
29
+ def add_line
30
+ puts "\n"
31
+ end
33
32
 
34
- def add_line
35
- puts "\n"
36
- end
37
-
38
- def self.check_ruby_version(ruby_version = RUBY_VERSION)
39
- if ruby_version < '2.2.0'
40
- abort "turksatkablo_cli requires Ruby 2.2.0 or higher"
41
- else
42
- ruby_version
43
- end
33
+ def check_ruby_version(ruby_version = RUBY_VERSION)
34
+ if ruby_version < '2.2.0'
35
+ abort "turksatkablo_cli requires Ruby 2.2.0 or higher"
36
+ else
37
+ ruby_version
44
38
  end
39
+ end
45
40
 
46
- def self.check_is_installed?(command, err_msg)
47
- if which(command)
48
- true
49
- else
50
- abort(err_msg)
51
- end
41
+ def check_is_installed?(command, err_msg)
42
+ if which(command)
43
+ true
44
+ else
45
+ abort(err_msg)
52
46
  end
47
+ end
53
48
 
54
- def self.which(command)
55
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
56
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
57
- exts.each { |ext|
58
- exe = File.join(path, "#{command}#{ext}")
59
- return exe if File.executable?(exe) && !File.directory?(exe)
60
- }
61
- end
62
- return nil
49
+ def which(command)
50
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
51
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
52
+ exts.each { |ext|
53
+ exe = File.join(path, "#{command}#{ext}")
54
+ return exe if File.executable?(exe) && !File.directory?(exe)
55
+ }
63
56
  end
64
-
57
+ return nil
65
58
  end
59
+
66
60
  end
67
61
  end
62
+ end
@@ -1,5 +1,5 @@
1
1
  module TurksatkabloCli
2
2
  module OnlineOperations
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -0,0 +1,72 @@
1
+
2
+ describe TurksatkabloCli::OnlineOperations::Helpers do
3
+ subject { described_class }
4
+
5
+ context '#check_ruby_version' do
6
+ it 'returns ruby version when correct version >= 2.2.0 installed' do
7
+ expect(subject.check_ruby_version("2.4.2")).to be >= "2.2.0"
8
+ end
9
+
10
+ it 'abort with error message when unsupported ruby version (< 2.2.0) installed' do
11
+ expect { subject.check_ruby_version("2.1.0") }.to raise_error(SystemExit)
12
+ end
13
+ end
14
+
15
+ context '#check_is_installed?' do
16
+ it 'returns true when phantomjs is in path' do
17
+ expect(subject.check_is_installed?("phantomjs", TurksatkabloCli::OnlineOperations::Enums::PHANTOM_JS_REQUIRED)).to be_truthy
18
+ end
19
+
20
+ it 'abort with error message because phantom_jsx can not be in path' do
21
+ expect { subject.check_is_installed?("phantom_jsx", "phantom_jsx can not be in path") }.to raise_error(SystemExit)
22
+ end
23
+ end
24
+
25
+ context '#which' do
26
+ it 'returns ruby\'s path when ruby is in path' do
27
+ expect(subject.which("ruby")).to be_instance_of(String)
28
+ end
29
+ end
30
+
31
+ context '#require_all' do
32
+ before {described_class.require_all("./spec/support/required_all")}
33
+
34
+ it 'needed files' do
35
+ notifier = class_double("ConsoleNotifier").as_stubbed_const
36
+ expect(notifier).to receive(:notify).with("suspended as")
37
+ user = User.new
38
+ user.suspend!
39
+
40
+ end
41
+ end
42
+
43
+ context '#agent' do
44
+ before(:all) do
45
+ require 'turksatkablo_cli/online_operations/agent'
46
+ require 'init/poltergeist'
47
+ end
48
+
49
+ it 'returns instance of Agent' do
50
+ expect(subject.agent).to be_instance_of(TurksatkabloCli::OnlineOperations::Agent)
51
+ end
52
+
53
+ it 'initializes capybara session w/ poltergeist' do
54
+ expect(subject.agent.session).to be_instance_of(Capybara::Session)
55
+ end
56
+ end
57
+
58
+ context '#add_line' do
59
+ it 'returns new line' do
60
+ expect do
61
+ subject.add_line
62
+ end.to output("\n").to_stdout
63
+ end
64
+ end
65
+
66
+ context '#internet_connection?' do
67
+ it 'returns false when blank address specified' do
68
+ expect(subject.internet_connection?('')).to be_falsey
69
+ end
70
+ end
71
+
72
+ end
@@ -1,11 +1,14 @@
1
1
 
2
2
 
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'simplecov'
4
+
5
+ SimpleCov.start do
6
+ add_filter '/spec/'
7
+ end
5
8
 
6
- require 'rspec'
7
9
  require 'turksatkablo_cli/online_operations/helpers'
8
10
  require 'turksatkablo_cli/online_operations/enums'
11
+ require 'turksatkablo_cli/online_operations/version'
9
12
 
10
13
  module SpecHelper
11
14
  end
@@ -21,4 +24,7 @@ RSpec.configure do |config|
21
24
 
22
25
  config.shared_context_metadata_behavior = :apply_to_host_groups
23
26
  config.include(SpecHelper)
27
+
28
+ config.before(:suite) do
29
+ end
24
30
  end
@@ -0,0 +1,5 @@
1
+ class ConsoleNotifier
2
+ def self.notify(message)
3
+ puts message
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class User
2
+ def suspend!
3
+ ConsoleNotifier.notify("suspended as")
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ describe TurksatkabloCli::OnlineOperations do
2
+
3
+ it 'returns turksatkablo_cli version' do
4
+ stub_const("VERSION", "0.3.0")
5
+ expect(VERSION).to eq(subject::VERSION)
6
+ end
7
+ end
@@ -27,6 +27,8 @@ Gem::Specification.new do |spec|
27
27
  # f.match(%r{^(test|spec|features)/})
28
28
  # end
29
29
 
30
+ # spec.platform = "x64-mingw32"
31
+
30
32
  spec.required_ruby_version = '>= 2.2.0'
31
33
  spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
32
34
  spec.files = `git ls-files`.split("\n")
@@ -34,6 +36,7 @@ Gem::Specification.new do |spec|
34
36
  spec.add_development_dependency "bundler", "~> 1.16"
35
37
  spec.add_development_dependency "rake", "~> 10.0"
36
38
  spec.add_development_dependency 'rspec', '~> 3.0'
39
+ spec.add_development_dependency 'simplecov', '~> 0'
37
40
 
38
41
  spec.add_runtime_dependency "thor", '~> 0.20.0'
39
42
  spec.add_runtime_dependency 'highline', '~> 1.7', '>= 1.7.8'
@@ -41,7 +44,9 @@ Gem::Specification.new do |spec|
41
44
  spec.add_runtime_dependency 'rack-test', '0.7.0'
42
45
  spec.add_runtime_dependency 'net-ping', '~> 2.0', '>= 2.0.2'
43
46
  spec.add_runtime_dependency 'capybara', '~> 2.16', '>= 2.16.1'
47
+ spec.add_runtime_dependency 'launchy', '~> 2.4.3', '>= 2.4.3'
44
48
  spec.add_runtime_dependency 'poltergeist', '~> 1.16', '>= 1.16.0'
45
49
  spec.add_runtime_dependency "ruby-enum", '~> 0.7.1'
46
50
  spec.add_runtime_dependency 'terminal-table', '~> 1.8', '>= 1.8.0'
51
+ # spec.add_runtime_dependency 'win32-security', '~> 0.5.0'
47
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turksatkablo_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samet Gunaydin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-23 00:00:00.000000000 Z
11
+ date: 2018-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: thor
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -154,6 +168,26 @@ dependencies:
154
168
  - - ">="
155
169
  - !ruby/object:Gem::Version
156
170
  version: 2.16.1
171
+ - !ruby/object:Gem::Dependency
172
+ name: launchy
173
+ requirement: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - "~>"
176
+ - !ruby/object:Gem::Version
177
+ version: 2.4.3
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: 2.4.3
181
+ type: :runtime
182
+ prerelease: false
183
+ version_requirements: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 2.4.3
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: 2.4.3
157
191
  - !ruby/object:Gem::Dependency
158
192
  name: poltergeist
159
193
  requirement: !ruby/object:Gem::Requirement
@@ -238,8 +272,11 @@ files:
238
272
  - lib/turksatkablo_cli/online_operations/enums.rb
239
273
  - lib/turksatkablo_cli/online_operations/helpers.rb
240
274
  - lib/turksatkablo_cli/online_operations/version.rb
241
- - spec/helper_spec.rb
275
+ - spec/helpers_spec.rb
242
276
  - spec/spec_helper.rb
277
+ - spec/support/required_all/console_notifier.rb
278
+ - spec/support/required_all/user.rb
279
+ - spec/version_spec.rb
243
280
  - turksatkablo_cli.gemspec
244
281
  homepage: https://github.com/rokumatsumoto/turksatkablo_cli
245
282
  licenses:
@@ -1,23 +0,0 @@
1
- RSpec.describe "environment" do
2
-
3
- it "ruby version is >= 2.2.0" do
4
- expect(TurksatkabloCli::OnlineOperations::Helpers.check_ruby_version("2.4.2")).to be >= "2.1.0"
5
- end
6
-
7
- it "ruby version is < 2.2.0" do
8
- expect { TurksatkabloCli::OnlineOperations::Helpers.check_ruby_version("2.1.0") }.to raise_error(SystemExit)
9
- end
10
-
11
- it "phantomjs needs to be in path" do
12
- expect(TurksatkabloCli::OnlineOperations::Helpers.check_is_installed?("phantomjs", TurksatkabloCli::OnlineOperations::Enums::PHANTOM_JS_REQUIRED)).to be_truthy
13
- end
14
-
15
- it "ruby is in path" do
16
- expect(TurksatkabloCli::OnlineOperations::Helpers.which("ruby")).to be_instance_of(String)
17
- end
18
-
19
- it "phantom_jsx is not in path" do
20
- expect { TurksatkabloCli::OnlineOperations::Helpers.check_is_installed?("phantom_jsx", "phantom_jsx is not in path") }.to raise_error(SystemExit)
21
- end
22
-
23
- end