Class: KaChing::ApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/ka_ching/api_client.rb

Overview

The base class for all API versions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_version: :v1, base_url: 'http://localhost:9292') ⇒ ApiClient

Returns a new instance of ApiClient.



11
12
13
14
# File 'lib/ka_ching/api_client.rb', line 11

def initialize(api_version: :v1, base_url: 'http://localhost:9292')
  @api_version = api_version
  @base_url = base_url
end

Instance Attribute Details

#api_versionObject (readonly)

Returns the value of attribute api_version.



9
10
11
# File 'lib/ka_ching/api_client.rb', line 9

def api_version
  @api_version
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



9
10
11
# File 'lib/ka_ching/api_client.rb', line 9

def base_url
  @base_url
end

#connObject

Returns the value of attribute conn.



8
9
10
# File 'lib/ka_ching/api_client.rb', line 8

def conn
  @conn
end

#v1Object (readonly)

Returns the value of attribute v1.



9
10
11
# File 'lib/ka_ching/api_client.rb', line 9

def v1
  @v1
end

Instance Method Details

#build_client!(faraday: nil) ⇒ Object



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

def build_client!(faraday: nil)
  @conn = faraday || default_faraday
  case @api_version
  when :v1, 'v1'
    @v1 = KaChing::ApiV1::Client.new(conn: @conn, base_url: @base_url)
  else
    raise ArgumentError, "Unknown API version: #{@api_version}"
  end
  self
end