picturepath 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ == 0.0.1 2007-06-20
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
5
+ * Support version 5 of PicturePath AUI
6
+ * Support minimal set of Request fields. Enough to submit a tour link to Realtor.com
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Esomnie, LLC
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,34 @@
1
+ History.txt
2
+ lib/picturepath
3
+ lib/picturepath/account.rb
4
+ lib/picturepath/client.rb
5
+ lib/picturepath/request.rb
6
+ lib/picturepath/response.rb
7
+ lib/picturepath/version.rb
8
+ lib/picturepath.rb
9
+ License.txt
10
+ Manifest.txt
11
+ Rakefile
12
+ README.txt
13
+ scripts/txt2html
14
+ setup.rb
15
+ spec/account_spec.rb
16
+ spec/expected_responses
17
+ spec/expected_responses/check_failed.xml
18
+ spec/expected_responses/check_success.xml
19
+ spec/expected_responses/check_success_partial.xml
20
+ spec/expected_responses/failed.xml
21
+ spec/expected_responses/success.xml
22
+ spec/expected_responses/success_partial.xml
23
+ spec/picturepath_spec.rb
24
+ spec/request_spec.rb
25
+ spec/response_spec.rb
26
+ spec/spec.opts
27
+ spec/spec_helper.rb
28
+ website/index.html
29
+ website/index.txt
30
+ website/javascripts
31
+ website/javascripts/rounded_corners_lite.inc.js
32
+ website/stylesheets
33
+ website/stylesheets/screen.css
34
+ website/template.rhtml
@@ -0,0 +1,3 @@
1
+ README for picturepath
2
+ ======================
3
+
@@ -0,0 +1,139 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ require 'hoe'
11
+ begin
12
+ require 'spec/rake/spectask'
13
+ rescue LoadError
14
+ puts 'To use rspec for testing you must install rspec gem:'
15
+ puts '$ sudo gem install rspec'
16
+ exit
17
+ end
18
+
19
+ include FileUtils
20
+ require File.join(File.dirname(__FILE__), 'lib', 'picturepath', 'version')
21
+
22
+ AUTHOR = 'Dean Mao, Ben Curren' # can also be an array of Authors
23
+ EMAIL = "dean@esomnie.com, ben@esomnie.com"
24
+ DESCRIPTION = "Ruby wrapper for submitting virtual tours to Realtor.com using the PicturePath AUI."
25
+ GEM_NAME = 'picturepath' # what ppl will type to install your gem
26
+
27
+ @config_file = "~/.rubyforge/user-config.yml"
28
+ @config = nil
29
+ def rubyforge_username
30
+ unless @config
31
+ begin
32
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
33
+ rescue
34
+ puts <<-EOS
35
+ ERROR: No rubyforge config file found: #{@config_file}"
36
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
37
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
38
+ EOS
39
+ exit
40
+ end
41
+ end
42
+ @rubyforge_username ||= @config["username"]
43
+ end
44
+
45
+ RUBYFORGE_PROJECT = 'picturepath' # The unix name for your project
46
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
47
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
48
+
49
+ NAME = "picturepath"
50
+ REV = nil
51
+ # UNCOMMENT IF REQUIRED:
52
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
53
+ VERS = PicturePath::VERSION::STRING + (REV ? ".#{REV}" : "")
54
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
55
+ RDOC_OPTS = ['--quiet', '--title', 'picturepath documentation',
56
+ "--opname", "index.html",
57
+ "--line-numbers",
58
+ "--main", "README",
59
+ "--inline-source"]
60
+
61
+ class Hoe
62
+ def extra_deps
63
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
64
+ end
65
+ end
66
+
67
+ # Generate all the Rake tasks
68
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
69
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
70
+ p.author = AUTHOR
71
+ p.description = DESCRIPTION
72
+ p.email = EMAIL
73
+ p.summary = DESCRIPTION
74
+ p.url = HOMEPATH
75
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
76
+ p.test_globs = ["test/**/test_*.rb"]
77
+ p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
78
+
79
+ # == Optional
80
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
81
+ p.extra_deps = ["builder", ">=2.1.0"] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
82
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
83
+ end
84
+
85
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
86
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
87
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
88
+
89
+ desc 'Generate website files'
90
+ task :website_generate do
91
+ Dir['website/**/*.txt'].each do |txt|
92
+ sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
93
+ end
94
+ end
95
+
96
+ desc 'Upload website files to rubyforge'
97
+ task :website_upload do
98
+ host = "#{rubyforge_username}@rubyforge.org"
99
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
100
+ local_dir = 'website'
101
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
102
+ end
103
+
104
+ desc 'Generate and upload website files'
105
+ task :website => [:website_generate, :website_upload, :publish_docs]
106
+
107
+ desc 'Release the website and new gem version'
108
+ task :deploy => [:check_version, :website, :release] do
109
+ puts "Remember to create SVN tag:"
110
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
111
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
112
+ puts "Suggested comment:"
113
+ puts "Tagging release #{CHANGES}"
114
+ end
115
+
116
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
117
+ task :local_deploy => [:website_generate, :install_gem]
118
+
119
+ task :check_version do
120
+ unless ENV['VERSION']
121
+ puts 'Must pass a VERSION=x.y.z release version'
122
+ exit
123
+ end
124
+ unless ENV['VERSION'] == VERS
125
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
126
+ exit
127
+ end
128
+ end
129
+
130
+ desc "Run the specs under spec/models"
131
+ Spec::Rake::SpecTask.new do |t|
132
+ t.libs.push "lib"
133
+ t.spec_opts = ['--options', "spec/spec.opts"]
134
+ t.spec_files = FileList['spec/*_spec.rb']
135
+ end
136
+
137
+ desc "Default task is to run specs"
138
+ task :default => :spec
139
+
@@ -0,0 +1,8 @@
1
+ module PicturePath #:nodoc
2
+ end
3
+
4
+ require 'picturepath/client'
5
+ require 'picturepath/request'
6
+ require 'picturepath/response'
7
+ require 'picturepath/account'
8
+ require 'picturepath/version'
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'cgi'
3
+
4
+ module PicturePath #:nodoc
5
+ # PicturePath account information
6
+ class Account
7
+ @@ESCAPE = "escape_"
8
+ attr_accessor :username, :password, :action_url
9
+
10
+ # Escape properties starting with escape_ using CGI.escape
11
+ def method_missing(method_id, *arguments)
12
+ method_name = method_id.to_s
13
+ if method_name[0..@@ESCAPE.length-1] == @@ESCAPE
14
+ method = method_name[@@ESCAPE.length..method_name.length].to_sym
15
+ return CGI.escape(send(method))
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'cgi'
3
+ require 'open-uri'
4
+
5
+ module PicturePath #:nodoc
6
+ # The client that submits a request and returns a response.
7
+ class Client
8
+
9
+ # Submit a request to the provided account. Use :check as the action to simulate a request and response
10
+ # and use :submit to actually submit the request.
11
+ def self.submit(request, account, action)
12
+ if action == :submit
13
+ action = "Submit"
14
+ elsif action == :check
15
+ action = "Check"
16
+ else
17
+ raise "Action can only be :submit or :check"
18
+ end
19
+ xml = CGI.escape(request.to_xml)
20
+ postUrl = "username=#{account.escape_username}&password=#{account.escape_password}&client=AUI&version=5.0&action=#{action}&xml=#{xml}"
21
+ url = "#{account.action_url}?#{postUrl}"
22
+
23
+ output = open(url).read
24
+
25
+ return Response.new(output)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'builder'
3
+
4
+ module PicturePath #:nodoc
5
+ class Request
6
+ VERSION = 5.0
7
+ COUNTRY_US = "US"
8
+
9
+ attr_accessor :customer_number, :order_number, :product_line, :street1, :street2,
10
+ :city, :state, :zip_code, :country, :mls_id, :tour_url, :site_realtor
11
+
12
+ # Create a valide XML request from the properties set on the request.
13
+ # Note: the PicturePath AUI requires capitalized tags
14
+ def to_xml
15
+ output = ""
16
+ x = Builder::XmlMarkup.new(:target => output, :indent => 1)
17
+ x.instruct!
18
+ x.AUI_SUBMISSION(:VERSION => VERSION) {
19
+ x.TOUR {
20
+ x.CUSTREFNUM customer_number
21
+ (order_number != nil) && (x.ORDERNUM order_number)
22
+ x.PRODUCT_LINE product_line
23
+ x.ADDRESS {
24
+ x.STREET1 street1
25
+ x.STREET2 street2
26
+ x.CITY city
27
+ x.STATE state
28
+ x.COUNTRY(:CODE => (country || COUNTRY_US))
29
+ x.ZIP zip_code
30
+ }
31
+ x.IDENTIFIERS {
32
+ x.ID1(:VALUE => mls_id, :TYPE => "MLSID")
33
+ }
34
+ x.DISTRIBUTION {
35
+ if site_realtor.class == Array
36
+ site_realtor.each do |site|
37
+ x.SITE site
38
+ end
39
+ else
40
+ x.SITE site_realtor
41
+ end
42
+ }
43
+ x.TOUR_URL tour_url
44
+ }
45
+ }
46
+ return output
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'rexml/document'
3
+
4
+ module PicturePath #:nodoc
5
+ # The PicturePath response returned from the client
6
+ class Response
7
+ include REXML
8
+ attr_accessor :status_code, :order_number, :messages, :price
9
+
10
+ # Create a response by parsing an xml response string.
11
+ def initialize(xml)
12
+ @messages = []
13
+ parse_xml(xml)
14
+ end
15
+
16
+ def success?
17
+ return status_code >= 0 && status_code <= 3
18
+ end
19
+
20
+ def warning?
21
+ return status_code >= 100 && status_code <= 200
22
+ end
23
+
24
+ def error?
25
+ return !success? && !warning?
26
+ end
27
+
28
+ def system_unavailable?
29
+ return status_code == 1000
30
+ end
31
+
32
+ # Return true if the submition charged the account money for the post.
33
+ def charge_applies?
34
+ return price != null && price > 0
35
+ end
36
+
37
+ # Parse the response xml to a Response object
38
+ def parse_xml(xml)
39
+ doc = Document.new(xml)
40
+ order_number_node = XPath.first(doc, '//ORDER_NUMBER')
41
+ @order_number = (order_number_node && order_number_node[0])
42
+
43
+ # which message do we use for the status_code??
44
+ XPath.each(doc, '//MESSAGE') do |message|
45
+ code = message.attributes['CODE'].to_i
46
+ description = message.attributes['DESCRIPTION']
47
+ text = message.text
48
+ @messages.push :code => code, :description => description, :text => text
49
+ if code >= 4000 && @order_number == nil && text =~ /Please use edit \(order number \w+\)/
50
+ @order_number = /order number (\w+)/.match(text.to_s)[1]
51
+ end
52
+ end
53
+ if @messages.size > 0
54
+ @status_code = @messages[0][:code]
55
+ end
56
+
57
+ @price = 0
58
+ XPath.each(doc, '//PRODUCT') do |message|
59
+ @price += message.attributes['PRICE'].to_f
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,9 @@
1
+ module PicturePath #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 5
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'redcloth'
5
+ require 'syntax/convertors/html'
6
+ require 'erb'
7
+ require File.dirname(__FILE__) + '/../lib/picturepath/version.rb'
8
+
9
+ version = PicturePath::VERSION::STRING
10
+ download = 'http://rubyforge.org/projects/picturepath'
11
+
12
+ class Fixnum
13
+ def ordinal
14
+ # teens
15
+ return 'th' if (10..19).include?(self % 100)
16
+ # others
17
+ case self % 10
18
+ when 1: return 'st'
19
+ when 2: return 'nd'
20
+ when 3: return 'rd'
21
+ else return 'th'
22
+ end
23
+ end
24
+ end
25
+
26
+ class Time
27
+ def pretty
28
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
29
+ end
30
+ end
31
+
32
+ def convert_syntax(syntax, source)
33
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
34
+ end
35
+
36
+ if ARGV.length >= 1
37
+ src, template = ARGV
38
+ template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
39
+
40
+ else
41
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
42
+ exit!
43
+ end
44
+
45
+ template = ERB.new(File.open(template).read)
46
+
47
+ title = nil
48
+ body = nil
49
+ File.open(src) do |fsrc|
50
+ title_text = fsrc.readline
51
+ body_text = fsrc.read
52
+ syntax_items = []
53
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
54
+ ident = syntax_items.length
55
+ element, syntax, source = $1, $2, $3
56
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
57
+ "syntax-temp-#{ident}"
58
+ }
59
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
60
+ body = RedCloth.new(body_text).to_html
61
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
62
+ end
63
+ stat = File.stat(src)
64
+ created = stat.ctime
65
+ modified = stat.mtime
66
+
67
+ $stdout << template.result(binding)