Skip to content

Commit

Permalink
Remove the login, mapper and parser examples into a new rets4r bin
Browse files Browse the repository at this point in the history
* bin/rets4r: add
* examples/client_login.rb, examples/client_mapper.rb
  examples/client_parser.rb: remove

* rets4r.gemspec: add cucumber, aruba deps
  • Loading branch information
josephholsten committed Aug 17, 2011
1 parent e792418 commit 2de3145
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 69 deletions.
5 changes: 3 additions & 2 deletions MANIFEST
Expand Up @@ -12,13 +12,14 @@ README.rdoc
RUBYS
Rakefile
TODO
bin/rets4r
examples/client_get_object.rb
examples/client_login.rb
examples/client_mapper.rb
examples/client_metadata.rb
examples/client_parser.rb
examples/client_search.rb
examples/settings.yml
features/commandline.feature
features/support/env.rb
lib/rets4r.rb
lib/rets4r/auth.rb
lib/rets4r/client.rb
Expand Down
4 changes: 4 additions & 0 deletions Rakefile
Expand Up @@ -22,6 +22,10 @@ namespace :test do
end
end

require 'cucumber/rake/task'
Cucumber::Rake::Task.new
task :default => :cucumber

require 'rdoc/task'
RDoc::Task.new do |rdoc|
if File.exist?('VERSION.yml')
Expand Down
70 changes: 70 additions & 0 deletions bin/rets4r
@@ -0,0 +1,70 @@
#!/usr/bin/env ruby
# rets4r: All-singing, all-dancing RETS cure-all
require 'active_support/core_ext/hash'
require 'active_support/ordered_hash'
require 'logger'
require 'thor'
require 'yaml'

require 'rets4r'

module RETS4R
class CLI < Thor

desc "parse", "take a RETS XML Document and print how it looks"
def parse(filename)
xml = File.open filename
transaction = RETS4R::ResponseDocument::Search.safe_parse(xml).validate!.results
transaction.each {|row| puts sorted_print(row) }
end

desc "map", "take a RETS XML Document and map it pretty"
def map(filename)
load_settings
xml = File.open filename
mapper = RETS4R::ListingMapper.new
RETS4R::Loader.load(xml) do |record|
attributes = mapper.map(record)
puts sorted_print(attributes)
end
end

desc "login", 'login to your rets server'
def login
settings = load_settings

client = RETS4R::Client.new(settings[:url])
# client.logger = Logger.new(STDOUT)

login_result = client.login(settings[:username], settings[:password])

if login_result.success?
puts "We successfully logged into the RETS server!"

# Print the action URL results (if any)
puts login_result.secondary_response

client.logout

puts "We just logged out of the server."
else
puts "We were unable to log into the RETS server."
puts "Please check that you have set the login variables correctly."
end
end
private
def load_settings(filename = 'settings.yml')
RETS4R::ListingService.configurations = YAML.load_file(filename)
RETS4R::ListingService.env = ENV['RETS4RENV'] || 'development'
RETS4R::ListingService.connection
end
def sorted_print(hash)
hash.to_a.
sort {|a,b| a.first.to_s <=> b.first.to_s }.
map {|pair| pair.join(': ') }.
join(', ')
end
end
end

RETS4R::CLI.start
40 changes: 0 additions & 40 deletions examples/client_login.rb

This file was deleted.

17 changes: 0 additions & 17 deletions examples/client_mapper.rb

This file was deleted.

9 changes: 0 additions & 9 deletions examples/client_parser.rb

This file was deleted.

52 changes: 52 additions & 0 deletions features/commandline.feature
@@ -0,0 +1,52 @@
Feature: Command Line Tool
As a new rets4r user
I want a tool to show how to use my data

Background:
Given a file named "settings.yml" with:
"""
development:
url: http://www.dis.com:6103/rets/login
username: Joe
password: Schmoe
select:
MLSNUM: :mls
AGENTLIST_FULLNAME: :agent_full_name
LISTPRICE: :list_price
"""
Given a file named "search_compact.xml" with:
"""
<RETS ReplyCode="0" ReplyText="SUCCESS">
<COUNT Records="4"/>
<DELIMITER value="09" />
<COLUMNS> MLSNUM LISTPRICE AGENTLIST_FULLNAME </COLUMNS>
<DATA> 1 2 Steve</DATA>
<DATA> 4 5 Bill</DATA>
<MAXROWS/>
</RETS>
"""

Scenario: parse
When I run `rets4r parse search_compact.xml`
Then the output should contain:
"""
AGENTLIST_FULLNAME: Steve, LISTPRICE: 2, MLSNUM: 1
AGENTLIST_FULLNAME: Bill, LISTPRICE: 5, MLSNUM: 4
"""

Scenario: Map
When I run `rets4r map search_compact.xml`
Then the output should contain:
"""
agent_full_name: Steve, list_price: 2, mls: 1
agent_full_name: Bill, list_price: 5, mls: 4
"""

Scenario: Login
When I run `rets4r login`
Then the output should contain:
"""
We successfully logged into the RETS server!
nil
We just logged out of the server.
"""
1 change: 1 addition & 0 deletions features/support/env.rb
@@ -0,0 +1 @@
require 'aruba/cucumber'
3 changes: 3 additions & 0 deletions rets4r.gemspec
Expand Up @@ -17,6 +17,9 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency 'nokogiri', '>= 1.3.2'
spec.add_runtime_dependency 'activesupport', '>= 2.3.2'
spec.add_runtime_dependency 'thor'
spec.add_development_dependency 'aruba'
spec.add_development_dependency 'cucumber'
spec.add_development_dependency 'i18n'
spec.add_development_dependency 'mocha'
spec.add_development_dependency 'rake'
Expand Down
2 changes: 1 addition & 1 deletion test/test_quality.rb
Expand Up @@ -59,6 +59,6 @@ def check_for_extra_spaces(filename)
end

def code_file?(filename)
!(filename =~ /.xml/)
!(filename =~ /.xml|.feature/)
end
end

0 comments on commit 2de3145

Please sign in to comment.