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 @@ def connection
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 @@ def make_api_call(*args)
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 @@ def failed_response(res)
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 @@ def faraday_options
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
0 commit comments