copiagenda4omf 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-05-05
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 FIXME full name
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.
@@ -0,0 +1,27 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.txt
6
+ Rakefile
7
+ config/hoe.rb
8
+ config/requirements.rb
9
+ lib/copiagenda.rb
10
+ lib/copiagenda/version.rb
11
+ script/console
12
+ script/destroy
13
+ script/generate
14
+ script/txt2html
15
+ setup.rb
16
+ spec/copiagenda_spec.rb
17
+ spec/spec.opts
18
+ spec/spec_helper.rb
19
+ tasks/deployment.rake
20
+ tasks/environment.rake
21
+ tasks/rspec.rake
22
+ tasks/website.rake
23
+ website/index.html
24
+ website/index.txt
25
+ website/javascripts/rounded_corners_lite.inc.js
26
+ website/stylesheets/screen.css
27
+ website/template.html.erb
@@ -0,0 +1,7 @@
1
+
2
+ For more information on copiagenda, see http://copiagenda.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
@@ -0,0 +1,48 @@
1
+ = copiagenda
2
+
3
+ * FIX (url)
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2008 FIX
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,73 @@
1
+ require 'copiagenda/version'
2
+
3
+ AUTHOR = 'manuel muñoz solera' # can also be an array of Authors
4
+ EMAIL = "mamuso@mamuso.net"
5
+ DESCRIPTION = "Get your mobile contacts from copiagenda (http://copiagenda.movistar.es/)"
6
+ GEM_NAME = 'copiagenda4omf' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'copiagenda4omf' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ # ['activesupport', '>= 1.3.1']
12
+ ] # An array of rubygem dependencies [name, version]
13
+
14
+ @config_file = "~/.rubyforge/user-config.yml"
15
+ @config = nil
16
+ RUBYFORGE_USERNAME = "mamuso"
17
+ def rubyforge_username
18
+ unless @config
19
+ begin
20
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
21
+ rescue
22
+ puts <<-EOS
23
+ ERROR: No rubyforge config file found: #{@config_file}
24
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
25
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
26
+ EOS
27
+ exit
28
+ end
29
+ end
30
+ RUBYFORGE_USERNAME.replace @config["username"]
31
+ end
32
+
33
+
34
+ REV = nil
35
+ # UNCOMMENT IF REQUIRED:
36
+ # REV = YAML.load(`svn info`)['Revision']
37
+ VERS = Copiagenda::VERSION::STRING + (REV ? ".#{REV}" : "")
38
+ RDOC_OPTS = ['--quiet', '--title', 'copiagenda documentation',
39
+ "--opname", "index.html",
40
+ "--line-numbers",
41
+ "--main", "README",
42
+ "--inline-source"]
43
+
44
+ class Hoe
45
+ def extra_deps
46
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
47
+ @extra_deps
48
+ end
49
+ end
50
+
51
+ # Generate all the Rake tasks
52
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
53
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
54
+ p.developer(AUTHOR, EMAIL)
55
+ p.description = DESCRIPTION
56
+ p.summary = DESCRIPTION
57
+ p.url = HOMEPATH
58
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
59
+ p.test_globs = ["test/**/test_*.rb"]
60
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
61
+
62
+ # == Optional
63
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
64
+ #p.extra_deps = EXTRA_DEPENDENCIES
65
+
66
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
+ end
68
+
69
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ $hoe.rsync_args = '-av --delete --ignore-errors'
73
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,20 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ require 'hpricot'
6
+ require 'net/http'
7
+ require 'net/https'
8
+ require 'uri'
9
+
10
+ %w[rake hoe newgem rubigen].each do |req_gem|
11
+ begin
12
+ require req_gem
13
+ rescue LoadError
14
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
15
+ puts "Installation: gem install #{req_gem} -y"
16
+ exit
17
+ end
18
+ end
19
+
20
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -0,0 +1,130 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'rubygems'
5
+ require 'hpricot'
6
+ require 'net/http'
7
+ require 'net/https'
8
+ require 'uri'
9
+
10
+ class Copiagenda
11
+
12
+ def initialize(login, password)
13
+ raise ArgumentError, "login can not be blank" if login == ""
14
+ raise ArgumentError, "password can not be blank" if password == ""
15
+ @login = login.to_s
16
+ @password = password.to_s
17
+ end
18
+
19
+
20
+ def RetrieveContacts
21
+ contacts = parse_contacts(get_data)
22
+ return contacts
23
+ end
24
+
25
+ alias_method :get_contacts, :RetrieveContacts
26
+
27
+
28
+ def get_data
29
+ # urlS
30
+ url = "copiagenda.movistar.es"
31
+ url_login = "/cp/ps/Main/login/Agenda"
32
+ url_verification = "/cp/ps/Main/login/Verificacion?d=movistar.es"
33
+ url_token = "/cp/ps/Main/login/Authenticate"
34
+ url_ask = "/cp/ps/PSPab/preferences/ExportContacts?d=movistar.es&c=yes"
35
+
36
+ ## iniciamos conexión
37
+ http = Net::HTTP.new(url, 443)
38
+ http.use_ssl = true
39
+
40
+ ## nos logueamos
41
+ data = "TM_ACTION=LOGIN&TM_LOGIN=#{@login}&TM_PASSWORD=#{@password}"
42
+ headers = {
43
+ 'User-Agent' => 'Mozilla/4.0',
44
+ 'Content-Type' => 'application/x-www-form-urlencoded',
45
+ 'Connection' => 'Keep-Alive'
46
+ }
47
+ resp, data = http.post(url_login, data, headers)
48
+ cookie = resp.response['set-cookie']
49
+ cookie = cookie.sub(" Path=/, "," ")
50
+ cookie = cookie.sub("; Domain=.movistar.es; Path=/","")
51
+ cookie = cookie.rstrip
52
+
53
+ ## conseguimos con la cookie el token de sesión
54
+ headers = {
55
+ 'Cookie' => cookie,
56
+ 'User-Agent' => 'Mozilla/4.0',
57
+ 'Content-Type' => 'application/x-www-form-urlencoded',
58
+ 'Connection' => 'Keep-Alive'
59
+ }
60
+ resp, data = http.get(url_verification, headers)
61
+
62
+ # pasamos la respuesta por hpricot para buscar la password codificada
63
+ doc = Hpricot(resp.response.body)
64
+ passfield = doc.search("//input[@name='password']")
65
+ # si no econtramos el campo no podemos verificarlo
66
+ raise "Invalid username or password" if passfield.size == 0
67
+ passCode = passfield.first.attributes['value']
68
+
69
+ data = "password=#{passCode}&u=#{@login}&d=movistar.es"
70
+ headers = {
71
+ 'Cookie' => cookie,
72
+ 'User-Agent' => 'Mozilla/4.0',
73
+ 'Accept-Encoding' => 'gzip, deflate',
74
+ 'Host' => 'copiagenda.movistar.es',
75
+ 'Referer' => 'https://copiagenda.movistar.es/cp/ps/Main/login/Verificacion?d=movistar.es',
76
+ 'Content-Type' => 'application/x-www-form-urlencoded',
77
+ 'Connection' => 'Keep-Alive'
78
+ }
79
+
80
+ resp, data = http.post(url_token, data, headers)
81
+ doc = Hpricot(resp.response.body)
82
+ frameSrc = doc.search("//frame[@name='BrandHeader']").first.attributes["src"].to_hash
83
+ token = frameSrc.fetch("t")
84
+
85
+ data = "fileFormat=TEXT&charset=UTF8&delimiter=TAB"
86
+ headers = {
87
+ 'Cookie' => cookie,
88
+ 'User-Agent' => 'Mozilla/4.0',
89
+ 'Accept-Encoding' => 'gzip, deflate',
90
+ 'Host' => 'copiagenda.movistar.es',
91
+ 'Referer' => 'https://copiagenda.movistar.es/cp/ps/Main/login/Verificacion?d=movistar.es',
92
+ 'Content-Type' => 'application/x-www-form-urlencoded',
93
+ 'Accept-Language' => 'es',
94
+ 'Cache-Control' => 'no-cache',
95
+ 'Connection' => 'Keep-Alive'
96
+ }
97
+ resp, data = http.post("#{url_ask}&u=#{@login}&t=#{token}", data, headers)
98
+
99
+ doc = Hpricot(resp.response.body)
100
+ # eliminamos script tag y comentarios
101
+ doc.search("script").remove
102
+ doc.search("*").map{|e| e.swap("") if e.comment?}
103
+ csv = doc.to_s
104
+
105
+ end
106
+
107
+
108
+ def parse_contacts(csv)
109
+ contactos = []
110
+ csv = csv.split("\r")
111
+ csv.each_with_index do |row, index|
112
+ if index > 0 && row.split("\"\t\"").size > 1
113
+ contactos << row.split("\"\t\"")
114
+ end
115
+ end
116
+ contactos
117
+ end
118
+
119
+ end
120
+
121
+ class String
122
+ def to_hash(seperation='&', assignment='=')
123
+ hash = Hash.new
124
+ self.split(seperation).each do |elemement|
125
+ pieces = elemement.split(assignment)
126
+ hash[pieces[0]] = pieces[1]
127
+ end
128
+ hash.delete_if { |key, value| value.nil? }
129
+ end
130
+ end
@@ -0,0 +1,9 @@
1
+ module Copiagenda #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/copiagenda.rb'}"
9
+ puts "Loading copiagenda gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ GEM_NAME = 'copiagenda' # what ppl will type to install your gem
4
+ RUBYFORGE_PROJECT = 'copiagenda'
5
+
6
+ require 'rubygems'
7
+ begin
8
+ require 'newgem'
9
+ require 'rubyforge'
10
+ rescue LoadError
11
+ puts "\n\nGenerating the website requires the newgem RubyGem"
12
+ puts "Install: gem install newgem\n\n"
13
+ exit(1)
14
+ end
15
+ require 'redcloth'
16
+ require 'syntax/convertors/html'
17
+ require 'erb'
18
+ require File.dirname(__FILE__) + "/../lib/#{GEM_NAME}/version.rb"
19
+
20
+ version = Copiagenda::VERSION::STRING
21
+ download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
22
+
23
+ def rubyforge_project_id
24
+ RubyForge.new.autoconfig["group_ids"][RUBYFORGE_PROJECT]
25
+ end
26
+
27
+ class Fixnum
28
+ def ordinal
29
+ # teens
30
+ return 'th' if (10..19).include?(self % 100)
31
+ # others
32
+ case self % 10
33
+ when 1: return 'st'
34
+ when 2: return 'nd'
35
+ when 3: return 'rd'
36
+ else return 'th'
37
+ end
38
+ end
39
+ end
40
+
41
+ class Time
42
+ def pretty
43
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
44
+ end
45
+ end
46
+
47
+ def convert_syntax(syntax, source)
48
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
49
+ end
50
+
51
+ if ARGV.length >= 1
52
+ src, template = ARGV
53
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
54
+ else
55
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
56
+ exit!
57
+ end
58
+
59
+ template = ERB.new(File.open(template).read)
60
+
61
+ title = nil
62
+ body = nil
63
+ File.open(src) do |fsrc|
64
+ title_text = fsrc.readline
65
+ body_text_template = fsrc.read
66
+ body_text = ERB.new(body_text_template).result(binding)
67
+ syntax_items = []
68
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
69
+ ident = syntax_items.length
70
+ element, syntax, source = $1, $2, $3
71
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
72
+ "syntax-temp-#{ident}"
73
+ }
74
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
75
+ body = RedCloth.new(body_text).to_html
76
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
77
+ end
78
+ stat = File.stat(src)
79
+ created = stat.ctime
80
+ modified = stat.mtime
81
+
82
+ $stdout << template.result(binding)