Class: SplitApi::Models::Attributes

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/splitapi-rb/models/attributes.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Attributes

Returns a new instance of Attributes.



7
8
9
# File 'lib/splitapi-rb/models/attributes.rb', line 7

def initialize(config)
  @config = config
end

Instance Method Details

#delete(traffic_type_id, attribute_id) ⇒ Object

DELETE /trafficTypes/traffic_type_id/schema/attribute_id



57
58
59
60
61
62
# File 'lib/splitapi-rb/models/attributes.rb', line 57

def delete(traffic_type_id, attribute_id)
  RestClient.delete(
    "#{@config.base_uri}/trafficTypes/#{traffic_type_id}" \
    "/schema/#{attribute_id}",
    auth_headers) == 'true'
end

#list(traffic_type_id) ⇒ Object

GET /trafficTypes/traffic_type_id/schema



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/splitapi-rb/models/attributes.rb', line 12

def list(traffic_type_id)
  JSON.parse(
    RestClient.get(
      "#{@config.base_uri}/trafficTypes/#{traffic_type_id}/schema", auth_headers
    ).body
  ).map do |attribute|
    DataObjects::Attribute.new(
      description: attribute['description'],
      display_name: attribute['displayName'],
      traffic_type_id: attribute['trafficTypeId'],
      id: attribute['id'],
      organization_id: attribute['organizationId'],
      data_type: attribute['dataType'],
      is_searchable: attribute['isSearchable']
    )
  end
end

#save(attribute) ⇒ Object

PUT /trafficTypes/traffic_type_id/schema



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/splitapi-rb/models/attributes.rb', line 31

def save(attribute)
  attribute = JSON.parse(
    RestClient.put(
      "#{@config.base_uri}/trafficTypes/#{attribute[:traffic_type_id]}/schema",
      {
        'id' => attribute[:id],
        'trafficTypeId' => attribute[:traffic_type_id],
        'displayName' => attribute[:display_name],
        'description' => attribute[:description],
        'dataType' => attribute[:data_type]
      }.to_json, auth_headers
    ).body
  )

  DataObjects::Attribute.new(
    description: attribute['description'],
    display_name: attribute['displayName'],
    traffic_type_id: attribute['trafficTypeId'],
    id: attribute['id'],
    organization_id: attribute['organizationId'],
    data_type: attribute['dataType'],
    is_searchable: attribute['isSearchable']
  )
end