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
data/.gitignore DELETED
@@ -1,20 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- bin
19
- script/*
20
- /development
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format progress
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.0
6
- script: "bundle exec rspec"
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in base_crm.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
3
-
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task :default => :spec
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
-
@@ -1,11 +0,0 @@
1
- module BaseCrm
2
- class Account < ApiClient::Resource::Base
3
-
4
- prefix "api/v1"
5
-
6
- always do
7
- endpoint BaseCrm.config.endpoints.sales
8
- end
9
-
10
- end
11
- end
@@ -1,6 +0,0 @@
1
- require "api_client/resource/scope"
2
-
3
- class ApiClient::Resource::Scope
4
- alias :all :find_all
5
- end
6
-
@@ -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
-
@@ -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
-
@@ -1,12 +0,0 @@
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
-
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
@@ -1,15 +0,0 @@
1
- module BaseCrm
2
- class Note < ApiClient::Resource::Base
3
-
4
- namespace "note"
5
-
6
- prefix "api/v1"
7
-
8
- always do
9
- endpoint BaseCrm.config.endpoints.common
10
- end
11
-
12
- end
13
-
14
- end
15
-
@@ -1,15 +0,0 @@
1
- module BaseCrm
2
- module Noteable
3
-
4
- def notes
5
- @notes ||= BaseCrm::RelatedObjectScope.new(self, Note, :noteable)
6
- end
7
-
8
- # Keeping it for legacy purposes
9
- def create_note(message)
10
- notes.create(:content => message)
11
- end
12
-
13
- end
14
- end
15
-
@@ -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
-
@@ -1,14 +0,0 @@
1
- module BaseCrm
2
-
3
- module Resource
4
-
5
- def pass_headers(klass)
6
- token_name = BaseCrm.config.token_name
7
- token = self.original_scope.headers[token_name]
8
- klass.headers({ token_name => token })
9
- end
10
-
11
- end
12
-
13
- end
14
-
@@ -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