Class: StitchData::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/stitch_data/api.rb

Constant Summary collapse

API_BASE_URL =
'https://api.stitchdata.com/v2/import'.freeze
DEFAULT_API_ACTION =
"upsert".freeze
DEFAULT_REQUEST_PARAMS =
{ content_type: 'application/json', accept: 'json' }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name, sequence, key_names, data) ⇒ Api

Returns a new instance of Api.



8
9
10
11
12
13
14
15
# File 'lib/stitch_data/api.rb', line 8

def initialize(table_name, sequence, key_names, data)
  validate_key_names_is_array(key_names)
  @request_params = { Authorization: "Bearer #{StitchData.configuration.token}" }.merge(DEFAULT_REQUEST_PARAMS)
  @table_name = table_name.to_s
  @sequence = sequence.to_sym
  @key_names = key_names.map(&:to_s)
  @data = build_records(data)
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/stitch_data/api.rb', line 3

def data
  @data
end

#key_namesObject

Returns the value of attribute key_names.



3
4
5
# File 'lib/stitch_data/api.rb', line 3

def key_names
  @key_names
end

#sequenceObject

Returns the value of attribute sequence.



3
4
5
# File 'lib/stitch_data/api.rb', line 3

def sequence
  @sequence
end

#table_nameObject

Returns the value of attribute table_name.



3
4
5
# File 'lib/stitch_data/api.rb', line 3

def table_name
  @table_name
end

Instance Method Details

#upsert!Object



17
18
19
# File 'lib/stitch_data/api.rb', line 17

def upsert!
  stitch_post_request("#{API_BASE_URL}/push")
end

#validate!Object



21
22
23
# File 'lib/stitch_data/api.rb', line 21

def validate!
  stitch_post_request("#{API_BASE_URL}/validate")
end