Class: Intercom::Client

Inherits:
Object
  • Object
show all
Includes:
DeprecatedResources, Options
Defined in:
lib/intercom/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DeprecatedResources

#deprecated__leads, #deprecated__users

Methods included from Options

#options

Constructor Details

#initialize(token: nil, base_url: 'https://api.intercom.io', handle_rate_limit: false, api_version: nil) ⇒ Client

Returns a new instance of Client.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/intercom/client.rb', line 31

def initialize(token: nil, base_url: 'https://api.intercom.io', handle_rate_limit: false, api_version: nil)
  @token = token
  validate_credentials!

  @api_version = api_version
  validate_api_version!

  @base_url = base_url
  @rate_limit_details = {}
  @handle_rate_limit = handle_rate_limit
  @timeouts = {
    open_timeout: 30,
    read_timeout: 90
  }
end

Instance Attribute Details

#api_versionObject (readonly)

Returns the value of attribute api_version.



8
9
10
# File 'lib/intercom/client.rb', line 8

def api_version
  @api_version
end

#base_urlObject

Returns the value of attribute base_url.



8
9
10
# File 'lib/intercom/client.rb', line 8

def base_url
  @base_url
end

#handle_rate_limitObject (readonly)

Returns the value of attribute handle_rate_limit.



8
9
10
# File 'lib/intercom/client.rb', line 8

def handle_rate_limit
  @handle_rate_limit
end

#rate_limit_detailsObject (readonly)

Returns the value of attribute rate_limit_details.



8
9
10
# File 'lib/intercom/client.rb', line 8

def rate_limit_details
  @rate_limit_details
end

#timeoutsObject

Returns the value of attribute timeouts.



8
9
10
# File 'lib/intercom/client.rb', line 8

def timeouts
  @timeouts
end

#tokenObject (readonly)

Returns the value of attribute token.



8
9
10
# File 'lib/intercom/client.rb', line 8

def token
  @token
end

Class Method Details

.set_base_url(base_url) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/intercom/client.rb', line 11

def set_base_url(base_url)
  proc do |o|
    old_url = o.base_url
    o.send(:base_url=, base_url)
    proc { |_obj| set_base_url(old_url).call(o) }
  end
end

.set_timeouts(open_timeout: nil, read_timeout: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/intercom/client.rb', line 19

def set_timeouts(open_timeout: nil, read_timeout: nil)
  proc do |o|
    old_timeouts = o.timeouts
    timeouts = {}
    timeouts[:open_timeout] = open_timeout if open_timeout
    timeouts[:read_timeout] = read_timeout if read_timeout
    o.send(:timeouts=, timeouts)
    proc { |_obj| set_timeouts(old_timeouts).call(o) }
  end
end

Instance Method Details

#adminsObject



47
48
49
# File 'lib/intercom/client.rb', line 47

def admins
  Intercom::Service::Admin.new(self)
end

#articlesObject



51
52
53
# File 'lib/intercom/client.rb', line 51

def articles
  Intercom::Service::Article.new(self)
end

#collectionsObject



127
128
129
# File 'lib/intercom/client.rb', line 127

def collections
  Intercom::Service::Collection.new(self)
end

#companiesObject



55
56
57
# File 'lib/intercom/client.rb', line 55

def companies
  Intercom::Service::Company.new(self)
end

#contactsObject



59
60
61
# File 'lib/intercom/client.rb', line 59

def contacts
  Intercom::Service::Contact.new(self)
end

#conversationsObject



63
64
65
# File 'lib/intercom/client.rb', line 63

def conversations
  Intercom::Service::Conversation.new(self)
end

#countsObject



67
68
69
# File 'lib/intercom/client.rb', line 67

def counts
  Intercom::Service::Counts.new(self)
end

#data_attributesObject



123
124
125
# File 'lib/intercom/client.rb', line 123

def data_attributes
  Intercom::Service::DataAttribute.new(self)
end

#delete(path, payload_hash) ⇒ Object



151
152
153
# File 'lib/intercom/client.rb', line 151

def delete(path, payload_hash)
  execute_request Intercom::Request.delete(path, payload_hash)
end

#eventsObject



71
72
73
# File 'lib/intercom/client.rb', line 71

def events
  Intercom::Service::Event.new(self)
end

#export_contentObject



131
132
133
# File 'lib/intercom/client.rb', line 131

def export_content
  Intercom::Service::ExportContent.new(self)
end

#get(path, params) ⇒ Object



139
140
141
# File 'lib/intercom/client.rb', line 139

def get(path, params)
  execute_request Intercom::Request.get(path, params)
end

#jobsObject



119
120
121
# File 'lib/intercom/client.rb', line 119

def jobs
  Intercom::Service::Job.new(self)
end

#leadsObject



111
112
113
# File 'lib/intercom/client.rb', line 111

def leads
  Intercom::Service::Lead.new(self)
end

#messagesObject



75
76
77
# File 'lib/intercom/client.rb', line 75

def messages
  Intercom::Service::Message.new(self)
end

#notesObject



79
80
81
# File 'lib/intercom/client.rb', line 79

def notes
  Intercom::Service::Note.new(self)
end

#phone_call_redirectObject



135
136
137
# File 'lib/intercom/client.rb', line 135

def phone_call_redirect
  Intercom::Service::PhoneCallRedirect.new(self)
end

#post(path, payload_hash) ⇒ Object



143
144
145
# File 'lib/intercom/client.rb', line 143

def post(path, payload_hash)
  execute_request Intercom::Request.post(path, payload_hash)
end

#put(path, payload_hash) ⇒ Object



147
148
149
# File 'lib/intercom/client.rb', line 147

def put(path, payload_hash)
  execute_request Intercom::Request.put(path, payload_hash)
end

#sectionsObject



95
96
97
# File 'lib/intercom/client.rb', line 95

def sections
  Intercom::Service::Section.new(self)
end

#segmentsObject



91
92
93
# File 'lib/intercom/client.rb', line 91

def segments
  Intercom::Service::Segment.new(self)
end

#subscription_typesObject



87
88
89
# File 'lib/intercom/client.rb', line 87

def subscription_types
  Intercom::Service::SubscriptionType.new(self)
end

#subscriptionsObject



83
84
85
# File 'lib/intercom/client.rb', line 83

def subscriptions
  Intercom::Service::Subscription.new(self)
end

#tagsObject



99
100
101
# File 'lib/intercom/client.rb', line 99

def tags
  Intercom::Service::Tag.new(self)
end

#teamsObject



103
104
105
# File 'lib/intercom/client.rb', line 103

def teams
  Intercom::Service::Team.new(self)
end

#usersObject



107
108
109
# File 'lib/intercom/client.rb', line 107

def users
  Intercom::Service::User.new(self)
end

#visitorsObject



115
116
117
# File 'lib/intercom/client.rb', line 115

def visitors
  Intercom::Service::Visitor.new(self)
end