quora-webdriver 0.1.2 → 0.1.3

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: 38e02b93497d477bd00e52f236109b707f4658bc
4
- data.tar.gz: 16b28115a48f4151fdf2a4efc45d10599e85d587
3
+ metadata.gz: 1885e29e7a94a6d00091e63177477f2000ea6473
4
+ data.tar.gz: ead5b8b14df5bf33c38856b4c747b08c5c6545c6
5
5
  SHA512:
6
- metadata.gz: eb752d4a455bb8e0b74fe7132ad292445bde00bb4dab9f42527874fef43745602b53c31852303483db49133bda70b92672bd33f03c1f1a641b895d8840eb1f59
7
- data.tar.gz: b90db238e482530912ce0714d439bf583aaddcdc052f15d5327daaf9aa82cba196c1ab82b3190b19b93e140abede427c5719b91691fbdb5706d7d6e63d523b0b
6
+ metadata.gz: fc56debc048690248ae6c55cfd146fc74a1bea8a157c819a89d53d0eea4e895d20e122f88630f0307c82d5456149f5135d4a0fae372c75629cd486005cf7412d
7
+ data.tar.gz: 5182d4478cf857d8e6c0a2ffd18cd1d2314534f9c68a70e9556a03da5afaa333469df7da9c67f37dd4da61468c2accabf9302517e9c5afaea5e9ca2dcf544d8a
data/Gemfile CHANGED
@@ -2,4 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in quora-webdriver.gemspec
4
4
  gemspec
5
-
data/README.md CHANGED
@@ -38,6 +38,13 @@ There are not a lot of features added yet. This is to get started and I welcome
38
38
 
39
39
  1. Fork it ( https://github.com/kratsg/quora-webdriver/fork )
40
40
  2. Create your feature branch (`git checkout -b my-new-feature`)
41
- 3. Commit your changes (`git commit -am 'Add some feature'`)
42
- 4. Push to the branch (`git push origin my-new-feature`)
43
- 5. Create a new Pull Request
41
+ 3. **Write your tests!**
42
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 5. Push to the branch (`git push origin my-new-feature`)
44
+ 6. Create a new Pull Request
45
+
46
+ ### Issue
47
+
48
+ Pull requests from forks will most likely have builds that fail because of private keys being used for OpenSauce. Please commit with a message that includes `[skip ci]` and I'll checkout and push myself to see if the pull request passes build before merging. This message should tell Travis to skip the build. More information
49
+ - http://docs.travis-ci.com/user/pull-requests/
50
+ - https://github.com/travis-ci/travis-ci/issues/1946
@@ -2,6 +2,9 @@ require "watir-webdriver"
2
2
  require "watir-scroll"
3
3
  require "highline/import"
4
4
 
5
- require "quora-webdriver/browser"
6
5
  require "quora-webdriver/quora"
7
6
  require "quora-webdriver/version"
7
+ require "quora-webdriver/stats"
8
+
9
+ require "quora-webdriver/base"
10
+
@@ -0,0 +1,19 @@
1
+ module Watir
2
+ class Browser
3
+
4
+ attr_reader :quora
5
+ def quora
6
+ @Quora ||= Quora.new(self)
7
+ end
8
+
9
+ class Quora
10
+ include QuoraWebDriver::QuoraModule
11
+
12
+ attr_reader :stats
13
+ def stats
14
+ @Stats ||= Stats.new(self)
15
+ end
16
+ end # Quora
17
+
18
+ end # Browser
19
+ end # Watir
@@ -1,131 +1,128 @@
1
- module Watir
2
- class Browser
3
- class Quora
1
+ module QuoraWebDriver
2
+ module QuoraModule
3
+ attr_reader :base_url, :url
4
+ attr_accessor :user
4
5
 
5
- attr_reader :base_url, :url
6
- attr_accessor :user
7
6
 
7
+ def initialize(browser)
8
+ @browser = browser
9
+ @base_url = "https://www.quora.com/"
10
+ @logged_in = false
11
+ end
8
12
 
9
- def initialize(browser)
10
- @browser = browser
11
- @base_url = "https://www.quora.com/"
12
- @logged_in = false
13
- end
13
+ def user
14
+ @user ||= :Giordon_Stark
15
+ end
14
16
 
15
- def user
16
- @user ||= :Giordon_Stark
17
- end
17
+ def stringify
18
+ @user.to_s.gsub("_","-")
19
+ end
18
20
 
19
- def stringify
20
- @user.to_s.gsub("_","-")
21
- end
21
+ def get_login_email_text
22
+ @browser.text_field({:name=>"email", :class=>/header_login_text_box/})
23
+ end
22
24
 
23
- def get_login_email_text
24
- @browser.text_field({:name=>"email", :class=>/header_login_text_box/})
25
- end
25
+ def get_login_password_text
26
+ @browser.text_field({:name=>"password", :class=>/header_login_text_box/})
27
+ end
26
28
 
27
- def get_login_password_text
28
- @browser.text_field({:name=>"password", :class=>/header_login_text_box/})
29
- end
29
+ def get_login_submit_button
30
+ @browser.button({:value=>"Login"})
31
+ end
30
32
 
31
- def get_login_submit_button
32
- @browser.button({:value=>"Login"})
33
- end
33
+ def get_add_question_div
34
+ @browser.div({:class=>/inner/, :text=>/Add Question/})
35
+ end
34
36
 
35
- def get_add_question_div
36
- @browser.div({:class=>/inner/, :text=>/Add Question/})
37
+ def login(choice='0')
38
+ return @logged_in if @logged_in
39
+ until ['1', '2'].include?(choice)
40
+ puts "This page requires a login.\n\t(1) Login via browser\n\t(2) Login via command line"
41
+ choice = gets.chomp
37
42
  end
38
-
39
- def login(choice='0')
40
- return @logged_in if @logged_in
41
- until ['1', '2'].include?(choice)
42
- puts "This page requires a login.\n\t(1) Login via browser\n\t(2) Login via command line"
43
- choice = gets.chomp
44
- end
45
- case choice
46
- when '1'
47
- puts "Please navigate to the browser and login."
48
- when '2'
49
- email = ask("Enter email: "){ |x| x.echo = true }
50
- password = ask("Enter password: "){ |x| x.echo = "*" }
51
- email_box = get_login_email_text
52
- password_box = get_login_password_text
53
- unless email_box.exist? and password_box.exist? then
54
- puts "There was an error getting the login boxes. Please login manually. Report this error to someone important."
55
- self.login('1')
56
- end
57
- email_box.set email
58
- password_box.set password
59
- get_login_submit_button.click
43
+ case choice
44
+ when '1'
45
+ puts "Please navigate to the browser and login."
46
+ when '2'
47
+ email = ask("Enter email: "){ |x| x.echo = true }
48
+ password = ask("Enter password: "){ |x| x.echo = "*" }
49
+ email_box = get_login_email_text
50
+ password_box = get_login_password_text
51
+ unless email_box.exist? and password_box.exist? then
52
+ puts "There was an error getting the login boxes. Please login manually. Report this error to someone important."
53
+ self.login('1')
60
54
  end
61
-
62
- self.verify_login
55
+ email_box.set email
56
+ password_box.set password
57
+ get_login_submit_button.click
63
58
  end
64
59
 
65
- def verify_login
66
- # check every 6 seconds for 1 minute
67
- login_count_checks = 0
68
- until @logged_in || (login_count_checks >= 60) do
69
- puts "\t Checking if logged in"
70
- @logged_in = get_add_question_div.exists?
71
- login_count_checks+=1
72
- sleep 1
73
- end
60
+ self.verify_login
61
+ end
74
62
 
75
- if @logged_in then
76
- puts "Successfully logged in!"
77
- elsif @browser.text_field(:name=> "email", :class=>/header_login_text_box/).exist? then
78
- puts "There was an error logging in. Most likely a wrong username or password."
79
- else
80
- puts "There was an error logging in."
81
- end
82
- self.login
63
+ def verify_login
64
+ # check every 6 seconds for 1 minute
65
+ login_count_checks = 0
66
+ until @logged_in || (login_count_checks >= 60) do
67
+ puts "\t Checking if logged in"
68
+ @logged_in = get_add_question_div.exists?
69
+ login_count_checks+=1
70
+ sleep 1
83
71
  end
84
72
 
85
- def goto(login = nil)
86
- @browser.goto "#{@url}#{login.nil? ? '?share=1' : ''}"
87
- unless login.nil? then
88
- self.login
89
- end
73
+ if @logged_in then
74
+ puts "Successfully logged in!"
75
+ elsif @browser.text_field(:name=> "email", :class=>/header_login_text_box/).exist? then
76
+ puts "There was an error logging in. Most likely a wrong username or password."
77
+ else
78
+ puts "There was an error logging in."
90
79
  end
80
+ self.login
81
+ end
91
82
 
92
- def home
93
- @url = "#{@base_url}"
94
- self.goto :login
83
+ def goto(login = nil)
84
+ @browser.goto "#{@url}#{login.nil? ? '?share=1' : ''}"
85
+ unless login.nil? then
86
+ self.login
95
87
  end
88
+ end
96
89
 
97
- def answers
98
- @url = "#{@base_url}#{self.stringify}/answers?share=1"
99
- self.goto
100
- end
90
+ def home
91
+ @url = "#{@base_url}"
92
+ self.goto :login
93
+ end
101
94
 
102
- def content(subcategory = :all)
103
- case subcategory
104
- when :questions_added,
105
- :questions_followed,
106
- :answers,
107
- :posts
108
- @url = "#{@base_url}content?content_types=#{subcategory}"
109
- else
110
- @url = "#{@base_url}content"
111
- end
112
- self.goto :login
95
+ def answers
96
+ @url = "#{@base_url}#{self.stringify}/answers?share=1"
97
+ self.goto
98
+ end
99
+
100
+ def content(subcategory = :all)
101
+ case subcategory
102
+ when :questions_added,
103
+ :questions_followed,
104
+ :answers,
105
+ :posts
106
+ @url = "#{@base_url}content?content_types=#{subcategory}"
107
+ else
108
+ @url = "#{@base_url}content"
113
109
  end
110
+ self.goto :login
111
+ end
114
112
 
115
- def scroll_n_times(n = 1)
116
- n.times do
117
- @browser.scroll.to :bottom
118
- end
113
+ def scroll_n_times(n = 1)
114
+ n.times do
115
+ @browser.scroll.to :bottom
119
116
  end
117
+ end
120
118
 
121
- def get_all
122
- last_size = 0
123
- while last_size != self.html.size do
124
- last_size = self.html.size
125
- @browser.scroll.to :bottom
126
- # sleep for 3 seconds to handle ajax request delay until page updates
127
- sleep 3
128
- end
119
+ def get_all
120
+ last_size = 0
121
+ while last_size != self.html.size do
122
+ last_size = self.html.size
123
+ @browser.scroll.to :bottom
124
+ # sleep for 3 seconds to handle ajax request delay until page updates
125
+ sleep 3
129
126
  end
130
127
  end
131
128
  end
@@ -0,0 +1,19 @@
1
+ module QuoraWebDriver
2
+ class Stats
3
+ attr_reader :notifs, :openqs
4
+
5
+ def initialize(browser)
6
+ @browser = browser
7
+ end
8
+
9
+ def notifs
10
+ el = @browser.div(:class=>/NotifsNavItem/).span(:class=>/badge/)
11
+ @notifs ||= (el.text.to_i && el.exist?) || 0
12
+ end
13
+
14
+ def openqs
15
+ el = @browser.div(:class=>/OpenQsNavItem/).span(:class=>/badge/)
16
+ @openqs ||= (el.text.to_i && el.exist?) || 0
17
+ end
18
+ end
19
+ end
@@ -1,7 +1,3 @@
1
- module Watir
2
- class Browser
3
- class Quora
4
- VERSION = "0.1.2"
5
- end # Quora
6
- end # Browser
7
- end # Watir
1
+ module QuoraWebDriver
2
+ VERSION = "0.1.3"
3
+ end # Version
@@ -5,7 +5,7 @@ require 'quora-webdriver/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "quora-webdriver"
8
- spec.version = Watir::Browser::Quora::VERSION
8
+ spec.version = QuoraWebDriver::VERSION
9
9
  spec.authors = ["Giordon Stark"]
10
10
  spec.email = ["kratsg@gmail.com"]
11
11
  spec.summary = %q{Interact with Quora via Command Line}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quora-webdriver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giordon Stark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-22 00:00:00.000000000 Z
11
+ date: 2014-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: watir-webdriver
@@ -108,8 +108,9 @@ files:
108
108
  - README.md
109
109
  - Rakefile
110
110
  - lib/quora-webdriver.rb
111
- - lib/quora-webdriver/browser.rb
111
+ - lib/quora-webdriver/base.rb
112
112
  - lib/quora-webdriver/quora.rb
113
+ - lib/quora-webdriver/stats.rb
113
114
  - lib/quora-webdriver/version.rb
114
115
  - quora-webdriver.gemspec
115
116
  - spec/quora_login.html
@@ -1,7 +0,0 @@
1
- module Watir
2
- class Browser
3
- def quora
4
- @Quora ||= Quora.new(self)
5
- end
6
- end # Browser
7
- end # Watir