Class: IllyanClient::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: nil, token: nil) ⇒ Client



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

def initialize(base_url: nil, token: nil)
  @base_url = base_url || IllyanClient.base_url
  @token = token || IllyanClient.token
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



6
7
8
# File 'lib/illyan_client/client.rb', line 6

def base_url
  @base_url
end

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/illyan_client/client.rb', line 6

def token
  @token
end

Instance Method Details

#connectionObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/illyan_client/client.rb', line 13

def connection
  @connection ||= Faraday.new(url: base_url, headers: {'Accept' => 'application/json'}) do |conn|
    conn.request :basic_auth, token, ''
    conn.request :json
    
    conn.response :json
    conn.response :logger
    
    conn.adapter Faraday.default_adapter
  end
end

#create_person(person) ⇒ Object



25
26
27
# File 'lib/illyan_client/client.rb', line 25

def create_person(person)
  connection.post "/admin/people", { person: person.serializable_hash }
end