Class: Intercom::Client

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Options

#options

Constructor Details

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

Returns a new instance of Client.



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

def initialize(app_id: 'my_app_id', api_key: 'my_api_key', token: nil, base_url:'https://api.intercom.io', handle_rate_limit: false, api_version: nil)
  if token
    @username_part = token
    @password_part = ""
  else
    @username_part = app_id
    @password_part = api_key
  end
  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.



5
6
7
# File 'lib/intercom/client.rb', line 5

def api_version
  @api_version
end

#base_urlObject

Returns the value of attribute base_url.



5
6
7
# File 'lib/intercom/client.rb', line 5

def base_url
  @base_url
end

#handle_rate_limitObject (readonly)

Returns the value of attribute handle_rate_limit.



5
6
7
# File 'lib/intercom/client.rb', line 5

def handle_rate_limit
  @handle_rate_limit
end

#password_partObject (readonly)

Returns the value of attribute password_part.



5
6
7
# File 'lib/intercom/client.rb', line 5

def password_part
  @password_part
end

#rate_limit_detailsObject (readonly)

Returns the value of attribute rate_limit_details.



5
6
7
# File 'lib/intercom/client.rb', line 5

def rate_limit_details
  @rate_limit_details
end

#timeoutsObject

Returns the value of attribute timeouts.



5
6
7
# File 'lib/intercom/client.rb', line 5

def timeouts
  @timeouts
end

#username_partObject (readonly)

Returns the value of attribute username_part.



5
6
7
# File 'lib/intercom/client.rb', line 5

def username_part
  @username_part
end

Class Method Details

.set_base_url(base_url) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/intercom/client.rb', line 8

def set_base_url(base_url)
  return Proc.new do |o|
    old_url = o.base_url
    o.send(:base_url=, base_url)
    Proc.new { |obj| set_base_url(old_url).call(o) }
  end
end

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



16
17
18
19
20
21
22
23
24
25
# File 'lib/intercom/client.rb', line 16

def set_timeouts(open_timeout: nil, read_timeout: nil)
  return Proc.new 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.new { |obj| set_timeouts(old_timeouts).call(o) }
  end
end

Instance Method Details

#adminsObject



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

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

#companiesObject



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

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

#contactsObject



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

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

#conversationsObject



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

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

#countsObject



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

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

#delete(path, payload_hash) ⇒ Object



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

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

#eventsObject



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

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

#get(path, params) ⇒ Object



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

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

#jobsObject



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

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

#messagesObject



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

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

#notesObject



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

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

#post(path, payload_hash) ⇒ Object



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

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

#put(path, payload_hash) ⇒ Object



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

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

#segmentsObject



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

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

#subscriptionsObject



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

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

#tagsObject



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

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

#usersObject



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

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

#visitorsObject



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

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