Class: Buezli::Api::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/buezli/api/client.rb,
lib/buezli/api/client/list.rb,
lib/buezli/api/client/error.rb,
lib/buezli/api/client/record.rb,
lib/buezli/api/client/download.rb

Defined Under Namespace

Classes: Download, Error, List, Record

Constant Summary collapse

DEFAULT_ENDPOINT =
"https://api.buezli.app"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token:, endpoint: DEFAULT_ENDPOINT, version: nil, schema: nil, host: nil) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
# File 'lib/buezli/api/client.rb', line 8

def initialize(access_token:, endpoint: DEFAULT_ENDPOINT, version: nil, schema: nil, host: nil)
  @access_token = access_token
  @endpoint = endpoint.chomp("/")
  @schema = schema || load_schema(version)
  @version = version || @schema.version
  @host = host
  raise ArgumentError, "Schema version does not match requested version" if @schema.version != @version

  define_methods_from_schema
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



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

def access_token
  @access_token
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



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

def endpoint
  @endpoint
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#schemaObject (readonly)

Returns the value of attribute schema.



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

def schema
  @schema
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#build_record(model_name, attributes) ⇒ Object



19
20
21
# File 'lib/buezli/api/client.rb', line 19

def build_record(model_name, attributes)
  Record.new(attributes:, model_name:, api_client: self, schema:)
end

#inspectObject



23
24
25
# File 'lib/buezli/api/client.rb', line 23

def inspect
  "#<#{self.class.name} endpoint=#{endpoint.inspect} version=#{version.inspect} host=#{host.inspect}>"
end