Sha256: 3a9ec8d03342975ff0b6f2be2232f5e53a87177562343a30c86ae9a361c4dfd7

Contents?: true

Size: 2 KB

Versions: 8

Compression:

Stored size: 2 KB

Contents

module Intercom
  class Client
    include Options
    attr_reader :base_url, :rate_limit_details

    class << self
      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
    end

    def initialize(app_id: 'my_app_id', api_key: 'my_api_key')
      @app_id = app_id
      @api_key = api_key
      @base_url = 'https://api.intercom.io'
      @rate_limit_details = {}
    end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    private

    def execute_request(request)
      result = request.execute(@base_url, username: @app_id, secret: @api_key)
      @rate_limit_details = request.rate_limit_details
      result
    end

    def base_url=(new_url)
      @base_url = new_url
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
intercom-3.2.0 lib/intercom/client.rb
intercom-3.1.0 lib/intercom/client.rb
intercom-3.0.6 lib/intercom/client.rb
intercom-3.0.5 lib/intercom/client.rb
intercom-3.0.4 lib/intercom/client.rb
intercom-3.0.3 lib/intercom/client.rb
intercom-3.0.2 lib/intercom/client.rb
intercom-3.0.0 lib/intercom/client.rb