Skip to content

Commit

Permalink
Merge 5065a4c into 50db849
Browse files Browse the repository at this point in the history
  • Loading branch information
theabuitendyk committed May 12, 2017
2 parents 50db849 + 5065a4c commit 0b3d701
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/dotloop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require 'dotloop/participant'
require 'dotloop/person'
require 'dotloop/task'
require 'dotloop/exceptions'

require 'dotloop/models/document'
require 'dotloop/models/document_activity'
Expand Down
14 changes: 13 additions & 1 deletion lib/dotloop/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,22 @@ def get(page, params = {})

def raw(page, params = {})
response = self.class.get(page, query: params, headers: headers, timeout: 60)
raise "Error communicating: Response code #{response.code}" unless response.code == 200
handle_dotloop_error(response.code) if response.code != 200
response.parsed_response
end

def handle_dotloop_error(response_code)
error = case response_code
when 401
Dotloop::Unauthorized
when 403
Dotloop::Forbidden
else
StandardError
end
raise error, "Error communicating: Response code #{response_code}"
end

def Profile
@profile ||= Dotloop::Profile.new(client: self)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/dotloop/exceptions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Dotloop
class Forbidden < StandardError; end
class Unauthorized < StandardError; end
end
4 changes: 2 additions & 2 deletions lib/dotloop/section.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Dotloop
class Section
attr_accessor :sections
FIXED_SECTIONS = %i(
FIXED_SECTIONS = %i[
contract_dates contract_info financials geographic_description listing_information
offer_dates property_address property referral
).freeze
].freeze

def initialize(data)
@sections = FIXED_SECTIONS.each_with_object({}) { |key, memo| memo[key] = {} }.merge(contacts: [])
Expand Down
19 changes: 18 additions & 1 deletion spec/dotloop/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative '../spec_helper'

# rubocop:disable Metrics/BlockLength
RSpec.describe Dotloop::Client do
let(:api_key) { 'blah' }
let(:application) { 'bloh' }
Expand Down Expand Up @@ -53,7 +54,23 @@
let(:code) { 234 }
it 'should raise an error if the response code is not 200' do
expect(subject.class).to receive(:get).with('foo', anything).and_return(response)
expect { subject.get('foo') }.to raise_error RuntimeError
expect { subject.get('foo') }.to raise_error StandardError
end
end

context 'when there is a 401 error' do
let(:code) { 401 }
it 'should raise an Unauthorized error' do
expect(subject.class).to receive(:get).with('foo', anything).and_return(response)
expect { subject.get('foo') }.to raise_error Dotloop::Unauthorized
end
end

context 'when there is a 403 error' do
let(:code) { 403 }
it 'should raise an Forbidden error' do
expect(subject.class).to receive(:get).with('foo', anything).and_return(response)
expect { subject.get('foo') }.to raise_error Dotloop::Forbidden
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/dotloop/document_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative '../spec_helper'

# rubocop:disable Metrics/BlockLength
RSpec.describe Dotloop::Document do
let(:client) { Dotloop::Client.new(api_key: SecureRandom.uuid) }
subject { Dotloop::Document.new(client: client) }
Expand Down
1 change: 1 addition & 0 deletions spec/dotloop/employee_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative '../spec_helper'

# rubocop:disable Metrics/BlockLength
RSpec.describe Dotloop::Employee do
let(:client) { Dotloop::Client.new(api_key: SecureRandom.uuid) }
subject { Dotloop::Employee.new(client: client) }
Expand Down
5 changes: 3 additions & 2 deletions spec/dotloop/loop_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative '../spec_helper'

# rubocop:disable Metrics/BlockLength
RSpec.describe Dotloop::Loop do
let(:client) { Dotloop::Client.new(api_key: SecureRandom.uuid) }
subject { Dotloop::Loop.new(client: client) }
Expand Down Expand Up @@ -54,7 +55,7 @@
).and_return([])
subject.all(
profile_id: '1234',
statuses: %i(private_listing active_listing under_contract),
statuses: %i[private_listing active_listing under_contract],
compliance_status_ids: [3, 4, 5],
tag_ids: [6, 7, 8],
sort_by: 'sort me',
Expand Down Expand Up @@ -114,7 +115,7 @@
end

describe '#statuses' do
let(:status_list) { %i(private_listing active_listing under_contract sold leased archived pre_listing pre_offer) }
let(:status_list) { %i[private_listing active_listing under_contract sold leased archived pre_listing pre_offer] }
it { expect(subject.statuses).to match_array(status_list) }
end
end
1 change: 1 addition & 0 deletions spec/dotloop/models/document_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative '../../spec_helper'

# rubocop:disable Metrics/BlockLength
RSpec.describe Dotloop::Models::Loop do
let(:profile_id) { 1234 }
let(:loop_view_id) { 76_046 }
Expand Down
1 change: 1 addition & 0 deletions spec/dotloop/models/loop_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative '../../spec_helper'

# rubocop:disable Metrics/BlockLength
RSpec.describe Dotloop::Models::Loop do
let(:profile_id) { 1234 }
let(:loop_view_id) { 76_046 }
Expand Down
1 change: 1 addition & 0 deletions spec/dotloop/person_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative '../spec_helper'

# rubocop:disable Metrics/BlockLength
RSpec.describe Dotloop::Person do
let(:client) { Dotloop::Client.new(api_key: SecureRandom.uuid) }
subject { Dotloop::Person.new(client: client) }
Expand Down
1 change: 1 addition & 0 deletions spec/dotloop/profile_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative '../spec_helper'

# rubocop:disable Metrics/BlockLength
RSpec.describe Dotloop::Profile do
let(:client) { Dotloop::Client.new(api_key: SecureRandom.uuid) }
subject { Dotloop::Profile.new(client: client) }
Expand Down
1 change: 1 addition & 0 deletions spec/dotloop/section_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative '../spec_helper'

# rubocop:disable Metrics/BlockLength
RSpec.describe Dotloop::Section do
let(:client) { Dotloop::Client.new(api_key: SecureRandom.uuid) }
let(:loop) { Dotloop::Loop.new(client: client) }
Expand Down
1 change: 1 addition & 0 deletions spec/dotloop/task_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative '../spec_helper'

# rubocop:disable Metrics/BlockLength
RSpec.describe Dotloop::Task do
let(:client) { Dotloop::Client.new(api_key: SecureRandom.uuid) }
subject { Dotloop::Task.new(client: client) }
Expand Down

0 comments on commit 0b3d701

Please sign in to comment.