rentjuicer 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ Gemfile.lock
23
+ *.gem
24
+ spec/rentjuicer_api_key.yml
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/README.rdoc CHANGED
@@ -1,10 +1,10 @@
1
1
  = rentjuicer
2
2
 
3
- Rentjuicer is a ruby gem that wraps the rentjucier.com api for listings, neighborhoods and adding leads. Rentjuicer is built on top of HTTParty.
3
+ Rentjuicer is a ruby gem that wraps the Zillow Rentals (formerly Rentjuice) API for listings, neighborhoods and adding leads. Rentjuicer is built on top of HTTParty.
4
4
 
5
5
  Rentjuicer requires access to rentjuice.com's api through an Rentjuice api key so make sure you have acquired a key from Rentjuice before starting with this gem.
6
6
 
7
- API documentation is here: http://api.rentjuice.com/documentation/RentJuice_API.pdf
7
+ API documentation is here: http://api.rentalapp.zillow.com/documentation/RentJuice_API.pdf
8
8
 
9
9
 
10
10
  == Installation
@@ -13,7 +13,7 @@ API documentation is here: http://api.rentjuice.com/documentation/RentJuice_API.
13
13
 
14
14
  In a rails 3 app
15
15
 
16
- gem 'rentjuicer', '~> 0.7.1'
16
+ gem 'rentjuicer', '~> 0.9.0'
17
17
 
18
18
  In a rails 2.3.x app (0.6.x only)
19
19
 
@@ -133,9 +133,10 @@ a Rentjuicer::Listing object responds to the following methods:
133
133
  :first_pic - returns the url for the main_pic fullsize photo
134
134
  :neighborhood_name - returns the first name in the neighborhoods hash
135
135
 
136
- Also, we have added another method :similar_listings which takes a Rentjuicer::Client object and does a search call
136
+ Also, we have added another method :similar_listings which takes an optional limit and optional search params and does a search call
137
+ Note: Starting with v0.9.0 similar_listings no longer takes a Rentjuicer::Client param as we are passing this to the Rentjuicer::Listing automatically
137
138
 
138
- @results.properties.first.similar_listings(@rentjuicer)
139
+ @results.properties.first.similar_listings
139
140
 
140
141
  This method performs a search and returns an array for Rentjuicer::Listing objects based on the following criteria
141
142
 
@@ -149,7 +150,12 @@ This method performs a search and returns an array for Rentjuicer::Listing objec
149
150
 
150
151
  You can also pass a limit to the similar_listings method, the default is 6 properties (max) returned
151
152
 
152
- @results.properties.first.similar_listings(@rentjuicer, 10) # returns max 10 similar listings
153
+ @results.properties.first.similar_listings(10) # returns max 10 similar listings
154
+
155
+ Finally, you can pass an optional hash of params to merge into the search
156
+
157
+ # would do the normal similar listings search but with the added condition of returning only featured listings
158
+ @results.properties.first.similar_listings(10, {:featured => 1})
153
159
 
154
160
  ===== Extending Rentjuicer::Listing
155
161
  Another benefit to this Rentjuicer::Listing class is that in your app you can open the class again and add more methods if you wish. For example create a file: RAILS_ROOT/lib/rentjuicer_extensions.rb with the following:
data/Rakefile CHANGED
@@ -1,27 +1,5 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "rentjuicer"
8
- gem.summary = %Q{ruby api wrapper for rentjuice}
9
- gem.description = %Q{Ruby API wrapper for rentjuice.com built with httparty}
10
- gem.email = "tom.cocca@gmail.com"
11
- gem.homepage = "http://github.com/tcocca/rentjuicer"
12
- gem.authors = ["tcocca"]
13
- gem.add_dependency "activesupport", '~> 3'
14
- gem.add_dependency "httparty", ">= 0.6.1"
15
- gem.add_dependency "rash", ">= 0.3.2"
16
- gem.add_dependency "will_paginate", ">= 3"
17
- gem.add_development_dependency "rspec", ">= 2.5.0"
18
- gem.add_development_dependency "webmock", ">= 1.6.2"
19
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
- end
21
- Jeweler::GemcutterTasks.new
22
- rescue LoadError
23
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
24
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
25
3
 
26
4
  require 'rspec/core/rake_task'
27
5
  RSpec::Core::RakeTask.new(:spec)
@@ -29,4 +7,12 @@ RSpec::Core::RakeTask.new(:spec)
29
7
  task :test => :spec
30
8
  task :default => :spec
31
9
 
32
- require 'rdoc/task'
10
+ require 'rake/rdoctask'
11
+ Rake::RDocTask.new do |rdoc|
12
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
13
+
14
+ rdoc.rdoc_dir = 'rdoc'
15
+ rdoc.title = "you_got_listed #{version}"
16
+ rdoc.rdoc_files.include('README*')
17
+ rdoc.rdoc_files.include('lib/**/*.rb')
18
+ end
@@ -1,29 +1,45 @@
1
1
  module Rentjuicer
2
2
  class Client
3
-
3
+
4
4
  include HTTParty
5
5
  format :json
6
-
7
- attr_accessor :api_key
8
-
9
- def initialize(api_key)
6
+
7
+ attr_accessor :api_key, :http_timeout
8
+
9
+ def initialize(api_key, http_timeout = nil)
10
10
  self.api_key = api_key
11
- self.class.base_uri "api.rentjuice.com/#{self.api_key}"
11
+ self.http_timeout = http_timeout
12
+ self.class.base_uri "api.rentalapp.zillow.com/#{self.api_key}"
12
13
  end
13
-
14
+
15
+ def listings
16
+ @listings ||= Rentjuicer::Listings.new(self)
17
+ end
18
+
19
+ def neighborhoods
20
+ @neighborhoods ||= Rentjuicer::Neighborhoods.new(self)
21
+ end
22
+
23
+ def leads
24
+ @leads ||= Rentjuicer::Lead.new(self)
25
+ end
26
+
14
27
  def process_get(resource, params = {})
15
28
  begin
29
+ http_params = {}
16
30
  unless params.blank?
17
- self.class.get(resource, :query => params)
18
- else
19
- self.class.get(resource)
31
+ http_params[:query] = params
32
+ end
33
+ unless self.http_timeout.nil?
34
+ http_params[:timeout] = self.http_timeout
20
35
  end
36
+ self.class.get(resource, http_params)
21
37
  rescue Timeout::Error
22
38
  {"status" => "timeout", "code" => "0", "message" => "Rentjuice API is timing out."}
23
39
  rescue Exception
24
40
  {"status" => "busted", "code" => "0", "message" => "Rentjuice API is erroring."}
25
41
  end
26
42
  end
27
-
43
+
28
44
  end
29
45
  end
@@ -1,17 +1,17 @@
1
1
  module Rentjuicer
2
2
  class Error < Exception
3
-
3
+
4
4
  attr_reader :code, :error
5
-
5
+
6
6
  def initialize(code, error)
7
7
  @code = code
8
8
  @error = error
9
9
  super(message)
10
10
  end
11
-
11
+
12
12
  def message
13
13
  "Rentjuicer Error: #{@error} (code: #{@code})"
14
14
  end
15
-
15
+
16
16
  end
17
17
  end
@@ -1,21 +1,21 @@
1
1
  module Rentjuicer
2
2
  class Lead
3
-
3
+
4
4
  attr_accessor :client, :resource
5
-
5
+
6
6
  def initialize(client)
7
7
  self.client = client
8
8
  self.resource = "/leads.add.json"
9
9
  end
10
-
10
+
11
11
  def create(name, params = {}, raise_error = false)
12
12
  params.merge!(:name => name)
13
13
  Response.new(self.client.process_get(resource, params), raise_error)
14
14
  end
15
-
15
+
16
16
  def create!(name, params = {})
17
17
  create(name, params = {}, true)
18
18
  end
19
-
19
+
20
20
  end
21
21
  end
@@ -1,14 +1,17 @@
1
1
  module Rentjuicer
2
2
  class Listing
3
3
 
4
- def initialize(listing)
4
+ attr_accessor :client
5
+
6
+ def initialize(listing, client)
5
7
  listing.each do |key, value|
6
8
  self.instance_variable_set("@#{key}", value)
7
9
  self.class.send(:attr_reader, key)
8
10
  end
11
+ self.client = client
9
12
  end
10
13
 
11
- def similar_listings(rj, limit = 6, search_options = {})
14
+ def similar_listings(limit = 6, search_options = {})
12
15
  search_params = {
13
16
  :limit => limit + 1,
14
17
  :min_rent => self.rent.to_i * 0.9,
@@ -21,7 +24,7 @@ module Rentjuicer
21
24
  }.merge(search_options)
22
25
  @cached_similars ||= begin
23
26
  similar = []
24
- listings = Rentjuicer::Listings.new(rj)
27
+ listings = Rentjuicer::Listings.new(self.client)
25
28
  listings.search(search_params).properties.each do |prop|
26
29
  similar << prop unless prop.id == self.id
27
30
  break if similar.size == limit
@@ -12,7 +12,7 @@ module Rentjuicer
12
12
  limit = params[:limit] || 20
13
13
  params[:order_by] ||= "rent"
14
14
  params[:order_direction] ||= "asc"
15
- SearchResponse.new(self.client.process_get(resource, params), limit)
15
+ SearchResponse.new(self.client.process_get(resource, params), self.client, limit)
16
16
  end
17
17
 
18
18
  def featured(params = {})
@@ -21,7 +21,7 @@ module Rentjuicer
21
21
  end
22
22
 
23
23
  def find_by_id(listing_id, params = {})
24
- response = SearchResponse.new(self.client.process_get(resource, params.merge(:rentjuice_id => listing_id)))
24
+ response = SearchResponse.new(self.client.process_get(resource, params.merge(:rentjuice_id => listing_id)), self.client)
25
25
  (response.success? && response.properties.size > 0) ? response.properties.first : nil
26
26
  end
27
27
 
@@ -56,11 +56,12 @@ module Rentjuicer
56
56
 
57
57
  class SearchResponse < Rentjuicer::Response
58
58
 
59
- attr_accessor :limit
59
+ attr_accessor :limit, :client
60
60
 
61
- def initialize(response, limit = 20)
61
+ def initialize(response, client, limit = 20)
62
62
  super(response)
63
63
  @limit = limit
64
+ @client = client
64
65
  end
65
66
 
66
67
  def properties
@@ -68,7 +69,7 @@ module Rentjuicer
68
69
  props = []
69
70
  if self.success? && !self.body.listings.blank?
70
71
  self.body.listings.each do |listing|
71
- props << Rentjuicer::Listing.new(listing)
72
+ props << Rentjuicer::Listing.new(listing, self.client)
72
73
  end
73
74
  end
74
75
  props
@@ -1,20 +1,20 @@
1
1
  module Rentjuicer
2
2
  class Neighborhoods
3
-
3
+
4
4
  attr_accessor :client, :resource
5
-
5
+
6
6
  def initialize(client)
7
7
  self.client = client
8
8
  self.resource = "/neighborhoods.json"
9
9
  end
10
-
10
+
11
11
  def find_all(raise_error = false)
12
12
  Response.new(self.client.process_get(resource), raise_error)
13
13
  end
14
-
14
+
15
15
  def find_all!
16
16
  find_all(true)
17
17
  end
18
-
18
+
19
19
  end
20
20
  end
@@ -1,17 +1,17 @@
1
1
  module Rentjuicer
2
2
  class Response
3
-
3
+
4
4
  attr_accessor :body
5
-
5
+
6
6
  def initialize(response, raise_error = false)
7
7
  rash_response(response)
8
8
  raise Error.new(self.body.code, self.body.message) if !success? && raise_error
9
9
  end
10
-
10
+
11
11
  def success?
12
12
  self.body && !self.body.blank? && self.body.respond_to?(:status) && self.body.status == "ok"
13
13
  end
14
-
14
+
15
15
  def method_missing(method_name, *args)
16
16
  if self.body.respond_to?(method_name)
17
17
  self.body.send(method_name)
@@ -19,9 +19,9 @@ module Rentjuicer
19
19
  super
20
20
  end
21
21
  end
22
-
22
+
23
23
  private
24
-
24
+
25
25
  def rash_response(response)
26
26
  if response.is_a?(Array)
27
27
  self.body = []
@@ -38,6 +38,6 @@ module Rentjuicer
38
38
  self.body = response
39
39
  end
40
40
  end
41
-
41
+
42
42
  end
43
43
  end
@@ -0,0 +1,3 @@
1
+ module Rentjuicer
2
+ VERSION = '0.9.0'
3
+ end
data/lib/rentjuicer.rb CHANGED
@@ -3,6 +3,7 @@ require 'httparty'
3
3
  require 'rash'
4
4
  require 'will_paginate/collection'
5
5
  require 'active_support/core_ext/array/grouping'
6
+ require 'active_support/core_ext/object/blank'
6
7
 
7
8
  require 'rentjuicer/client'
8
9
  require 'rentjuicer/response'
data/rentjuicer.gemspec CHANGED
@@ -1,107 +1,31 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rentjuicer/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
6
  s.name = %q{rentjuicer}
8
- s.version = "0.8.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["tcocca"]
12
- s.date = %q{2012-05-03}
7
+ s.authors = ["Tom Cocca"]
8
+ s.date = %q{2011-04-11}
13
9
  s.description = %q{Ruby API wrapper for rentjuice.com built with httparty}
14
10
  s.email = %q{tom.cocca@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "lib/rentjuicer.rb",
26
- "lib/rentjuicer/client.rb",
27
- "lib/rentjuicer/error.rb",
28
- "lib/rentjuicer/lead.rb",
29
- "lib/rentjuicer/listing.rb",
30
- "lib/rentjuicer/listings.rb",
31
- "lib/rentjuicer/neighborhoods.rb",
32
- "lib/rentjuicer/response.rb",
33
- "rentjuicer.gemspec",
34
- "spec/.rspec",
35
- "spec/rentjuicer/client_spec.rb",
36
- "spec/rentjuicer/error_spec.rb",
37
- "spec/rentjuicer/lead_spec.rb",
38
- "spec/rentjuicer/listing_spec.rb",
39
- "spec/rentjuicer/listings_spec.rb",
40
- "spec/rentjuicer/neighborhoods_spec.rb",
41
- "spec/rentjuicer/response_spec.rb",
42
- "spec/rentjuicer_api_key.yml.example",
43
- "spec/responses/empty_response.json",
44
- "spec/responses/error.json",
45
- "spec/responses/featured.json",
46
- "spec/responses/find_all_1.json",
47
- "spec/responses/find_all_2.json",
48
- "spec/responses/find_all_3.json",
49
- "spec/responses/find_all_by_ids.json",
50
- "spec/responses/find_all_by_ids_2.json",
51
- "spec/responses/find_by_id.json",
52
- "spec/responses/lead.json",
53
- "spec/responses/lead_error.json",
54
- "spec/responses/listings.json",
55
- "spec/responses/missing_listings.json",
56
- "spec/responses/mls_listings.json",
57
- "spec/responses/neighborhoods.json",
58
- "spec/responses/null_listings.json",
59
- "spec/spec_helper.rb",
60
- "spec/support/listing_helper.rb",
61
- "spec/support/webmock_helper.rb"
62
- ]
63
11
  s.homepage = %q{http://github.com/tcocca/rentjuicer}
64
- s.require_paths = ["lib"]
65
- s.rubygems_version = %q{1.4.2}
12
+ s.rdoc_options = ["--charset=UTF-8"]
13
+ s.rubygems_version = %q{1.3.5}
66
14
  s.summary = %q{ruby api wrapper for rentjuice}
67
- s.test_files = [
68
- "spec/rentjuicer/client_spec.rb",
69
- "spec/rentjuicer/error_spec.rb",
70
- "spec/rentjuicer/lead_spec.rb",
71
- "spec/rentjuicer/listing_spec.rb",
72
- "spec/rentjuicer/listings_spec.rb",
73
- "spec/rentjuicer/neighborhoods_spec.rb",
74
- "spec/rentjuicer/response_spec.rb",
75
- "spec/spec_helper.rb",
76
- "spec/support/listing_helper.rb",
77
- "spec/support/webmock_helper.rb"
78
- ]
79
15
 
80
- if s.respond_to? :specification_version then
81
- s.specification_version = 3
16
+ s.version = Rentjuicer::VERSION
17
+ s.platform = Gem::Platform::RUBY
82
18
 
83
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
84
- s.add_runtime_dependency(%q<activesupport>, ["~> 3"])
85
- s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
86
- s.add_runtime_dependency(%q<rash>, [">= 0.3.2"])
87
- s.add_runtime_dependency(%q<will_paginate>, [">= 3"])
88
- s.add_development_dependency(%q<rspec>, [">= 2.5.0"])
89
- s.add_development_dependency(%q<webmock>, [">= 1.6.2"])
90
- else
91
- s.add_dependency(%q<activesupport>, ["~> 3"])
92
- s.add_dependency(%q<httparty>, [">= 0.6.1"])
93
- s.add_dependency(%q<rash>, [">= 0.3.2"])
94
- s.add_dependency(%q<will_paginate>, [">= 3"])
95
- s.add_dependency(%q<rspec>, [">= 2.5.0"])
96
- s.add_dependency(%q<webmock>, [">= 1.6.2"])
97
- end
98
- else
99
- s.add_dependency(%q<activesupport>, ["~> 3"])
100
- s.add_dependency(%q<httparty>, [">= 0.6.1"])
101
- s.add_dependency(%q<rash>, [">= 0.3.2"])
102
- s.add_dependency(%q<will_paginate>, [">= 3"])
103
- s.add_dependency(%q<rspec>, [">= 2.5.0"])
104
- s.add_dependency(%q<webmock>, [">= 1.6.2"])
105
- end
106
- end
19
+ s.add_dependency "activesupport", "~> 3"
20
+ s.add_dependency "httparty", "~> 0.8.3"
21
+ s.add_dependency "rash", ">= 0.3.2"
22
+ s.add_dependency "will_paginate", ">= 3"
23
+ s.add_development_dependency "rake", "~> 0.9.2"
24
+ s.add_development_dependency "rspec", ">= 2.5.0"
25
+ s.add_development_dependency "webmock", ">= 1.6.2"
107
26
 
27
+ s.require_paths = ['lib']
28
+ s.files = `git ls-files`.split("\n")
29
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
30
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
31
+ end
@@ -1,17 +1,34 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rentjuicer::Client do
4
-
5
- before do
6
- @rentjuicer = new_rentjuicer
7
- end
8
-
9
- it "should set the api_key" do
10
- @rentjuicer.api_key.should == RENTJUICER_API_KEY
4
+
5
+ context "basic" do
6
+ before do
7
+ @rentjuicer = new_rentjuicer
8
+ end
9
+
10
+ it "should set the api_key" do
11
+ @rentjuicer.api_key.should == RENTJUICER_API_KEY
12
+ @rentjuicer.http_timeout.should == nil
13
+ end
14
+
15
+ it "should set the base uri" do
16
+ @rentjuicer.class.base_uri.should == "http://api.rentalapp.zillow.com/#{RENTJUICER_API_KEY}"
17
+ end
11
18
  end
12
-
13
- it "should set the base uri" do
14
- @rentjuicer.class.base_uri.should == "http://api.rentjuice.com/#{RENTJUICER_API_KEY}"
19
+
20
+ context "timeout" do
21
+ before do
22
+ @rentjuicer = new_timeout_5_rentjuicer
23
+ end
24
+
25
+ it "should set the api_key" do
26
+ @rentjuicer.api_key.should == RENTJUICER_API_KEY
27
+ @rentjuicer.http_timeout.should == 5
28
+ end
29
+
30
+ it "should set the base uri" do
31
+ @rentjuicer.class.base_uri.should == "http://api.rentalapp.zillow.com/#{RENTJUICER_API_KEY}"
32
+ end
15
33
  end
16
-
17
34
  end
@@ -1,23 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rentjuicer::Error do
4
-
4
+
5
5
  before do
6
6
  @rentjuicer = new_rentjuicer
7
7
  @neighborhoods = Rentjuicer::Neighborhoods.new(@rentjuicer)
8
8
  mock_get(@neighborhoods.resource, 'error.json')
9
9
  end
10
-
10
+
11
11
  it "should not return an error" do
12
12
  lambda {
13
13
  @neighborhoods.find_all
14
14
  }.should_not raise_exception
15
15
  end
16
-
16
+
17
17
  it "should return an error" do
18
18
  lambda {
19
19
  @neighborhoods.find_all!
20
20
  }.should raise_exception(Rentjuicer::Error, "Rentjuicer Error: Invalid API key. (code: 1)")
21
21
  end
22
-
22
+
23
23
  end
@@ -5,48 +5,47 @@ describe Rentjuicer::Lead do
5
5
  @rentjuicer = new_rentjuicer
6
6
  @lead = Rentjuicer::Lead.new(@rentjuicer)
7
7
  end
8
-
8
+
9
9
  context "a successfull creation" do
10
10
  before do
11
11
  mock_get(@lead.resource, 'lead.json', :name => 'Tom Cocca')
12
12
  end
13
-
13
+
14
14
  it "should not return an error on create" do
15
15
  lambda {
16
16
  @lead.create('Tom Cocca')
17
17
  }.should_not raise_exception
18
18
  end
19
-
19
+
20
20
  it "should not return an error on create!" do
21
21
  lambda {
22
22
  @lead.create!('Tom Cocca')
23
23
  }.should_not raise_exception
24
24
  end
25
-
25
+
26
26
  it "should be a success?" do
27
27
  @response = @lead.create('Tom Cocca')
28
28
  @response.success?.should be_true
29
29
  end
30
30
  end
31
-
32
-
31
+
33
32
  context "unsucessful submission" do
34
33
  before do
35
34
  mock_get(@lead.resource, 'lead_error.json', :name => '')
36
35
  end
37
-
36
+
38
37
  it "should return an error on create!" do
39
38
  lambda {
40
39
  @lead.create!('')
41
40
  }.should raise_exception(Rentjuicer::Error, "Rentjuicer Error: invalid parameter - `name` is required (code: 3)")
42
41
  end
43
-
42
+
44
43
  it "should not return an error on create" do
45
44
  lambda {
46
45
  @lead.create('')
47
46
  }.should_not raise_exception
48
47
  end
49
-
48
+
50
49
  it "should not be a successful submission on create" do
51
50
  @result = @lead.create('')
52
51
  @result.success?.should be_false
@@ -3,7 +3,8 @@ require 'spec_helper'
3
3
  describe Rentjuicer::Listing do
4
4
 
5
5
  before do
6
- @listing = Rentjuicer::Listing.new(valid_listing_rash)
6
+ @rentjuicer = new_rentjuicer
7
+ @listing = Rentjuicer::Listing.new(valid_listing_rash, @rentjuicer)
7
8
  end
8
9
 
9
10
  it "should create methods from all hash keys" do
@@ -46,7 +47,6 @@ describe Rentjuicer::Listing do
46
47
 
47
48
  context "default similar listings" do
48
49
  before do
49
- @rentjuicer = new_rentjuicer
50
50
  mock_get('/listings.json', 'listings.json', {
51
51
  :neighborhoods => "South Boston",
52
52
  :min_rent => "2250.0",
@@ -59,7 +59,7 @@ describe Rentjuicer::Listing do
59
59
  :order_by => "rent",
60
60
  :order_direction => "asc"
61
61
  })
62
- @similar_props = @listing.similar_listings(@rentjuicer)
62
+ @similar_props = @listing.similar_listings
63
63
  end
64
64
 
65
65
  it "should return an array of listings" do
@@ -71,7 +71,6 @@ describe Rentjuicer::Listing do
71
71
 
72
72
  context "similar listings with custom limit" do
73
73
  before do
74
- @rentjuicer = new_rentjuicer
75
74
  mock_get('/listings.json', 'listings.json', {
76
75
  :neighborhoods => "South Boston",
77
76
  :min_rent => "2250.0",
@@ -84,7 +83,7 @@ describe Rentjuicer::Listing do
84
83
  :order_by => "rent",
85
84
  :order_direction => "asc"
86
85
  })
87
- @similar_props = @listing.similar_listings(@rentjuicer, 4)
86
+ @similar_props = @listing.similar_listings(4)
88
87
  end
89
88
 
90
89
  it "should return an array of listings" do
@@ -97,7 +96,6 @@ describe Rentjuicer::Listing do
97
96
  context "nil similar listings" do
98
97
  context "null listings" do
99
98
  before do
100
- @rentjuicer = new_rentjuicer
101
99
  mock_get('/listings.json', 'null_listings.json', {
102
100
  :neighborhoods => "South Boston",
103
101
  :min_rent => "2250.0",
@@ -110,7 +108,7 @@ describe Rentjuicer::Listing do
110
108
  :order_by => "rent",
111
109
  :order_direction => "asc"
112
110
  })
113
- @similar_props = @listing.similar_listings(@rentjuicer)
111
+ @similar_props = @listing.similar_listings
114
112
  end
115
113
 
116
114
  it "should return an empty array of listings" do
@@ -120,7 +118,6 @@ describe Rentjuicer::Listing do
120
118
 
121
119
  context "missing listings" do
122
120
  before do
123
- @rentjuicer = new_rentjuicer
124
121
  mock_get('/listings.json', 'missing_listings.json', {
125
122
  :neighborhoods => "South Boston",
126
123
  :min_rent => "2250.0",
@@ -133,7 +130,7 @@ describe Rentjuicer::Listing do
133
130
  :order_by => "rent",
134
131
  :order_direction => "asc"
135
132
  })
136
- @similar_props = @listing.similar_listings(@rentjuicer)
133
+ @similar_props = @listing.similar_listings
137
134
  end
138
135
 
139
136
  it "should return an empty array of listings" do
@@ -143,7 +140,6 @@ describe Rentjuicer::Listing do
143
140
 
144
141
  context "empty response" do
145
142
  before do
146
- @rentjuicer = new_rentjuicer
147
143
  mock_get('/listings.json', 'empty_response.json', {
148
144
  :neighborhoods => "South Boston",
149
145
  :min_rent => "2250.0",
@@ -156,7 +152,7 @@ describe Rentjuicer::Listing do
156
152
  :order_by => "rent",
157
153
  :order_direction => "asc"
158
154
  })
159
- @similar_props = @listing.similar_listings(@rentjuicer)
155
+ @similar_props = @listing.similar_listings
160
156
  end
161
157
 
162
158
  it "should return an empty array of listings" do
@@ -172,7 +168,7 @@ describe Rentjuicer::Listing do
172
168
  "source_type" => "mls",
173
169
  "source_name" => "MLS PIN",
174
170
  "attribution" => "This listing courtesy of Holly Kampler at Classic Realty<br \/><br \/>The property listing data and information, or the Images, set forth herein were provided to MLS Property Information Network, Inc. from third party sources, including sellers, lessors and public records, and were compiled by MLS Property Information Network, Inc. The property listing data and information, and the Images, are for the personal, non-commercial use of consumers having a good faith interest in purchasing or leasing listed properties of the type displayed to them and may not be used for any purpose other than to identify prospective properties which such consumers may have a good faith interest in purchasing or leasing. MLS Property Information Network, Inc. and its subscribers disclaim any and all representations and warranties as to the accuracy of the property listing data and information, or as to the accuracy of any of the Images, set forth herein."
175
- }))
171
+ }), @rentjuicer)
176
172
  end
177
173
 
178
174
  it { @listing.mls_listing?.should be_true }
@@ -188,7 +184,7 @@ describe Rentjuicer::Listing do
188
184
  "source_type" => "mls",
189
185
  "source_name" => "RAMB",
190
186
  "attribution" => "This listing is courtesy of XYZ Realty"
191
- }))
187
+ }), @rentjuicer)
192
188
  end
193
189
 
194
190
  it { @listing.mls_listing?.should be_true }
@@ -204,7 +200,7 @@ describe Rentjuicer::Listing do
204
200
  "source_type" => "mls",
205
201
  "source_name" => "MRED",
206
202
  "attribution" => "<img src=\"http://idx.advancedaccess.com/disclaimer/brlogo125.jpg\" style=\"float:left; padding-right:10px;\" />Listing office: XYZ Realty<br />Properties marked with the MRED approved icon are courtesy of Midwest Real Estate Data, LLC. Information deemed reliable but not guaranteed. Copyright&copy; 2010 Midwest Real Estate Data LLC. All rights reserved."
207
- }))
203
+ }), @rentjuicer)
208
204
  end
209
205
 
210
206
  it { @listing.mls_listing?.should be_true }
@@ -220,7 +216,7 @@ describe Rentjuicer::Listing do
220
216
  "source_type" => "mls",
221
217
  "source_name" => "MLS PIN",
222
218
  "attribution" => nil
223
- }))
219
+ }), @rentjuicer)
224
220
  end
225
221
 
226
222
  it { @listing.mls_listing?.should be_true }
@@ -235,7 +231,7 @@ describe Rentjuicer::Listing do
235
231
  @listing = Rentjuicer::Listing.new(valid_listing_rash.merge({
236
232
  "source_type" => "mls",
237
233
  "source_name" => "MLS PIN"
238
- }))
234
+ }), @rentjuicer)
239
235
  end
240
236
 
241
237
  it { @listing.mls_listing?.should be_true }
@@ -251,7 +247,7 @@ describe Rentjuicer::Listing do
251
247
  "source_type" => "mls",
252
248
  "source_name" => "MLS PIN",
253
249
  "attribution" => ""
254
- }))
250
+ }), @rentjuicer)
255
251
  end
256
252
 
257
253
  it { @listing.mls_listing?.should be_true }
@@ -23,7 +23,7 @@ describe Rentjuicer::Listing do
23
23
  context "search response" do
24
24
  it { @result.should be_kind_of(Rentjuicer::Response)}
25
25
 
26
- it { @result.should respond_to(:properties, :paginator) }
26
+ it { @result.should respond_to(:properties, :paginator, :client) }
27
27
 
28
28
  it "should return an array of properties" do
29
29
  @result.properties.should be_kind_of(Array)
@@ -38,7 +38,7 @@ describe Rentjuicer::Listing do
38
38
  end
39
39
  end
40
40
  end
41
-
41
+
42
42
  context "mls_search" do
43
43
  before do
44
44
  mock_get('/listings.json', 'mls_listings.json', {
@@ -1,30 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rentjuicer::Neighborhoods do
4
-
4
+
5
5
  before do
6
6
  @rentjuicer = new_rentjuicer
7
7
  @neighborhoods = Rentjuicer::Neighborhoods.new(@rentjuicer)
8
8
  mock_get(@neighborhoods.resource, 'neighborhoods.json')
9
9
  end
10
-
10
+
11
11
  context "find_all" do
12
12
  before do
13
13
  @response = @neighborhoods.find_all
14
14
  end
15
-
15
+
16
16
  it "should be a success" do
17
17
  @response.success?.should be_true
18
18
  end
19
-
19
+
20
20
  it "should return Rash for response for body" do
21
21
  @response.body.should be_kind_of(Hashie::Rash)
22
22
  end
23
-
23
+
24
24
  it "should set an array of neighborhoods on the body" do
25
25
  @response.body.neighborhoods.should be_kind_of(Array)
26
26
  @response.body.neighborhoods.first.should be_kind_of(Hashie::Rash)
27
27
  end
28
28
  end
29
-
29
+
30
30
  end
@@ -1,26 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rentjuicer::Response do
4
-
4
+
5
5
  context "should raise errors" do
6
6
  before do
7
7
  @rentjuicer = new_rentjuicer
8
8
  @neighborhoods = Rentjuicer::Neighborhoods.new(@rentjuicer)
9
9
  mock_get(@neighborhoods.resource, 'error.json')
10
10
  end
11
-
11
+
12
12
  it "should not raise an exception" do
13
13
  lambda {
14
14
  @neighborhoods.find_all
15
15
  }.should_not raise_exception
16
16
  end
17
-
17
+
18
18
  it "should not be a success" do
19
19
  @response = Rentjuicer::Response.new(httparty_get('/neighborhoods.json', 'error.json'))
20
20
  @response.success?.should be_false
21
21
  end
22
22
  end
23
-
23
+
24
24
  context "passing raise_errors = true" do
25
25
  it "should raise errors when raise_errors is false" do
26
26
  lambda {
@@ -28,26 +28,26 @@ describe Rentjuicer::Response do
28
28
  }.should raise_exception(Rentjuicer::Error, "Rentjuicer Error: Invalid API key. (code: 1)")
29
29
  end
30
30
  end
31
-
31
+
32
32
  context "should return a response" do
33
33
  before do
34
34
  @rentjuicer = new_rentjuicer
35
35
  @neighborhoods = Rentjuicer::Neighborhoods.new(@rentjuicer)
36
36
  mock_get(@neighborhoods.resource, 'neighborhoods.json')
37
37
  end
38
-
38
+
39
39
  it "should not raise an exception" do
40
40
  lambda {
41
41
  @neighborhoods.find_all
42
42
  }.should_not raise_exception
43
43
  end
44
-
44
+
45
45
  it "should be a success" do
46
46
  @results = @neighborhoods.find_all
47
47
  @results.success?.should be_true
48
48
  end
49
49
  end
50
-
50
+
51
51
  context "method missing" do
52
52
  before do
53
53
  @rentjuicer = new_rentjuicer
@@ -59,13 +59,13 @@ describe Rentjuicer::Response do
59
59
  })
60
60
  @results = @listings.search(:neighborhoods => "South Boston")
61
61
  end
62
-
62
+
63
63
  it "should allow response.body methods to be called on response" do
64
64
  body = stub(:total_count => 25)
65
65
  @results.body = body
66
66
  @results.total_count.should == 25
67
67
  end
68
-
68
+
69
69
  it "should return @properties.size when total_count is nil for total_results" do
70
70
  @results.body.stub!(:total_count).and_return(nil)
71
71
  @results.total_results.should == 20
@@ -75,5 +75,5 @@ describe Rentjuicer::Response do
75
75
  lambda { @results.bad_method }.should raise_error(NoMethodError, /undefined method `bad_method'/)
76
76
  end
77
77
  end
78
-
78
+
79
79
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,3 @@ require 'rspec'
5
5
  require 'webmock/rspec'
6
6
 
7
7
  Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
8
-
9
- RSpec.configure do |config|
10
-
11
- end
@@ -4,8 +4,12 @@ def new_rentjuicer
4
4
  Rentjuicer::Client.new(RENTJUICER_API_KEY)
5
5
  end
6
6
 
7
+ def new_timeout_5_rentjuicer
8
+ Rentjuicer::Client.new(RENTJUICER_API_KEY, 5)
9
+ end
10
+
7
11
  def mock_get(resource, response_fixture, params = {})
8
- url = "http://api.rentjuice.com/#{RENTJUICER_API_KEY}#{resource}"
12
+ url = "http://api.rentalapp.zillow.com/#{RENTJUICER_API_KEY}#{resource}"
9
13
  unless params.blank?
10
14
  stub_http_request(:get, url).with(:query => params).to_return(:body => mocked_response(response_fixture))
11
15
  else
@@ -18,7 +22,7 @@ def mocked_response(response_fixture)
18
22
  end
19
23
 
20
24
  def httparty_get(resource, response_fixture, params = {})
21
- url = "http://api.rentjuice.com/#{RENTJUICER_API_KEY}#{resource}"
25
+ url = "http://api.rentalapp.zillow.com/#{RENTJUICER_API_KEY}#{resource}"
22
26
  mock_get(resource, response_fixture, params)
23
27
  HTTParty.get url, :format => :json
24
28
  end
metadata CHANGED
@@ -1,27 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rentjuicer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 59
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 8
8
+ - 9
9
9
  - 0
10
- version: 0.8.0
10
+ version: 0.9.0
11
11
  platform: ruby
12
12
  authors:
13
- - tcocca
13
+ - Tom Cocca
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-03 00:00:00 -04:00
18
+ date: 2011-04-11 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: activesupport
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
23
  none: false
26
24
  requirements:
27
25
  - - ~>
@@ -30,28 +28,28 @@ dependencies:
30
28
  segments:
31
29
  - 3
32
30
  version: "3"
31
+ requirement: *id001
33
32
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: httparty
33
+ name: activesupport
37
34
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ - !ruby/object:Gem::Dependency
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
37
  none: false
40
38
  requirements:
41
- - - ">="
39
+ - - ~>
42
40
  - !ruby/object:Gem::Version
43
- hash: 5
41
+ hash: 57
44
42
  segments:
45
43
  - 0
46
- - 6
47
- - 1
48
- version: 0.6.1
44
+ - 8
45
+ - 3
46
+ version: 0.8.3
47
+ requirement: *id002
49
48
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: rash
49
+ name: httparty
53
50
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
51
+ - !ruby/object:Gem::Dependency
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
53
  none: false
56
54
  requirements:
57
55
  - - ">="
@@ -62,12 +60,12 @@ dependencies:
62
60
  - 3
63
61
  - 2
64
62
  version: 0.3.2
63
+ requirement: *id003
65
64
  type: :runtime
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: will_paginate
65
+ name: rash
69
66
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
67
+ - !ruby/object:Gem::Dependency
68
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
69
  none: false
72
70
  requirements:
73
71
  - - ">="
@@ -76,12 +74,28 @@ dependencies:
76
74
  segments:
77
75
  - 3
78
76
  version: "3"
77
+ requirement: *id004
79
78
  type: :runtime
80
- version_requirements: *id004
79
+ name: will_paginate
80
+ prerelease: false
81
81
  - !ruby/object:Gem::Dependency
82
- name: rspec
82
+ version_requirements: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ hash: 63
88
+ segments:
89
+ - 0
90
+ - 9
91
+ - 2
92
+ version: 0.9.2
93
+ requirement: *id005
94
+ type: :development
95
+ name: rake
83
96
  prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
97
+ - !ruby/object:Gem::Dependency
98
+ version_requirements: &id006 !ruby/object:Gem::Requirement
85
99
  none: false
86
100
  requirements:
87
101
  - - ">="
@@ -92,12 +106,12 @@ dependencies:
92
106
  - 5
93
107
  - 0
94
108
  version: 2.5.0
109
+ requirement: *id006
95
110
  type: :development
96
- version_requirements: *id005
97
- - !ruby/object:Gem::Dependency
98
- name: webmock
111
+ name: rspec
99
112
  prerelease: false
100
- requirement: &id006 !ruby/object:Gem::Requirement
113
+ - !ruby/object:Gem::Dependency
114
+ version_requirements: &id007 !ruby/object:Gem::Requirement
101
115
  none: false
102
116
  requirements:
103
117
  - - ">="
@@ -108,23 +122,25 @@ dependencies:
108
122
  - 6
109
123
  - 2
110
124
  version: 1.6.2
125
+ requirement: *id007
111
126
  type: :development
112
- version_requirements: *id006
127
+ name: webmock
128
+ prerelease: false
113
129
  description: Ruby API wrapper for rentjuice.com built with httparty
114
130
  email: tom.cocca@gmail.com
115
131
  executables: []
116
132
 
117
133
  extensions: []
118
134
 
119
- extra_rdoc_files:
120
- - LICENSE
121
- - README.rdoc
135
+ extra_rdoc_files: []
136
+
122
137
  files:
123
138
  - .document
139
+ - .gitignore
140
+ - Gemfile
124
141
  - LICENSE
125
142
  - README.rdoc
126
143
  - Rakefile
127
- - VERSION
128
144
  - lib/rentjuicer.rb
129
145
  - lib/rentjuicer/client.rb
130
146
  - lib/rentjuicer/error.rb
@@ -133,6 +149,7 @@ files:
133
149
  - lib/rentjuicer/listings.rb
134
150
  - lib/rentjuicer/neighborhoods.rb
135
151
  - lib/rentjuicer/response.rb
152
+ - lib/rentjuicer/version.rb
136
153
  - rentjuicer.gemspec
137
154
  - spec/.rspec
138
155
  - spec/rentjuicer/client_spec.rb
@@ -167,8 +184,8 @@ homepage: http://github.com/tcocca/rentjuicer
167
184
  licenses: []
168
185
 
169
186
  post_install_message:
170
- rdoc_options: []
171
-
187
+ rdoc_options:
188
+ - --charset=UTF-8
172
189
  require_paths:
173
190
  - lib
174
191
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -204,6 +221,23 @@ test_files:
204
221
  - spec/rentjuicer/listings_spec.rb
205
222
  - spec/rentjuicer/neighborhoods_spec.rb
206
223
  - spec/rentjuicer/response_spec.rb
224
+ - spec/rentjuicer_api_key.yml.example
225
+ - spec/responses/empty_response.json
226
+ - spec/responses/error.json
227
+ - spec/responses/featured.json
228
+ - spec/responses/find_all_1.json
229
+ - spec/responses/find_all_2.json
230
+ - spec/responses/find_all_3.json
231
+ - spec/responses/find_all_by_ids.json
232
+ - spec/responses/find_all_by_ids_2.json
233
+ - spec/responses/find_by_id.json
234
+ - spec/responses/lead.json
235
+ - spec/responses/lead_error.json
236
+ - spec/responses/listings.json
237
+ - spec/responses/missing_listings.json
238
+ - spec/responses/mls_listings.json
239
+ - spec/responses/neighborhoods.json
240
+ - spec/responses/null_listings.json
207
241
  - spec/spec_helper.rb
208
242
  - spec/support/listing_helper.rb
209
243
  - spec/support/webmock_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.8.0