josephholsten-rets4r 1.1.13 → 1.1.14

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -34,7 +34,7 @@ end
34
34
  require 'rake/testtask'
35
35
  Rake::TestTask.new(:test) do |test|
36
36
  test.libs << "test"
37
- test.pattern = "test/test_*.rb"
37
+ test.pattern = ["test/test_*.rb", "test/*_test.rb"]
38
38
  test.verbose = true
39
39
  end
40
40
 
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :minor: 1
3
2
  :build:
4
- :patch: 13
3
+ :minor: 1
4
+ :patch: 14
5
5
  :major: 1
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift 'lib'
3
+ require 'rubygems'
4
+ require 'rets4r'
5
+
6
+ xml = ARGF
7
+
8
+ parser = RETS4R::Client::ResponseParser.new
9
+ transaction = parser.parse_results(xml, 'COMPACT')
10
+ transaction.response.each {|row| puts row.inspect }
@@ -27,7 +27,7 @@ login_result = client.login(settings[:username], settings[:password])
27
27
  if login_result.success?
28
28
  puts "We successfully logged into the RETS server!"
29
29
 
30
- options = {'Limit' => 5}
30
+ options = {'Limit' => settings[:limit]}
31
31
 
32
32
  client.search(settings[:resource], settings[:class], settings[:query], options) do |result|
33
33
  result.response.each do |row|
@@ -1,9 +1,12 @@
1
1
  settings:
2
- :rets_url: http://server.com/my/rets/url
3
- :username: username
4
- :password: password
2
+ :url: http://demo.crt.realtors.org:6103/rets/login
3
+ :username: Joe
4
+ :password: Schmoe
5
5
  :resource: Property
6
- :class: Residential
7
- :query: (ModificationTimestamp=2000-01-01-TODAY)
6
+ :class: RES
7
+ :query: (MODIFIED=2009-11-14-TODAY)
8
8
  :object_type: Photo
9
- :resource_id: 'id:*'
9
+ :resource_id: '11003049:*'
10
+ :limit: 400
11
+ #:query: (LISTPRICE=0+)
12
+ #:query: (MODIFIED=2009-11-14-TODAY)
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+ module RETS4R
4
+ class Client
5
+ class CompactNokogiriParser < Nokogiri::XML::SAX::Document
6
+ def parse_results(file)
7
+ doc = CompactDocument.new
8
+ parser = Nokogiri::XML::SAX::Parser.new(doc)
9
+ parser.parse_file(file)
10
+ doc.results
11
+ end
12
+ class CompactDocument < Nokogiri::XML::SAX::Document
13
+ attr_reader :results
14
+
15
+ def initialize
16
+ @results = []
17
+ end
18
+ def start_element name, attrs = []
19
+ case name
20
+ when 'DELIMITER'
21
+ @delimiter = attrs.last.to_i.chr
22
+ when 'COLUMNS'
23
+ @columns_element = true
24
+ when 'DATA'
25
+ @data_element = true
26
+ end
27
+ end
28
+
29
+ def end_element name
30
+ case name
31
+ when 'COLUMNS'
32
+ @columns_element = false
33
+ when 'DATA'
34
+ @data_element = false
35
+ end
36
+ end
37
+
38
+ def characters string
39
+ if @columns_element
40
+ @columns = string.split(@delimiter)
41
+ elsif @data_element
42
+ data = @columns.zip(string.split(@delimiter)).inject({}) do | h,(k,v) |
43
+ h[k] = v unless k.empty?
44
+ next h
45
+ end
46
+ @results << data
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+ module RETS4R
2
+ class Loader
3
+ def self.load(file)
4
+ parser = RETS4R::Client::CompactNokogiriParser.new
5
+ listings = parser.parse_results(file)
6
+
7
+ listings.each {|original|
8
+ yield original
9
+ }
10
+ end
11
+ end
12
+ end
data/lib/rets4r.rb CHANGED
@@ -3,3 +3,5 @@ dir = File.join File.dirname(__FILE__), 'rets4r'
3
3
  $:.unshift(dir) unless $:.include?(dir) || $:.include?(File.expand_path(dir))
4
4
 
5
5
  require 'client'
6
+ require 'loader'
7
+ require 'client/parsers/compact_nokogiri'
@@ -8,6 +8,6 @@ begin
8
8
  end
9
9
  rescue LoadError
10
10
  task :rcov do
11
- abort "RCov is not available. In order to run rcov, you must: sudo gem install relevance-rcov"
11
+ abort "RCov is not available. In order to run rcov, you must: gem install rcov"
12
12
  end
13
13
  end
@@ -0,0 +1,13 @@
1
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
2
+
3
+ require 'test/unit'
4
+ require 'rets4r'
5
+
6
+ class CompactNokogiriTest < Test::Unit::TestCase
7
+ def test_should_do_stuff
8
+ file = File.expand_path(File.join('test', 'data', '1.5', 'search_compact.xml'))
9
+ listings = RETS4R::Client::CompactNokogiriParser.new.parse_results(file)
10
+ assert_equal({"Third"=>"Datum3", "Second"=>"Datum2", "First"=>"Datum1"}, listings[0])
11
+ assert_equal({"Third"=>"Datum6", "Second"=>"Datum5", "First"=>"Datum4"}, listings[1])
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
2
+
3
+ require 'rets4r'
4
+ require 'test/unit'
5
+
6
+ class LoaderTest < Test::Unit::TestCase
7
+ def test_should_pass_records_to_block
8
+ file = File.expand_path(File.join('test', 'data', '1.5', 'search_compact.xml'))
9
+
10
+ listings = []
11
+ RETS4R::Loader.load(file) do |record|
12
+ listings << record
13
+ end
14
+
15
+ assert_equal 2, listings.length
16
+ assert_equal "Datum1", listings[0]['First']
17
+ assert_equal "Datum2", listings[0]['Second']
18
+ assert_equal "Datum3", listings[0]['Third']
19
+ assert_equal "Datum4", listings[1]['First']
20
+ assert_equal "Datum5", listings[1]['Second']
21
+ assert_equal "Datum6", listings[1]['Third']
22
+
23
+ end
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: josephholsten-rets4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.13
4
+ version: 1.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Patterson
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2010-01-21 00:00:00 -06:00
15
+ date: 2010-01-22 00:00:00 -06:00
16
16
  default_executable:
17
17
  dependencies: []
18
18
 
@@ -47,6 +47,7 @@ files:
47
47
  - examples/client_get_object.rb
48
48
  - examples/client_login.rb
49
49
  - examples/client_metadata.rb
50
+ - examples/client_parser.rb
50
51
  - examples/client_search.rb
51
52
  - examples/settings.yml
52
53
  - lib/rets4r.rb
@@ -57,17 +58,21 @@ files:
57
58
  - lib/rets4r/client/metadata.rb
58
59
  - lib/rets4r/client/metadataindex.rb
59
60
  - lib/rets4r/client/parsers/compact.rb
61
+ - lib/rets4r/client/parsers/compact_nokogiri.rb
60
62
  - lib/rets4r/client/parsers/metadata.rb
61
63
  - lib/rets4r/client/parsers/response_parser.rb
62
64
  - lib/rets4r/client/transaction.rb
65
+ - lib/rets4r/loader.rb
63
66
  - lib/tasks/annotations.rake
64
67
  - lib/tasks/coverage.rake
68
+ - test/compact_nokogiri_test.rb
65
69
  - test/data/1.5/error.xml
66
70
  - test/data/1.5/invalid_compact.xml
67
71
  - test/data/1.5/login.xml
68
72
  - test/data/1.5/metadata.xml
69
73
  - test/data/1.5/search_compact.xml
70
74
  - test/data/1.5/search_unescaped_compact.xml
75
+ - test/loader_test.rb
71
76
  - test/test_auth.rb
72
77
  - test/test_client.rb
73
78
  - test/test_metadataindex.rb