Sha256: b54baebe8becc0b3ce3f59e5e81f79b1ee204466f6081ca9878a5a0b97b351ee

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

#!/usr/bin/env ruby
#
# This is an example of how to use the RETS client to retrieve an objet.
#
# You will need to set the necessary variables below.
#
#############################################################################################
# Settings

require 'yaml'
require 'active_support/core_ext/hash'
settings_file = File.expand_path(File.join(File.dirname(__FILE__), "settings.yml"))
env = ENV['LISTING_ENV'] || 'development'
settings = YAML.load_file(settings_file)[env].symbolize_keys

#############################################################################################
$:.unshift 'lib'

require 'rets4r'
require 'logger'

def handle_object(object)
    case object.info['Content-Type']
        when 'image/jpeg' then extension = 'jpg'
        when 'image/gif'  then extension = 'gif'
        when 'image/png'  then extension = 'png'
        else extension = 'unknown'
    end

    File.open("#{object.info['Content-ID']}_#{object.info['Object-ID']}.#{extension}", 'w') do |f|
        f.write(object.data)
    end
end

client = RETS4R::Client.new(settings[:url])

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

    if login_result.success?
        ## Method 1
        # Get objects using a block
        client.get_object(settings[:resource], settings[:object_type], settings[:resource_id] + ':0:*') do |object|
            handle_object(object)
        end
    else
        puts "We were unable to log into the RETS server."
        puts "Please check that you have set the login variables correctly."
    end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
rets4r-1.1.18 examples/client_get_object.rb
jschairb-rets4r-1.1.18 examples/client_get_object.rb