Class: GoogleText::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/google_text/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
  @configuration = GoogleText.configuration   
     
  [:login_url, :dashboard_url, :inbox_url, :mark_as_read_url, :send_url, :service].each do |key|
    self.send("#{key}=", options[key] || @configuration.send(key))
  end
  
  @account = Account.new(@configuration.email,@configuration.password)
  @messages = []
  establish_session
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



3
4
5
# File 'lib/google_text/client.rb', line 3

def 
  @account
end

#configurationObject

Returns the value of attribute configuration.



3
4
5
# File 'lib/google_text/client.rb', line 3

def configuration
  @configuration
end

#dashboard_urlObject

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_urlObject

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_urlObject

Returns the value of attribute login_url.



3
4
5
# File 'lib/google_text/client.rb', line 3

def 
  @login_url
end

#mark_as_read_urlObject

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

#messagesObject

Returns the value of attribute messages.



3
4
5
# File 'lib/google_text/client.rb', line 3

def messages
  @messages
end

#send_urlObject

Returns the value of attribute send_url.



3
4
5
# File 'lib/google_text/client.rb', line 3

def send_url
  @send_url
end

#serviceObject

Returns the value of attribute service.



3
4
5
# File 'lib/google_text/client.rb', line 3

def service
  @service
end

#sessionObject

Returns the value of attribute session.



3
4
5
# File 'lib/google_text/client.rb', line 3

def session
  @session
end

#session_idObject

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_tokenObject

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_pageObject



55
56
57
# File 'lib/google_text/client.rb', line 55

def current_page
  @session.body
end

#current_urlObject

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_pageObject



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_messagesObject



46
47
48
# File 'lib/google_text/client.rb', line 46

def get_messages
  @messages = Parsers::Inbox.new(inbox_page).messages
end

#get_session_idObject



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_tokenObject



29
30
31
# File 'lib/google_text/client.rb', line 29

def get_xsrf_token
  @xsrf_token = Parsers::Login.new().xsrf_token
end

#inbox_pageObject



64
65
66
# File 'lib/google_text/client.rb', line 64

def inbox_page
  get inbox_url
end

#logged_in?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/google_text/client.rb', line 25

def logged_in?
  !session_id.nil?
end

#loginObject



19
20
21
22
23
# File 'lib/google_text/client.rb', line 19

def 
  get_xsrf_token
  
  get_session_id
end

#login_pageObject



76
77
78
# File 'lib/google_text/client.rb', line 76

def 
  get  
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

#parserObject



80
81
82
# File 'lib/google_text/client.rb', line 80

def parser
  @parser ||= Parser.new
end

#post_to_loginObject



72
73
74
# File 'lib/google_text/client.rb', line 72

def 
  post , 
end

#send_message(phone_number, text) ⇒ Object



41
42
43
44
# File 'lib/google_text/client.rb', line 41

def send_message(phone_number,text)
  fields = fields_for 'phoneNumber' => phone_number, 'text' => text, '_rnr_se' => session_id
  post send_url, fields
end