pipejump 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -1
- data/.rspec +1 -0
- data/Gemfile +4 -3
- data/Gemfile.lock +20 -15
- data/Rakefile +4 -31
- data/VERSION +1 -1
- data/lib/pipejump/base/collection.rb +15 -15
- data/lib/pipejump/base/connection.rb +14 -14
- data/lib/pipejump/base/resource.rb +49 -41
- data/lib/pipejump/base/session.rb +81 -69
- data/lib/pipejump/resources/contact.rb +131 -121
- data/lib/pipejump/resources/deal.rb +122 -122
- data/lib/pipejump/resources/reminder.rb +97 -94
- data/lib/pipejump/version.rb +3 -0
- data/lib/pipejump.rb +1 -2
- data/pipejump.gemspec +21 -0
- data/spec/pipejump/resources/contact/note_spec.rb +100 -0
- data/spec/pipejump/resources/contact/reminder_spec.rb +128 -0
- data/spec/pipejump/resources/contact_spec.rb +45 -37
- data/spec/pipejump/resources/{note_spec.rb → deal/note_spec.rb} +29 -28
- data/spec/pipejump/resources/{reminder_spec.rb → deal/reminder_spec.rb} +43 -35
- data/spec/pipejump/resources/deal_spec.rb +45 -39
- data/spec/pipejump/resources/source_spec.rb +29 -26
- data/spec/pipejump/session_spec.rb +12 -13
- data/spec/spec_helper.rb +17 -2
- metadata +25 -45
- data/lib/pipejump/resources/client.rb +0 -162
- data/spec/pipejump/resources/client_spec.rb +0 -119
@@ -1,61 +1,67 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
|
+
|
2
3
|
describe Pipejump::Deal do
|
3
4
|
|
4
|
-
before do
|
5
|
+
before do
|
5
6
|
@session = PipejumpSpec.session
|
6
|
-
@client = @session.
|
7
|
+
@client = @session.contacts.create(:name => 'Client2' + uuid, :is_organisation => true)
|
8
|
+
@client.id.should_not be_nil
|
7
9
|
end
|
8
|
-
|
10
|
+
|
9
11
|
after do
|
10
12
|
@client.destroy
|
11
13
|
end
|
12
|
-
|
14
|
+
|
13
15
|
describe '#create' do
|
14
|
-
|
16
|
+
|
15
17
|
it "should create deal with valid params" do
|
16
|
-
@deal = @session.deals.create(:name => 'New deal', :
|
17
|
-
@deal.
|
18
|
-
|
18
|
+
@deal = @session.deals.create(:name => 'New deal' + uuid, :entity_id => @client.id)
|
19
|
+
@deal.id.should_not be_nil
|
20
|
+
["entity_id", "deal_tags", "hot", "id", "last_stage_change_at", "name", "scope", "stage_name"].each do |key|
|
21
|
+
@deal.attributes.keys.should include(key)
|
22
|
+
end
|
23
|
+
|
24
|
+
(@deal.attributes.keys - ['entity']).each do |attribute|
|
19
25
|
@deal.send(attribute).should == @deal.attributes[attribute]
|
20
26
|
end
|
21
|
-
@deal.
|
27
|
+
@deal.entity.class.should == Pipejump::Contact
|
22
28
|
@deal.destroy
|
23
29
|
end
|
24
|
-
|
30
|
+
|
25
31
|
it "should return errors with invalid params" do
|
26
32
|
@deal = @session.deals.create({})
|
27
33
|
@deal.id.should == nil
|
28
|
-
@deal.errors['deal'].collect{ |e| e['error']['field'] }.sort.should == ['
|
34
|
+
@deal.errors['deal'].collect{ |e| e['error']['field'] }.sort.should == ['entity', 'name']
|
29
35
|
end
|
30
|
-
|
36
|
+
|
31
37
|
end
|
32
|
-
|
38
|
+
|
33
39
|
describe '.find' do
|
34
40
|
|
35
41
|
it "should find deal" do
|
36
|
-
@deal = @session.deals.create(:name => 'New deal', :
|
42
|
+
@deal = @session.deals.create(:name => 'New deal' + uuid, :entity_id => @client.id)
|
37
43
|
@found = @session.deals.find(@deal.id)
|
38
44
|
@found.name == @deal.name
|
39
45
|
@deal.destroy
|
40
46
|
end
|
41
|
-
|
47
|
+
|
42
48
|
it "should raise error if not found" do
|
43
49
|
lambda {
|
44
50
|
@session.deals.find(-1)
|
45
51
|
}.should raise_error(Pipejump::ResourceNotFound)
|
46
52
|
end
|
47
53
|
end
|
48
|
-
|
54
|
+
|
49
55
|
describe '#update' do
|
50
|
-
|
56
|
+
|
51
57
|
before do
|
52
|
-
@deal = @session.deals.create(:name => 'New deal', :
|
58
|
+
@deal = @session.deals.create(:name => 'New deal' + uuid, :entity_id => @client.id)
|
53
59
|
end
|
54
|
-
|
55
|
-
after do
|
60
|
+
|
61
|
+
after do
|
56
62
|
@deal.destroy
|
57
|
-
end
|
58
|
-
|
63
|
+
end
|
64
|
+
|
59
65
|
it "should update deal with valid params" do
|
60
66
|
@deal.name = 'Updated deal'
|
61
67
|
@deal.save
|
@@ -63,38 +69,38 @@ describe Pipejump::Deal do
|
|
63
69
|
@found = @session.deals.find(@deal.id)
|
64
70
|
@found.name.should == 'Updated deal'
|
65
71
|
end
|
66
|
-
|
72
|
+
|
67
73
|
it "should return errors with invalid params" do
|
68
74
|
@deal.name = ''
|
69
|
-
@deal.save.should == false
|
75
|
+
@deal.save.should == false
|
70
76
|
@deal.errors['deal'].collect{ |e| e['error']['field'] }.sort.should == ['name']
|
71
77
|
end
|
72
|
-
|
78
|
+
|
73
79
|
end
|
74
|
-
|
80
|
+
|
75
81
|
describe '#contacts' do
|
76
|
-
|
77
|
-
before do
|
78
|
-
@deal = @session.deals.create(:name => 'New deal', :
|
79
|
-
@contact = @session.contacts.create(:name => 'Tom', :
|
80
|
-
@contact2 = @session.contacts.create(:name => 'Mike', :
|
82
|
+
|
83
|
+
before do
|
84
|
+
@deal = @session.deals.create(:name => 'New deal' + uuid, :entity_id => @client.id)
|
85
|
+
@contact = @session.contacts.create(:name => 'Tom' + uuid, :contact_id => @client.id)
|
86
|
+
@contact2 = @session.contacts.create(:name => 'Mike' + uuid, :contact_id => @client.id)
|
81
87
|
@deal.contacts.update(@contact.id).should == true
|
82
88
|
end
|
83
|
-
|
89
|
+
|
84
90
|
after do
|
85
91
|
@contact.destroy
|
86
92
|
@contact2.destroy
|
87
93
|
end
|
88
|
-
|
94
|
+
|
89
95
|
it "should return a collection of contacts" do
|
90
96
|
contacts = @deal.contacts
|
91
97
|
contacts.class.should == Pipejump::Collection
|
92
98
|
contacts.respond_to?(:update).should == true
|
93
99
|
contacts.size.should == 1
|
94
100
|
end
|
95
|
-
|
101
|
+
|
96
102
|
describe '#update' do
|
97
|
-
|
103
|
+
|
98
104
|
it "should update a collection of contacts and be smart about it" do
|
99
105
|
@deal.contacts.update([@contact.id, @contact2.id])
|
100
106
|
@deal.contacts.size.should == 2
|
@@ -107,9 +113,9 @@ describe Pipejump::Deal do
|
|
107
113
|
@deal.contacts.update([@contact.id, @contact2.id].join(','))
|
108
114
|
@deal.contacts.size.should == 2
|
109
115
|
end
|
110
|
-
|
116
|
+
|
111
117
|
end
|
112
|
-
|
118
|
+
|
113
119
|
end
|
114
|
-
|
120
|
+
|
115
121
|
end
|
@@ -1,42 +1,45 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
|
+
|
2
3
|
describe Pipejump::Source do
|
3
4
|
|
4
|
-
before do
|
5
|
+
before do
|
5
6
|
@session = PipejumpSpec.session
|
6
|
-
@source1 = @session.sources.create(:name => 'Source1')
|
7
|
+
@source1 = @session.sources.create(:name => 'Source1'+uuid)
|
7
8
|
@source1.id.should_not be_nil
|
8
|
-
@source2 = @session.sources.create(:name => 'Source2')
|
9
|
+
@source2 = @session.sources.create(:name => 'Source2'+uuid)
|
9
10
|
@source2.id.should_not be_nil
|
10
11
|
end
|
11
|
-
|
12
|
+
|
12
13
|
after do
|
13
14
|
@source1.destroy
|
14
15
|
@source2.destroy
|
15
16
|
end
|
16
|
-
|
17
|
+
|
17
18
|
describe '@session.sources' do
|
18
|
-
|
19
|
+
|
19
20
|
it ".all should return all sources" do
|
20
|
-
@session.sources.all.collect(&:name)
|
21
|
+
sources = @session.sources.all.collect(&:name)
|
22
|
+
sources.should include(@source1.name)
|
23
|
+
sources.should include(@source2.name)
|
21
24
|
end
|
22
25
|
|
23
26
|
it ".first should return first source" do
|
24
|
-
@session.sources.first.
|
27
|
+
@session.sources.first.should be_a(Pipejump::Source)
|
25
28
|
end
|
26
29
|
|
27
30
|
it ".last should return last source" do
|
28
|
-
@session.sources.last.
|
31
|
+
@session.sources.last.should be_a(Pipejump::Source)
|
29
32
|
end
|
30
|
-
|
33
|
+
|
31
34
|
it ".find should find exact source" do
|
32
35
|
@session.sources.find(@source1.id).name.should == @source1.name
|
33
36
|
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
+
|
38
|
+
end
|
39
|
+
|
37
40
|
describe '#method_missing' do
|
38
|
-
|
39
|
-
it "should correctly get and set attributes" do
|
41
|
+
|
42
|
+
it "should correctly get and set attributes" do
|
40
43
|
@source1.attributes.keys.sort.should == ['id', 'name']
|
41
44
|
@source1.attributes.keys.each do |attribute|
|
42
45
|
@source1.send(attribute).should == @source1.attributes[attribute]
|
@@ -45,17 +48,17 @@ describe Pipejump::Source do
|
|
45
48
|
@source1.name.should == 'Different name'
|
46
49
|
@source1.attributes['name'].should == 'Different name'
|
47
50
|
end
|
48
|
-
|
51
|
+
|
49
52
|
it "should raise a NoMethodError when no accessor is set" do
|
50
53
|
lambda {
|
51
54
|
@source1.not_a_method_name
|
52
55
|
}.should raise_error(NoMethodError)
|
53
56
|
end
|
54
|
-
|
57
|
+
|
55
58
|
end
|
56
59
|
|
57
60
|
describe '#create' do
|
58
|
-
|
61
|
+
|
59
62
|
it "should create record" do
|
60
63
|
@source3 = @session.sources.create(:name => 'Source3')
|
61
64
|
@source3.id.should_not be_nil
|
@@ -63,29 +66,29 @@ describe Pipejump::Source do
|
|
63
66
|
@session.sources.find(@source3.id).name.should == 'Source3'
|
64
67
|
@source3.destroy
|
65
68
|
end
|
66
|
-
|
69
|
+
|
67
70
|
it "should return error on validation fail" do
|
68
71
|
@source3 = @session.sources.create(:name => '')
|
69
72
|
@source3.id.should be_nil
|
70
|
-
@source3.errors.should_not == {}
|
73
|
+
@source3.errors.should_not == {}
|
71
74
|
end
|
72
|
-
|
75
|
+
|
73
76
|
end
|
74
77
|
|
75
78
|
describe '#update' do
|
76
|
-
|
79
|
+
|
77
80
|
it "should update record" do
|
78
81
|
@source1.name = 'Different name'
|
79
82
|
@source1.save.should == true
|
80
83
|
@session.sources.find(@source1.id).name.should == 'Different name'
|
81
84
|
end
|
82
|
-
|
85
|
+
|
83
86
|
it "should return error on validation fail" do
|
84
87
|
@source1.name = ''
|
85
88
|
@source1.save.should == false
|
86
|
-
@source1.errors.should_not == {}
|
89
|
+
@source1.errors.should_not == {}
|
87
90
|
end
|
88
|
-
|
91
|
+
|
89
92
|
end
|
90
93
|
|
91
94
|
end
|
@@ -1,33 +1,32 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
|
+
|
2
3
|
describe Pipejump::Session do
|
3
4
|
|
4
|
-
before do
|
5
|
+
before do
|
5
6
|
@session = Pipejump::Session.new(AUTH.dup)
|
6
7
|
end
|
7
|
-
|
8
|
+
|
8
9
|
it "should have token" do
|
9
10
|
@session.token.should_not be_nil
|
10
11
|
end
|
11
|
-
|
12
|
+
|
12
13
|
it "should raise an error on wrong credentials" do
|
13
14
|
lambda {
|
14
15
|
@session = Pipejump::Session.new(AUTH.merge({'password' => 'NOT_CORRECT_PASSWORD_123qwe'}).dup)
|
15
16
|
}.should raise_error(Pipejump::AuthenticationFailed)
|
16
17
|
end
|
17
|
-
|
18
|
+
|
18
19
|
it "should return account data on /account" do
|
19
20
|
account = @session.account
|
20
21
|
account.class.should == Pipejump::Account
|
21
|
-
|
22
|
+
["currency_name", "id", "name"].each do |key|
|
23
|
+
account.attributes.keys.should include(key)
|
24
|
+
end
|
22
25
|
end
|
23
|
-
|
26
|
+
|
24
27
|
it "#connection should return a connection" do
|
25
28
|
@session.connection.class.should == Pipejump::Connection
|
26
29
|
end
|
27
|
-
|
28
|
-
it "#clients should return a collection of clients" do
|
29
|
-
@session.clients.class.should == Pipejump::Collection
|
30
|
-
end
|
31
30
|
|
32
31
|
it "#contacts should return a collection of contacts" do
|
33
32
|
@session.contacts.class.should == Pipejump::Collection
|
@@ -40,5 +39,5 @@ describe Pipejump::Session do
|
|
40
39
|
it "#deals should return a collection of deals" do
|
41
40
|
@session.deals.class.should == Pipejump::Collection
|
42
41
|
end
|
43
|
-
|
44
|
-
end
|
42
|
+
|
43
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
require
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler/setup"
|
5
|
+
require 'pipejump'
|
4
6
|
require 'yaml'
|
5
7
|
AUTH = YAML.load_file(File.join(Dir.pwd, 'spec', 'connection.yml'))
|
6
8
|
|
@@ -9,4 +11,17 @@ class PipejumpSpec
|
|
9
11
|
attr_accessor :session
|
10
12
|
end
|
11
13
|
end
|
12
|
-
PipejumpSpec.session = Pipejump::Session.new(AUTH.dup)
|
14
|
+
PipejumpSpec.session = Pipejump::Session.new(AUTH.dup)
|
15
|
+
|
16
|
+
def uuid
|
17
|
+
Time.now.to_i.to_s + 'x' + rand(100000000).to_s + 'X' + rand(100000000).to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
config.before(:all) do
|
23
|
+
end
|
24
|
+
|
25
|
+
config.after(:all) do
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipejump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 0.2.0
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Marcin Bunsch
|
@@ -15,35 +10,22 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
13
|
+
date: 2011-08-31 00:00:00 +02:00
|
19
14
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
name: bundler
|
25
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
|
-
requirements:
|
28
|
-
- - ">="
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
hash: 3
|
31
|
-
segments:
|
32
|
-
- 0
|
33
|
-
version: "0"
|
34
|
-
requirement: *id001
|
15
|
+
dependencies: []
|
16
|
+
|
35
17
|
description: Pipejump API Ruby client
|
36
|
-
email: marcin@
|
18
|
+
email: marcin@futuresimple.com
|
37
19
|
executables: []
|
38
20
|
|
39
21
|
extensions: []
|
40
22
|
|
41
|
-
extra_rdoc_files:
|
42
|
-
|
43
|
-
- README.rdoc
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
44
25
|
files:
|
45
26
|
- .document
|
46
27
|
- .gitignore
|
28
|
+
- .rspec
|
47
29
|
- Gemfile
|
48
30
|
- Gemfile.lock
|
49
31
|
- LICENSE
|
@@ -57,28 +39,30 @@ files:
|
|
57
39
|
- lib/pipejump/base/resource.rb
|
58
40
|
- lib/pipejump/base/session.rb
|
59
41
|
- lib/pipejump/resources/account.rb
|
60
|
-
- lib/pipejump/resources/client.rb
|
61
42
|
- lib/pipejump/resources/contact.rb
|
62
43
|
- lib/pipejump/resources/deal.rb
|
63
44
|
- lib/pipejump/resources/note.rb
|
64
45
|
- lib/pipejump/resources/reminder.rb
|
65
46
|
- lib/pipejump/resources/source.rb
|
47
|
+
- lib/pipejump/version.rb
|
48
|
+
- pipejump.gemspec
|
66
49
|
- spec/connection.sample.yml
|
67
|
-
- spec/pipejump/resources/
|
50
|
+
- spec/pipejump/resources/contact/note_spec.rb
|
51
|
+
- spec/pipejump/resources/contact/reminder_spec.rb
|
68
52
|
- spec/pipejump/resources/contact_spec.rb
|
53
|
+
- spec/pipejump/resources/deal/note_spec.rb
|
54
|
+
- spec/pipejump/resources/deal/reminder_spec.rb
|
69
55
|
- spec/pipejump/resources/deal_spec.rb
|
70
|
-
- spec/pipejump/resources/note_spec.rb
|
71
|
-
- spec/pipejump/resources/reminder_spec.rb
|
72
56
|
- spec/pipejump/resources/source_spec.rb
|
73
57
|
- spec/pipejump/session_spec.rb
|
74
58
|
- spec/spec_helper.rb
|
75
59
|
has_rdoc: true
|
76
|
-
homepage: http://
|
60
|
+
homepage: http://pipejump.com/api
|
77
61
|
licenses: []
|
78
62
|
|
79
63
|
post_install_message:
|
80
|
-
rdoc_options:
|
81
|
-
|
64
|
+
rdoc_options: []
|
65
|
+
|
82
66
|
require_paths:
|
83
67
|
- lib
|
84
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -86,32 +70,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
70
|
requirements:
|
87
71
|
- - ">="
|
88
72
|
- !ruby/object:Gem::Version
|
89
|
-
hash: 3
|
90
|
-
segments:
|
91
|
-
- 0
|
92
73
|
version: "0"
|
93
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
75
|
none: false
|
95
76
|
requirements:
|
96
77
|
- - ">="
|
97
78
|
- !ruby/object:Gem::Version
|
98
|
-
hash: 3
|
99
|
-
segments:
|
100
|
-
- 0
|
101
79
|
version: "0"
|
102
80
|
requirements: []
|
103
81
|
|
104
|
-
rubyforge_project:
|
105
|
-
rubygems_version: 1.
|
82
|
+
rubyforge_project: pipejump
|
83
|
+
rubygems_version: 1.6.2
|
106
84
|
signing_key:
|
107
85
|
specification_version: 3
|
108
86
|
summary: Pipejump API Ruby client
|
109
87
|
test_files:
|
110
|
-
- spec/
|
88
|
+
- spec/connection.sample.yml
|
89
|
+
- spec/pipejump/resources/contact/note_spec.rb
|
90
|
+
- spec/pipejump/resources/contact/reminder_spec.rb
|
111
91
|
- spec/pipejump/resources/contact_spec.rb
|
92
|
+
- spec/pipejump/resources/deal/note_spec.rb
|
93
|
+
- spec/pipejump/resources/deal/reminder_spec.rb
|
112
94
|
- spec/pipejump/resources/deal_spec.rb
|
113
|
-
- spec/pipejump/resources/note_spec.rb
|
114
|
-
- spec/pipejump/resources/reminder_spec.rb
|
115
95
|
- spec/pipejump/resources/source_spec.rb
|
116
96
|
- spec/pipejump/session_spec.rb
|
117
97
|
- spec/spec_helper.rb
|
@@ -1,162 +0,0 @@
|
|
1
|
-
module Pipejump
|
2
|
-
|
3
|
-
|
4
|
-
# The Client resource is represented by an instance of Pipejump::Client.
|
5
|
-
#
|
6
|
-
# *Note*: To access any resources, you need a valid Session instance, referred to as @session in the following examples.
|
7
|
-
#
|
8
|
-
# == Access
|
9
|
-
#
|
10
|
-
# === Collection
|
11
|
-
#
|
12
|
-
# To fetch a collection of Pipejump::Client instances, call
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# @session.clients
|
16
|
-
# # => #<Pipejump::Collection resource: Pipejump::Client>
|
17
|
-
#
|
18
|
-
#
|
19
|
-
# This returns a Pipejump::Collection instance. To retrieve an array of Pipejump::Client instances, call the _all_ method on the collection:
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# @session.clients.all
|
23
|
-
# # => [#<Pipejump::Client name: "My Client", id: "1">, #<Pipejump::Client name: "Another Client", id: "2">]
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# Instead of _all_, you can also call a variety of Array methods in the collection which will be delegated to the array returned by _all_, such as:
|
27
|
-
#
|
28
|
-
# * first
|
29
|
-
# * last
|
30
|
-
# * each
|
31
|
-
# * size
|
32
|
-
# * collect
|
33
|
-
# * reject
|
34
|
-
#
|
35
|
-
# *Examples*:
|
36
|
-
#
|
37
|
-
# @session.clients.first
|
38
|
-
# # => #<Pipejump::Client name: "My Client", id: "1">
|
39
|
-
# @session.clients.last
|
40
|
-
# # => #<Pipejump::Client name: "Another Client", id: "2">
|
41
|
-
# @session.clients.size
|
42
|
-
# # => 2
|
43
|
-
# @session.clients.each { |client| puts client.name }
|
44
|
-
# # Prints out "My Client" and "Another Client"
|
45
|
-
# @session.clients.collect { |client| client.name }
|
46
|
-
# # => ["My Client", "Another Client"]
|
47
|
-
# @session.clients.reject { |client| client.name == 'My Client' }
|
48
|
-
# # => ["My Client", "Another Client"]
|
49
|
-
#
|
50
|
-
#
|
51
|
-
# === Resource
|
52
|
-
#
|
53
|
-
# To fetch a single resource, call the _find_ method with the resource id as an argument:
|
54
|
-
#
|
55
|
-
#
|
56
|
-
# @session.clients.find(1)
|
57
|
-
# # => #<Pipejump::Client name: "My Client", id: "1">
|
58
|
-
#
|
59
|
-
#
|
60
|
-
# == Creation
|
61
|
-
#
|
62
|
-
# *Note*: Clients require the following fields in the hash of attributes:
|
63
|
-
#
|
64
|
-
# * _name_: a valid name
|
65
|
-
#
|
66
|
-
# To create a new client, call the _create_ method on the Client Pipejump::Collection with a hash of attributes as an argument:
|
67
|
-
#
|
68
|
-
#
|
69
|
-
# @session.clients.create(:name => 'Third Client')
|
70
|
-
# # => #<Pipejump::Client name: "Third Client", id: "3">
|
71
|
-
#
|
72
|
-
#
|
73
|
-
# If the resource was created properly, it will be returned with a id assigned to it. You can check it by calling the created? method
|
74
|
-
#
|
75
|
-
#
|
76
|
-
# client = @session.clients.create(:name => 'Third Client')
|
77
|
-
# # => #<Pipejump::Client name: "Third Client", id: "3">
|
78
|
-
# client.created?
|
79
|
-
# # => true
|
80
|
-
# client = @session.clients.create(:name => '')
|
81
|
-
# # => #<Pipejump::Client name: "">
|
82
|
-
# client.created?
|
83
|
-
# # => false
|
84
|
-
#
|
85
|
-
#
|
86
|
-
# You can access validation/creation errors by calling the _errors_ method on the instance returned by _create_:
|
87
|
-
#
|
88
|
-
#
|
89
|
-
# client = @session.clients.create(:name => '')
|
90
|
-
# # => #<Pipejump::Client name: "">
|
91
|
-
# client.created?
|
92
|
-
# # => false
|
93
|
-
# client.errors
|
94
|
-
# # => {"client"=>[{"error"=>{"code"=>"E0001", "field"=>"name", "description"=>"can't be blank"}}]}
|
95
|
-
#
|
96
|
-
#
|
97
|
-
# == Update
|
98
|
-
#
|
99
|
-
# To update a resource, change the attributes and call the _save_ method.
|
100
|
-
#
|
101
|
-
# === Changing attributes
|
102
|
-
#
|
103
|
-
# Each attribute has an accessor which you can use to change the values:
|
104
|
-
#
|
105
|
-
#
|
106
|
-
# client = @session.clients.create(:name => 'Third Client')
|
107
|
-
# # => #<Pipejump::Client name: "Third Client", id: "3">
|
108
|
-
# client.name
|
109
|
-
# # => 'Third Client'
|
110
|
-
# client.name = 'Super Client'
|
111
|
-
# # => 'Super Client'
|
112
|
-
# client.name
|
113
|
-
# # => 'Super Client'
|
114
|
-
#
|
115
|
-
#
|
116
|
-
# === Saving
|
117
|
-
#
|
118
|
-
# Once you've changed the attributes, call the _save_ method on the resource instance:
|
119
|
-
#
|
120
|
-
#
|
121
|
-
# client = @session.clients.create(:name => 'Third Client')
|
122
|
-
# # => #<Pipejump::Client name: "Third Client", id: "3">
|
123
|
-
# client.name
|
124
|
-
# # => 'Third Client'
|
125
|
-
# client.save
|
126
|
-
# # => true
|
127
|
-
#
|
128
|
-
#
|
129
|
-
# _save_ returns _true_ if save was successful and _false_ if it failed. In the latter scenario, you can access the errors via the _errors_ method:
|
130
|
-
#
|
131
|
-
#
|
132
|
-
# client = @session.clients.create(:name => 'Third Client')
|
133
|
-
# # => #<Pipejump::Client name: "Third Client", id: "3">
|
134
|
-
# client.name = 'Super Client'
|
135
|
-
# # => 'Super Client'
|
136
|
-
# client.save
|
137
|
-
# # => true
|
138
|
-
# client.name = ''
|
139
|
-
# # => ''
|
140
|
-
# client.save
|
141
|
-
# # => false
|
142
|
-
# client.errors
|
143
|
-
# # => {"client"=>[{"error"=>{"code"=>"E0001", "field"=>"name", "description"=>"can't be blank"}}]}
|
144
|
-
#
|
145
|
-
#
|
146
|
-
# == Removal
|
147
|
-
#
|
148
|
-
# To remove a resource, call the _destroy_ method on the instance:
|
149
|
-
#
|
150
|
-
#
|
151
|
-
# client = @session.clients.find(1)
|
152
|
-
# # => #<Pipejump::Client name: "My Client", id: "1">
|
153
|
-
# client.destroy
|
154
|
-
# # => true
|
155
|
-
#
|
156
|
-
class Client < Resource
|
157
|
-
has_many :contacts do
|
158
|
-
disable :create
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|