Class: Google::Voice::Sms
Instance Method Summary collapse
Methods inherited from Base
#archive, #delete, #finalize, #initialize, #mark
Constructor Details
This class inherits a constructor from Google::Voice::Base
Instance Method Details
#recent ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/google/voice/sms.rb', line 18 def recent @curb.url = "https://www.google.com/voice/inbox/recent/" @curb.http_get doc = Nokogiri::XML::Document.parse(@curb.body_str) data = doc.xpath('/response/json').first.text html = Nokogiri::HTML::DocumentFragment.parse(doc.to_html) json = JSON.parse(data) # Format for messages is [id, {attributes}] json['messages'].map do |conversation| next unless conversation[1]['labels'].include? "sms" html.css("##{conversation[0]} div.gc-message-sms-row").map do |row| next if row.css('span.gc-message-sms-from').inner_html.strip! =~ /Me:/ text = row.css('span.gc-message-sms-text').inner_html time = row.css('span.gc-message-sms-time').inner_html from = conversation[1]['phoneNumber'] { :id => Digest::SHA1.hexdigest(conversation[0]+text+from), :text => text, :time => time, :from => from } end end.flatten.compact end |
#sms(number, text) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/google/voice/sms.rb', line 7 def sms(number, text) @curb.http_post([ Curl::PostField.content('phoneNumber', number), Curl::PostField.content('text', text), Curl::PostField.content('_rnr_se', @_rnr_se) ]) @curb.url = "https://www.google.com/voice/sms/send" @curb.perform @curb.response_code end |