Class: GoogleText::Client
- Inherits:
-
Object
- Object
- GoogleText::Client
- Defined in:
- lib/google_text/client.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#dashboard_url ⇒ Object
Returns the value of attribute dashboard_url.
-
#inbox_url ⇒ Object
Returns the value of attribute inbox_url.
-
#login_url ⇒ Object
Returns the value of attribute login_url.
-
#mark_as_read_url ⇒ Object
Returns the value of attribute mark_as_read_url.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#send_url ⇒ Object
Returns the value of attribute send_url.
-
#service ⇒ Object
Returns the value of attribute service.
-
#session ⇒ Object
Returns the value of attribute session.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#xsrf_token ⇒ Object
Returns the value of attribute xsrf_token.
Instance Method Summary collapse
- #current_page ⇒ Object
-
#current_url ⇒ Object
TODO: this does not update when being forwarded, prolly need to access last response object directly.
- #dashboard_page ⇒ Object
- #get_messages ⇒ Object
- #get_session_id ⇒ Object
- #get_xsrf_token ⇒ Object
- #inbox_page ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #logged_in? ⇒ Boolean
- #login ⇒ Object
- #login_page ⇒ Object
- #mark_as_read(id) ⇒ Object
- #parser ⇒ Object
- #post_to_login ⇒ Object
- #send_message(phone_number, text) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/google_text/client.rb', line 7 def initialize(={}) @configuration = GoogleText.configuration [:login_url, :dashboard_url, :inbox_url, :mark_as_read_url, :send_url, :service].each do |key| self.send("#{key}=", [key] || @configuration.send(key)) end @account = Account.new(@configuration.email,@configuration.password) @messages = [] establish_session end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
3 4 5 |
# File 'lib/google_text/client.rb', line 3 def account @account end |
#configuration ⇒ Object
Returns the value of attribute configuration.
3 4 5 |
# File 'lib/google_text/client.rb', line 3 def configuration @configuration end |
#dashboard_url ⇒ Object
Returns the value of attribute dashboard_url.
3 4 5 |
# File 'lib/google_text/client.rb', line 3 def dashboard_url @dashboard_url end |
#inbox_url ⇒ Object
Returns the value of attribute inbox_url.
3 4 5 |
# File 'lib/google_text/client.rb', line 3 def inbox_url @inbox_url end |
#login_url ⇒ Object
Returns the value of attribute login_url.
3 4 5 |
# File 'lib/google_text/client.rb', line 3 def login_url @login_url end |
#mark_as_read_url ⇒ Object
Returns the value of attribute mark_as_read_url.
3 4 5 |
# File 'lib/google_text/client.rb', line 3 def mark_as_read_url @mark_as_read_url end |
#messages ⇒ Object
Returns the value of attribute messages.
3 4 5 |
# File 'lib/google_text/client.rb', line 3 def @messages end |
#send_url ⇒ Object
Returns the value of attribute send_url.
3 4 5 |
# File 'lib/google_text/client.rb', line 3 def send_url @send_url end |
#service ⇒ Object
Returns the value of attribute service.
3 4 5 |
# File 'lib/google_text/client.rb', line 3 def service @service end |
#session ⇒ Object
Returns the value of attribute session.
3 4 5 |
# File 'lib/google_text/client.rb', line 3 def session @session end |
#session_id ⇒ Object
Returns the value of attribute session_id.
3 4 5 |
# File 'lib/google_text/client.rb', line 3 def session_id @session_id end |
#xsrf_token ⇒ Object
Returns the value of attribute xsrf_token.
3 4 5 |
# File 'lib/google_text/client.rb', line 3 def xsrf_token @xsrf_token end |
Instance Method Details
#current_page ⇒ Object
55 56 57 |
# File 'lib/google_text/client.rb', line 55 def current_page @session.body end |
#current_url ⇒ Object
TODO: this does not update when being forwarded, prolly need to access last response object directly
60 61 62 |
# File 'lib/google_text/client.rb', line 60 def current_url @session.url end |
#dashboard_page ⇒ Object
68 69 70 |
# File 'lib/google_text/client.rb', line 68 def dashboard_page current_url == @configuration.dashboard_url ? current_page : get(dashboard_url) end |
#get_messages ⇒ Object
46 47 48 |
# File 'lib/google_text/client.rb', line 46 def @messages = Parsers::Inbox.new(inbox_page). end |
#get_session_id ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/google_text/client.rb', line 33 def get_session_id begin @session_id = Parsers::Dashboard.new(dashboard_page).session_id rescue raise "Could not retrieve Google Voice Session ID" end end |
#get_xsrf_token ⇒ Object
29 30 31 |
# File 'lib/google_text/client.rb', line 29 def get_xsrf_token @xsrf_token = Parsers::Login.new(login_page).xsrf_token end |
#inbox_page ⇒ Object
64 65 66 |
# File 'lib/google_text/client.rb', line 64 def inbox_page get inbox_url end |
#logged_in? ⇒ Boolean
25 26 27 |
# File 'lib/google_text/client.rb', line 25 def logged_in? !session_id.nil? end |
#login ⇒ Object
19 20 21 22 23 |
# File 'lib/google_text/client.rb', line 19 def login get_xsrf_token post_to_login get_session_id end |
#login_page ⇒ Object
76 77 78 |
# File 'lib/google_text/client.rb', line 76 def login_page get login_url end |
#mark_as_read(id) ⇒ Object
50 51 52 53 |
# File 'lib/google_text/client.rb', line 50 def mark_as_read(id) fields = fields_for 'messages' => id, 'read' => 1, '_rnr_se' => session_id post mark_as_read_url, fields end |
#parser ⇒ Object
80 81 82 |
# File 'lib/google_text/client.rb', line 80 def parser @parser ||= Parser.new end |
#post_to_login ⇒ Object
72 73 74 |
# File 'lib/google_text/client.rb', line 72 def post_to_login post login_url, login_fields end |
#send_message(phone_number, text) ⇒ Object
41 42 43 44 |
# File 'lib/google_text/client.rb', line 41 def (phone_number,text) fields = fields_for 'phoneNumber' => phone_number, 'text' => text, '_rnr_se' => session_id post send_url, fields end |