google-voice 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/google/voice/sms.rb +15 -30
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.3
@@ -1,8 +1,6 @@
1
1
  # coding: UTF-8
2
2
  require File.join(File.expand_path(File.dirname(__FILE__)), 'base')
3
3
 
4
- GOOGLE_VOICE_SMS_TYPE = 11
5
-
6
4
  module Google
7
5
  module Voice
8
6
  class Sms < Base
@@ -20,40 +18,27 @@ module Google
20
18
  def recent
21
19
  @curb.url = "https://www.google.com/voice/inbox/recent/"
22
20
  @curb.http_get
23
- sms = []
24
21
  doc = Nokogiri::XML::Document.parse(@curb.body_str)
25
22
  data = doc.xpath('/response/json').first.text
26
23
  html = Nokogiri::HTML::DocumentFragment.parse(doc.to_html)
27
24
  json = JSON.parse(data)
28
25
  # Format for messages is [id, {attributes}]
29
- json['messages'].each do |message|
30
- if message[1]['type'].to_i != GOOGLE_VOICE_SMS_TYPE
31
- next
32
- else
33
- messages = []
34
- html.css('div.gc-message-sms-row').each do |row|
35
- if row.css('span.gc-message-sms-from').inner_html.strip! =~ /Me:/
36
- next
37
- elsif row.css('span.gc-message-sms-time').inner_html =~ Regexp.new(txt_obj.display_start_time)
38
- messages << {
39
- :to => 'Me',
40
- :from => row.css('span.gc-message-sms-from').inner_html.strip!.gsub!(':', ''),
41
- :text => row.css('span.gc-message-sms-text').inner_html,
42
- :time => row.css('span.gc-message-sms-time').inner_html
43
- }
44
- end
45
- end
46
- # Google is using milliseconds since epoch for time
47
- sms << {
48
- :id => message[0],
49
- :phone_number => message[1]['phoneNumber'],
50
- :start_time => Time.at(message[1]['startTime'].to_i / 1000),
51
- :messages => messages}
26
+ json['messages'].map do |conversation|
27
+ next unless conversation[1]['labels'].include? "sms"
28
+ html.css("##{conversation[0]} div.gc-message-sms-row").map do |row|
29
+ next if row.css('span.gc-message-sms-from').inner_html.strip! =~ /Me:/
30
+ text = row.css('span.gc-message-sms-text').inner_html
31
+ time = row.css('span.gc-message-sms-time').inner_html
32
+ from = conversation[1]['phoneNumber']
33
+ {
34
+ :id => Digest::SHA1.hexdigest(conversation[0]+text+from),
35
+ :text => text,
36
+ :time => time,
37
+ :from => from
38
+ }
52
39
  end
53
- end
54
- sms
40
+ end.flatten.compact
55
41
  end
56
-
57
42
  end
58
43
  end
59
- end
44
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jeff Rafter
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-01 00:00:00 -07:00
17
+ date: 2010-04-02 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency