basecrm 1.3.2 → 1.3.3

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 (45) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +1 -1
  3. data/README.md +24 -0
  4. data/lib/basecrm.rb +22 -0
  5. data/lib/basecrm/models/deal.rb +3 -3
  6. data/lib/basecrm/models/deal_unqualified_reason.rb +22 -0
  7. data/lib/basecrm/models/lead_unqualified_reason.rb +22 -0
  8. data/lib/basecrm/services/accounts_service.rb +3 -3
  9. data/lib/basecrm/services/associated_contacts_service.rb +12 -12
  10. data/lib/basecrm/services/contacts_service.rb +19 -19
  11. data/lib/basecrm/services/deal_unqualified_reasons_service.rb +133 -0
  12. data/lib/basecrm/services/lead_sources_service.rb +19 -19
  13. data/lib/basecrm/services/lead_unqualified_reasons_service.rb +45 -0
  14. data/lib/basecrm/services/leads_service.rb +19 -19
  15. data/lib/basecrm/services/loss_reasons_service.rb +19 -19
  16. data/lib/basecrm/services/notes_service.rb +19 -19
  17. data/lib/basecrm/services/pipelines_service.rb +5 -5
  18. data/lib/basecrm/services/sources_service.rb +19 -19
  19. data/lib/basecrm/services/stages_service.rb +5 -5
  20. data/lib/basecrm/services/tags_service.rb +19 -19
  21. data/lib/basecrm/services/tasks_service.rb +19 -19
  22. data/lib/basecrm/services/users_service.rb +11 -11
  23. data/lib/basecrm/version.rb +1 -1
  24. data/spec/factories/deal_unqualified_reason.rb +11 -0
  25. data/spec/factories/lead_unqualified_reason.rb +0 -0
  26. data/spec/services/accounts_service_spec.rb +1 -2
  27. data/spec/services/associated_contacts_service_spec.rb +0 -1
  28. data/spec/services/contacts_service_spec.rb +1 -2
  29. data/spec/services/deal_sources_service_spec.rb +1 -2
  30. data/spec/services/deal_unqualified_reasons_service_spec.rb +57 -0
  31. data/spec/services/lead_sources_service_spec.rb +1 -2
  32. data/spec/services/lead_unqualified_reasons_service_spec.rb +22 -0
  33. data/spec/services/leads_service_spec.rb +1 -2
  34. data/spec/services/line_items_service_spec.rb +0 -1
  35. data/spec/services/loss_reasons_service_spec.rb +1 -2
  36. data/spec/services/notes_service_spec.rb +1 -2
  37. data/spec/services/orders_service_spec.rb +0 -1
  38. data/spec/services/pipelines_service_spec.rb +0 -1
  39. data/spec/services/products_service_spec.rb +1 -2
  40. data/spec/services/sources_service_spec.rb +1 -2
  41. data/spec/services/stages_service_spec.rb +0 -1
  42. data/spec/services/tags_service_spec.rb +1 -2
  43. data/spec/services/tasks_service_spec.rb +1 -2
  44. data/spec/services/users_service_spec.rb +1 -3
  45. metadata +15 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: a9b11989ce99c253d1924a4cf9994e941d28c003d2f4af414224bc0b05990b82
4
- data.tar.gz: 129afc0658fb9f5320fef56bc3f243651e4725ce485a94976c22b3c4c5f0c1f8
2
+ SHA1:
3
+ metadata.gz: c69d41cdc396cd95c74e3bdd2f778aa78ac0cf2e
4
+ data.tar.gz: dc6e97c0e908d384fc7f7eb4ad3abe03f726ecfe
5
5
  SHA512:
6
- metadata.gz: 5330a0039bced2ce1aca5bbb078f8698e495737a41d14a63682638d7cddf4633c9d290cd402ff8e03a34fbffce4c758d0f768bbb1c870fa54d23f6253808eaf8
7
- data.tar.gz: d2bfcdf4ad1868f75bf24ca628c7cf2739391730f99173de9e8068932dec3b6420327e7413fc4a7238b559d043e88f6369ef64573d2e5c778135b650ee0ef0b0
6
+ metadata.gz: 1ce204616d05b6cb7a9ad00e90a910f23cf16e8ec7c4f3541e827bd7ddb9090225b1043c8717980e90e8cf35e6ee47c9960f16edc7cea28022cf1cf5c31fc8e7
7
+ data.tar.gz: ffa2c34f7aafc77cf05cefeffc3e174b4fd2729bafb91c30ea8b94acbffd52cefdf3b025fa60242d4d869646c7ee815cbdc8fbb0cc19bbdec69fa8eb2924c4ac
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015-2017 BaseCRM developers
1
+ Copyright (c) 2015-2018 BaseCRM developers
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -230,6 +230,20 @@ Actions:
230
230
  * Update a source - `client.deal_sources.update`
231
231
  * Delete a source - `client.deal_sources.destroy`
232
232
 
233
+ ### DealUnqualifiedReason
234
+
235
+ ```ruby
236
+ client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
237
+ client.deal_unqualified_reasons # => BaseCRM::DealUnqualifiedReasonsService
238
+ ```
239
+
240
+ Actions:
241
+ * Retrieve all deal unqualified reasons - `client.deal_unqualified_reasons.all`
242
+ * Create a deal unqualified reason - `client.deal_unqualified_reasons.create`
243
+ * Retrieve a single deal unqualified reason - `client.deal_unqualified_reasons.find`
244
+ * Update a deal unqualified reason - `client.deal_unqualified_reasons.update`
245
+ * Delete a deal unqualified reason - `client.deal_unqualified_reasons.destroy`
246
+
233
247
  ### Lead
234
248
 
235
249
  ```ruby
@@ -258,6 +272,16 @@ Actions:
258
272
  * Update a source - `client.lead_sources.update`
259
273
  * Delete a source - `client.lead_sources.destroy`
260
274
 
275
+ ### LeadUnqualifiedReason
276
+
277
+ ```ruby
278
+ client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
279
+ client.lead_unqualified_reasons # => BaseCRM::LeadUnqualifiedReasonsService
280
+ ```
281
+
282
+ Actions:
283
+ * Retrieve all lead unqualified reasons - `client.lead_unqualified_reasons.all`
284
+
261
285
  ### LineItem
262
286
 
263
287
  ```ruby
@@ -17,8 +17,10 @@ require 'basecrm/models/associated_contact'
17
17
  require 'basecrm/models/contact'
18
18
  require 'basecrm/models/deal'
19
19
  require 'basecrm/models/deal_source'
20
+ require 'basecrm/models/deal_unqualified_reason'
20
21
  require 'basecrm/models/lead'
21
22
  require 'basecrm/models/lead_source'
23
+ require 'basecrm/models/lead_unqualified_reason'
22
24
  require 'basecrm/models/line_item'
23
25
  require 'basecrm/models/loss_reason'
24
26
  require 'basecrm/models/note'
@@ -41,8 +43,10 @@ require 'basecrm/services/associated_contacts_service'
41
43
  require 'basecrm/services/contacts_service'
42
44
  require 'basecrm/services/deals_service'
43
45
  require 'basecrm/services/deal_sources_service'
46
+ require 'basecrm/services/deal_unqualified_reasons_service'
44
47
  require 'basecrm/services/leads_service'
45
48
  require 'basecrm/services/lead_sources_service'
49
+ require 'basecrm/services/lead_unqualified_reasons_service'
46
50
  require 'basecrm/services/line_items_service'
47
51
  require 'basecrm/services/loss_reasons_service'
48
52
  require 'basecrm/services/notes_service'
@@ -131,6 +135,15 @@ module BaseCRM
131
135
  @deal_sources ||= DealSourcesService.new(@http_client)
132
136
  end
133
137
 
138
+ # Access all DealUnqualifiedReasons related actions.
139
+ # @see DealUnqualifiedReasonsService
140
+ # @see DealUnqualifiedReason
141
+ #
142
+ # @return [DealUnqualifiedReasonsService] Service object for resources.
143
+ def deal_unqualified_reasons
144
+ @deal_unqualified_reasons ||= DealUnqualifiedReasonsService.new(@http_client)
145
+ end
146
+
134
147
  # Access all Leads related actions.
135
148
  # @see LeadsService
136
149
  # @see Lead
@@ -149,6 +162,15 @@ module BaseCRM
149
162
  @lead_sources ||= LeadSourcesService.new(@http_client)
150
163
  end
151
164
 
165
+ # Access all LeadUnqualifiedReasons related actions.
166
+ # @see LeadUnqualifiedReasonsService
167
+ # @see LeadUnqualifiedReason
168
+ #
169
+ # @return [LeadUnqualifiedReasonsService] Service object for resources.
170
+ def lead_unqualified_reasons
171
+ @lead_unqualified_reasons ||= LeadUnqualifiedReasonsService.new(@http_client)
172
+ end
173
+
152
174
  # Access all LineItems related actions.
153
175
  # @see LineItemsService
154
176
  # @see LineItem
@@ -14,9 +14,6 @@ module BaseCRM
14
14
  # @!attribute [r] id
15
15
  # @return [Integer] Unique identifier of the deal.
16
16
  # attr_reader :id
17
- # @!attribute [r] last_stage_change_at
18
- # @return [DateTime] Date and time when the deal was moved into the current stage in UTC (ISO8601 format).
19
- # attr_reader :last_stage_change_at
20
17
  # @!attribute [r] last_stage_change_by_id
21
18
  # @return [Integer] Unique identifier of the user who moved the deal into the current stage.
22
19
  # attr_reader :last_stage_change_by_id
@@ -45,6 +42,9 @@ module BaseCRM
45
42
  # @!attribute [rw] hot
46
43
  # @return [Boolean] Indicator of whether or not the deal is hot.
47
44
  # attr_accessor :hot
45
+ # @!attribute [rw] last_stage_change_at
46
+ # @return [DateTime] Date and time when the deal was moved into the current stage in UTC (ISO8601 format).
47
+ # attr_accessor :last_stage_change_at
48
48
  # @!attribute [rw] loss_reason_id
49
49
  # @return [Integer] Reason why the deal was lost.
50
50
  # attr_accessor :loss_reason_id
@@ -0,0 +1,22 @@
1
+ # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
2
+
3
+ module BaseCRM
4
+ class DealUnqualifiedReason < Model
5
+ # @!attribute [r] created_at
6
+ # @return [DateTime] Date and time of creation in UTC ISO8601 format.
7
+ # attr_reader :created_at
8
+ # @!attribute [r] creator_id
9
+ # @return [Integer] Unique identifier of the user the deal unqualified reason was created by.
10
+ # attr_reader :creator_id
11
+ # @!attribute [r] id
12
+ # @return [Integer] Unique identifier of the deal unqualified reason.
13
+ # attr_reader :id
14
+ # @!attribute [r] updated_at
15
+ # @return [DateTime] Date and time of the last update in UTC ISO8601 format.
16
+ # attr_reader :updated_at
17
+
18
+ # @!attribute [rw] name
19
+ # @return [String] Human-friendly unqualified reason explanation.
20
+ # attr_accessor :name
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
2
+
3
+ module BaseCRM
4
+ class LeadUnqualifiedReason < Model
5
+ # @!attribute [r] created_at
6
+ # @return [DateTime] Date and time of creation in UTC ISO8601 format.
7
+ # attr_reader :created_at
8
+ # @!attribute [r] creator_id
9
+ # @return [Integer] Unique identifier of the user the lead unqualified reason was created by.
10
+ # attr_reader :creator_id
11
+ # @!attribute [r] id
12
+ # @return [Integer] Unique identifier of the lead unqualified reason.
13
+ # attr_reader :id
14
+ # @!attribute [r] updated_at
15
+ # @return [DateTime] Date and time of the last update in UTC ISO8601 format.
16
+ # attr_reader :updated_at
17
+
18
+ # @!attribute [rw] name
19
+ # @return [String] Human-friendly unqualified reason explanation.
20
+ # attr_accessor :name
21
+ end
22
+ end
@@ -5,14 +5,14 @@ module BaseCRM
5
5
  def initialize(client)
6
6
  @client = client
7
7
  end
8
-
8
+
9
9
  # Retrieve account details
10
- #
10
+ #
11
11
  # get '/accounts/self'
12
12
  #
13
13
  # Returns detailed information about your account
14
14
  #
15
- # @return [Account] Resource object.
15
+ # @return [Account] Resource object.
16
16
  def self
17
17
  _, _, root = @client.get("/accounts/self")
18
18
  Account.new(root[:data])
@@ -9,17 +9,17 @@ module BaseCRM
9
9
  end
10
10
 
11
11
  # Retrieve deal's associated contacts
12
- #
12
+ #
13
13
  # get '/deals/{deal_id}/associated_contacts'
14
14
  #
15
15
  # If you want to use filtering or sorting (see #where).
16
- # @return [Enumerable] Paginated resource you can use to iterate over all the resources.
16
+ # @return [Enumerable] Paginated resource you can use to iterate over all the resources.
17
17
  def all(deal_id)
18
18
  PaginatedResource.new(self, deal_id)
19
19
  end
20
20
 
21
21
  # Retrieve deal's associated contacts
22
- #
22
+ #
23
23
  # get '/deals/{deal_id}/associated_contacts'
24
24
  #
25
25
  # Returns all deal associated contacts
@@ -28,24 +28,24 @@ module BaseCRM
28
28
  # @param options [Hash] Search options
29
29
  # @option options [Integer] :page (1) Page number to start from. Page numbering starts at 1, and omitting the `page` parameter will return the first page.
30
30
  # @option options [Integer] :per_page (25) Number of records to return per page. Default limit is *25* and the maximum number that can be returned is *100*.
31
- # @return [Array<AssociatedContact>] The list of AssociatedContacts for the first page, unless otherwise specified.
31
+ # @return [Array<AssociatedContact>] The list of AssociatedContacts for the first page, unless otherwise specified.
32
32
  def where(deal_id, options = {})
33
33
  _, _, root = @client.get("/deals/#{deal_id}/associated_contacts", options)
34
34
 
35
35
  root[:items].map{ |item| AssociatedContact.new(item[:data]) }
36
36
  end
37
-
37
+
38
38
 
39
39
  # Create an associated contact
40
- #
40
+ #
41
41
  # post '/deals/{deal_id}/associated_contacts'
42
42
  #
43
43
  # Creates a deal's associated contact and its role
44
44
  # If the specified deal or contact does not exist, the request will return an error
45
45
  #
46
46
  # @param deal_id [Integer] Unique identifier of a Deal
47
- # @param associated_contact [AssociatedContact, Hash] Either object of the AssociatedContact type or Hash. This object's attributes describe the object to be created.
48
- # @return [AssociatedContact] The resulting object represting created resource.
47
+ # @param associated_contact [AssociatedContact, Hash] Either object of the AssociatedContact type or Hash. This object's attributes describe the object to be created.
48
+ # @return [AssociatedContact] The resulting object represting created resource.
49
49
  def create(deal_id, associated_contact)
50
50
  validate_type!(associated_contact)
51
51
 
@@ -54,10 +54,10 @@ module BaseCRM
54
54
 
55
55
  AssociatedContact.new(root[:data])
56
56
  end
57
-
57
+
58
58
 
59
59
  # Remove an associated contact
60
- #
60
+ #
61
61
  # delete '/deals/{deal_id}/associated_contacts/{contact_id}'
62
62
  #
63
63
  # Remove a deal's associated contact
@@ -71,7 +71,7 @@ module BaseCRM
71
71
  status, _, _ = @client.delete("/deals/#{deal_id}/associated_contacts/#{contact_id}")
72
72
  status == 204
73
73
  end
74
-
74
+
75
75
 
76
76
  private
77
77
  def validate_type!(associated_contact)
@@ -83,7 +83,7 @@ module BaseCRM
83
83
  raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
84
84
  params
85
85
  end
86
-
86
+
87
87
  def sanitize(associated_contact)
88
88
  associated_contact.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) }
89
89
  end
@@ -9,17 +9,17 @@ module BaseCRM
9
9
  end
10
10
 
11
11
  # Retrieve all contacts
12
- #
12
+ #
13
13
  # get '/contacts'
14
14
  #
15
15
  # If you want to use filtering or sorting (see #where).
16
- # @return [Enumerable] Paginated resource you can use to iterate over all the resources.
16
+ # @return [Enumerable] Paginated resource you can use to iterate over all the resources.
17
17
  def all
18
18
  PaginatedResource.new(self)
19
19
  end
20
20
 
21
21
  # Retrieve all contacts
22
- #
22
+ #
23
23
  # get '/contacts'
24
24
  #
25
25
  # Returns all contacts available to the user according to the parameters provided
@@ -38,23 +38,23 @@ module BaseCRM
38
38
  # @option options [Integer] :page (1) The page number to start from. Page numbering is 1-based and omitting the `page` parameter will return the first page.
39
39
  # @option options [Integer] :per_page (25) The number of records to return per page. Default limit is *25* and maximum number that can be returned is *100*.
40
40
  # @option options [String] :sort_by (last_name:asc) A field to sort by. **Default** ordering is **ascending**. If you want to change the sort order to descending, append `:desc` to the field e.g. `sort_by=last_name:desc`.
41
- # @return [Array<Contact>] The list of Contacts for the first page, unless otherwise specified.
41
+ # @return [Array<Contact>] The list of Contacts for the first page, unless otherwise specified.
42
42
  def where(options = {})
43
43
  _, _, root = @client.get("/contacts", options)
44
44
 
45
45
  root[:items].map{ |item| Contact.new(item[:data]) }
46
46
  end
47
-
47
+
48
48
 
49
49
  # Create a contact
50
- #
50
+ #
51
51
  # post '/contacts'
52
52
  #
53
53
  # Create a new contact
54
54
  # A contact may represent a single individual or an organization
55
55
  #
56
- # @param contact [Contact, Hash] Either object of the Contact type or Hash. This object's attributes describe the object to be created.
57
- # @return [Contact] The resulting object represting created resource.
56
+ # @param contact [Contact, Hash] Either object of the Contact type or Hash. This object's attributes describe the object to be created.
57
+ # @return [Contact] The resulting object represting created resource.
58
58
  def create(contact)
59
59
  validate_type!(contact)
60
60
 
@@ -63,26 +63,26 @@ module BaseCRM
63
63
 
64
64
  Contact.new(root[:data])
65
65
  end
66
-
66
+
67
67
 
68
68
  # Retrieve a single contact
69
- #
69
+ #
70
70
  # get '/contacts/{id}'
71
71
  #
72
72
  # Returns a single contact available to the user, according to the unique contact ID provided
73
73
  # If the specified contact does not exist, the request will return an error
74
74
  #
75
75
  # @param id [Integer] Unique identifier of a Contact
76
- # @return [Contact] Searched resource object.
76
+ # @return [Contact] Searched resource object.
77
77
  def find(id)
78
78
  _, _, root = @client.get("/contacts/#{id}")
79
79
 
80
80
  Contact.new(root[:data])
81
81
  end
82
-
82
+
83
83
 
84
84
  # Update a contact
85
- #
85
+ #
86
86
  # put '/contacts/{id}'
87
87
  #
88
88
  # Updates contact information
@@ -90,8 +90,8 @@ module BaseCRM
90
90
  # **Notice** When updating contact tags, you need to provide all tags
91
91
  # Any missing tag will be removed from a contact's tags
92
92
  #
93
- # @param contact [Contact, Hash] Either object of the Contact type or Hash. This object's attributes describe the object to be updated.
94
- # @return [Contact] The resulting object represting updated resource.
93
+ # @param contact [Contact, Hash] Either object of the Contact type or Hash. This object's attributes describe the object to be updated.
94
+ # @return [Contact] The resulting object represting updated resource.
95
95
  def update(contact)
96
96
  validate_type!(contact)
97
97
  params = extract_params!(contact, :id)
@@ -102,10 +102,10 @@ module BaseCRM
102
102
 
103
103
  Contact.new(root[:data])
104
104
  end
105
-
105
+
106
106
 
107
107
  # Delete a contact
108
- #
108
+ #
109
109
  # delete '/contacts/{id}'
110
110
  #
111
111
  # Delete an existing contact
@@ -118,7 +118,7 @@ module BaseCRM
118
118
  status, _, _ = @client.delete("/contacts/#{id}")
119
119
  status == 204
120
120
  end
121
-
121
+
122
122
 
123
123
  private
124
124
  def validate_type!(contact)
@@ -130,7 +130,7 @@ module BaseCRM
130
130
  raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
131
131
  params
132
132
  end
133
-
133
+
134
134
  def sanitize(contact)
135
135
  contact.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) }
136
136
  end
@@ -0,0 +1,133 @@
1
+ # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
2
+
3
+ module BaseCRM
4
+ class DealUnqualifiedReasonsService
5
+ OPTS_KEYS_TO_PERSIST = Set[:name]
6
+
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ # Retrieve all deal unqualified reasons
12
+ #
13
+ # get '/deal_unqualified_reasons'
14
+ #
15
+ # If you want to use filtering or sorting (see #where).
16
+ # @return [Enumerable] Paginated resource you can use to iterate over all the resources.
17
+ def all
18
+ PaginatedResource.new(self)
19
+ end
20
+
21
+ # Retrieve all deal unqualified reasons
22
+ #
23
+ # get '/deal_unqualified_reasons'
24
+ #
25
+ # Returns all deal unqualified reasons available to the user according to the parameters provided
26
+ #
27
+ # @param options [Hash] Search options
28
+ # @option options [String] :ids Comma separated list of deal unqualified reasons unique identifiers to be returned in a request.
29
+ # @option options [String] :name Name of the deal unqualified reason to search for. This parameter is used in a strict sense.
30
+ # @option options [Integer] :page (1) Page number to start from. Page numbering is 1-based and omitting `page` parameter will return the first page.
31
+ # @option options [Integer] :per_page (25) Number of records to return per page. Default limit is *25* and maximum number that can be returned is *100*.
32
+ # @option options [String] :sort_by (id:asc) A field to sort by. **Default** ordering is **ascending**. If you want to change the sort ordering to descending, append `:desc` to the field e.g. `sort_by=name:desc`.
33
+ # @return [Array<DealUnqualifiedReason>] The list of DealUnqualifiedReasons for the first page, unless otherwise specified.
34
+ def where(options = {})
35
+ _, _, root = @client.get("/deal_unqualified_reasons", options)
36
+
37
+ root[:items].map{ |item| DealUnqualifiedReason.new(item[:data]) }
38
+ end
39
+
40
+
41
+ # Create a deal unqualified reason
42
+ #
43
+ # post '/deal_unqualified_reasons'
44
+ #
45
+ # Create a new deal unqualified reason
46
+ # <figure class="notice">
47
+ # Deal unqualified reason's name **must** be unique
48
+ # </figure>
49
+ #
50
+ # @param deal_unqualified_reason [DealUnqualifiedReason, Hash] Either object of the DealUnqualifiedReason type or Hash. This object's attributes describe the object to be created.
51
+ # @return [DealUnqualifiedReason] The resulting object represting created resource.
52
+ def create(deal_unqualified_reason)
53
+ validate_type!(deal_unqualified_reason)
54
+
55
+ attributes = sanitize(deal_unqualified_reason)
56
+ _, _, root = @client.post("/deal_unqualified_reasons", attributes)
57
+
58
+ DealUnqualifiedReason.new(root[:data])
59
+ end
60
+
61
+
62
+ # Retrieve a single deal unqualified reason
63
+ #
64
+ # get '/deal_unqualified_reasons/{id}'
65
+ #
66
+ # Returns a single deal unqualified reason available to the user by the provided id
67
+ # If a loss reason with the supplied unique identifier does not exist, it returns an error
68
+ #
69
+ # @param id [Integer] Unique identifier of a DealUnqualifiedReason
70
+ # @return [DealUnqualifiedReason] Searched resource object.
71
+ def find(id)
72
+ _, _, root = @client.get("/deal_unqualified_reasons/#{id}")
73
+
74
+ DealUnqualifiedReason.new(root[:data])
75
+ end
76
+
77
+
78
+ # Update a deal unqualified reason
79
+ #
80
+ # put '/deal_unqualified_reasons/{id}'
81
+ #
82
+ # Updates a deal unqualified reason information
83
+ # If the specified deal unqualified reason does not exist, the request will return an error
84
+ # <figure class="notice">
85
+ # If you want to update deal unqualified reason you **must** make sure name of the reason is unique
86
+ # </figure>
87
+ #
88
+ # @param deal_unqualified_reason [DealUnqualifiedReason, Hash] Either object of the DealUnqualifiedReason type or Hash. This object's attributes describe the object to be updated.
89
+ # @return [DealUnqualifiedReason] The resulting object represting updated resource.
90
+ def update(deal_unqualified_reason)
91
+ validate_type!(deal_unqualified_reason)
92
+ params = extract_params!(deal_unqualified_reason, :id)
93
+ id = params[:id]
94
+
95
+ attributes = sanitize(deal_unqualified_reason)
96
+ _, _, root = @client.put("/deal_unqualified_reasons/#{id}", attributes)
97
+
98
+ DealUnqualifiedReason.new(root[:data])
99
+ end
100
+
101
+
102
+ # Delete a deal unqualified reason
103
+ #
104
+ # delete '/deal_unqualified_reasons/{id}'
105
+ #
106
+ # Delete an existing deal unqualified reason
107
+ # If the reason with supplied unique identifier does not exist it returns an error
108
+ # This operation cannot be undone
109
+ #
110
+ # @param id [Integer] Unique identifier of a DealUnqualifiedReason
111
+ # @return [Boolean] Status of the operation.
112
+ def destroy(id)
113
+ status, _, _ = @client.delete("/deal_unqualified_reasons/#{id}")
114
+ status == 204
115
+ end
116
+
117
+
118
+ private
119
+ def validate_type!(deal_unqualified_reason)
120
+ raise TypeError unless deal_unqualified_reason.is_a?(DealUnqualifiedReason) || deal_unqualified_reason.is_a?(Hash)
121
+ end
122
+
123
+ def extract_params!(deal_unqualified_reason, *args)
124
+ params = deal_unqualified_reason.to_h.select{ |k, _| args.include?(k) }
125
+ raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
126
+ params
127
+ end
128
+
129
+ def sanitize(deal_unqualified_reason)
130
+ deal_unqualified_reason.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) }
131
+ end
132
+ end
133
+ end