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) ⇒ Client

Returns a new instance of Client.


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

def initialize(app_id: 'my_app_id', api_key: 'my_api_key', token: nil, base_url:'https://api.intercom.io', handle_rate_limit: false)
  if token
    @username_part = token
    @password_part = ""
  else
    @username_part = app_id
    @password_part = api_key
  end
  validate_credentials!

  @base_url = base_url
  @rate_limit_details = {}
  @handle_rate_limit = handle_rate_limit
end

Instance Attribute Details

#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

#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

Instance Method Details

#adminsObject


32
33
34
# File 'lib/intercom/client.rb', line 32

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

#companiesObject


36
37
38
# File 'lib/intercom/client.rb', line 36

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

#contactsObject


40
41
42
# File 'lib/intercom/client.rb', line 40

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

#conversationsObject


44
45
46
# File 'lib/intercom/client.rb', line 44

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

#countsObject


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

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

#delete(path, payload_hash) ⇒ Object


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

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

#eventsObject


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

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

#get(path, params) ⇒ Object


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

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

#jobsObject


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

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

#messagesObject


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

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

#notesObject


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

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

#post(path, payload_hash) ⇒ Object


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

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

#put(path, payload_hash) ⇒ Object


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

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

#segmentsObject


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

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

#subscriptionsObject


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

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

#tagsObject


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

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

#usersObject


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

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

#visitorsObject


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

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