pipedrive_jetrockets 0.0.54 → 0.0.55

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8be07ade0babaff812cca99ea18f840b7bbd8a491300e2ca88b2a52a2b8ec124
4
- data.tar.gz: 81245098213950af6bbe1732c833bfc144636b07fbccc77adbc3c4d2600bf053
3
+ metadata.gz: e872b160dc14ea553d1a7a11c40e927d496e9a05bc90683c7ec78ed089bc6c5a
4
+ data.tar.gz: 6e860c042f2feb5abb992c6a13a0a8243dd5e338079becf8b086a2905d6060ed
5
5
  SHA512:
6
- metadata.gz: 969bddfd34547499ff06218b2b77c4019df6d63275dd327dc9dee4734339c2cdfb3acb8d6ec4cf7515eaaaab086519a38e04cd816655cad98bf1e4f8f7d54068
7
- data.tar.gz: b13054531dce420583355312c5eebe18dac7ae095bc72d2812232572f28521deacac012d406c196b42de87abb6b53afb3362532c8322d4d8a5b250c6a7a5d1c4
6
+ metadata.gz: f4e496807253c7a407c8c25d667504c56c81b93d71375eb3a4c83769b7fa1f86fa93248d01a3db8f5d740645f2daebfe23558a973f1c74274d7070a0192f5bb0
7
+ data.tar.gz: 4770210888593712da635721dbea71476e7947984bd8f302f51a05f0f588f1af3212271c256db08392729930f9120dbfc7555883d095fc55591e3aa0ccb69423
@@ -1,6 +1,9 @@
1
1
  require 'net/http'
2
+ require 'pipedrive_jetrockets/entity'
2
3
  require 'pipedrive_jetrockets/engine'
3
4
  require 'pipedrive_jetrockets/service'
5
+ require 'pipedrive_jetrockets/person_service'
6
+ require 'pipedrive_jetrockets/field_service'
4
7
 
5
8
  class Pipedrive
6
9
 
@@ -8,6 +11,10 @@ class Pipedrive
8
11
  @@deals_service ||= PipedriveJetrockets::Service.new('deal')
9
12
  end
10
13
 
14
+ def self.deal_fields
15
+ @@deal_fields_service ||= PipedriveJetrockets::FieldService.new('dealField')
16
+ end
17
+
11
18
  def self.notes
12
19
  @@notes_service ||= PipedriveJetrockets::Service.new('note')
13
20
  end
@@ -17,7 +24,7 @@ class Pipedrive
17
24
  end
18
25
 
19
26
  def self.persons
20
- @@persons_service ||= PipedriveJetrockets::Service.new('person')
27
+ @@persons_service ||= PipedriveJetrockets::PersonService.new('person')
21
28
  end
22
29
 
23
30
  def self.pipelines
@@ -1,4 +1,3 @@
1
- require 'pipedrive_jetrockets/entity'
2
1
  require 'pipedrive_jetrockets/organization'
3
2
  require 'pipedrive_jetrockets/person'
4
3
 
@@ -7,10 +6,18 @@ module PipedriveJetrockets
7
6
  attr_accessor :id, :organization, :title, :value, :currency, :status,
8
7
  :stage_id, :person, :add_time, :update_time
9
8
  def initialize(hash)
10
- super
9
+ @@key_name_hash ||= Pipedrive.deal_fields.key_name_hash
10
+ super(hash.except(*@@key_name_hash.keys))
11
+
11
12
  org_id = hash['org_id']
12
13
  person_id = hash['person_id']
13
14
 
15
+ @@key_name_hash.each do |key, name|
16
+ name = name.underscore.gsub(' ','_')
17
+ instance_variable_set("@#{name}", hash[key])
18
+ Deal.class_eval {attr_accessor name}
19
+ end
20
+
14
21
  if org_id
15
22
  if org_id.kind_of? Integer
16
23
  @organization = Pipedrive.organizations.find(org_id)
@@ -0,0 +1,5 @@
1
+ module PipedriveJetrockets
2
+ class DealField < Entity
3
+ attr_accessor :id, :key, :name
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ module PipedriveJetrockets
2
+ class FieldService < Service
3
+ HOST = 'https://api.pipedrive.com/v1'
4
+
5
+ def initialize(resource_name)
6
+ @resource_name = resource_name
7
+ end
8
+
9
+ def key_name_hash
10
+ Pipedrive.deal_fields.all.map{|field|{field.key => field.name}}.inject(:merge)
11
+ end
12
+
13
+ def name_key_hash
14
+ Pipedrive.deal_fields.all.map{|field|{field.name => field.key}}.inject(:merge)
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,3 @@
1
- require 'pipedrive_jetrockets/entity'
2
-
3
1
  module PipedriveJetrockets
4
2
  class Note < Entity
5
3
  attr_accessor :id, :deal_id, :person_id, :org_id, :content, :add_time, :update_time
@@ -1,5 +1,3 @@
1
- require 'pipedrive_jetrockets/entity'
2
-
3
1
  module PipedriveJetrockets
4
2
  class Organization < Entity
5
3
  attr_accessor :id, :name, :owner_id, :address, :cc_email, :add_time, :update_time
@@ -1,5 +1,3 @@
1
- require 'pipedrive_jetrockets/entity'
2
-
3
1
  module PipedriveJetrockets
4
2
  class Person < Entity
5
3
  attr_accessor :id, :name, :email, :phone, :open_deals_count, :closed_deals_count,
@@ -0,0 +1,26 @@
1
+ module PipedriveJetrockets
2
+ class PersonService < Service
3
+ HOST = 'https://api.pipedrive.com/v1'
4
+
5
+ def initialize(resource_name)
6
+ @resource_name = resource_name
7
+ end
8
+
9
+ def find_by_email(email)
10
+ uri = build_uri({term: email, search_by_email: true }, 'find')
11
+ response = HTTP.get(uri)
12
+
13
+ case response.code
14
+ when 200
15
+ json_array = ::JSON.parse(response)['data']
16
+ return [] unless json_array
17
+ json_array.map{|raw|build_entity(raw)}
18
+ else
19
+ raise PipedriveJetrockets::Error.new(response.code)
20
+ end
21
+ rescue HTTP::ConnectionError
22
+ raise PipedriveJetrockets::Error.new(408)
23
+ end
24
+
25
+ end
26
+ end
@@ -1,5 +1,3 @@
1
- require 'pipedrive_jetrockets/entity'
2
-
3
1
  module PipedriveJetrockets
4
2
  class Pipeline < Entity
5
3
  attr_accessor :id, :name, :add_time, :update_time
@@ -1,5 +1,6 @@
1
1
  require 'http'
2
2
  require 'pipedrive_jetrockets/deal'
3
+ require 'pipedrive_jetrockets/deal_field'
3
4
  require 'pipedrive_jetrockets/note'
4
5
  require 'pipedrive_jetrockets/organization'
5
6
  require 'pipedrive_jetrockets/person'
@@ -11,13 +12,15 @@ require 'pipedrive_jetrockets/error'
11
12
  module PipedriveJetrockets
12
13
  class Service
13
14
  HOST = 'https://api.pipedrive.com/v1'
15
+ RESOURCES_WITH_CUSTOM_FIELDS = %w(deal organization person)
14
16
 
15
17
  def initialize(resource_name)
16
18
  @resource_name = resource_name
19
+ @has_custom_fields = RESOURCES_WITH_CUSTOM_FIELDS.include?(@resource_name)
17
20
  end
18
21
 
19
22
  def build_entity(raw)
20
- "PipedriveJetrockets::#{@resource_name.titleize}".constantize.new(raw)
23
+ "PipedriveJetrockets::#{@resource_name.titleize.delete(' ')}".constantize.new(raw)
21
24
  end
22
25
 
23
26
  def build_uri(params = {}, specificator = nil)
@@ -71,30 +74,13 @@ module PipedriveJetrockets
71
74
  raise PipedriveJetrockets::Error.new(408)
72
75
  end
73
76
 
74
- def find_by_email(email)
75
- raise NoMethodError if @resource_name != 'person'
76
- uri = build_uri({term: email, search_by_email: true }, 'find')
77
- response = HTTP.get(uri)
78
-
79
- case response.code
80
- when 200
81
- json_array = ::JSON.parse(response)['data']
82
- return [] unless json_array
83
- json_array.map{|raw|build_entity(raw)}
84
- else
85
- raise PipedriveJetrockets::Error.new(response.code)
86
- end
87
- rescue HTTP::ConnectionError
88
- raise PipedriveJetrockets::Error.new(408)
89
- end
90
-
91
77
  def first
92
78
  self.all.first
93
79
  end
94
80
 
95
81
  def update(id, params)
96
82
  uri = build_uri({}, id)
97
- response = HTTP.put(uri, form: params)
83
+ response = HTTP.put(uri, form: transform_custom_fields(params))
98
84
 
99
85
  case response.code
100
86
  when 200
@@ -105,5 +91,24 @@ module PipedriveJetrockets
105
91
  rescue HTTP::ConnectionError
106
92
  raise PipedriveJetrockets::Error.new(408)
107
93
  end
94
+
95
+ protected
96
+
97
+ def transform_custom_fields(params)
98
+ return params unless @has_custom_fields
99
+
100
+ @@name_key_hash = Pipedrive.send("#{@resource_name}_fields").name_key_hash
101
+ keys = @@name_key_hash.keys
102
+ res = {}
103
+ params.each do |name, value|
104
+ if keys.include?(name.to_s) #Custom Field
105
+ res[@@name_key_hash[name.to_s]] = value
106
+ else
107
+ res[name] = value
108
+ end
109
+ end
110
+ res
111
+ end
112
+
108
113
  end
109
114
  end
@@ -1,5 +1,3 @@
1
- require 'pipedrive_jetrockets/entity'
2
-
3
1
  module PipedriveJetrockets
4
2
  class Stage < Entity
5
3
  attr_accessor :id, :name, :pipeline_id, :add_time, :update_time
@@ -1,5 +1,3 @@
1
- require 'pipedrive_jetrockets/entity'
2
-
3
1
  module PipedriveJetrockets
4
2
  class User < Entity
5
3
  attr_accessor :id, :name, :email, :phone
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipedrive_jetrockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.54
4
+ version: 0.0.55
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agafonov Maksim
@@ -34,12 +34,15 @@ files:
34
34
  - config/routes.rb
35
35
  - lib/pipedrive_jetrockets.rb
36
36
  - lib/pipedrive_jetrockets/deal.rb
37
+ - lib/pipedrive_jetrockets/deal_field.rb
37
38
  - lib/pipedrive_jetrockets/engine.rb
38
39
  - lib/pipedrive_jetrockets/entity.rb
39
40
  - lib/pipedrive_jetrockets/error.rb
41
+ - lib/pipedrive_jetrockets/field_service.rb
40
42
  - lib/pipedrive_jetrockets/note.rb
41
43
  - lib/pipedrive_jetrockets/organization.rb
42
44
  - lib/pipedrive_jetrockets/person.rb
45
+ - lib/pipedrive_jetrockets/person_service.rb
43
46
  - lib/pipedrive_jetrockets/pipeline.rb
44
47
  - lib/pipedrive_jetrockets/service.rb
45
48
  - lib/pipedrive_jetrockets/stage.rb