Class: Dotloop::Loop
- Inherits:
-
Object
- Object
- Dotloop::Loop
- Includes:
- QueryParamHelpers
- Defined in:
- lib/dotloop/loop.rb
Constant Summary collapse
- LOOP_FIELDS =
%w[name status transactionType].freeze
- LOOP_DETAILS_FIELDS =
{ "Property Address" => [ "Country", "Street Number", "Street Name", "Unit Number", "City", "State/Prov", "Zip/Postal Code", "County", "MLS Number", "Parcel/Tax ID" ], "Financials" => [ "Purchase/Sale Price", "Sale Commission Rate", "Sale Commission Split % - Buy Side", "Sale Commission Split % - Sell Side", "Sale Commission Total", "Earnest Money Amount", "Earnest Money Held By", "Sale Commission Split $ - Buy Side", "Sale Commission Split $ - Sell Side" ], "Contract Dates" => [ "Contract Agreement Date", "Closing Date" ], "Offer Dates" => [ "Inspection Date", "Offer Date", "Offer Expiration Date", "Occupancy Date" ], "Contract Info" => [ "Transaction Number", "Class", "Type" ], "Referral" => [ "Referral %", "Referral Source" ], "Listing Information" => [ "Expiration Date", "Listing Date", "Original Price", "Current Price", "1st Mortgage Balance", "2nd Mortgage Balance", "Other Liens", "Description of Other Liens", "Homeowner's Association", "Homeowner's Association Dues", "Total Encumbrances", "Property Includes", "Property Excludes", "Remarks" ], "Geographic Description" => [ "MLS Area", "Legal Description", "Map Grid", "Subdivision", "Lot", "Deed Page", "Deed Book", "Section", "Addition", "Block" ], "Property" => [ "Year Built", "Bedrooms", "Square Footage", "School District", "Type", "Bathrooms", "Lot Size" ] }.freeze
Constants included from QueryParamHelpers
QueryParamHelpers::BATCH_SIZE, QueryParamHelpers::MAX_CONTACTS, QueryParamHelpers::MAX_LOOPS
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #all(options = {}) ⇒ Object
- #batch(options = {}) ⇒ Object
- #create(profile_id:, params: {}) ⇒ Object
- #detail(profile_id:, loop_id:) ⇒ Object
- #find(profile_id:, loop_id:) ⇒ Object
-
#initialize(client:) ⇒ Loop
constructor
A new instance of Loop.
- #loop_it(profile_id:, params: {}) ⇒ Object
- #update(profile_id:, loop_id:, params: {}) ⇒ Object
- #update_details(profile_id:, loop_id:, params: {}) ⇒ Object
Constructor Details
#initialize(client:) ⇒ Loop
Returns a new instance of Loop.
50 51 52 |
# File 'lib/dotloop/loop.rb', line 50 def initialize(client:) @client = client end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/dotloop/loop.rb', line 6 def client @client end |
Instance Method Details
#all(options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dotloop/loop.rb', line 54 def all( = {}) loops = [] [:batch_size] = BATCH_SIZE (1..MAX_LOOPS).each do |i| [:batch_number] = i current_batch = batch() loops += current_batch break if current_batch.size < [:batch_size] end loops end |
#batch(options = {}) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/dotloop/loop.rb', line 66 def batch( = {}) @client.get("/profile/#{profile_id(options)}/loop", query_params())[:data].map do |attrs| lp = Dotloop::Models::Loop.new(attrs) lp.client = client lp.profile_id = profile_id() lp end end |
#create(profile_id:, params: {}) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/dotloop/loop.rb', line 92 def create(profile_id:, params: {}) data = { name: params['name'], status: params['status'], transactionType: params['transactionType'] } loop_data = @client.post("/profile/#{profile_id.to_i}/loop", data)[:data] lp = Dotloop::Models::Loop.new(loop_data) lp.client = client lp.profile_id = profile_id.to_i lp end |
#detail(profile_id:, loop_id:) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/dotloop/loop.rb', line 83 def detail(profile_id:, loop_id:) loop_detail = @client.get("/profile/#{profile_id.to_i}/loop/#{loop_id.to_i}/detail")[:data] loop_detail = Dotloop::LoopDetail.new(loop_detail).details ld = Dotloop::Models::LoopDetail.new(loop_detail) ld.profile_id = profile_id.to_i ld.loop_id = loop_id.to_i ld end |
#find(profile_id:, loop_id:) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/dotloop/loop.rb', line 75 def find(profile_id:, loop_id:) loop_data = @client.get("/profile/#{profile_id.to_i}/loop/#{loop_id.to_i}")[:data] lp = Dotloop::Models::Loop.new(loop_data) lp.client = client lp.profile_id = profile_id.to_i lp end |
#loop_it(profile_id:, params: {}) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/dotloop/loop.rb', line 106 def loop_it(profile_id:, params: {}) loop_data = @client.post("/loop-it?profile_id=#{profile_id}", params)[:data] lp = Dotloop::Models::Loop.new(loop_data) lp.client = client lp.profile_id = profile_id.to_i lp end |
#update(profile_id:, loop_id:, params: {}) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/dotloop/loop.rb', line 114 def update(profile_id:, loop_id:, params: {}) data = {} params.each do |key, value| LOOP_FIELDS.include?(key.to_s) || next data[key] = value.to_s end loop_data = @client.patch("/profile/#{profile_id.to_i}/loop/#{loop_id.to_i}", data)[:data] lp = Dotloop::Models::Loop.new(loop_data) lp.client = client lp.profile_id = profile_id.to_i lp end |
#update_details(profile_id:, loop_id:, params: {}) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/dotloop/loop.rb', line 128 def update_details(profile_id:, loop_id:, params: {}) data = {} LOOP_DETAILS_FIELDS.keys.each do |key| (detail_fields = params[key]) detail_fields.is_a?(Hash) || next data[key] = {} detail_fields.each do |k, v| LOOP_DETAILS_FIELDS[key].include?(k.to_s) || next data[key][k] = v.to_s end end loop_detail = @client.patch("/profile/#{profile_id.to_i}/loop/#{loop_id.to_i}/detail", data)[:data] loop_detail = Dotloop::LoopDetail.new(loop_detail).details Dotloop::Models::LoopDetail.new(loop_detail) end |