pipedrive.rb 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +98 -10
  3. data/.travis.yml +4 -7
  4. data/Gemfile +4 -6
  5. data/HISTORY.md +43 -0
  6. data/Rakefile +5 -2
  7. data/lib/pipedrive.rb +9 -1
  8. data/lib/pipedrive/activity.rb +2 -0
  9. data/lib/pipedrive/activity_type.rb +2 -0
  10. data/lib/pipedrive/base.rb +14 -11
  11. data/lib/pipedrive/deal.rb +2 -0
  12. data/lib/pipedrive/deal_field.rb +2 -0
  13. data/lib/pipedrive/file.rb +2 -0
  14. data/lib/pipedrive/filter.rb +2 -0
  15. data/lib/pipedrive/goal.rb +2 -0
  16. data/lib/pipedrive/note.rb +2 -0
  17. data/lib/pipedrive/operations/create.rb +2 -0
  18. data/lib/pipedrive/operations/delete.rb +2 -0
  19. data/lib/pipedrive/operations/read.rb +6 -3
  20. data/lib/pipedrive/operations/update.rb +4 -1
  21. data/lib/pipedrive/organization.rb +6 -3
  22. data/lib/pipedrive/organization_field.rb +2 -0
  23. data/lib/pipedrive/person.rb +7 -3
  24. data/lib/pipedrive/person_field.rb +2 -0
  25. data/lib/pipedrive/pipeline.rb +10 -0
  26. data/lib/pipedrive/product.rb +2 -0
  27. data/lib/pipedrive/product_field.rb +2 -0
  28. data/lib/pipedrive/railties.rb +2 -0
  29. data/lib/pipedrive/role.rb +2 -0
  30. data/lib/pipedrive/stage.rb +2 -0
  31. data/lib/pipedrive/user.rb +10 -0
  32. data/lib/pipedrive/utils.rb +6 -4
  33. data/lib/pipedrive/version.rb +3 -1
  34. data/pipedrive.gemspec +12 -8
  35. data/spec/lib/pipedrive/activity_spec.rb +6 -2
  36. data/spec/lib/pipedrive/activity_type_spec.rb +6 -2
  37. data/spec/lib/pipedrive/base_spec.rb +82 -49
  38. data/spec/lib/pipedrive/deal_field_spec.rb +6 -2
  39. data/spec/lib/pipedrive/deal_spec.rb +6 -2
  40. data/spec/lib/pipedrive/file_spec.rb +6 -2
  41. data/spec/lib/pipedrive/filter_spec.rb +6 -2
  42. data/spec/lib/pipedrive/goal_spec.rb +6 -2
  43. data/spec/lib/pipedrive/note_spec.rb +6 -2
  44. data/spec/lib/pipedrive/ogranization_spec.rb +6 -2
  45. data/spec/lib/pipedrive/operations/create_spec.rb +5 -3
  46. data/spec/lib/pipedrive/operations/delete_spec.rb +8 -5
  47. data/spec/lib/pipedrive/operations/read_spec.rb +32 -24
  48. data/spec/lib/pipedrive/operations/update_spec.rb +9 -6
  49. data/spec/lib/pipedrive/organization_field_spec.rb +6 -2
  50. data/spec/lib/pipedrive/person_field_spec.rb +6 -2
  51. data/spec/lib/pipedrive/person_spec.rb +18 -12
  52. data/spec/lib/pipedrive/product_field_spec.rb +6 -2
  53. data/spec/lib/pipedrive/product_spec.rb +6 -2
  54. data/spec/lib/pipedrive_spec.rb +28 -20
  55. data/spec/spec_helper.rb +2 -2
  56. metadata +40 -10
  57. data/Guardfile +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 174f47371cadbd8c2b38b1df1b578b4b2a51d26047e0cd276a6cd775e2269b84
4
- data.tar.gz: '0887f64ee16bea1c672d666b6b6039e907b0494de309f017e6e9aedaff75cf9b'
3
+ metadata.gz: f7e40f6c74545bc03a4ff8c6d21ebbd6cecebbc4dd7ac7d850762282e1934ea9
4
+ data.tar.gz: 6803a9949ee5045b78b21b1fd26839070606745e7fe72e3b3e6f3cf968967c51
5
5
  SHA512:
6
- metadata.gz: d1c4295874a4652eda241e363bebc5f5efe7b877f8a124d066febef50616ae580b50ef29c21cb05d684c4ceabad4988f8d8ea974f3c5de0a2916c73aa6e094d4
7
- data.tar.gz: 830f1e1829b68811fcb0dd73369a44e015e6a2844b073928b2456c5799b9f224cf0dafc26ddbe587db07bbdeddb027f2d2d5965399d7d93b43ccb8c5dccff58d
6
+ metadata.gz: 990a3812062360039f8b50d2a5e295a6839f9c28ec0220f4675c8ff560f7b26b9430ca7a1cbaf802115667344fdb038047fb5c8d433323e302e2a129c9d7004c
7
+ data.tar.gz: 1e4c52a0bfc631c21675efc1560ebdc400ae06f48e9b224043bd7dd28f6e0bd5818ca7e41d5e62f0862cdba8f879cbacb23bf0a5235088980f8537390a2608dc
@@ -1,17 +1,105 @@
1
+ require:
2
+ - rubocop/cop/internal_affairs
3
+ - rubocop-performance
4
+ - rubocop-rspec
1
5
  AllCops:
2
- Include:
3
- - '**/Rakefile'
6
+ NewCops: enable
4
7
  Exclude:
5
- - 'spec/**/*'
6
- Metrics/LineLength:
7
- Max: 99
8
- Naming/FileName:
8
+ - "bin/*"
9
+ - "vendor/**/*"
10
+ - "Rakefile"
11
+ - "tmp/**/*"
12
+ - ".git/**/*"
13
+ TargetRubyVersion: 2.5
14
+ Style/Documentation:
15
+ Enabled: false
16
+ Layout/LineLength:
17
+ Max: 1000
18
+ Metrics/MethodLength:
19
+ Max: 250
20
+ Metrics/ClassLength:
21
+ Max: 1000
22
+ Metrics/AbcSize:
23
+ Max: 250
24
+ Metrics/BlockLength:
25
+ Max: 1500
26
+ Metrics/CyclomaticComplexity:
27
+ Max: 50
28
+ Metrics/PerceivedComplexity:
29
+ Max: 50
30
+ Style/ClassAndModuleChildren:
9
31
  Enabled: false
10
32
  Style/ModuleFunction:
11
33
  Enabled: false
12
- Style/Encoding:
34
+ Style/ParallelAssignment:
13
35
  Enabled: false
14
- Documentation:
36
+ Style/SymbolProc:
37
+ Enabled: false
38
+ Layout/HashAlignment:
39
+ Enabled: false
40
+ Metrics/BlockNesting:
41
+ Enabled: false
42
+ Lint/NonLocalExitFromIterator:
43
+ Enabled: false
44
+ Style/HashEachMethods:
45
+ Enabled: true
46
+ Style/HashTransformKeys:
47
+ Enabled: true
48
+ Style/HashTransformValues:
49
+ Enabled: true
50
+ Style/AndOr:
51
+ Enabled: false
52
+ RSpec/ExampleLength:
53
+ Enabled: false
54
+ RSpec/MultipleExpectations:
55
+ Enabled: false
56
+ RSpec/DescribeClass:
57
+ Enabled: false
58
+ Style/IfInsideElse:
59
+ Enabled: false
60
+ Layout/EmptyLinesAroundAttributeAccessor:
61
+ Enabled: true
62
+ Layout/SpaceAroundMethodCallOperator:
63
+ Enabled: true
64
+ Lint/DeprecatedOpenSSLConstant:
65
+ Enabled: true
66
+ Lint/MixedRegexpCaptureTypes:
67
+ Enabled: true
68
+ Lint/RaiseException:
69
+ Enabled: true
70
+ Lint/StructNewOverride:
71
+ Enabled: true
72
+ Style/ExponentialNotation:
73
+ Enabled: false
74
+ Style/RedundantFetchBlock:
75
+ Enabled: true
76
+ Style/RedundantRegexpCharacterClass:
77
+ Enabled: true
78
+ Style/RedundantRegexpEscape:
79
+ Enabled: true
80
+ Style/SlicingWithRange:
81
+ Enabled: true
82
+ Style/AccessorGrouping:
83
+ Enabled: true
84
+ Style/BisectedAttrAccessor:
85
+ Enabled: true
86
+ Style/RedundantAssignment:
87
+ Enabled: true
88
+ Performance/AncestorsInclude:
89
+ Enabled: true
90
+ Performance/BigDecimalWithNumericArgument:
91
+ Enabled: true
92
+ Performance/RedundantSortBlock:
93
+ Enabled: true
94
+ Performance/RedundantStringChars:
95
+ Enabled: true
96
+ Performance/ReverseFirst:
97
+ Enabled: true
98
+ Performance/SortReverse:
99
+ Enabled: true
100
+ Performance/Squeeze:
101
+ Enabled: true
102
+ Performance/StringInclude:
103
+ Enabled: true
104
+ RSpec/ContextWording:
15
105
  Enabled: false
16
- Metrics/MethodLength:
17
- Max: 15
@@ -2,19 +2,16 @@ language: ruby
2
2
  rvm:
3
3
  - ruby-head
4
4
  - jruby-19mode
5
- - rbx-2
6
- - 2.1.10
7
- - 2.2.10
8
- - 2.3.8
9
- - 2.4.6
10
- - 2.5.5
11
5
  - 2.6.3
6
+ - 2.7.2
7
+
8
+ jdk:
9
+ - openjdk8
12
10
 
13
11
  matrix:
14
12
  allow_failures:
15
13
  - rvm: ruby-head
16
14
  - rvm: jruby-19mode
17
- - rvm: rbx-2
18
15
 
19
16
  bundler_args: --without local_development
20
17
 
data/Gemfile CHANGED
@@ -1,17 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in pipedrive.gemspec
4
6
  gemspec
5
7
 
6
8
  group :test do
7
- gem 'simplecov', '>= 0.9.0', :require => false
8
- gem 'coveralls', :require => false
9
+ gem 'coveralls', require: false
10
+ gem 'simplecov', require: false
9
11
  end
10
12
 
11
13
  group :local_development do
12
- gem 'terminal-notifier-guard', require: false if RUBY_PLATFORM.downcase.include?('darwin')
13
- gem 'guard-rspec', '>= 4.3.1' ,require: false
14
- gem 'guard-bundler', require: false
15
- gem 'guard-rubocop', require: false
16
14
  gem 'pry'
17
15
  end
@@ -0,0 +1,43 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [v0.3.0](https://github.com/amoniacou/pipedrive.rb/compare/v0.2.0...v0.3.0) - 2020-10-10
9
+
10
+ ### Merged
11
+
12
+ - add User endpoints [`#15`](https://github.com/amoniacou/pipedrive.rb/pull/15)
13
+ - add pipeline endpoints [`#17`](https://github.com/amoniacou/pipedrive.rb/pull/17)
14
+ - add pipeline endpoints [`#2`](https://github.com/amoniacou/pipedrive.rb/pull/2)
15
+
16
+ ### Commits
17
+
18
+ - Small code improvements [`fb28bb4`](https://github.com/amoniacou/pipedrive.rb/commit/fb28bb4ed3d86c15a4f2a95247e13393d598aad1)
19
+ - Fix specs [`e772b83`](https://github.com/amoniacou/pipedrive.rb/commit/e772b837c61150b574ef3f6c95b495e1f2dfda9a)
20
+ - Update .travis.yml [`873cea4`](https://github.com/amoniacou/pipedrive.rb/commit/873cea4cfd82806ef71f62a3db823322b168f964)
21
+
22
+ ## [v0.2.0](https://github.com/amoniacou/pipedrive.rb/compare/v0.1.0...v0.2.0) - 2020-01-14
23
+
24
+ ### Merged
25
+
26
+ - Inflection fix for persons [`#9`](https://github.com/amoniacou/pipedrive.rb/pull/9)
27
+ - Move adapter setup to the last line in defining connection [`#7`](https://github.com/amoniacou/pipedrive.rb/pull/7)
28
+ - Replace find by find_by_id in the docs [`#5`](https://github.com/amoniacou/pipedrive.rb/pull/5)
29
+ - Find by name organisation && update personfields [`#3`](https://github.com/amoniacou/pipedrive.rb/pull/3)
30
+
31
+ ### Commits
32
+
33
+ - Remove problematic reek and cane [`bf8535c`](https://github.com/amoniacou/pipedrive.rb/commit/bf8535c10d0894fb508828a43aefb036b000c263)
34
+ - Fix tests [`bca6171`](https://github.com/amoniacou/pipedrive.rb/commit/bca6171ae43068bd671bf6b8ecf924a7e2ad1af3)
35
+ - Fix outdated rubocop, contrain on rake to pass reek [`e799cbc`](https://github.com/amoniacou/pipedrive.rb/commit/e799cbca4eada29582e6c5a1e20e8f97ed709713)
36
+
37
+ ## v0.1.0 - 2014-10-16
38
+
39
+ ### Commits
40
+
41
+ - Initial commit [`cbd2138`](https://github.com/amoniacou/pipedrive.rb/commit/cbd2138ae11a19f4a398af3c25fac8ed2e6a0e1b)
42
+ - Test coverage and small refactoring [`ca0577f`](https://github.com/amoniacou/pipedrive.rb/commit/ca0577fef23f59515cb58ea152e10d3130f26730)
43
+ - Add more entities basic support. Add support for field selector [`73b47a4`](https://github.com/amoniacou/pipedrive.rb/commit/73b47a4455b1c50906bbc811bddac7d979fae966)
data/Rakefile CHANGED
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
4
 
6
- RSpec::Core::RakeTask.new(:spec)
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ rescue LoadError
9
+ end
7
10
 
8
11
  # rubocop
9
12
  require 'rubocop/rake_task'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'logger'
2
4
  require 'active_support/core_ext/hash'
3
5
  require 'active_support/concern'
@@ -33,7 +35,7 @@ module Pipedrive
33
35
  end
34
36
 
35
37
  def logger
36
- @logger ||= Logger.new(STDOUT)
38
+ @logger ||= Logger.new($stdout)
37
39
  end
38
40
 
39
41
  reset!
@@ -86,3 +88,9 @@ require 'pipedrive/file'
86
88
 
87
89
  # Notes
88
90
  require 'pipedrive/note'
91
+
92
+ # Users
93
+ require 'pipedrive/user'
94
+
95
+ # Pipelines
96
+ require 'pipedrive/pipeline'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class Activity < Base
3
5
  include ::Pipedrive::Operations::Create
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class ActivityType < Base
3
5
  include ::Pipedrive::Operations::Create
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class Base
3
5
  def initialize(api_token = ::Pipedrive.api_token)
4
- fail 'api_token should be set' unless api_token.present?
6
+ raise 'api_token should be set' unless api_token.present?
7
+
5
8
  @api_token = api_token
6
9
  end
7
10
 
@@ -12,7 +15,8 @@ module Pipedrive
12
15
  def make_api_call(*args)
13
16
  params = args.extract_options!
14
17
  method = args[0]
15
- fail 'method param missing' unless method.present?
18
+ raise 'method param missing' unless method.present?
19
+
16
20
  url = build_url(args, params.delete(:fields_to_select))
17
21
  begin
18
22
  res = connection.__send__(method.to_sym, url, params)
@@ -26,11 +30,9 @@ module Pipedrive
26
30
  end
27
31
 
28
32
  def build_url(args, fields_to_select = nil)
29
- url = "/v1/#{entity_name}"
33
+ url = +"/v1/#{entity_name}"
30
34
  url << "/#{args[1]}" if args[1]
31
- if fields_to_select.is_a?(::Array) && fields_to_select.size > 0
32
- url << ":(#{fields_to_select.join(',')})"
33
- end
35
+ url << ":(#{fields_to_select.join(',')})" if fields_to_select.is_a?(::Array) && fields_to_select.size.positive?
34
36
  url << "?api_token=#{@api_token}"
35
37
  url
36
38
  end
@@ -52,16 +54,16 @@ module Pipedrive
52
54
  failed: false)
53
55
  case res.status
54
56
  when 401
55
- failed_res.merge! not_authorized: true
57
+ failed_res[:not_authorized] = true
56
58
  when 420
57
- failed_res.merge! failed: true
59
+ failed_res[:failed] = true
58
60
  end
59
61
  failed_res
60
62
  end
61
63
 
62
64
  def entity_name
63
- class_name = self.class.name.split("::")[-1].downcase.pluralize
64
- class_names = { "people" => "persons" }
65
+ class_name = self.class.name.split('::')[-1].downcase.pluralize
66
+ class_names = { 'people' => 'persons' }
65
67
  class_names[class_name] || class_name
66
68
  end
67
69
 
@@ -77,7 +79,8 @@ module Pipedrive
77
79
  end
78
80
 
79
81
  # This method smells of :reek:TooManyStatements
80
- def connection # :nodoc
82
+ # :nodoc
83
+ def connection
81
84
  @connection ||= Faraday.new(faraday_options) do |conn|
82
85
  conn.request :url_encoded
83
86
  conn.response :mashify
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class Deal < Base
3
5
  include ::Pipedrive::Operations::Create
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class DealField < Base
3
5
  include ::Pipedrive::Operations::Create
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class File < Base
3
5
  include ::Pipedrive::Operations::Create
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class Filter < Base
3
5
  include ::Pipedrive::Operations::Read
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class Goal < Base
3
5
  include ::Pipedrive::Operations::Create
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class Note < Base
3
5
  include ::Pipedrive::Operations::Create
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  module Operations
3
5
  module Create
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  module Operations
3
5
  module Delete
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  module Operations
3
5
  module Read
@@ -5,10 +7,10 @@ module Pipedrive
5
7
  include ::Enumerable
6
8
  include ::Pipedrive::Utils
7
9
 
8
- # This method smells of :reek:TooManyStatements but ignores them
9
- def each(params = {})
10
+ def each(params = {}, &block)
10
11
  return to_enum(:each, params) unless block_given?
11
- follow_pagination(:chunk, [], params) { |item| yield item }
12
+
13
+ follow_pagination(:chunk, [], params, &block)
12
14
  end
13
15
 
14
16
  def all(params = {})
@@ -18,6 +20,7 @@ module Pipedrive
18
20
  def chunk(params = {})
19
21
  res = make_api_call(:get, params)
20
22
  return [] unless res.success?
23
+
21
24
  res
22
25
  end
23
26
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  module Operations
3
5
  module Update
@@ -7,7 +9,8 @@ module Pipedrive
7
9
  params = args.extract_options!
8
10
  params.symbolize_keys!
9
11
  id = params.delete(:id) || args[0]
10
- fail 'id must be provided' unless id
12
+ raise 'id must be provided' unless id
13
+
11
14
  make_api_call(:put, id, params)
12
15
  end
13
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class Organization < Base
3
5
  include ::Pipedrive::Operations::Read
@@ -6,12 +8,13 @@ module Pipedrive
6
8
  include ::Pipedrive::Operations::Delete
7
9
  include ::Pipedrive::Utils
8
10
 
9
- def find_by_name(*args)
11
+ def find_by_name(*args, &block)
10
12
  params = args.extract_options!
11
13
  params[:term] ||= args[0]
12
- fail 'term is missing' unless params[:term]
14
+ raise 'term is missing' unless params[:term]
13
15
  return to_enum(:find_by_name, params) unless block_given?
14
- follow_pagination(:make_api_call, [:get, 'find'], params) { |item| yield item }
16
+
17
+ follow_pagination(:make_api_call, [:get, 'find'], params, &block)
15
18
  end
16
19
  end
17
20
  end