Skip to content

Commit

Permalink
Merge fad9205 into f7222b2
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbeedle committed May 12, 2013
2 parents f7222b2 + fad9205 commit de07594
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/capsule_crm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'capsule_crm/email'
require 'capsule_crm/party'
require 'capsule_crm/phone'
require 'capsule_crm/user'
require 'capsule_crm/website'
require 'capsule_crm/hash_helper'
require 'capsule_crm/results_proxy'
Expand Down
34 changes: 34 additions & 0 deletions lib/capsule_crm/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module CapsuleCRM
class User
include Virtus

extend ActiveModel::Naming
include ActiveModel::Conversion
include ActiveModel::Validations

include CapsuleCRM::Associations::BelongsTo

attribute :username, String
attribute :name, String
attribute :currency, String
attribute :timezone, String
attribute :logged_in, Boolean

belongs_to :party, class_name: 'CapsuleCRM::Party'

# Public: Retrieve all users from CapsuleCRM
#
# Examples:
#
# CapsuleCRM::User.all
#
# Returns a CapsuleCRM::ResultsProxy of CapsuleCRM::User objects
def self.all
CapsuleCRM::ResultsProxy.new(
CapsuleCRM::Connection.get('/api/users')['users']['user'].map do |item|
new item
end
)
end
end
end
20 changes: 20 additions & 0 deletions spec/lib/capsule_crm/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'spec_helper'

describe CapsuleCRM::User do
before { configure }

describe '.all' do
before do
stub_request(:get, /\/api\/users$/).
to_return(body: File.read('spec/support/all_users.json'))
end

subject { CapsuleCRM::User.all }

it { should be_a(Array) }

it { subject.length.should eql(2) }

it { subject.all? { |item| item.is_a?(CapsuleCRM::User) }.should be_true }
end
end
21 changes: 21 additions & 0 deletions spec/support/all_users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"users": {
"user": [
{
"username": "a.user",
"currency": "GBP",
"name": "Alfred User",
"loggedIn": "true",
"timezone": "Europe/London",
"partyId": "100"
},
{
"username": "j.joe",
"currency": "GBP",
"name": "Jane Doe",
"timezone": "Europe/London",
"partyId": "101"
}
]
}
}

0 comments on commit de07594

Please sign in to comment.