Class: Pixela::Pixel

Inherits:
Object
  • Object
show all
Defined in:
lib/pixela/pixel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, graph_id:, date:) ⇒ Pixel

Returns a new instance of Pixel.

Parameters:



18
19
20
21
22
# File 'lib/pixela/pixel.rb', line 18

def initialize(client:, graph_id:, date:)
  @client   = client
  @graph_id = graph_id
  @date     = date
end

Instance Attribute Details

#clientPixela::Client (readonly)

Returns:



5
6
7
# File 'lib/pixela/pixel.rb', line 5

def client
  @client
end

#dateDate (readonly)

Returns:

  • (Date)


13
14
15
# File 'lib/pixela/pixel.rb', line 13

def date
  @date
end

#graph_idString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/pixela/pixel.rb', line 9

def graph_id
  @graph_id
end

Instance Method Details

#create(quantity:, optional_data: nil) ⇒ Pixela::Response

It records the quantity of the specified date as a “Pixel”.

Examples:

client.graph("test-graph").pixel(Date.new(2018, 9, 15)).create(quantity: 5, optional_data: {key: "value"})

Parameters:

  • quantity (Integer, Float)
  • optional_data (Object) (defaults to: nil)

    Additional information other than quantity

Returns:

Raises:

See Also:



37
38
39
# File 'lib/pixela/pixel.rb', line 37

def create(quantity:, optional_data: nil)
  client.create_pixel(graph_id: graph_id, date: date, quantity: quantity, optional_data: optional_data)
end

#create_multi(pixels:) ⇒ Pixela::Response

This API is used to register multiple Pixels (quantities for a specific day) at a time.

Examples:

client.graph("test-graph").create_multi(pixels: [{date: Date.new(2018, 9, 15), quantity: 5, optional_data: {key: "value"}}])

Parameters:

  • pixels (Array<Hash>)

    key: date, quantity, optional_data

Returns:

Raises:

See Also:



53
54
55
# File 'lib/pixela/pixel.rb', line 53

def create_multi(pixels:)
  client.create_pixels(graph_id: graph_id, pixels: pixels)
end

#deletePixela::Response

Delete the registered “Pixel”.

Examples:

client.graph("test-graph").pixel(Date.new(2018, 9, 15)).delete

Returns:

Raises:

See Also:



98
99
100
# File 'lib/pixela/pixel.rb', line 98

def delete
  client.delete_pixel(graph_id: graph_id, date: date)
end

#getPixela::Response

Get registered quantity as “Pixel”.

Examples:

client.graph("test-graph").pixel(Date.new(2018, 9, 15)).get

Returns:

Raises:

See Also:



67
68
69
# File 'lib/pixela/pixel.rb', line 67

def get
  client.get_pixel(graph_id: graph_id, date: date)
end

#update(quantity:, optional_data: nil) ⇒ Pixela::Response

Update the quantity already registered as a “Pixel”.

Examples:

client.graph("test-graph").pixel(Date.new(2018, 9, 15)).update(quantity: 7, optional_data: {key: "value"})

Parameters:

  • quantity (Integer, Float)
  • optional_data (Object) (defaults to: nil)

    Additional information other than quantity

Returns:

Raises:

See Also:



84
85
86
# File 'lib/pixela/pixel.rb', line 84

def update(quantity:, optional_data: nil)
  client.update_pixel(graph_id: graph_id, date: date, quantity: quantity, optional_data: optional_data)
end