basecrm 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -7,7 +7,19 @@ breaking changes. You have been warned.
7
7
 
8
8
  ## Installation
9
9
 
10
- The gem is no available via Rubygems just yet. To install it, put this on your Gemfile:
10
+ The gem available via Rubygems. To install it, use the following command:
11
+
12
+ ```ruby
13
+ sudo gem install basecrm
14
+ ```
15
+
16
+ If you use Bundler, put this in your Gemfile:
17
+
18
+ ```ruby
19
+ gem 'basecrm'
20
+ ```
21
+
22
+ To get the latest version, put this in your Gemfile:
11
23
 
12
24
  ```ruby
13
25
  gem 'basecrm', :git => 'git://github.com/basecrm/basecrm.git'
@@ -9,6 +9,7 @@ module BaseCrm
9
9
  autoload :Contact, "base_crm/contact"
10
10
  autoload :Session, "base_crm/session"
11
11
  autoload :Deal, "base_crm/deal"
12
+ autoload :Forecasting, "base_crm/forecasting"
12
13
  autoload :Source, "base_crm/source"
13
14
  autoload :Resource, "base_crm/resource"
14
15
  autoload :Note, "base_crm/note"
@@ -5,21 +5,23 @@ module BaseCrm
5
5
  include BaseCrm::Noteable
6
6
  include BaseCrm::Taskable
7
7
 
8
- namespace "deal"
8
+ namespace false
9
9
 
10
- prefix "api/v1"
10
+ prefix "api/v1"
11
11
 
12
12
  always do
13
13
  endpoint BaseCrm.config.endpoints.sales
14
14
  end
15
15
 
16
16
  def source
17
- Source.find(self.source_id)
17
+ if self.source_id
18
+ pass_headers(Source).find(self.source_id)
19
+ end
18
20
  rescue ApiClient::Errors::NotFound
19
21
  end
20
22
 
21
23
  def contact
22
- Contact.find(self.entity_id)
24
+ pass_headers(Contact).find(self.entity_id)
23
25
  rescue ApiClient::Errors::NotFound
24
26
  end
25
27
 
@@ -27,6 +29,10 @@ module BaseCrm
27
29
  pass_headers(Contact).fetch_for_deal(self)
28
30
  end
29
31
 
32
+ def forecasting
33
+ pass_headers(Forecasting).fetch_for_deal(self)
34
+ end
35
+
30
36
  def noteable_type
31
37
  "Deal"
32
38
  end
@@ -35,6 +41,10 @@ module BaseCrm
35
41
  "Deal"
36
42
  end
37
43
 
44
+ def self.build_one(result)
45
+ super result['deal']
46
+ end
47
+
38
48
  end
39
49
  end
40
50
 
@@ -0,0 +1,12 @@
1
+ module BaseCrm
2
+ class Forecasting < ApiClient::Resource::Base
3
+ always do
4
+ endpoint BaseCrm.config.endpoints.sales
5
+ end
6
+
7
+ def self.fetch_for_deal(deal)
8
+ scope.get("/api/v1/deals/#{deal.id}/forecasting.json")
9
+ end
10
+ end
11
+ end
12
+
@@ -1,3 +1,3 @@
1
1
  module BaseCrm
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -55,7 +55,6 @@ describe BaseCrm::Contact do
55
55
  and_return(scope)
56
56
  BaseCrm::Contact.fetch_for_deal(deal).should == scope
57
57
  end
58
-
59
58
  end
60
59
 
61
60
  describe "#notes" do
@@ -3,12 +3,34 @@ require "spec_helper"
3
3
  describe BaseCrm::Deal do
4
4
 
5
5
  subject do
6
- BaseCrm::Deal.new({ :id => 334 })
6
+ d = BaseCrm::Deal.new({ :id => 334 })
7
+ d.original_scope = ApiClient::Resource::Scope.new(BaseCrm::Deal)
8
+ d
7
9
  end
8
10
 
9
11
  it_behaves_like "noteable", "Deal"
10
12
  it_behaves_like "taskable", "Deal"
11
13
 
14
+ describe "namespace" do
15
+
16
+ it "has no default namespace" do
17
+ BaseCrm::Deal.namespace.should be_false
18
+ end
19
+
20
+ context "when instantiating" do
21
+ let(:name) { "deal name" }
22
+
23
+ it "uses a namespace" do
24
+ result = BaseCrm::Deal.build_one 'name' => name
25
+ result.name.should be_nil
26
+ result = BaseCrm::Deal.build_one 'deal' => { 'name' => name }
27
+ result.name.should == name
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
12
34
  describe "endpoint" do
13
35
 
14
36
  it "uses the production endpoint" do
@@ -22,7 +44,8 @@ describe BaseCrm::Deal do
22
44
  describe "#source" do
23
45
 
24
46
  let(:source) { mock }
25
- let(:source_id) { mock }
47
+ let(:source_id) { 444 }
48
+ let(:scope) { mock }
26
49
 
27
50
  before do
28
51
  subject.source_id = source_id
@@ -30,7 +53,8 @@ describe BaseCrm::Deal do
30
53
 
31
54
  context "when it is found" do
32
55
  before do
33
- BaseCrm::Source.
56
+ subject.stub(:pass_headers).with(BaseCrm::Source).and_return(scope)
57
+ scope.
34
58
  stub(:find).
35
59
  with(source_id).
36
60
  and_return(source)
@@ -40,7 +64,8 @@ describe BaseCrm::Deal do
40
64
 
41
65
  context "when it is not found" do
42
66
  before do
43
- BaseCrm::Source.
67
+ subject.stub(:pass_headers).with(BaseCrm::Source).and_return(scope)
68
+ scope.
44
69
  stub(:find).
45
70
  with(source_id).
46
71
  and_raise(ApiClient::Errors::NotFound)
@@ -48,12 +73,23 @@ describe BaseCrm::Deal do
48
73
  it { subject.source.should == nil }
49
74
  end
50
75
 
76
+ context "when there is no source_id" do
77
+ let(:source_id) { nil }
78
+
79
+ it "does nothing" do
80
+ subject.should_not_receive(:pass_headers)
81
+ subject.source.should be_nil
82
+ end
83
+
84
+ end
85
+
51
86
  end
52
87
 
53
88
  describe "#contact" do
54
89
 
55
90
  let(:contact) { mock }
56
91
  let(:entity_id) { mock }
92
+ let(:scope) { mock }
57
93
 
58
94
  before do
59
95
  subject.entity_id = entity_id
@@ -61,7 +97,8 @@ describe BaseCrm::Deal do
61
97
 
62
98
  context "when it is found" do
63
99
  before do
64
- BaseCrm::Contact.
100
+ subject.stub(:pass_headers).with(BaseCrm::Contact).and_return(scope)
101
+ scope.
65
102
  stub(:find).
66
103
  with(entity_id).
67
104
  and_return(contact)
@@ -71,7 +108,8 @@ describe BaseCrm::Deal do
71
108
 
72
109
  context "when it is not found" do
73
110
  before do
74
- BaseCrm::Contact.
111
+ subject.stub(:pass_headers).with(BaseCrm::Contact).and_return(scope)
112
+ scope.
75
113
  stub(:find).
76
114
  with(entity_id).
77
115
  and_raise(ApiClient::Errors::NotFound)
@@ -90,8 +128,17 @@ describe BaseCrm::Deal do
90
128
  scope.should_receive(:fetch_for_deal).with(subject).and_return(fetch_scope)
91
129
  subject.contacts.should == fetch_scope
92
130
  end
93
-
94
131
  end
95
132
 
133
+ describe "#forecasting" do
134
+ let(:scope) { mock }
135
+ let(:fetch_scope) { mock }
136
+
137
+ it "passes the token and uses fetch_for_deal" do
138
+ subject.should_receive(:pass_headers).with(BaseCrm::Forecasting).and_return(scope)
139
+ scope.should_receive(:fetch_for_deal).with(subject).and_return(fetch_scope)
140
+ subject.forecasting.should == fetch_scope
141
+ end
142
+ end
96
143
  end
97
144
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basecrm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-12 00:00:00.000000000 Z
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: api_client
@@ -48,6 +48,7 @@ files:
48
48
  - lib/base_crm/contact.rb
49
49
  - lib/base_crm/custom_fieldable.rb
50
50
  - lib/base_crm/deal.rb
51
+ - lib/base_crm/forecasting.rb
51
52
  - lib/base_crm/lead.rb
52
53
  - lib/base_crm/note.rb
53
54
  - lib/base_crm/noteable.rb