basecrm 0.0.3 → 0.1.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.
- checksums.yaml +7 -0
- data/.travis.yml +7 -0
- data/Gemfile +2 -1
- data/README.md +2 -0
- data/Rakefile +6 -0
- data/basecrm.gemspec +1 -1
- data/lib/base_crm.rb +14 -13
- data/lib/base_crm/noteable.rb +3 -9
- data/lib/base_crm/related_object_scope.rb +35 -0
- data/lib/base_crm/taskable.rb +3 -8
- data/lib/base_crm/version.rb +1 -1
- data/spec/base_crm/contact_spec.rb +4 -4
- data/spec/base_crm/deal_spec.rb +9 -9
- data/spec/base_crm/forecasting_spec.rb +3 -3
- data/spec/base_crm/lead_spec.rb +1 -1
- data/spec/base_crm/resource_mixin_spec.rb +2 -2
- data/spec/base_crm/session_spec.rb +2 -2
- data/spec/support/noteable_shared_examples.rb +25 -4
- data/spec/support/taskable_shared_examples.rb +27 -5
- metadata +12 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5944afdba7dc0d91c937ab939bb6e1fb019e058f
|
4
|
+
data.tar.gz: a1939878b665013a2a9591beea66f448e0b17a78
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2d5710f54131a3461b6c7ae51fda0bf8e1f83bc8366e0406a2b901acb1853a6520b903b3c2cdfd24feea9c6362d520bbca213abb55cdc9c0f6a3b914e0d429b9
|
7
|
+
data.tar.gz: 1e537e6befde7c148eb1c570cd602bc1abcd067c2594b06c45a374e516cacb56b19eab9443438f3ec716a0f1832341b6db67d46b631d5120fdcefeb765f69594
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/basecrm.gemspec
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../lib/base_crm/version', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Marcin Bunsch"]
|
6
|
-
gem.email = ["marcin@
|
6
|
+
gem.email = ["marcin@getbase.com"]
|
7
7
|
gem.description = %q{Base CRM API Client}
|
8
8
|
gem.summary = %q{Base CRM API Client}
|
9
9
|
gem.homepage = "https://github.com/basecrm/basecrm"
|
data/lib/base_crm.rb
CHANGED
@@ -5,19 +5,20 @@ require "base_crm/api_client_ext"
|
|
5
5
|
|
6
6
|
module BaseCrm
|
7
7
|
|
8
|
-
autoload :
|
9
|
-
autoload :
|
10
|
-
autoload :
|
11
|
-
autoload :
|
12
|
-
autoload :
|
13
|
-
autoload :
|
14
|
-
autoload :
|
15
|
-
autoload :
|
16
|
-
autoload :
|
17
|
-
autoload :
|
18
|
-
autoload :
|
19
|
-
autoload :
|
20
|
-
autoload :
|
8
|
+
autoload :RelatedObjectScope, "base_crm/related_object_scope"
|
9
|
+
autoload :Account, "base_crm/account"
|
10
|
+
autoload :Contact, "base_crm/contact"
|
11
|
+
autoload :Session, "base_crm/session"
|
12
|
+
autoload :Deal, "base_crm/deal"
|
13
|
+
autoload :Forecasting, "base_crm/forecasting"
|
14
|
+
autoload :Source, "base_crm/source"
|
15
|
+
autoload :Resource, "base_crm/resource"
|
16
|
+
autoload :Note, "base_crm/note"
|
17
|
+
autoload :Noteable, "base_crm/noteable"
|
18
|
+
autoload :Task, "base_crm/task"
|
19
|
+
autoload :Taskable, "base_crm/taskable"
|
20
|
+
autoload :Lead, "base_crm/lead"
|
21
|
+
autoload :CustomFieldable, "base_crm/custom_fieldable"
|
21
22
|
|
22
23
|
end
|
23
24
|
|
data/lib/base_crm/noteable.rb
CHANGED
@@ -2,18 +2,12 @@ module BaseCrm
|
|
2
2
|
module Noteable
|
3
3
|
|
4
4
|
def notes
|
5
|
-
|
6
|
-
:noteable_type => self.noteable_type,
|
7
|
-
:noteable_id => self.id
|
8
|
-
})
|
5
|
+
@notes ||= BaseCrm::RelatedObjectScope.new(self, Note, :noteable)
|
9
6
|
end
|
10
7
|
|
8
|
+
# Keeping it for legacy purposes
|
11
9
|
def create_note(message)
|
12
|
-
|
13
|
-
:content => message,
|
14
|
-
:noteable_type => self.noteable_type,
|
15
|
-
:noteable_id => self.id
|
16
|
-
})
|
10
|
+
notes.create(:content => message)
|
17
11
|
end
|
18
12
|
|
19
13
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "delegate"
|
2
|
+
module BaseCrm
|
3
|
+
|
4
|
+
class RelatedObjectScope < SimpleDelegator
|
5
|
+
|
6
|
+
attr_accessor :object, :subobject, :type
|
7
|
+
|
8
|
+
def initialize(object, subobject, key, type = nil)
|
9
|
+
@object = object
|
10
|
+
@subobject = subobject
|
11
|
+
@type = type || object.class.name.split('::').last
|
12
|
+
@type_key = "#{key}_type".to_sym
|
13
|
+
@id_key = "#{key}_id".to_sym
|
14
|
+
super(subobject_scope)
|
15
|
+
end
|
16
|
+
|
17
|
+
def subobject_scope
|
18
|
+
@subobject_scope ||= object.pass_headers(subobject).params(type_and_id_scope)
|
19
|
+
end
|
20
|
+
|
21
|
+
def create(params)
|
22
|
+
subobject_scope.create(type_and_id_scope.merge(params))
|
23
|
+
end
|
24
|
+
|
25
|
+
def type_and_id_scope
|
26
|
+
{
|
27
|
+
@type_key => type,
|
28
|
+
@id_key => object.id
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
data/lib/base_crm/taskable.rb
CHANGED
@@ -2,17 +2,12 @@ module BaseCrm
|
|
2
2
|
module Taskable
|
3
3
|
|
4
4
|
def tasks
|
5
|
-
|
6
|
-
:taskable_type => self.taskable_type,
|
7
|
-
:taskable_id => self.id
|
8
|
-
})
|
5
|
+
@tasks ||= BaseCrm::RelatedObjectScope.new(self, Task, :taskable)
|
9
6
|
end
|
10
7
|
|
8
|
+
# Keeping it for legacy purposes
|
11
9
|
def create_task(params)
|
12
|
-
|
13
|
-
:taskable_type => self.taskable_type,
|
14
|
-
:taskable_id => self.id
|
15
|
-
}.merge(params))
|
10
|
+
tasks.create(params)
|
16
11
|
end
|
17
12
|
|
18
13
|
end
|
data/lib/base_crm/version.rb
CHANGED
@@ -42,8 +42,8 @@ describe BaseCrm::Contact do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
describe ".fetch_for_deal" do
|
45
|
-
let(:scope) {
|
46
|
-
let(:deal) {
|
45
|
+
let(:scope) { double }
|
46
|
+
let(:deal) { double(:id => 444) }
|
47
47
|
|
48
48
|
it "returns the scope" do
|
49
49
|
BaseCrm::Contact.should_receive(:scope).and_return(scope)
|
@@ -58,8 +58,8 @@ describe BaseCrm::Contact do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
describe "#notes" do
|
61
|
-
let(:scope) {
|
62
|
-
let(:fetch_scope) {
|
61
|
+
let(:scope) { double }
|
62
|
+
let(:fetch_scope) { double }
|
63
63
|
|
64
64
|
it "passes the token and applies the params" do
|
65
65
|
subject.
|
data/spec/base_crm/deal_spec.rb
CHANGED
@@ -43,9 +43,9 @@ describe BaseCrm::Deal do
|
|
43
43
|
|
44
44
|
describe "#source" do
|
45
45
|
|
46
|
-
let(:source) {
|
46
|
+
let(:source) { double }
|
47
47
|
let(:source_id) { 444 }
|
48
|
-
let(:scope) {
|
48
|
+
let(:scope) { double }
|
49
49
|
|
50
50
|
before do
|
51
51
|
subject.source_id = source_id
|
@@ -87,9 +87,9 @@ describe BaseCrm::Deal do
|
|
87
87
|
|
88
88
|
describe "#contact" do
|
89
89
|
|
90
|
-
let(:contact) {
|
91
|
-
let(:entity_id) {
|
92
|
-
let(:scope) {
|
90
|
+
let(:contact) { double }
|
91
|
+
let(:entity_id) { double }
|
92
|
+
let(:scope) { double }
|
93
93
|
|
94
94
|
before do
|
95
95
|
subject.entity_id = entity_id
|
@@ -120,8 +120,8 @@ describe BaseCrm::Deal do
|
|
120
120
|
end
|
121
121
|
|
122
122
|
describe "#contacts" do
|
123
|
-
let(:scope) {
|
124
|
-
let(:fetch_scope) {
|
123
|
+
let(:scope) { double }
|
124
|
+
let(:fetch_scope) { double }
|
125
125
|
|
126
126
|
it "passes the token and users fetch_for_deal" do
|
127
127
|
subject.should_receive(:pass_headers).with(BaseCrm::Contact).and_return(scope)
|
@@ -131,8 +131,8 @@ describe BaseCrm::Deal do
|
|
131
131
|
end
|
132
132
|
|
133
133
|
describe "#forecasting" do
|
134
|
-
let(:scope) {
|
135
|
-
let(:fetch_scope) {
|
134
|
+
let(:scope) { double }
|
135
|
+
let(:fetch_scope) { double }
|
136
136
|
|
137
137
|
it "passes the token and uses fetch_for_deal" do
|
138
138
|
subject.should_receive(:pass_headers).with(BaseCrm::Forecasting).and_return(scope)
|
@@ -17,9 +17,9 @@ describe BaseCrm::Forecasting do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
describe ".fetch_for_deal" do
|
20
|
-
let(:scope) {
|
21
|
-
let(:deal) {
|
22
|
-
let(:result) {
|
20
|
+
let(:scope) { double }
|
21
|
+
let(:deal) { double(:id => 444) }
|
22
|
+
let(:result) { double }
|
23
23
|
|
24
24
|
it "returns the scope" do
|
25
25
|
BaseCrm::Forecasting.should_receive(:scope).and_return(scope)
|
data/spec/base_crm/lead_spec.rb
CHANGED
@@ -9,11 +9,11 @@ describe BaseCrm::Resource do
|
|
9
9
|
describe "#pass_headers" do
|
10
10
|
let(:instance) { ResourceMixinTestClass.headers(headers).build_one({}) }
|
11
11
|
let(:token_name) { BaseCrm.config.token_name }
|
12
|
-
let(:token) {
|
12
|
+
let(:token) { double }
|
13
13
|
let(:headers) do
|
14
14
|
{ token_name => token }
|
15
15
|
end
|
16
|
-
let(:other_klass) {
|
16
|
+
let(:other_klass) { double }
|
17
17
|
|
18
18
|
it "copies the token header from the original scope" do
|
19
19
|
other_klass.should_receive(:headers).with(token_name => token)
|
@@ -1,9 +1,9 @@
|
|
1
1
|
shared_examples "noteable" do |noteable_type|
|
2
2
|
|
3
|
-
let(:scope) {
|
3
|
+
let(:scope) { double }
|
4
4
|
|
5
5
|
describe "#notes" do
|
6
|
-
let(:fetch_scope) {
|
6
|
+
let(:fetch_scope) { double }
|
7
7
|
|
8
8
|
it "passes the token and applies the params" do
|
9
9
|
subject.
|
@@ -20,20 +20,41 @@ shared_examples "noteable" do |noteable_type|
|
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
-
describe "#
|
23
|
+
describe "#notes.create" do
|
24
24
|
let(:message) { mock }
|
25
25
|
let(:note) { mock }
|
26
|
+
let(:fetch_scope) { mock }
|
26
27
|
|
27
|
-
it "
|
28
|
+
it "passes the token and applies the params" do
|
28
29
|
subject.
|
29
30
|
should_receive(:pass_headers).
|
30
31
|
with(BaseCrm::Note).
|
31
32
|
and_return(scope)
|
33
|
+
scope.should_receive(:params).
|
34
|
+
with({
|
35
|
+
:noteable_type => noteable_type,
|
36
|
+
:noteable_id => subject.id
|
37
|
+
}).and_return(scope)
|
32
38
|
scope.should_receive(:create).with({
|
33
39
|
:content => message,
|
34
40
|
:noteable_type => noteable_type,
|
35
41
|
:noteable_id => subject.id
|
36
42
|
}).and_return(note)
|
43
|
+
subject.notes.create(:content => message).should == note
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#create_note" do
|
49
|
+
let(:message) { mock }
|
50
|
+
let(:notes) { mock }
|
51
|
+
let(:note) { mock }
|
52
|
+
|
53
|
+
it "creates a new note" do
|
54
|
+
subject.should_receive(:notes).and_return(notes)
|
55
|
+
notes.should_receive(:create).with({
|
56
|
+
:content => message
|
57
|
+
}).and_return(note)
|
37
58
|
subject.create_note(message).should == note
|
38
59
|
end
|
39
60
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
shared_examples "taskable" do |taskable_type|
|
2
2
|
|
3
|
-
let(:scope) {
|
3
|
+
let(:scope) { double }
|
4
4
|
|
5
5
|
describe "#tasks" do
|
6
|
-
let(:fetch_scope) {
|
6
|
+
let(:fetch_scope) { double }
|
7
7
|
|
8
8
|
it "passes the token and applies the params" do
|
9
9
|
subject.
|
@@ -20,18 +20,23 @@ shared_examples "taskable" do |taskable_type|
|
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
-
describe "#
|
23
|
+
describe "#tasks.create" do
|
24
24
|
let(:params) do
|
25
25
|
{ :content => task_content }
|
26
26
|
end
|
27
|
-
let(:task_content) {
|
28
|
-
let(:task) {
|
27
|
+
let(:task_content) { double }
|
28
|
+
let(:task) { double }
|
29
29
|
|
30
30
|
it "creates a new task" do
|
31
31
|
subject.
|
32
32
|
should_receive(:pass_headers).
|
33
33
|
with(BaseCrm::Task).
|
34
34
|
and_return(scope)
|
35
|
+
scope.should_receive(:params).
|
36
|
+
with({
|
37
|
+
:taskable_type => taskable_type,
|
38
|
+
:taskable_id => subject.id
|
39
|
+
}).and_return(scope)
|
35
40
|
scope.should_receive(:create).with({
|
36
41
|
:content => task_content,
|
37
42
|
:taskable_type => taskable_type,
|
@@ -39,6 +44,23 @@ shared_examples "taskable" do |taskable_type|
|
|
39
44
|
}).and_return(task)
|
40
45
|
subject.create_task(params).should == task
|
41
46
|
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#create_task" do
|
50
|
+
let(:params) do
|
51
|
+
{ :content => task_content }
|
52
|
+
end
|
53
|
+
let(:task_content) { mock }
|
54
|
+
let(:tasks) { mock }
|
55
|
+
let(:task) { mock }
|
56
|
+
|
57
|
+
it "creates a new task" do
|
58
|
+
subject.should_receive(:tasks).and_return(tasks)
|
59
|
+
tasks.should_receive(:create).with({
|
60
|
+
:content => task_content
|
61
|
+
}).and_return(task)
|
62
|
+
subject.create_task(params).should == task
|
63
|
+
end
|
42
64
|
|
43
65
|
end
|
44
66
|
|
metadata
CHANGED
@@ -1,41 +1,39 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basecrm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Marcin Bunsch
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-10-14 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: api_client
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.4.2
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.4.2
|
30
27
|
description: Base CRM API Client
|
31
28
|
email:
|
32
|
-
- marcin@
|
29
|
+
- marcin@getbase.com
|
33
30
|
executables: []
|
34
31
|
extensions: []
|
35
32
|
extra_rdoc_files: []
|
36
33
|
files:
|
37
34
|
- .gitignore
|
38
35
|
- .rspec
|
36
|
+
- .travis.yml
|
39
37
|
- Gemfile
|
40
38
|
- LICENSE
|
41
39
|
- README.md
|
@@ -52,6 +50,7 @@ files:
|
|
52
50
|
- lib/base_crm/lead.rb
|
53
51
|
- lib/base_crm/note.rb
|
54
52
|
- lib/base_crm/noteable.rb
|
53
|
+
- lib/base_crm/related_object_scope.rb
|
55
54
|
- lib/base_crm/resource.rb
|
56
55
|
- lib/base_crm/session.rb
|
57
56
|
- lib/base_crm/source.rb
|
@@ -74,27 +73,26 @@ files:
|
|
74
73
|
- spec/support/taskable_shared_examples.rb
|
75
74
|
homepage: https://github.com/basecrm/basecrm
|
76
75
|
licenses: []
|
76
|
+
metadata: {}
|
77
77
|
post_install_message:
|
78
78
|
rdoc_options: []
|
79
79
|
require_paths:
|
80
80
|
- lib
|
81
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
82
|
requirements:
|
84
|
-
- -
|
83
|
+
- - '>='
|
85
84
|
- !ruby/object:Gem::Version
|
86
85
|
version: '0'
|
87
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
-
none: false
|
89
87
|
requirements:
|
90
|
-
- -
|
88
|
+
- - '>='
|
91
89
|
- !ruby/object:Gem::Version
|
92
90
|
version: '0'
|
93
91
|
requirements: []
|
94
92
|
rubyforge_project:
|
95
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.0.5
|
96
94
|
signing_key:
|
97
|
-
specification_version:
|
95
|
+
specification_version: 4
|
98
96
|
summary: Base CRM API Client
|
99
97
|
test_files:
|
100
98
|
- spec/base_crm/account_spec.rb
|
@@ -110,4 +108,3 @@ test_files:
|
|
110
108
|
- spec/spec_helper.rb
|
111
109
|
- spec/support/noteable_shared_examples.rb
|
112
110
|
- spec/support/taskable_shared_examples.rb
|
113
|
-
has_rdoc:
|