Permalink
Browse files

Adding flyer support.

  • Loading branch information...
1 parent 7e79f40 commit d4422575f4ab4e7e3cfa00d86383ebe15f52e2ef @waratuman waratuman committed Aug 9, 2012
View
1 lib/mls.rb
@@ -186,3 +186,4 @@ def self.parse(json)
require 'mls/models/address'
require 'mls/models/photo'
require 'mls/models/tour_request'
+require 'mls/models/flyer'
View
2 lib/mls/models/account.rb
@@ -21,7 +21,7 @@ class MLS::Account < MLS::Resource
property :twitter, String
property :facebook, String
property :web, String
- property :mls_number, String
+ property :system_phone, String
property :city, String
property :state, String
View
28 lib/mls/models/flyer.rb
@@ -0,0 +1,28 @@
+require 'restclient'
+
+class MLS::Flyer < MLS::Resource
+
+ property :id, Fixnum
+ property :created_at, DateTime
+ property :updated_at, DateTime
+ property :file_content_type, String
+ property :file_name, String
+ property :file_size, Fixnum
+ property :url, String
+
+ def self.create(file)
+ file.rewind
+ url = MLS.url.dup
+ url.user = nil
+ url.path = "/api/flyers"
+ response = RestClient.post(url.to_s, {:file => file}, MLS.headers)
+ file.close unless file.closed?
+
+ MLS::Flyer::Parser.parse(response.body)
+ end
+
+end
+
+class MLS::Flyer::Parser < MLS::Parser
+
+end
View
6 lib/mls/models/listing.rb
@@ -12,6 +12,8 @@ class MLS::Listing < MLS::Resource
property :use, String
property :account_id, Fixnum
property :hidden, Boolean, :default => false
+ property :source, String
+ property :source_url, String
property :name, String
property :kind, String, :default => 'lease'
@@ -62,7 +64,7 @@ class MLS::Listing < MLS::Resource
property :updated_at, DateTime
- attr_accessor :address, :agents, :account, :photos, :address_attributes, :agents_attributes
+ attr_accessor :address, :agents, :account, :photos#, :address_attributes, :agents_attributes, :photo_ids
def sublease?
kind == 'sublease'
@@ -87,6 +89,8 @@ def create
def to_hash
hash = super
hash[:address_attributes] = address.to_hash if address
+ hash[:agents_attributes] = agents.inject({}) { |acc, x| acc[acc.length] = x.to_hash; acc } if agents
+ hash[:photo_ids] = photos.map(&:id) if photos
hash
end
View
BIN test/fixtures/flyer.pdf
Binary file not shown.
View
4 test/test_helper.rb
@@ -10,5 +10,7 @@
require 'test/unit'
require 'factory_girl'
-puts FactoryGirl.find_definitions
+FactoryGirl.find_definitions
+
+MLS.url = ENV["MLS_TEST_URL"]
View
11 test/units/models/test_flyer.rb
@@ -0,0 +1,11 @@
+require 'test_helper'
+
+class TestFlyer < ::Test::Unit::TestCase
+
+
+ def test_create_flyer
+ flyer = MLS::Flyer.create(File.new('test/fixtures/flyer.pdf'))
+ assert flyer.id
+ end
+
+end

0 comments on commit d442257

Please sign in to comment.