pipedrive_jetrockets 0.0.24 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pipedrive_jetrockets.rb +56 -48
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8847a7d34cc1e81886835f10af0c9d72083b8efcc340bb67a71a0f4416722ea3
4
- data.tar.gz: 889cfe293c39d413a7abc8b920ed247f232044891cfae6b8c2b1e20b3e51b984
3
+ metadata.gz: 7ab9b0331d3fc8ea29b5b64749ded2cd2511b85cfd7bdb4913e7385c611d7ab9
4
+ data.tar.gz: '08e9f87c78bd71c42af0e9d147c9e5b3a651c738ff60c8a8553fd854221af1af'
5
5
  SHA512:
6
- metadata.gz: 1e9893329c864e5d08aad73ca0266173dcdeb7203ca840e3a6c2924dc18ee95816bae7acd60241d81ee01a4d3e6c47ab70d03ba9deeda09344d36299f316c131
7
- data.tar.gz: ae45c68d5a8c01fa539711be697ffd5b10cb501891fd7715268f11a9be72462491e0bf232aa0cd6eeab1c905f754e2a911a2bd1732bd258920f3bb01b35034d9
6
+ metadata.gz: 2a1cab1b4c9b4579c9cc8301ebb68b89b198416e569cd6ff0e343d463b83f27f95dfd35b9608390839d6483aec73d73780aade6f4d784f361be758d63f1c748e
7
+ data.tar.gz: 505e552ee66b29a157d1d85925f706f0d9b4977f0114635aa267d1fb9620d6ac06a9186dbee39482bd92219f64c0ae0403f77b3d336b07f1dc73669e6e754fca
@@ -1,7 +1,12 @@
1
1
  require 'net/http'
2
2
  require 'pipedrive_jetrockets/engine'
3
3
 
4
- class PipedriveAPI
4
+ class Pipedrive
5
+
6
+ def self.deals
7
+ @@deals_service ||= Pipedrive::DealsService.new
8
+ end
9
+
5
10
  #Entities
6
11
 
7
12
  class Entity
@@ -10,40 +15,45 @@ class PipedriveAPI
10
15
  end
11
16
  end
12
17
 
13
- class Organization < PipedriveAPI::Entity
14
- attr_accessor :name, :owner_id, :address, :cc_email
18
+ class Organisation < Pipedrive::Entity
19
+ attr_accessor :id, :name, :owner_id, :address, :cc_email
20
+ end
21
+
22
+ class Person < Pipedrive::Entity
23
+ attr_accessor :name, :email, :phone
24
+ def initialize(hash)
25
+ super
26
+ @email = hash['email'].first['value'] if hash['email']
27
+ @phone = hash['phone'].first['value'] if hash['phone']
28
+ end
15
29
  end
16
30
 
17
- class User < PipedriveAPI::Entity
18
- attr_accessor :id, :name, :email
31
+ class User < Pipedrive::Entity
32
+ attr_accessor :id, :name, :email, :phone
19
33
  end
20
34
 
21
- class Deal < PipedriveAPI::Entity
22
- attr_accessor :id, :creator, :organization, :title, :value, :currency, :status
35
+ class Deal < Pipedrive::Entity
36
+ attr_accessor :id, :organisation, :title, :value, :currency, :status, :stage_id, :person
23
37
  def initialize(hash)
24
38
  super
25
- @creator = PipedriveAPI::User.new(hash['creator_user_id']) if hash['creator_user_id']
26
- @organization = PipedriveAPI::Organization.new(hash['org_id']) if hash['org_id']
39
+ @organisation = Pipedrive::Organisation.new(hash['org_id']) if hash['org_id']
40
+ @person = Pipedrive::Person.new(hash['person_id']) if hash['person_id']
27
41
  end
28
42
  end
29
43
 
30
44
  #Services
31
45
 
32
46
  class Service
33
- def initialize(api_token)
34
- @api_token = api_token
35
- end
36
-
37
- def build_uri(action)
38
- uri = URI("#{PipedriveAPI::HOST}/#{action}?api_token=#{@api_token}")
47
+ def build_uri(action, id = nil)
48
+ uri = URI("#{Pipedrive::HOST}/#{action}/#{id}?api_token=#{ENV['pipedrive_api_token']}")
39
49
  end
40
50
  end
41
51
 
42
- class DealsService < PipedriveAPI::Service
52
+ class DealsService < Pipedrive::Service
43
53
  def all
44
54
  uri = build_uri('deals')
45
55
  json_array = ::JSON.parse(Net::HTTP.get(uri))['data']
46
- json_array.map{|raw|PipedriveAPI::Deal.new(raw)}
56
+ json_array.map{|raw|Pipedrive::Deal.new(raw)}
47
57
  end
48
58
 
49
59
  def create(title, value = nil, user_id = nil, person_id = nil, org_id = nil)
@@ -53,6 +63,12 @@ class PipedriveAPI
53
63
  response.kind_of? Net::HTTPSuccess
54
64
  end
55
65
 
66
+ def find(id)
67
+ uri = build_uri('deals', id)
68
+ raw = ::JSON.parse(Net::HTTP.get(uri))['data']
69
+ Pipedrive::Deal.new(raw)
70
+ end
71
+
56
72
  def first
57
73
  self.all.first
58
74
  end
@@ -60,39 +76,31 @@ class PipedriveAPI
60
76
 
61
77
  HOST = 'https://api.pipedrive.com/v1'
62
78
 
63
- def initialize(api_token)
64
- @api_token = api_token
65
- end
66
-
67
- #Actions
68
-
69
- def deals
70
- @deals_serice ||= PipedriveAPI::DealsService.new(@api_token)
71
- end
72
-
73
- def activities
74
- uri = build_uri('activities')
75
- ::JSON.parse(Net::HTTP.get(uri))['data']
76
- end
79
+ #Service Methods
77
80
 
78
- def activity_types
79
- uri = build_uri('activities')
80
- ::JSON.parse(Net::HTTP.get(uri))['data']
81
- end
81
+ # def activities
82
+ # uri = build_uri('activities')
83
+ # ::JSON.parse(Net::HTTP.get(uri))['data']
84
+ # end
85
+ #
86
+ # def activity_types
87
+ # uri = build_uri('activities')
88
+ # ::JSON.parse(Net::HTTP.get(uri))['data']
89
+ # end
82
90
 
83
91
  #POST
84
92
 
85
- def add_activity(subject, type, deal_id, due_date = nil, due_time = nil, duration = nil, org_id = nil)
86
- uri = build_uri('activities')
87
- response = Net::HTTP.post_form(uri, subject: subject, type: type, deal_id: deal_id, due_date: due_date, due_time: due_time, duration: duration, org_id: org_id)
88
-
89
- response.kind_of? Net::HTTPSuccess
90
- end
91
-
92
- def add_deal(title, value = nil, user_id = nil, person_id = nil, org_id = nil)
93
- uri = build_uri('deals')
94
- response = Net::HTTP.post_form(uri, title: title, value: value, user_id: user_id, person_id: person_id, org_id: org_id)
95
-
96
- response.kind_of? Net::HTTPSuccess
97
- end
93
+ # def add_activity(subject, type, deal_id, due_date = nil, due_time = nil, duration = nil, org_id = nil)
94
+ # uri = build_uri('activities')
95
+ # response = Net::HTTP.post_form(uri, subject: subject, type: type, deal_id: deal_id, due_date: due_date, due_time: due_time, duration: duration, org_id: org_id)
96
+ #
97
+ # response.kind_of? Net::HTTPSuccess
98
+ # end
99
+ #
100
+ # def add_deal(title, value = nil, user_id = nil, person_id = nil, org_id = nil)
101
+ # uri = build_uri('deals')
102
+ # response = Net::HTTP.post_form(uri, title: title, value: value, user_id: user_id, person_id: person_id, org_id: org_id)
103
+ #
104
+ # response.kind_of? Net::HTTPSuccess
105
+ # end
98
106
  end
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.24
4
+ version: 0.0.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agafonov Maksim