Class: IdentityCRM::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/identity_crm/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user: nil, token: nil, url: nil) ⇒ Client

Returns a new instance of Client.



3
4
5
6
7
8
9
10
# File 'lib/identity_crm/client.rb', line 3

def initialize user: nil, token: nil, url: nil
  @url = url.chomp('/')
  raise 'Identity URL is not valid' if URI.parse(@url).host.blank?
  raise 'A username and token is mandatory' unless [user, token].all? &:present?

  @user = user
  @token = token
end

Class Method Details

.resource(path) ⇒ Object



16
17
18
19
20
# File 'lib/identity_crm/client.rb', line 16

def self.resource path
  define_method path do
    IdentityCRM::Resource.new "#{base_url}/#{path}", @user, @token
  end
end

Instance Method Details

#base_urlObject



12
13
14
# File 'lib/identity_crm/client.rb', line 12

def base_url
  "#{@url}/api/v2"
end