diff --git a/.gitignore b/.gitignore index e23729cc..90e205aa 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ tmp/* .buildpath .project *.swp +.bundle diff --git a/lib/spark_api/models.rb b/lib/spark_api/models.rb index bf8f7172..3ce5ab4a 100644 --- a/lib/spark_api/models.rb +++ b/lib/spark_api/models.rb @@ -7,6 +7,8 @@ require 'spark_api/models/concerns' require 'spark_api/models/account' +require 'spark_api/models/account_report' +require 'spark_api/models/account_roster' require 'spark_api/models/activity' require 'spark_api/models/connect_prefs' require 'spark_api/models/contact' diff --git a/lib/spark_api/models/account_report.rb b/lib/spark_api/models/account_report.rb new file mode 100644 index 00000000..c9d95bb4 --- /dev/null +++ b/lib/spark_api/models/account_report.rb @@ -0,0 +1,31 @@ +module SparkApi + module Models + class AccountReport < Account + def self.report(account_id, arguments={}) + collect(connection.get("/accounts/#{account_id}/report", arguments)).first + end + + def DisplayName + self.Name + end + + def primary_email + if Array(emails).any? && emails.primary + emails.primary.Address + end + end + + def primary_phone + if Array(phones).any? && phones.primary + phones.primary.Number + end + end + + def logo + if images.kind_of? Array + images.find { |image| image.Type == "Logo" } + end + end + end + end +end diff --git a/lib/spark_api/models/account_roster.rb b/lib/spark_api/models/account_roster.rb new file mode 100644 index 00000000..b9d15d04 --- /dev/null +++ b/lib/spark_api/models/account_roster.rb @@ -0,0 +1,9 @@ +module SparkApi + module Models + class AccountRoster < Account + def self.roster(account_id, arguments={}) + collect(connection.get("/accounts/#{account_id}/roster", arguments)).first + end + end + end +end diff --git a/spec/unit/spark_api/models/account_report_spec.rb b/spec/unit/spark_api/models/account_report_spec.rb new file mode 100644 index 00000000..1075d8b7 --- /dev/null +++ b/spec/unit/spark_api/models/account_report_spec.rb @@ -0,0 +1,77 @@ +require './spec/spec_helper' + +describe AccountReport do + + let(:account_report) { + AccountReport.new({ + "Id" => "12345", + "Name" => "Agent McAgentson", + "Office" => "Office Name", + "Emails"=> [], + "Phones"=> [], + "Websites"=> [], + "Addresses"=> [] + }) + } + + describe 'primary_email' do + + it 'returns the primary email address' do + account_report.emails << double(:Address => 'foo@foo.com', :primary? => true) + expect(account_report.primary_email).to eq account_report.emails.primary.Address + end + + it 'returns nil when there is no primary email address' do + account_report.emails << double(:Address => 'foo@foo.com', :primary? => false) + expect(account_report.primary_email).to eq nil + end + + it 'returns nil when there are no email addresses' do + allow(account_report).to receive(:emails).and_return nil + expect(account_report.primary_email).to eq nil + end + + end + + describe 'primary_phone' do + + it 'returns the primary phone number' do + account_report.phones << double(:Number => '88', :primary? => true) + expect(account_report.primary_phone).to eq account_report.phones.primary.Number + end + + it 'returns nil when there is no primary phone number' do + account_report.phones << double(:Number => '88', :primary? => false) + expect(account_report.primary_phone).to eq nil + end + + it 'returns nil when there are no phone numbers' do + allow(account_report).to receive(:phones).and_return nil + expect(account_report.primary_phone).to eq nil + end + + end + + describe 'logo' do + + it 'returns the logo' do + logo = SparkApi::Models::Base.new( {"Type" => "Logo"} ) + not_logo = SparkApi::Models::Base.new( {"Type" => "Nope" } ) + account_report.images = [logo, not_logo] + expect(account_report.logo).to be logo + end + + it 'returns nil if there is no logo' do + not_logo = SparkApi::Models::Base.new( {"Type" => "Nope" } ) + account_report.images = [not_logo] + expect(account_report.logo).to be nil + end + + it 'returns nil if there are no images' do + expect(account_report.images).to be nil + expect(account_report.logo).to be nil + end + + end + +end