pipe_rocket 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/pipe_rocket/events_controller.rb +2 -1
- data/lib/pipe_rocket/deal.rb +4 -0
- data/lib/pipe_rocket/entity.rb +2 -0
- data/lib/pipe_rocket/field.rb +3 -1
- data/lib/pipe_rocket/field_service.rb +3 -0
- data/lib/pipe_rocket/organization.rb +1 -0
- data/lib/pipe_rocket/person.rb +2 -1
- data/lib/pipe_rocket/person_service.rb +1 -0
- data/lib/pipe_rocket/service.rb +9 -7
- data/lib/pipe_rocket/stage.rb +2 -0
- data/lib/pipe_rocket.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6bedc748fe28608525bb671fe7eedf03c5bbc0e5547b4dcae221b94a014c96e
|
4
|
+
data.tar.gz: 97661f23343b9cfd705b9212039c63c13956bdaca73e3731bfd2d527802aa670
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1fc43d0728dac71a4fafa9c0dd4e2cf933aec20ee6a62ab0e986aa3078662afe74f943a396e21b1b196c97957401af4c1f7dac8105a9f44261685e55ca4e0ed
|
7
|
+
data.tar.gz: 3b4a31dc6b8838e2f66ef296aa42d34367d7b6bc754d9ac26762ed4f7043ed33fdf287a648e0b6719d471feb5dd9bf402a93094531783db0e4505217aeb43c7d
|
@@ -2,7 +2,8 @@ module PipeRocket
|
|
2
2
|
class EventsController < ApplicationController
|
3
3
|
skip_before_action :verify_authenticity_token
|
4
4
|
def handle
|
5
|
-
|
5
|
+
json = params[:current] || params[:previous]
|
6
|
+
ActiveSupport::Notifications.instrument "#{params[:object]}_#{params[:event]}", {params[:object].to_sym => "PipeRocket::#{params[:object].titleize}".constantize.new(json)}
|
6
7
|
end
|
7
8
|
end
|
8
9
|
end
|
data/lib/pipe_rocket/deal.rb
CHANGED
@@ -4,6 +4,8 @@ require 'pipe_rocket/person'
|
|
4
4
|
module PipeRocket
|
5
5
|
class Deal < Entity
|
6
6
|
attr_accessor :organization, :person
|
7
|
+
|
8
|
+
# Returns hash {custom_field_key: PipeRocket::Field object}
|
7
9
|
def self.key_field_hash
|
8
10
|
@@key_field_hash ||= Pipedrive.deal_fields.key_field_hash
|
9
11
|
end
|
@@ -39,10 +41,12 @@ module PipeRocket
|
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
44
|
+
# Returns PipeRocket::Stage object corresponding to current deal stage
|
42
45
|
def stage
|
43
46
|
Pipedrive.stages.find(self.stage_id)
|
44
47
|
end
|
45
48
|
|
49
|
+
# Returns stage name like PipelineName:StageName
|
46
50
|
def display_stage_name
|
47
51
|
self.stage.display_name
|
48
52
|
end
|
data/lib/pipe_rocket/entity.rb
CHANGED
@@ -9,6 +9,7 @@ module PipeRocket
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
# Assign custom fields, using their names but not keys
|
12
13
|
def assign_custom_fields(key_name_hash, entity_hash)
|
13
14
|
names = key_name_hash.map do |key, field|
|
14
15
|
name = field.name
|
@@ -28,6 +29,7 @@ module PipeRocket
|
|
28
29
|
self.class.class_eval {attr_accessor *names}
|
29
30
|
end
|
30
31
|
|
32
|
+
# Override custom field name if it present in CUSTOM_FIELD_NAMES
|
31
33
|
def transform_field_name(key, name)
|
32
34
|
hash = ::CUSTOM_FIELD_NAMES
|
33
35
|
class_name = self.class.name.demodulize.underscore.to_sym
|
data/lib/pipe_rocket/field.rb
CHANGED
@@ -6,11 +6,13 @@ module PipeRocket
|
|
6
6
|
@is_subfield ||= false
|
7
7
|
end
|
8
8
|
|
9
|
+
# Return hash {option_id: option_value}
|
9
10
|
def options_hash
|
10
11
|
return {} unless @options
|
11
12
|
@options.map{|option|{option['id'].to_s => option['label']}}.inject(:merge)
|
12
13
|
end
|
13
|
-
|
14
|
+
|
15
|
+
# Return value of field
|
14
16
|
def value
|
15
17
|
options_hash[option_id]
|
16
18
|
end
|
@@ -6,14 +6,17 @@ module PipeRocket
|
|
6
6
|
@resource_name = resource_name
|
7
7
|
end
|
8
8
|
|
9
|
+
# Returns hash {custom_field_key: PipeRocket::Field object}
|
9
10
|
def key_field_hash
|
10
11
|
Pipedrive.send("#{@resource_name.split(/(?=[A-Z])/).first}_fields").all.select{|field|field.edit_flag || field.is_subfield}.map{|field|{field.key => field}}.inject(:merge) || {}
|
11
12
|
end
|
12
13
|
|
14
|
+
# Returns hash {custom_field_key: custom_field_name}
|
13
15
|
def key_name_hash
|
14
16
|
Pipedrive.send("#{@resource_name.split(/(?=[A-Z])/).first}_fields").all.select{|field|field.edit_flag || field.is_subfield}.map{|field|{field.key => field.name}}.inject(:merge) || {}
|
15
17
|
end
|
16
18
|
|
19
|
+
# Returns hash {custom_field_name: custom_field_key}
|
17
20
|
def name_key_hash
|
18
21
|
Pipedrive.send("#{@resource_name.split(/(?=[A-Z])/).first}_fields").all.select{|field|field.edit_flag || field.is_subfield}.map{|field|{field.name => field.key}}.inject(:merge) || {}
|
19
22
|
end
|
data/lib/pipe_rocket/person.rb
CHANGED
@@ -2,6 +2,7 @@ module PipeRocket
|
|
2
2
|
class Person < Entity
|
3
3
|
attr_accessor :email, :phone, :organization, :id
|
4
4
|
|
5
|
+
# Returns hash {custom_field_key: PipeRocket::Field object}
|
5
6
|
def self.key_field_hash
|
6
7
|
@@key_field_hash ||= Pipedrive.person_fields.key_field_hash
|
7
8
|
end
|
@@ -25,6 +26,6 @@ module PipeRocket
|
|
25
26
|
nil
|
26
27
|
end
|
27
28
|
end
|
28
|
-
end
|
29
|
+
end
|
29
30
|
end
|
30
31
|
end
|
data/lib/pipe_rocket/service.rb
CHANGED
@@ -21,10 +21,12 @@ module PipeRocket
|
|
21
21
|
@has_custom_fields = RESOURCES_WITH_CUSTOM_FIELDS.include?(@resource_name)
|
22
22
|
end
|
23
23
|
|
24
|
+
# Build resource_name class object from hash
|
24
25
|
def build_entity(raw)
|
25
26
|
"PipeRocket::#{@resource_name.titleize.delete(' ')}".constantize.new(raw)
|
26
27
|
end
|
27
28
|
|
29
|
+
# Build uri for request
|
28
30
|
def build_uri(params = {}, specificator = nil)
|
29
31
|
params.merge!(api_token: ENV['pipedrive_api_token'])
|
30
32
|
query_string = params.map{|k,v|"#{k}=#{v}"}.join('&')
|
@@ -32,6 +34,7 @@ module PipeRocket
|
|
32
34
|
uri = URI("#{HOST}/#{plural_resource_name}/#{specificator}?#{query_string}")
|
33
35
|
end
|
34
36
|
|
37
|
+
# Getting all @resource_name object from Pipedrive
|
35
38
|
def all
|
36
39
|
uri = build_uri
|
37
40
|
response = HTTP.get(uri)
|
@@ -47,6 +50,7 @@ module PipeRocket
|
|
47
50
|
raise PipeRocket::Error.new(408)
|
48
51
|
end
|
49
52
|
|
53
|
+
# Create @resource_name in Pipedrive
|
50
54
|
def create(params)
|
51
55
|
uri = build_uri
|
52
56
|
response = HTTP.post(uri, form: transform_custom_fields(params))
|
@@ -61,6 +65,7 @@ module PipeRocket
|
|
61
65
|
raise PipeRocket::Error.new(408)
|
62
66
|
end
|
63
67
|
|
68
|
+
# Find @resource_name object by id
|
64
69
|
def find(id)
|
65
70
|
uri = build_uri({}, id)
|
66
71
|
response = HTTP.get(uri)
|
@@ -76,10 +81,12 @@ module PipeRocket
|
|
76
81
|
raise PipeRocket::Error.new(408)
|
77
82
|
end
|
78
83
|
|
84
|
+
# Getting first @resource_name object
|
79
85
|
def first
|
80
86
|
self.all.first
|
81
87
|
end
|
82
88
|
|
89
|
+
# Update @resource_name object by id
|
83
90
|
def update(id, params)
|
84
91
|
uri = build_uri({}, id)
|
85
92
|
response = HTTP.put(uri, form: transform_custom_fields(params))
|
@@ -96,6 +103,7 @@ module PipeRocket
|
|
96
103
|
|
97
104
|
protected
|
98
105
|
|
106
|
+
# Trasform custom fields from their names to keys
|
99
107
|
def transform_custom_fields(params)
|
100
108
|
return params unless @has_custom_fields
|
101
109
|
|
@@ -120,13 +128,7 @@ module PipeRocket
|
|
120
128
|
res
|
121
129
|
end
|
122
130
|
|
123
|
-
|
124
|
-
hash = ::CUSTOM_FIELD_NAMES
|
125
|
-
class_name = @resource_name
|
126
|
-
return name if hash.nil? || hash[class_name].nil? || hash[class_name].key(key.to_sym).nil?
|
127
|
-
hash[class_name][key.to_sym]
|
128
|
-
end
|
129
|
-
|
131
|
+
# Clear string from forbidden symbols for ruby variables
|
130
132
|
def clear_key(key)
|
131
133
|
key = key.underscore.gsub(' ','_')
|
132
134
|
key = key.gsub('%','percent').gsub(/[^a-zA-Z0-9_]/,'')
|
data/lib/pipe_rocket/stage.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module PipeRocket
|
2
2
|
class Stage < Entity
|
3
|
+
# Return PipeRocket::Pipeline object which related with stage
|
3
4
|
def pipeline
|
4
5
|
Pipedrive.pipelines.find(self.pipeline_id)
|
5
6
|
end
|
6
7
|
|
8
|
+
# Returns stage name like PipelineName:StageName
|
7
9
|
def display_name
|
8
10
|
"#{pipeline.name}:#{name}"
|
9
11
|
end
|
data/lib/pipe_rocket.rb
CHANGED
@@ -10,38 +10,47 @@ require 'pipe_rocket/field_service'
|
|
10
10
|
|
11
11
|
class Pipedrive
|
12
12
|
|
13
|
+
# Getting deal service object(PipeRocket::Servcice)
|
13
14
|
def self.deals
|
14
15
|
@@deals_service ||= PipeRocket::Service.new('deal')
|
15
16
|
end
|
16
17
|
|
18
|
+
# Getting \deal_fields service object(PipeRocket::FieldServcice)
|
17
19
|
def self.deal_fields
|
18
20
|
@@deal_fields_service ||= PipeRocket::FieldService.new('dealField')
|
19
21
|
end
|
20
22
|
|
23
|
+
# Getting note service object(PipeRocket::Servcice)
|
21
24
|
def self.notes
|
22
25
|
@@notes_service ||= PipeRocket::Service.new('note')
|
23
26
|
end
|
24
27
|
|
28
|
+
# Getting organization service object(PipeRocket::Servcice)
|
25
29
|
def self.organizations
|
26
30
|
@@organizations_service ||= PipeRocket::Service.new('organization')
|
27
31
|
end
|
28
32
|
|
33
|
+
# Getting \organization_field service object(PipeRocket::FieldServcice)
|
29
34
|
def self.organization_fields
|
30
35
|
@@organization_fields ||= PipeRocket::FieldService.new('organizationField')
|
31
36
|
end
|
32
37
|
|
38
|
+
# Getting person service object(PipeRocket::PersonServcice)
|
33
39
|
def self.persons
|
34
40
|
@@persons_service ||= PipeRocket::PersonService.new('person')
|
35
41
|
end
|
36
42
|
|
43
|
+
# Getting \person_field service object(PipeRocket::FieldServcice)
|
37
44
|
def self.person_fields
|
38
45
|
@@person_fields ||= PipeRocket::FieldService.new('personField')
|
39
46
|
end
|
40
47
|
|
48
|
+
# Getting pipeline service object(PipeRocket::Servcice)
|
41
49
|
def self.pipelines
|
42
50
|
@@pipelines_service ||= PipeRocket::Service.new('pipeline')
|
43
51
|
end
|
44
52
|
|
53
|
+
# Getting stages service object(PipeRocket::Servcice)
|
45
54
|
def self.stages
|
46
55
|
@@stages_service ||= PipeRocket::Service.new('stage')
|
47
56
|
end
|