google_text 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec'
4
+ require 'fakeweb'
5
+
1
6
  require File.expand_path(File.dirname(__FILE__) + "/../lib/google_text")
2
7
 
3
- Rspec.configure do |c|
4
- c.mock_with :rspec
8
+ RSpec.configure do |config|
9
+ config.color_enabled = true
10
+ config.formatter = 'documentation'
11
+ config.mock_with :rspec
12
+
13
+ config.before(:each) do
14
+ FakeWeb.allow_net_connect = false
15
+ end
16
+
5
17
  end
metadata CHANGED
@@ -1,130 +1,142 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: google_text
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Sebastian Friedrich
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-10-04 00:00:00 -05:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: curb
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ~>
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 7
30
- - 6
31
- version: 0.7.6
12
+ date: 2011-09-23 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &70186820751120 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: nokogiri
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- version: "0"
24
+ version_requirements: *70186820751120
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ requirement: &70186820747380 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
44
33
  type: :runtime
45
- version_requirements: *id002
46
- - !ruby/object:Gem::Dependency
47
- name: json
48
34
  prerelease: false
49
- requirement: &id003 !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
- version: "0"
35
+ version_requirements: *70186820747380
36
+ - !ruby/object:Gem::Dependency
37
+ name: curb
38
+ requirement: &70186820746460 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.7.6
56
44
  type: :runtime
57
- version_requirements: *id003
58
- - !ruby/object:Gem::Dependency
45
+ prerelease: false
46
+ version_requirements: *70186820746460
47
+ - !ruby/object:Gem::Dependency
59
48
  name: rspec
49
+ requirement: &70186820745880 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
60
56
  prerelease: false
61
- requirement: &id004 !ruby/object:Gem::Requirement
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- segments:
66
- - 0
67
- version: "0"
57
+ version_requirements: *70186820745880
58
+ - !ruby/object:Gem::Dependency
59
+ name: fakeweb
60
+ requirement: &70186820745300 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
68
66
  type: :development
69
- version_requirements: *id004
70
- description: GoogleText is a SMS client library for sending and receiving free SMS through Google Voice. Alas, Google Voice does not yet have an API, so GoogleText uses Curl and Nokogiri to scrape and post using Google Voice web URLs.
67
+ prerelease: false
68
+ version_requirements: *70186820745300
69
+ description: GoogleText is a SMS client library for sending and receiving free SMS
70
+ through Google Voice. Alas, Google Voice does not yet have an API, so GoogleText
71
+ uses Curl and Nokogiri to scrape and post using Google Voice web URLs.
71
72
  email: sebastian@feldpost.com
72
73
  executables: []
73
-
74
74
  extensions: []
75
-
76
75
  extra_rdoc_files: []
77
-
78
- files:
79
- - README.md
80
- - Rakefile
81
- - LICENSE
76
+ files:
77
+ - .gitignore
82
78
  - CONTRIBUTORS
79
+ - Gemfile
80
+ - Gemfile.lock
83
81
  - HISTORY.md
84
- - VERSION
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - google_text.gemspec
86
+ - lib/google_text.rb
85
87
  - lib/google_text/account.rb
86
88
  - lib/google_text/client.rb
87
89
  - lib/google_text/configuration.rb
88
90
  - lib/google_text/message.rb
89
- - lib/google_text/parser.rb
91
+ - lib/google_text/parsers/base.rb
92
+ - lib/google_text/parsers/dashboard.rb
93
+ - lib/google_text/parsers/inbox.rb
94
+ - lib/google_text/parsers/login.rb
90
95
  - lib/google_text/session.rb
91
96
  - lib/google_text/version.rb
92
- - lib/google_text.rb
97
+ - spec/data/dashboard_url.html
98
+ - spec/data/login_url.html
99
+ - spec/data/recent_messages.html
93
100
  - spec/google-text/client_spec.rb
94
101
  - spec/google-text/configuration_spec.rb
95
102
  - spec/google-text/message_spec.rb
103
+ - spec/google-text/parsers/dashboard_spec.rb
104
+ - spec/google-text/parsers/inbox_spec.rb
105
+ - spec/google-text/parsers/login_spec.rb
96
106
  - spec/spec_helper.rb
97
- has_rdoc: true
98
107
  homepage: http://github.com/feldpost/google_text
99
108
  licenses: []
100
-
101
109
  post_install_message:
102
110
  rdoc_options: []
103
-
104
- require_paths:
111
+ require_paths:
105
112
  - lib
106
- required_ruby_version: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- segments:
111
- - 0
112
- version: "0"
113
- required_rubygems_version: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- segments:
118
- - 0
119
- version: "0"
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
120
125
  requirements: []
121
-
122
126
  rubyforge_project: google_text
123
- rubygems_version: 1.3.6
127
+ rubygems_version: 1.8.10
124
128
  signing_key:
125
129
  specification_version: 3
126
- summary: GoogleText is a SMS client library for sending and receiving free SMS through Google Voice.
127
- test_files:
130
+ summary: GoogleText is a SMS client library for sending and receiving free SMS through
131
+ Google Voice.
132
+ test_files:
133
+ - spec/data/dashboard_url.html
134
+ - spec/data/login_url.html
135
+ - spec/data/recent_messages.html
128
136
  - spec/google-text/client_spec.rb
129
137
  - spec/google-text/configuration_spec.rb
130
138
  - spec/google-text/message_spec.rb
139
+ - spec/google-text/parsers/dashboard_spec.rb
140
+ - spec/google-text/parsers/inbox_spec.rb
141
+ - spec/google-text/parsers/login_spec.rb
142
+ - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.2
@@ -1,107 +0,0 @@
1
- module GoogleText
2
- class Parser
3
- attr_accessor :messages
4
-
5
- CSS_SELECTORS = {
6
- :session_id => 'form#gc-search-form',
7
- :xsrf_token => 'div.loginBox table#gaia_table input',
8
- :message_row => 'div.gc-message-sms-row',
9
- :message_from => 'span.gc-message-sms-from',
10
- :message_time => 'span.gc-message-sms-time',
11
- :message_text => 'span.gc-message-sms-text'
12
- }
13
-
14
- def session_id_from(string)
15
- section = html_for parse_document(string), CSS_SELECTORS[:session_id]
16
- section.match(/value="(.+)"/)[1]
17
- end
18
-
19
- def xsrf_token_from(string)
20
- token = nil
21
- html_for parse_fragment(string), CSS_SELECTORS[:xsrf_token] do |input|
22
- if input.to_s =~ /GALX/
23
- token = input.to_s.scan(/value\="(.+?)"/).flatten.pop
24
- end
25
- end
26
- return token
27
- end
28
-
29
- def messages_from(string)
30
- @messages = []
31
- document = Nokogiri::XML.parse string
32
- html_fragment = parse_fragment document.to_html
33
- string = document.css('json').first.to_s.scan(/CDATA\[(.+)\]\]/).flatten
34
- inbox = JSON.parse(string.first)
35
- parse_messages(inbox['messages'], html_fragment)
36
- return @messages
37
- end
38
-
39
- protected
40
-
41
- def html_for(string,selector)
42
- selected = string.css(selector)
43
- if block_given?
44
- selected.each do |item|
45
- yield(item)
46
- end
47
- else
48
- selected.inner_html
49
- end
50
- end
51
-
52
- def parse_document(string)
53
- Nokogiri::HTML::Document.parse(string)
54
- end
55
-
56
- def parse_fragment(string)
57
- Nokogiri::HTML::DocumentFragment.parse(string)
58
- end
59
-
60
- def parse_messages(json_messages, page_fragment)
61
- build_messages(json_messages)
62
- read_message_details(page_fragment)
63
- return @messages
64
- end
65
-
66
- def build_messages(json_messages)
67
- json_messages.each do |json_message|
68
- if json_message[1]['type'].to_i == 2
69
- next
70
- else
71
- @messages << parse_message(json_message)
72
- end
73
- @messages.sort_by {|message| message.start_time}
74
- end
75
- end
76
-
77
- def read_message_details(page_fragment)
78
- @messages.each do |message|
79
- html_for page_fragment, CSS_SELECTORS[:message_row] do |row|
80
- if html_for(row,CSS_SELECTORS[:message_from]).strip! =~ /Me:/
81
- next
82
- elsif html_for(row, CSS_SELECTORS[:message_time]) =~ Regexp.new(message.display_start_time)
83
- message.to = 'Me'
84
- message.from = html_for(row, CSS_SELECTORS[:message_from]).strip!.gsub!(':', '')
85
- message.text = html_for row, CSS_SELECTORS[:message_text]
86
- else
87
- next
88
- end
89
- end
90
- end
91
- end
92
-
93
- def parse_message(json_array)
94
- message = Message.new
95
- message.id = json_array[0]
96
- message.start_time = json_array[1]['startTime'].to_i
97
- message.read_status = json_array[1]['isRead']
98
- message.display_start_time = json_array[1]['displayStartTime']
99
- message.relative_start_time = json_array[1]['relativeStartTime']
100
- message.display_number = json_array[1]['displayNumber']
101
- message.display_start_date_time = json_array[1]['displayStartDateTime']
102
- message.labels = json_array[1]['labels']
103
- return message
104
- end
105
-
106
- end
107
- end