pipedrive_jetrockets 0.0.38 → 0.0.39
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pipedrive_jetrockets.rb +126 -13
- 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: 9b8919f1678a43eba744bd482ec84964bde61b391e703345db029a7966afc30e
|
4
|
+
data.tar.gz: 87ab78c5f34bfa916996fe642d0fa2005c7e56837b281066d7fac97ebf87f7bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fa02c2d39002763d3f1192f6934cbd2ced32ac2f69b3a3a98f76f5f6895b8defa5e0210fc024dd961c5054b9544676daa511b98898d35a265f5be9521a6148d
|
7
|
+
data.tar.gz: a1c6545e8334c622589be660ae63dd37c485da34cf5872f08f6fd8d16a071f2b990511f8b7d83d9444c4e1af7bf6ac5a9e98321f12a381584b5a2ece53c6f4d8
|
data/lib/pipedrive_jetrockets.rb
CHANGED
@@ -4,7 +4,19 @@ require 'pipedrive_jetrockets/engine'
|
|
4
4
|
class Pipedrive
|
5
5
|
|
6
6
|
def self.deals
|
7
|
-
@@deals_service ||= Pipedrive::
|
7
|
+
@@deals_service ||= Pipedrive::Service.new('deal')
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.notes
|
11
|
+
@@persons_service ||= Pipedrive::Service.new('note')
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.persons
|
15
|
+
@@persons_service ||= Pipedrive::Service.new('person')
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.stages
|
19
|
+
@@stages_service ||= Pipedrive::Service.new('stage')
|
8
20
|
end
|
9
21
|
|
10
22
|
#Entities
|
@@ -15,6 +27,10 @@ class Pipedrive
|
|
15
27
|
end
|
16
28
|
end
|
17
29
|
|
30
|
+
class Note < Pipedrive::Entity
|
31
|
+
attr_accessor :id, :deal_id, :person_id, :org_id, :content
|
32
|
+
end
|
33
|
+
|
18
34
|
class Organisation < Pipedrive::Entity
|
19
35
|
attr_accessor :id, :name, :owner_id, :address, :cc_email
|
20
36
|
end
|
@@ -39,41 +55,138 @@ class Pipedrive
|
|
39
55
|
@organisation = Pipedrive::Organisation.new(hash['org_id']) if hash['org_id']
|
40
56
|
@person = Pipedrive::Person.new(hash['person_id']) if hash['person_id']
|
41
57
|
end
|
58
|
+
|
59
|
+
def stage
|
60
|
+
Pipedrive.stages.find(self.stage_id)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Stage < Pipedrive::Entity
|
65
|
+
attr_accessor :id, :name, :pipeline_name
|
66
|
+
def display_name
|
67
|
+
"#{pipeline_name}:#{name}"
|
68
|
+
end
|
42
69
|
end
|
43
70
|
|
44
71
|
#Services
|
45
72
|
|
46
73
|
class Service
|
47
|
-
def
|
48
|
-
|
74
|
+
def initialize(resource_name)
|
75
|
+
@resource_name = resource_name
|
76
|
+
end
|
77
|
+
|
78
|
+
def build_entity(raw)
|
79
|
+
"Pipedrive::#{@resource_name.titleize}".constantize.new(raw)
|
80
|
+
end
|
81
|
+
|
82
|
+
def build_uri(id = nil)
|
83
|
+
uri = URI("#{Pipedrive::HOST}/#{@resource_name.pluralize}/#{id}?api_token=#{ENV['pipedrive_api_token']}")
|
49
84
|
end
|
50
|
-
end
|
51
85
|
|
52
|
-
class DealsService < Pipedrive::Service
|
53
86
|
def all
|
54
|
-
uri = build_uri
|
87
|
+
uri = build_uri
|
55
88
|
json_array = ::JSON.parse(Net::HTTP.get(uri))['data']
|
56
|
-
json_array.map{|raw|
|
89
|
+
json_array.map{|raw|build_entity(raw)}
|
57
90
|
end
|
58
91
|
|
59
|
-
def create(
|
60
|
-
uri = build_uri
|
61
|
-
response = Net::HTTP.post_form(uri,
|
92
|
+
def create(params)
|
93
|
+
uri = build_uri
|
94
|
+
response = Net::HTTP.post_form(uri, params)
|
62
95
|
|
63
|
-
response.kind_of? Net::HTTPSuccess
|
96
|
+
if response.kind_of? Net::HTTPSuccess
|
97
|
+
JSON.parse(response.body)['data']['id']
|
98
|
+
else
|
99
|
+
nil
|
100
|
+
end
|
64
101
|
end
|
65
102
|
|
66
103
|
def find(id)
|
67
|
-
uri = build_uri(
|
104
|
+
uri = build_uri(id)
|
68
105
|
raw = ::JSON.parse(Net::HTTP.get(uri))['data']
|
69
|
-
|
106
|
+
build_entity(raw)
|
70
107
|
end
|
71
108
|
|
72
109
|
def first
|
73
110
|
self.all.first
|
74
111
|
end
|
112
|
+
|
75
113
|
end
|
76
114
|
|
115
|
+
# class DealsService < Pipedrive::Service
|
116
|
+
# # def all
|
117
|
+
# # uri = build_uri('deals')
|
118
|
+
# # json_array = ::JSON.parse(Net::HTTP.get(uri))['data']
|
119
|
+
# # json_array.map{|raw|Pipedrive::Deal.new(raw)}
|
120
|
+
# # end
|
121
|
+
# def resource_name
|
122
|
+
# 'deal'
|
123
|
+
# end
|
124
|
+
#
|
125
|
+
# def create(params)
|
126
|
+
# uri = build_uri('deals')
|
127
|
+
# response = Net::HTTP.post_form(params)
|
128
|
+
#
|
129
|
+
# if responce['success']
|
130
|
+
# responce['data']['id']
|
131
|
+
# else
|
132
|
+
# nil
|
133
|
+
# end
|
134
|
+
# end
|
135
|
+
#
|
136
|
+
# def find(id)
|
137
|
+
# uri = build_uri('deals', id)
|
138
|
+
# raw = ::JSON.parse(Net::HTTP.get(uri))['data']
|
139
|
+
# Pipedrive::Deal.new(raw)
|
140
|
+
# end
|
141
|
+
#
|
142
|
+
# def first
|
143
|
+
# self.all.first
|
144
|
+
# end
|
145
|
+
# end
|
146
|
+
#
|
147
|
+
# class PersonsService < Pipedrive::Service
|
148
|
+
# # def all
|
149
|
+
# # uri = build_uri('persons')
|
150
|
+
# # json_array = ::JSON.parse(Net::HTTP.get(uri))['data']
|
151
|
+
# # json_array.map{|raw|Pipedrive::Person.new(raw)}
|
152
|
+
# # end
|
153
|
+
# def resource_name
|
154
|
+
# 'person'
|
155
|
+
# end
|
156
|
+
#
|
157
|
+
# def find(id)
|
158
|
+
# uri = build_uri('persons', id)
|
159
|
+
# raw = ::JSON.parse(Net::HTTP.get(uri))['data']
|
160
|
+
# Pipedrive::Person.new(raw)
|
161
|
+
# end
|
162
|
+
#
|
163
|
+
# def first
|
164
|
+
# self.all.first
|
165
|
+
# end
|
166
|
+
# end
|
167
|
+
#
|
168
|
+
# class StagesService < Pipedrive::Service
|
169
|
+
# # def all
|
170
|
+
# # uri = build_uri('stages')
|
171
|
+
# # json_array = ::JSON.parse(Net::HTTP.get(uri))['data']
|
172
|
+
# # json_array.map{|raw|Pipedrive::Stage.new(raw)}
|
173
|
+
# # end
|
174
|
+
#
|
175
|
+
# def resource_name
|
176
|
+
# 'stage'
|
177
|
+
# end
|
178
|
+
#
|
179
|
+
# def find(id)
|
180
|
+
# uri = build_uri('stages', id)
|
181
|
+
# raw = ::JSON.parse(Net::HTTP.get(uri))['data']
|
182
|
+
# Pipedrive::Stage.new(raw)
|
183
|
+
# end
|
184
|
+
#
|
185
|
+
# def first
|
186
|
+
# self.all.first
|
187
|
+
# end
|
188
|
+
# end
|
189
|
+
|
77
190
|
HOST = 'https://api.pipedrive.com/v1'
|
78
191
|
|
79
192
|
#Service Methods
|