basecrm 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -2
  3. data/README.md +273 -17
  4. data/lib/basecrm.rb +185 -1
  5. data/lib/basecrm/configuration.rb +59 -0
  6. data/lib/basecrm/envelope.rb +7 -0
  7. data/lib/basecrm/errors.rb +65 -0
  8. data/lib/basecrm/http_client.rb +91 -0
  9. data/lib/basecrm/middlewares/oauth_bearer_token.rb +18 -0
  10. data/lib/basecrm/middlewares/raise_error.rb +31 -0
  11. data/lib/basecrm/model.rb +6 -0
  12. data/lib/basecrm/models/account.rb +31 -0
  13. data/lib/basecrm/models/address.rb +22 -0
  14. data/lib/basecrm/models/associated_contact.rb +19 -0
  15. data/lib/basecrm/models/contact.rb +88 -0
  16. data/lib/basecrm/models/deal.rb +58 -0
  17. data/lib/basecrm/models/lead.rb +79 -0
  18. data/lib/basecrm/models/loss_reason.rb +22 -0
  19. data/lib/basecrm/models/note.rb +28 -0
  20. data/lib/basecrm/models/pipeline.rb +19 -0
  21. data/lib/basecrm/models/source.rb +22 -0
  22. data/lib/basecrm/models/stage.rb +34 -0
  23. data/lib/basecrm/models/tag.rb +25 -0
  24. data/lib/basecrm/models/task.rb +46 -0
  25. data/lib/basecrm/models/user.rb +31 -0
  26. data/lib/basecrm/paginated_resource.rb +32 -0
  27. data/lib/basecrm/services/accounts_service.rb +33 -0
  28. data/lib/basecrm/services/associated_contacts_service.rb +91 -0
  29. data/lib/basecrm/services/contacts_service.rb +138 -0
  30. data/lib/basecrm/services/deals_service.rb +137 -0
  31. data/lib/basecrm/services/leads_service.rb +140 -0
  32. data/lib/basecrm/services/loss_reasons_service.rb +133 -0
  33. data/lib/basecrm/services/notes_service.rb +134 -0
  34. data/lib/basecrm/services/pipelines_service.rb +50 -0
  35. data/lib/basecrm/services/sources_service.rb +133 -0
  36. data/lib/basecrm/services/stages_service.rb +52 -0
  37. data/lib/basecrm/services/tags_service.rb +132 -0
  38. data/lib/basecrm/services/tasks_service.rb +141 -0
  39. data/lib/basecrm/services/users_service.rb +83 -0
  40. data/lib/basecrm/version.rb +3 -0
  41. data/spec/factories/associated_contact.rb +14 -0
  42. data/spec/factories/contact.rb +27 -0
  43. data/spec/factories/deal.rb +17 -0
  44. data/spec/factories/lead.rb +26 -0
  45. data/spec/factories/loss_reason.rb +11 -0
  46. data/spec/factories/note.rb +13 -0
  47. data/spec/factories/source.rb +11 -0
  48. data/spec/factories/tag.rb +12 -0
  49. data/spec/factories/task.rb +15 -0
  50. data/spec/services/accounts_service_spec.rb +16 -0
  51. data/spec/services/associated_contacts_service_spec.rb +43 -0
  52. data/spec/services/contacts_service_spec.rb +58 -0
  53. data/spec/services/deals_service_spec.rb +58 -0
  54. data/spec/services/leads_service_spec.rb +58 -0
  55. data/spec/services/loss_reasons_service_spec.rb +58 -0
  56. data/spec/services/notes_service_spec.rb +58 -0
  57. data/spec/services/pipelines_service_spec.rb +23 -0
  58. data/spec/services/sources_service_spec.rb +58 -0
  59. data/spec/services/stages_service_spec.rb +23 -0
  60. data/spec/services/tags_service_spec.rb +58 -0
  61. data/spec/services/tasks_service_spec.rb +58 -0
  62. data/spec/services/users_service_spec.rb +39 -0
  63. data/spec/spec_helper.rb +24 -12
  64. data/spec/support/client_helpers.rb +19 -0
  65. metadata +160 -71
  66. data/.gitignore +0 -20
  67. data/.rspec +0 -2
  68. data/.travis.yml +0 -6
  69. data/Gemfile +0 -4
  70. data/Rakefile +0 -8
  71. data/basecrm.gemspec +0 -23
  72. data/lib/base_crm.rb +0 -24
  73. data/lib/base_crm/account.rb +0 -11
  74. data/lib/base_crm/api_client_ext.rb +0 -6
  75. data/lib/base_crm/config.rb +0 -21
  76. data/lib/base_crm/contact.rb +0 -44
  77. data/lib/base_crm/custom_fieldable.rb +0 -32
  78. data/lib/base_crm/deal.rb +0 -50
  79. data/lib/base_crm/forecasting.rb +0 -12
  80. data/lib/base_crm/lead.rb +0 -36
  81. data/lib/base_crm/note.rb +0 -15
  82. data/lib/base_crm/noteable.rb +0 -15
  83. data/lib/base_crm/related_object_scope.rb +0 -35
  84. data/lib/base_crm/resource.rb +0 -14
  85. data/lib/base_crm/session.rb +0 -48
  86. data/lib/base_crm/source.rb +0 -14
  87. data/lib/base_crm/task.rb +0 -16
  88. data/lib/base_crm/taskable.rb +0 -15
  89. data/lib/base_crm/version.rb +0 -3
  90. data/spec/base_crm/account_spec.rb +0 -20
  91. data/spec/base_crm/contact_spec.rb +0 -92
  92. data/spec/base_crm/deal_spec.rb +0 -138
  93. data/spec/base_crm/forecasting_spec.rb +0 -34
  94. data/spec/base_crm/lead_spec.rb +0 -63
  95. data/spec/base_crm/note_spec.rb +0 -20
  96. data/spec/base_crm/resource_mixin_spec.rb +0 -26
  97. data/spec/base_crm/session_spec.rb +0 -97
  98. data/spec/base_crm/source_spec.rb +0 -20
  99. data/spec/base_crm/task_spec.rb +0 -21
  100. data/spec/support/noteable_shared_examples.rb +0 -64
  101. data/spec/support/taskable_shared_examples.rb +0 -69
@@ -1,14 +0,0 @@
1
- module BaseCrm
2
- class Source < ApiClient::Resource::Base
3
-
4
- namespace "source"
5
-
6
- prefix "api/v1"
7
-
8
- always do
9
- endpoint BaseCrm.config.endpoints.sales
10
- end
11
-
12
- end
13
- end
14
-
data/lib/base_crm/task.rb DELETED
@@ -1,16 +0,0 @@
1
- module BaseCrm
2
- class Task < ApiClient::Resource::Base
3
-
4
- namespace "task"
5
-
6
- prefix "api/v1"
7
-
8
- always do
9
- endpoint BaseCrm.config.endpoints.common
10
- end
11
-
12
- end
13
-
14
- end
15
-
16
-
@@ -1,15 +0,0 @@
1
- module BaseCrm
2
- module Taskable
3
-
4
- def tasks
5
- @tasks ||= BaseCrm::RelatedObjectScope.new(self, Task, :taskable)
6
- end
7
-
8
- # Keeping it for legacy purposes
9
- def create_task(params)
10
- tasks.create(params)
11
- end
12
-
13
- end
14
- end
15
-
@@ -1,3 +0,0 @@
1
- module BaseCrm
2
- VERSION = "0.1.2"
3
- end
@@ -1,20 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe BaseCrm::Account do
4
-
5
- subject do
6
- BaseCrm::Account.new({})
7
- end
8
-
9
- describe "endpoint" do
10
-
11
- it "uses the production endpoint" do
12
- BaseCrm::Account.scope.instance_eval do
13
- @endpoint.should == "https://sales.futuresimple.com"
14
- end
15
- end
16
-
17
- end
18
-
19
- end
20
-
@@ -1,92 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe BaseCrm::Contact do
4
-
5
- subject do
6
- BaseCrm::Contact.new({ :id => 1234 })
7
- end
8
-
9
- it_behaves_like "noteable", "Contact"
10
- it_behaves_like "taskable", "Contact"
11
-
12
- describe "endpoint" do
13
-
14
- it "uses the production endpoint" do
15
- BaseCrm::Contact.scope.instance_eval do
16
- @endpoint.should == "https://crm.futuresimple.com"
17
- end
18
- end
19
-
20
- end
21
-
22
- describe "simplify_custom_fields" do
23
-
24
- it "converts a hash into the value" do
25
- subject.custom_fields = {
26
- 'test' => { 'value' => 'yes!' }
27
- }
28
- result = subject.simplify_custom_fields
29
- result.should == { 'test' => 'yes!' }
30
- end
31
- end
32
-
33
- describe "#payload" do
34
- it "removes wrong fields from payload" do
35
- subject.tags_joined_by_comma = 'ARRG'
36
- subject.linkedin_display = 'THIS IS SO WRONG'
37
- hash = subject.payload
38
- hash.has_key?('tags_joined_by_comma').should be_false
39
- hash.has_key?('linkedin_display').should be_false
40
- end
41
-
42
- it "uses tags_joined_by_comma to update tags" do
43
- subject.tags_joined_by_comma = "abc, dce"
44
-
45
- expect(subject.payload["tag_list"]).to eq("abc, dce")
46
- end
47
-
48
- it "uses tag_list to update tags if provided (backwards compatibility)" do
49
- subject.tags_joined_by_comma = "abc, dce"
50
- subject.tag_list = "bob, joe"
51
-
52
- expect(subject.payload["tag_list"]).to eq("bob, joe")
53
- end
54
- end
55
-
56
- describe ".fetch_for_deal" do
57
- let(:scope) { double }
58
- let(:deal) { double(:id => 444) }
59
-
60
- it "returns the scope" do
61
- BaseCrm::Contact.should_receive(:scope).and_return(scope)
62
- scope.should_receive(:endpoint).
63
- with(BaseCrm.config.endpoints.sales).
64
- and_return(scope)
65
- scope.should_receive(:path).
66
- with("/api/v1/deals/#{deal.id}/contacts").
67
- and_return(scope)
68
- BaseCrm::Contact.fetch_for_deal(deal).should == scope
69
- end
70
- end
71
-
72
- describe "#notes" do
73
- let(:scope) { double }
74
- let(:fetch_scope) { double }
75
-
76
- it "passes the token and applies the params" do
77
- subject.
78
- should_receive(:pass_headers).
79
- with(BaseCrm::Note).
80
- and_return(scope)
81
- scope.should_receive(:params).
82
- with({
83
- :noteable_type => "Contact",
84
- :noteable_id => subject.id
85
- }).and_return(fetch_scope)
86
- subject.notes.should == fetch_scope
87
- end
88
-
89
- end
90
-
91
- end
92
-
@@ -1,138 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe BaseCrm::Deal do
4
-
5
- subject do
6
- d = BaseCrm::Deal.new({ :id => 334 })
7
- d.original_scope = ApiClient::Resource::Scope.new(BaseCrm::Deal)
8
- d
9
- end
10
-
11
- it_behaves_like "noteable", "Deal"
12
- it_behaves_like "taskable", "Deal"
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
-
34
- describe "endpoint" do
35
-
36
- it "uses the production endpoint" do
37
- BaseCrm::Deal.scope.instance_eval do
38
- @endpoint.should == "https://sales.futuresimple.com"
39
- end
40
- end
41
-
42
- end
43
-
44
- describe "#source" do
45
-
46
- let(:source) { double }
47
- let(:source_id) { 444 }
48
- let(:scope) { double }
49
-
50
- before do
51
- subject.source_id = source_id
52
- end
53
-
54
- context "when it is found" do
55
- before do
56
- subject.stub(:pass_headers).with(BaseCrm::Source).and_return(scope)
57
- scope.
58
- stub(:find).
59
- with(source_id).
60
- and_return(source)
61
- end
62
- it { subject.source.should == source }
63
- end
64
-
65
- context "when it is not found" do
66
- before do
67
- subject.stub(:pass_headers).with(BaseCrm::Source).and_return(scope)
68
- scope.stub(:find).with(source_id)
69
- end
70
- it { subject.source.should == nil }
71
- end
72
-
73
- context "when there is no source_id" do
74
- let(:source_id) { nil }
75
-
76
- it "does nothing" do
77
- subject.should_not_receive(:pass_headers)
78
- subject.source.should be_nil
79
- end
80
-
81
- end
82
-
83
- end
84
-
85
- describe "#contact" do
86
-
87
- let(:contact) { double }
88
- let(:entity_id) { double }
89
- let(:scope) { double }
90
-
91
- before do
92
- subject.entity_id = entity_id
93
- end
94
-
95
- context "when it is found" do
96
- before do
97
- subject.stub(:pass_headers).with(BaseCrm::Contact).and_return(scope)
98
- scope.
99
- stub(:find).
100
- with(entity_id).
101
- and_return(contact)
102
- end
103
- it { subject.contact.should == contact }
104
- end
105
-
106
- context "when it is not found" do
107
- before do
108
- subject.stub(:pass_headers).with(BaseCrm::Contact).and_return(scope)
109
- scope.stub(:find).with(entity_id)
110
- end
111
- it { subject.contact.should == nil }
112
- end
113
-
114
- end
115
-
116
- describe "#contacts" do
117
- let(:scope) { double }
118
- let(:fetch_scope) { double }
119
-
120
- it "passes the token and users fetch_for_deal" do
121
- subject.should_receive(:pass_headers).with(BaseCrm::Contact).and_return(scope)
122
- scope.should_receive(:fetch_for_deal).with(subject).and_return(fetch_scope)
123
- subject.contacts.should == fetch_scope
124
- end
125
- end
126
-
127
- describe "#forecasting" do
128
- let(:scope) { double }
129
- let(:fetch_scope) { double }
130
-
131
- it "passes the token and uses fetch_for_deal" do
132
- subject.should_receive(:pass_headers).with(BaseCrm::Forecasting).and_return(scope)
133
- scope.should_receive(:fetch_for_deal).with(subject).and_return(fetch_scope)
134
- subject.forecasting.should == fetch_scope
135
- end
136
- end
137
- end
138
-
@@ -1,34 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe BaseCrm::Forecasting do
4
-
5
- subject do
6
- BaseCrm::Forecasting.new({})
7
- end
8
-
9
- describe "endpoint" do
10
-
11
- it "uses the production endpoint" do
12
- BaseCrm::Forecasting.scope.instance_eval do
13
- @endpoint.should == "https://sales.futuresimple.com"
14
- end
15
- end
16
-
17
- end
18
-
19
- describe ".fetch_for_deal" do
20
- let(:scope) { double }
21
- let(:deal) { double(:id => 444) }
22
- let(:result) { double }
23
-
24
- it "returns the scope" do
25
- BaseCrm::Forecasting.should_receive(:scope).and_return(scope)
26
- scope.should_receive(:get).
27
- with("/api/v1/deals/#{deal.id}/forecasting.json").
28
- and_return(result)
29
- BaseCrm::Forecasting.fetch_for_deal(deal).should == result
30
- end
31
- end
32
-
33
- end
34
-
@@ -1,63 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe BaseCrm::Lead do
4
-
5
- subject do
6
- BaseCrm::Lead.new({ :id => 1234 })
7
- end
8
-
9
- it_behaves_like "noteable", "Lead"
10
- it_behaves_like "taskable", "Lead"
11
-
12
- describe "endpoint" do
13
-
14
- it "uses the production endpoint" do
15
- BaseCrm::Lead.scope.instance_eval do
16
- @endpoint.should == "https://leads.futuresimple.com"
17
- end
18
- end
19
-
20
- end
21
-
22
- describe "simplify_custom_fields" do
23
-
24
- it "converts a hash into the value" do
25
- subject.custom_field_values = {
26
- 'test' => { 'value' => 'yes!' }
27
- }
28
- result = subject.simplify_custom_fields
29
- result.should == { 'test' => 'yes!' }
30
- end
31
- end
32
-
33
- describe "response parsing" do
34
- let(:response) do
35
- {}
36
- end
37
-
38
- context "collection" do
39
- let(:items) { double }
40
- let(:response) do
41
- { "items" => items }
42
- end
43
-
44
- it "extracts the items" do
45
- BaseCrm::Lead.should_receive(:build_many).with(items)
46
- BaseCrm::Lead.build(response)
47
- end
48
-
49
- end
50
-
51
- context "single" do
52
-
53
- it "extracts the items" do
54
- BaseCrm::Lead.should_receive(:build_one).with(response)
55
- BaseCrm::Lead.build(response)
56
- end
57
-
58
- end
59
-
60
- end
61
-
62
- end
63
-
@@ -1,20 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe BaseCrm::Note do
4
-
5
- subject do
6
- BaseCrm::Note.new({})
7
- end
8
-
9
- describe "endpoint" do
10
-
11
- it "uses the production endpoint" do
12
- BaseCrm::Note.scope.instance_eval do
13
- @endpoint.should == "https://common.futuresimple.com"
14
- end
15
- end
16
-
17
- end
18
-
19
- end
20
-
@@ -1,26 +0,0 @@
1
- require "spec_helper"
2
-
3
- class ResourceMixinTestClass < ApiClient::Resource::Base
4
- include BaseCrm::Resource
5
- end
6
-
7
- describe BaseCrm::Resource do
8
-
9
- describe "#pass_headers" do
10
- let(:instance) { ResourceMixinTestClass.headers(headers).build_one({}) }
11
- let(:token_name) { BaseCrm.config.token_name }
12
- let(:token) { double }
13
- let(:headers) do
14
- { token_name => token }
15
- end
16
- let(:other_klass) { double }
17
-
18
- it "copies the token header from the original scope" do
19
- other_klass.should_receive(:headers).with(token_name => token)
20
- instance.pass_headers(other_klass)
21
- end
22
-
23
- end
24
-
25
- end
26
-