google-voice 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Some portions Copyright (c) 2009 Jeff Rafter
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,20 @@
1
+ = Google Voice
2
+
3
+ There is not currently an api for Google Voice. This lib tries to get around
4
+ that. Most of this is based on http://github.com/kgautreaux/gvoice-ruby.
5
+
6
+ == Resources
7
+
8
+ http://adriel.dynalias.com/blog/?p=252
9
+ http://posttopic.com/topic/google-voice-add-on-development
10
+
11
+ == Note on Patches/Pull Requests
12
+
13
+ * Fork the project.
14
+ * Make your feature addition or bug fix.
15
+ * Add tests for it. This is important so I don't break it in a
16
+ future version unintentionally.
17
+ * Commit, do not mess with rakefile, version, or history.
18
+ (if you want to have your own version, that is fine but
19
+ bump version in a commit by itself I can ignore when I pull)
20
+ * Send me a pull request. Bonus points for topic branches
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "google-voice"
8
+ gem.summary = %Q{Google Voice Library}
9
+ gem.description = %Q{Google Voice does not have an API. This library gets around that limitation. }
10
+ gem.email = "jeff@socialrange.org"
11
+ gem.homepage = "http://github.com/jeffrafter/google-voice"
12
+ gem.authors = ["Jeff Rafter"]
13
+ gem.add_development_dependency "shoulda"
14
+ gem.add_dependency "curb"
15
+ gem.add_dependency "nokogiri"
16
+ gem.add_dependency "json"
17
+ gem.files = FileList["[A-Z]*", "{lib}/**/*"]
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/*_test.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/*_test.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ if File.exist?('VERSION')
51
+ version = File.read('VERSION')
52
+ else
53
+ version = ""
54
+ end
55
+
56
+ rdoc.rdoc_dir = 'rdoc'
57
+ rdoc.title = "google-voice #{version}"
58
+ rdoc.rdoc_files.include('README*')
59
+ rdoc.rdoc_files.include('lib/**/*.rb')
60
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,3 @@
1
+ require 'google/voice/base'
2
+ require 'google/voice/sms'
3
+ require 'google/voice/missed'
@@ -0,0 +1,90 @@
1
+ # coding: UTF-8
2
+ require 'rubygems'
3
+ require 'curb'
4
+ require 'nokogiri'
5
+
6
+ module Google
7
+ module Voice
8
+ class Base
9
+ def initialize(email, password)
10
+ @email = email
11
+ @password = password
12
+ login
13
+ set_rnr_se_token
14
+ end
15
+
16
+ def finalize
17
+ logout
18
+ end
19
+
20
+ def delete(ids)
21
+ ids = Array(ids)
22
+ fields = [
23
+ Curl::PostField.content('_rnr_se', @_rnr_se),
24
+ Curl::PostField.content('trash', '1')]
25
+ ids.each{|id| fields << Curl::PostField.content('messages', id)}
26
+ @curb.http_post(fields)
27
+ @curb.url = "https://www.google.com/voice/inbox/deleteMessages/"
28
+ @curb.perform
29
+ @curb.response_code
30
+ end
31
+
32
+ def mark(ids, read = true)
33
+ ids = Array(ids)
34
+ fields = [
35
+ Curl::PostField.content('_rnr_se', @_rnr_se),
36
+ Curl::PostField.content('read', read ? '1' : '0')]
37
+ ids.each{|id| fields << Curl::PostField.content('messages', id)}
38
+ @curb.http_post(fields)
39
+ @curb.url = "https://www.google.com/voice/inbox/mark/"
40
+ @curb.perform
41
+ @curb.response_code
42
+ end
43
+
44
+ private
45
+ def login
46
+ @curb = Curl::Easy.new('https://www.google.com/accounts/ServiceLoginAuth') do |curl|
47
+ curl.headers["User-Agent"] = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2"
48
+ # curl.verbose = true
49
+ curl.follow_location = true
50
+ curl.enable_cookies = true
51
+ curl.perform
52
+
53
+ # Defeat Google's XSRF protection
54
+ doc = Nokogiri::HTML::DocumentFragment.parse(curl.body_str)
55
+ doc.css('div.loginBox table#gaia_table input').each do |input|
56
+ if input.to_s =~ /GALX/
57
+ @galx = input.to_s.scan(/value\="(.+?)"/).flatten!.pop
58
+ end
59
+ end
60
+
61
+ curl.http_post([
62
+ Curl::PostField.content('continue', 'https://www.google.com/voice'),
63
+ Curl::PostField.content('service', 'grandcentral'),
64
+ Curl::PostField.content('GALX', @galx),
65
+ Curl::PostField.content('Email', @email),
66
+ Curl::PostField.content('Passwd', @password)
67
+ ])
68
+ end
69
+
70
+ unless @curb.instance_of?(Curl::Easy) && @curb.response_code == 200
71
+ raise IOError, "Could not login to service"
72
+ end
73
+ end
74
+
75
+ def logout
76
+ @curb.url = "https://www.google.com/voice/account/signout"
77
+ @curb.perform
78
+ @curb = nil
79
+ end
80
+
81
+ def set_rnr_se_token
82
+ @curb.url = "http://www.google.com/voice"
83
+ @curb.perform
84
+ @_rnr_se = Nokogiri::HTML::Document.parse(@curb.body_str).css('form#gc-search-form').inner_html
85
+ /value="(.+)"/.match(@_rnr_se)
86
+ @_rnr_se = $1
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,31 @@
1
+ # coding: UTF-8
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'base')
3
+ require 'json'
4
+
5
+ module Google
6
+ module Voice
7
+ class Missed < Base
8
+ def missed
9
+ @curb.url = "https://www.google.com/voice/inbox/recent/missed/"
10
+ @curb.http_get
11
+ calls = []
12
+ doc = Nokogiri::XML::Document.parse(@curb.body_str)
13
+ box = doc.xpath('/response/json').first.text
14
+ json = JSON.parse(box)
15
+ # Format for messages is [id, {attributes}]
16
+ json['messages'].each do |message|
17
+ if message[1]['type'].to_i == 2
18
+ next
19
+ else
20
+ # Google is using milliseconds since epoch for time
21
+ calls << {
22
+ :id => message[0],
23
+ :phone_number => message[1]['phoneNumber'],
24
+ :start_time => Time.at(message[1]['startTime'].to_i / 1000)}
25
+ end
26
+ end
27
+ calls
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ # coding: UTF-8
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'base')
3
+
4
+ module Google
5
+ module Voice
6
+ class Sms < Base
7
+ def sms(number, text)
8
+ @curb.http_post([
9
+ Curl::PostField.content('phoneNumber', number),
10
+ Curl::PostField.content('text', text),
11
+ Curl::PostField.content('_rnr_se', @_rnr_se)
12
+ ])
13
+ @curb.url = "https://www.google.com/voice/sms/send"
14
+ @curb.perform
15
+ @curb.response_code
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'vox'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google-voice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Rafter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-11 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: curb
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: nokogiri
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: json
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ description: "Google Voice does not have an API. This library gets around that limitation. "
56
+ email: jeff@socialrange.org
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - LICENSE
63
+ - README.rdoc
64
+ files:
65
+ - LICENSE
66
+ - README.rdoc
67
+ - Rakefile
68
+ - VERSION
69
+ - lib/google/voice.rb
70
+ - lib/google/voice/base.rb
71
+ - lib/google/voice/missed.rb
72
+ - lib/google/voice/sms.rb
73
+ has_rdoc: true
74
+ homepage: http://github.com/jeffrafter/google-voice
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --charset=UTF-8
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.4
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Google Voice Library
101
+ test_files:
102
+ - test/test_helper.rb