File tree Expand file tree Collapse file tree 9 files changed +76
-3
lines changed
Expand file tree Collapse file tree 9 files changed +76
-3
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,16 @@ contact.remove_company(id: company.id)
162162
163163# List companies for a contact
164164contact.companies.each {|c | p c.name}
165+
166+ # attach a subscription_types on a contact
167+ contact.create_subscription_types(id: ' 1' )
168+
169+ # List subscription_types for a contact
170+ contact.subscription_types.each {|n | p n.body}
171+
172+ # Remove subscription_types
173+ contact.remove_subscription_type({ " id" : subscription.id })
174+
165175```
166176
167177#### Visitors
@@ -586,6 +596,19 @@ intercom.subscriptions.delete(subscription)
586596intercom.subscriptions.all
587597```
588598
599+
600+ #### Subscription Types
601+
602+ Subscribe to events in Intercom to receive webhooks.
603+
604+ ``` ruby
605+
606+ # fetch a subscription
607+ intercom.subscription_types.find(id: " 1" )
608+
609+ intercom.subscription_types.all
610+ ```
611+
589612#### Articles
590613
591614``` ruby
Original file line number Diff line number Diff line change 1212require 'intercom/service/message'
1313require 'intercom/service/note'
1414require 'intercom/service/job'
15+ require 'intercom/service/subscription_type'
1516require 'intercom/service/subscription'
1617require 'intercom/service/segment'
1718require 'intercom/service/section'
4445require 'intercom/article'
4546require 'intercom/request'
4647require 'intercom/subscription'
48+ require 'intercom/subscription_type'
4749require 'intercom/team'
4850require 'intercom/errors'
4951require 'intercom/visitor'
Original file line number Diff line number Diff line change @@ -13,9 +13,7 @@ def nested_resource_methods(resource,
1313 raise ArgumentError , 'operations array required' if operations . nil?
1414
1515 resource_url_method = :"#{ resource_plural } _url"
16-
1716 resource_name = Utils . resource_class_to_collection_name ( self )
18-
1917 define_method ( resource_url_method . to_sym ) do |id , nested_id = nil |
2018 url = "/#{ resource_name } /#{ id } /#{ path } "
2119 url += "/#{ nested_id } " unless nested_id . nil?
Original file line number Diff line number Diff line change @@ -84,6 +84,10 @@ def subscriptions
8484 Intercom ::Service ::Subscription . new ( self )
8585 end
8686
87+ def subscription_types
88+ Intercom ::Service ::SubscriptionType . new ( self )
89+ end
90+
8791 def segments
8892 Intercom ::Service ::Segment . new ( self )
8993 end
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ class Contact
1212
1313 nested_resource_methods :tag , operations : %i[ add delete list ]
1414 nested_resource_methods :note , operations : %i[ create list ]
15+ nested_resource_methods :subscription_type , operations : %i[ create delete list ]
1516 nested_resource_methods :company , operations : %i[ add delete list ]
1617 nested_resource_methods :segment , operations : %i[ list ]
1718
Original file line number Diff line number Diff line change 1+ require 'intercom/api_operations/list'
2+ require 'intercom/api_operations/find_all'
3+ require 'intercom/api_operations/find'
4+
5+ module Intercom
6+ module Service
7+ class SubscriptionType < BaseService
8+ include ApiOperations ::List
9+ include ApiOperations ::Find
10+ include ApiOperations ::FindAll
11+ include ApiOperations ::Delete
12+
13+ def collection_class
14+ Intercom ::SubscriptionType
15+ end
16+ end
17+ end
18+ end
Original file line number Diff line number Diff line change 1+
2+ require 'intercom/traits/api_resource'
3+
4+ module Intercom
5+ class SubscriptionType
6+ include Traits ::ApiResource
7+
8+ def self . collection_proxy_class
9+ Intercom ::BaseCollectionProxy
10+ end
11+ end
12+ end
Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ def constantize(camel_cased_word)
2525 constant
2626 end
2727
28+ def camelize ( snake_cased_word )
29+ snake_cased_word . split ( /_/ ) . map ( &:capitalize ) . join
30+ end
31+
2832 def resource_class_to_singular_name ( resource_class )
2933 resource_name = resource_class . to_s . split ( '::' ) [ -1 ]
3034 resource_name = maybe_underscore_name ( resource_name )
@@ -40,7 +44,7 @@ def resource_class_to_collection_name(resource_class)
4044 end
4145
4246 def constantize_resource_name ( resource_name )
43- class_name = Utils . singularize ( resource_name . capitalize )
47+ class_name = camelize Utils . singularize ( resource_name . capitalize )
4448 define_lightweight_class ( class_name ) unless Intercom . const_defined? ( class_name , false )
4549 namespaced_class_name = "Intercom::#{ class_name } "
4650 constantize namespaced_class_name
Original file line number Diff line number Diff line change 276276 let ( :contact ) { Intercom ::Contact . new ( id : '1' , client : client ) }
277277 let ( :contact_no_tags ) { Intercom ::Contact . new ( id : '2' , client : client , tags : [ ] ) }
278278 let ( :company ) { Intercom ::Company . new ( id : '1' ) }
279+ let ( :subscription ) { Intercom ::Subscription . new ( id : '1' , client : client ) }
279280 let ( :tag ) { Intercom ::Tag . new ( id : '1' ) }
280281 let ( :note ) { Intercom ::Note . new ( body : "<p>Text for the note</p>" ) }
281282
338339 contact . add_tag ( { "id" : tag . id } )
339340 end
340341
342+ it 'removes a subscription to a contact' do
343+ client . expects ( :delete ) . with ( "/contacts/1/subscription_types/#{ subscription . id } " , "id" : subscription . id ) . returns ( subscription . to_hash )
344+ contact . remove_subscription_type ( { "id" : subscription . id } )
345+ end
346+
341347 it 'removes a tag from a contact' do
342348 client . expects ( :delete ) . with ( "/contacts/1/tags/#{ tag . id } " , "id" : tag . id ) . returns ( tag . to_hash )
343349 contact . remove_tag ( { "id" : tag . id } )
387393 contact . create_note ( { body : note . body } )
388394 end
389395
396+ it 'adds a subscription to a contact' do
397+ client . expects ( :post ) . with ( '/contacts/1/subscription_types' , "id" : subscription . id ) . returns ( subscription . to_hash )
398+ contact . create_subscription_type ( { "id" : subscription . id } )
399+ end
400+
390401 it 'adds a tag to a contact' do
391402 client . expects ( :post ) . with ( '/contacts/1/tags' , "id" : tag . id ) . returns ( tag . to_hash )
392403 contact . add_tag ( { "id" : tag . id } )
You can’t perform that action at this time.
0 commit comments