basecrm 0.1.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +2 -2
- data/README.md +273 -17
- data/lib/basecrm.rb +185 -1
- data/lib/basecrm/configuration.rb +59 -0
- data/lib/basecrm/envelope.rb +7 -0
- data/lib/basecrm/errors.rb +65 -0
- data/lib/basecrm/http_client.rb +91 -0
- data/lib/basecrm/middlewares/oauth_bearer_token.rb +18 -0
- data/lib/basecrm/middlewares/raise_error.rb +31 -0
- data/lib/basecrm/model.rb +6 -0
- data/lib/basecrm/models/account.rb +31 -0
- data/lib/basecrm/models/address.rb +22 -0
- data/lib/basecrm/models/associated_contact.rb +19 -0
- data/lib/basecrm/models/contact.rb +88 -0
- data/lib/basecrm/models/deal.rb +58 -0
- data/lib/basecrm/models/lead.rb +79 -0
- data/lib/basecrm/models/loss_reason.rb +22 -0
- data/lib/basecrm/models/note.rb +28 -0
- data/lib/basecrm/models/pipeline.rb +19 -0
- data/lib/basecrm/models/source.rb +22 -0
- data/lib/basecrm/models/stage.rb +34 -0
- data/lib/basecrm/models/tag.rb +25 -0
- data/lib/basecrm/models/task.rb +46 -0
- data/lib/basecrm/models/user.rb +31 -0
- data/lib/basecrm/paginated_resource.rb +32 -0
- data/lib/basecrm/services/accounts_service.rb +33 -0
- data/lib/basecrm/services/associated_contacts_service.rb +91 -0
- data/lib/basecrm/services/contacts_service.rb +138 -0
- data/lib/basecrm/services/deals_service.rb +137 -0
- data/lib/basecrm/services/leads_service.rb +140 -0
- data/lib/basecrm/services/loss_reasons_service.rb +133 -0
- data/lib/basecrm/services/notes_service.rb +134 -0
- data/lib/basecrm/services/pipelines_service.rb +50 -0
- data/lib/basecrm/services/sources_service.rb +133 -0
- data/lib/basecrm/services/stages_service.rb +52 -0
- data/lib/basecrm/services/tags_service.rb +132 -0
- data/lib/basecrm/services/tasks_service.rb +141 -0
- data/lib/basecrm/services/users_service.rb +83 -0
- data/lib/basecrm/version.rb +3 -0
- data/spec/factories/associated_contact.rb +14 -0
- data/spec/factories/contact.rb +27 -0
- data/spec/factories/deal.rb +17 -0
- data/spec/factories/lead.rb +26 -0
- data/spec/factories/loss_reason.rb +11 -0
- data/spec/factories/note.rb +13 -0
- data/spec/factories/source.rb +11 -0
- data/spec/factories/tag.rb +12 -0
- data/spec/factories/task.rb +15 -0
- data/spec/services/accounts_service_spec.rb +16 -0
- data/spec/services/associated_contacts_service_spec.rb +43 -0
- data/spec/services/contacts_service_spec.rb +58 -0
- data/spec/services/deals_service_spec.rb +58 -0
- data/spec/services/leads_service_spec.rb +58 -0
- data/spec/services/loss_reasons_service_spec.rb +58 -0
- data/spec/services/notes_service_spec.rb +58 -0
- data/spec/services/pipelines_service_spec.rb +23 -0
- data/spec/services/sources_service_spec.rb +58 -0
- data/spec/services/stages_service_spec.rb +23 -0
- data/spec/services/tags_service_spec.rb +58 -0
- data/spec/services/tasks_service_spec.rb +58 -0
- data/spec/services/users_service_spec.rb +39 -0
- data/spec/spec_helper.rb +24 -12
- data/spec/support/client_helpers.rb +19 -0
- metadata +160 -71
- data/.gitignore +0 -20
- data/.rspec +0 -2
- data/.travis.yml +0 -6
- data/Gemfile +0 -4
- data/Rakefile +0 -8
- data/basecrm.gemspec +0 -23
- data/lib/base_crm.rb +0 -24
- data/lib/base_crm/account.rb +0 -11
- data/lib/base_crm/api_client_ext.rb +0 -6
- data/lib/base_crm/config.rb +0 -21
- data/lib/base_crm/contact.rb +0 -44
- data/lib/base_crm/custom_fieldable.rb +0 -32
- data/lib/base_crm/deal.rb +0 -50
- data/lib/base_crm/forecasting.rb +0 -12
- data/lib/base_crm/lead.rb +0 -36
- data/lib/base_crm/note.rb +0 -15
- data/lib/base_crm/noteable.rb +0 -15
- data/lib/base_crm/related_object_scope.rb +0 -35
- data/lib/base_crm/resource.rb +0 -14
- data/lib/base_crm/session.rb +0 -48
- data/lib/base_crm/source.rb +0 -14
- data/lib/base_crm/task.rb +0 -16
- data/lib/base_crm/taskable.rb +0 -15
- data/lib/base_crm/version.rb +0 -3
- data/spec/base_crm/account_spec.rb +0 -20
- data/spec/base_crm/contact_spec.rb +0 -92
- data/spec/base_crm/deal_spec.rb +0 -138
- data/spec/base_crm/forecasting_spec.rb +0 -34
- data/spec/base_crm/lead_spec.rb +0 -63
- data/spec/base_crm/note_spec.rb +0 -20
- data/spec/base_crm/resource_mixin_spec.rb +0 -26
- data/spec/base_crm/session_spec.rb +0 -97
- data/spec/base_crm/source_spec.rb +0 -20
- data/spec/base_crm/task_spec.rb +0 -21
- data/spec/support/noteable_shared_examples.rb +0 -64
- data/spec/support/taskable_shared_examples.rb +0 -69
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/basecrm.gemspec
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/base_crm/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Marcin Bunsch"]
|
6
|
-
gem.email = ["marcin@getbase.com"]
|
7
|
-
gem.description = %q{Base CRM API Client}
|
8
|
-
gem.summary = %q{Base CRM API Client}
|
9
|
-
gem.homepage = "https://github.com/basecrm/basecrm"
|
10
|
-
|
11
|
-
gem.files = `git ls-files`.split($\)
|
12
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
-
gem.name = "basecrm"
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = BaseCrm::VERSION
|
17
|
-
gem.add_dependency "api_client", '>=0.4.2'
|
18
|
-
|
19
|
-
gem.add_development_dependency "rspec", "~>2.14.1"
|
20
|
-
gem.add_development_dependency "simplecov"
|
21
|
-
gem.add_development_dependency "rake"
|
22
|
-
end
|
23
|
-
|
data/lib/base_crm.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require "api_client"
|
2
|
-
require "base_crm/version"
|
3
|
-
require "base_crm/config"
|
4
|
-
require "base_crm/api_client_ext"
|
5
|
-
require "base_crm/custom_fieldable"
|
6
|
-
|
7
|
-
module BaseCrm
|
8
|
-
|
9
|
-
autoload :RelatedObjectScope, "base_crm/related_object_scope"
|
10
|
-
autoload :Account, "base_crm/account"
|
11
|
-
autoload :Contact, "base_crm/contact"
|
12
|
-
autoload :Session, "base_crm/session"
|
13
|
-
autoload :Deal, "base_crm/deal"
|
14
|
-
autoload :Forecasting, "base_crm/forecasting"
|
15
|
-
autoload :Source, "base_crm/source"
|
16
|
-
autoload :Resource, "base_crm/resource"
|
17
|
-
autoload :Note, "base_crm/note"
|
18
|
-
autoload :Noteable, "base_crm/noteable"
|
19
|
-
autoload :Task, "base_crm/task"
|
20
|
-
autoload :Taskable, "base_crm/taskable"
|
21
|
-
autoload :Lead, "base_crm/lead"
|
22
|
-
|
23
|
-
end
|
24
|
-
|
data/lib/base_crm/account.rb
DELETED
data/lib/base_crm/config.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require "hashie/mash"
|
2
|
-
|
3
|
-
module BaseCrm
|
4
|
-
|
5
|
-
def self.config
|
6
|
-
@config ||= Hashie::Mash.new
|
7
|
-
end
|
8
|
-
|
9
|
-
self.config.token_name = "X-Pipejump-Auth"
|
10
|
-
|
11
|
-
self.config.endpoints = {
|
12
|
-
:app => "https://app.futuresimple.com",
|
13
|
-
:core => "https://core.futuresimple.com",
|
14
|
-
:crm => "https://crm.futuresimple.com",
|
15
|
-
:sales => "https://sales.futuresimple.com",
|
16
|
-
:leads => "https://leads.futuresimple.com",
|
17
|
-
:common => "https://common.futuresimple.com"
|
18
|
-
}
|
19
|
-
|
20
|
-
end
|
21
|
-
|
data/lib/base_crm/contact.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
module BaseCrm
|
2
|
-
class Contact < ApiClient::Resource::Base
|
3
|
-
|
4
|
-
include BaseCrm::Resource
|
5
|
-
include BaseCrm::Noteable
|
6
|
-
include BaseCrm::Taskable
|
7
|
-
include BaseCrm::CustomFieldable('custom_fields')
|
8
|
-
|
9
|
-
namespace "contact"
|
10
|
-
|
11
|
-
prefix "api/v1"
|
12
|
-
|
13
|
-
always do
|
14
|
-
endpoint BaseCrm.config.endpoints.crm
|
15
|
-
end
|
16
|
-
|
17
|
-
def payload
|
18
|
-
hash = super
|
19
|
-
|
20
|
-
tags_joined_by_comma = hash.delete('tags_joined_by_comma')
|
21
|
-
hash['tag_list'] ||= tags_joined_by_comma
|
22
|
-
|
23
|
-
hash.delete('linkedin_display')
|
24
|
-
|
25
|
-
hash
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.fetch_for_deal(deal)
|
29
|
-
scope.
|
30
|
-
endpoint(BaseCrm.config.endpoints.sales).
|
31
|
-
path("/api/v1/deals/#{deal.id}/contacts")
|
32
|
-
end
|
33
|
-
|
34
|
-
def noteable_type
|
35
|
-
"Contact"
|
36
|
-
end
|
37
|
-
|
38
|
-
def taskable_type
|
39
|
-
"Contact"
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module BaseCrm
|
2
|
-
def self.CustomFieldable(custom_fields_field_name)
|
3
|
-
Module.new do
|
4
|
-
def initialize(attributes, original_scope = nil)
|
5
|
-
super
|
6
|
-
simplify_custom_fields
|
7
|
-
end
|
8
|
-
|
9
|
-
define_method :simplify_custom_fields do
|
10
|
-
fields = self[custom_fields_field_name] || {}
|
11
|
-
self[custom_fields_field_name] = fields.inject(Hashie::Mash.new) do |memo, field|
|
12
|
-
name, value = field
|
13
|
-
memo[name] = value['value']
|
14
|
-
memo
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
# Because custom fields are hashes, and hashes result in
|
21
|
-
# new instances of BaseCrm::Contact, we end up with a stack level too deep
|
22
|
-
# because simplify_custom_fields gets fired all the time
|
23
|
-
def convert_value(val, duping=false) #:nodoc:
|
24
|
-
if val.is_a?(Hash) or val.is_a?(::Hash)
|
25
|
-
val
|
26
|
-
else
|
27
|
-
super
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/lib/base_crm/deal.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
module BaseCrm
|
2
|
-
class Deal < ApiClient::Resource::Base
|
3
|
-
|
4
|
-
include BaseCrm::Resource
|
5
|
-
include BaseCrm::Noteable
|
6
|
-
include BaseCrm::Taskable
|
7
|
-
|
8
|
-
namespace false
|
9
|
-
|
10
|
-
prefix "api/v1"
|
11
|
-
|
12
|
-
always do
|
13
|
-
endpoint BaseCrm.config.endpoints.sales
|
14
|
-
end
|
15
|
-
|
16
|
-
def source
|
17
|
-
if self.source_id
|
18
|
-
pass_headers(Source).find(self.source_id)
|
19
|
-
end
|
20
|
-
rescue ApiClient::Errors::NotFound
|
21
|
-
end
|
22
|
-
|
23
|
-
def contact
|
24
|
-
pass_headers(Contact).find(self.entity_id)
|
25
|
-
rescue ApiClient::Errors::NotFound
|
26
|
-
end
|
27
|
-
|
28
|
-
def contacts
|
29
|
-
pass_headers(Contact).fetch_for_deal(self)
|
30
|
-
end
|
31
|
-
|
32
|
-
def forecasting
|
33
|
-
pass_headers(Forecasting).fetch_for_deal(self)
|
34
|
-
end
|
35
|
-
|
36
|
-
def noteable_type
|
37
|
-
"Deal"
|
38
|
-
end
|
39
|
-
|
40
|
-
def taskable_type
|
41
|
-
"Deal"
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.build_one(result)
|
45
|
-
super result['deal']
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
data/lib/base_crm/forecasting.rb
DELETED
data/lib/base_crm/lead.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module BaseCrm
|
2
|
-
class Lead < ApiClient::Resource::Base
|
3
|
-
|
4
|
-
include BaseCrm::Resource
|
5
|
-
include BaseCrm::Noteable
|
6
|
-
include BaseCrm::Taskable
|
7
|
-
include BaseCrm::CustomFieldable('custom_field_values')
|
8
|
-
|
9
|
-
namespace "lead"
|
10
|
-
|
11
|
-
prefix "api/v1"
|
12
|
-
|
13
|
-
always do
|
14
|
-
endpoint BaseCrm.config.endpoints.leads
|
15
|
-
end
|
16
|
-
|
17
|
-
def noteable_type
|
18
|
-
"Lead"
|
19
|
-
end
|
20
|
-
|
21
|
-
def taskable_type
|
22
|
-
"Lead"
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.build(result_or_array)
|
26
|
-
if result_or_array.has_key?('items')
|
27
|
-
build_many(result_or_array['items'])
|
28
|
-
else
|
29
|
-
build_one(result_or_array)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
|
data/lib/base_crm/note.rb
DELETED
data/lib/base_crm/noteable.rb
DELETED
@@ -1,35 +0,0 @@
|
|
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/resource.rb
DELETED
data/lib/base_crm/session.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
module BaseCrm
|
2
|
-
class Session
|
3
|
-
|
4
|
-
attr_accessor :token
|
5
|
-
|
6
|
-
def initialize(token)
|
7
|
-
@token = token
|
8
|
-
end
|
9
|
-
|
10
|
-
def account
|
11
|
-
pass_headers(BaseCrm::Account).
|
12
|
-
fetch('/api/v1/account.json')
|
13
|
-
end
|
14
|
-
|
15
|
-
def contacts
|
16
|
-
pass_headers BaseCrm::Contact
|
17
|
-
end
|
18
|
-
|
19
|
-
def deals
|
20
|
-
pass_headers BaseCrm::Deal
|
21
|
-
end
|
22
|
-
|
23
|
-
def sources
|
24
|
-
pass_headers BaseCrm::Source
|
25
|
-
end
|
26
|
-
|
27
|
-
def notes
|
28
|
-
pass_headers BaseCrm::Note
|
29
|
-
end
|
30
|
-
|
31
|
-
def tasks
|
32
|
-
pass_headers BaseCrm::Task
|
33
|
-
end
|
34
|
-
|
35
|
-
def leads
|
36
|
-
pass_headers BaseCrm::Lead
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def pass_headers(klass)
|
42
|
-
klass.
|
43
|
-
headers("X-Pipejump-Auth" => self.token).
|
44
|
-
headers("X-Futuresimple-Token" => self.token)
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|