class Pixela::Graph

Attributes

client[R]

@!attribute [r] client @return [Pixela::Client]

graph_id[R]

@!attribute [r] graph_id @return [String]

Public Class Methods

new(client:, graph_id:) click to toggle source

@param client [Pixela::Client] @param graph_id [String]

# File lib/pixela/graph.rb, line 13
def initialize(client:, graph_id:)
  @client   = client
  @graph_id = graph_id
end

Public Instance Methods

create(name:, unit:, type:, color:, timezone: nil, self_sufficient: nil, is_secret: nil, publish_optional_data: nil) click to toggle source

Create a new pixelation graph definition.

@param name [String] @param unit [String] @param type [String] @param color [String] @param timezone [String] @param self_sufficient [String] If SVG graph with this field `increment` or `decrement` is referenced, Pixel of this graph itself will be incremented or decremented @param is_secret [Boolean] @param publish_optional_data [Boolean]

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/post-graph

@example

client.graph("test-graph").create(name: "graph-name", unit: "commit", type: "int", color: "shibafu", timezone: "Asia/Tokyo", self_sufficient: "increment", is_secret: true, publish_optional_data: true)
# File lib/pixela/graph.rb, line 44
def create(name:, unit:, type:, color:, timezone: nil, self_sufficient: nil, is_secret: nil, publish_optional_data: nil)
  client.create_graph(
    graph_id: graph_id, name: name, unit: unit, type: type, color: color, timezone: timezone, self_sufficient: self_sufficient,
    is_secret: is_secret, publish_optional_data: publish_optional_data,
  )
end
decrement() click to toggle source

Decrement quantity “Pixel” of the day (UTC).

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/decrement-pixel

@example

client.graph("test-graph").decrement
# File lib/pixela/graph.rb, line 131
def decrement
  client.decrement_pixel(graph_id: graph_id)
end
def() click to toggle source

Get a predefined pixelation graph definition.

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/get-a-graph-def

@example

client.graph("test-graph").def
# File lib/pixela/graph.rb, line 210
def def
  client.get_graph_def(graph_id: graph_id)
end
Also aliased as: definition
definition()
Alias for: def
delete() click to toggle source

Delete the predefined pixelation graph definition.

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/put-graph

@example

client.graph("test-graph").delete
# File lib/pixela/graph.rb, line 103
def delete
  client.delete_graph(graph_id)
end
end_stopwatch()
Alias for: run_stopwatch
increment() click to toggle source

Increment quantity “Pixel” of the day (UTC).

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/increment-pixel

@example

client.graph("test-graph").increment
# File lib/pixela/graph.rb, line 117
def increment
  client.increment_pixel(graph_id: graph_id)
end
pixel(date = Date.today) click to toggle source

@param date [Date,Time]

@return [Pixela::Pixel]

# File lib/pixela/graph.rb, line 21
def pixel(date = Date.today)
  Pixel.new(client: client, graph_id: graph_id, date: date)
end
pixel_dates(from: nil, to: nil) click to toggle source

Get a Date list of Pixel registered in the graph specified by graphID.

@param from [Date] Specify the start position of the period. @param to [Date] Specify the end position of the period.

@return [Array<Date>]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/get-graph-pixels

@example

client.graph("test-graph").pixel_dates(from: Date.new(2018, 1, 1), to: Date.new(2018, 12, 31))
# File lib/pixela/graph.rb, line 148
def pixel_dates(from: nil, to: nil)
  client.get_pixel_dates(graph_id: graph_id, from: from, to: to)
end
pixels(from: nil, to: nil) click to toggle source

Get a Date list of Pixel registered in the graph specified by graphID.

@param from [Date] Specify the start position of the period. @param to [Date] Specify the end position of the period.

@return [Array<Hashie::Mash>]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/get-graph-pixels

@example

client.graph("test-graph").pixels(from: Date.new(2018, 1, 1), to: Date.new(2018, 12, 31))
# File lib/pixela/graph.rb, line 165
def pixels(from: nil, to: nil)
  client.get_pixels(graph_id: graph_id, from: from, to: to)
end
run_stopwatch() click to toggle source

This will start and end the measurement of the time.

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/post-stopwatch

@example

client.graph("test-graph").run_stopwatch
# File lib/pixela/graph.rb, line 193
def run_stopwatch
  client.run_stopwatch(graph_id: graph_id)
end
Also aliased as: start_stopwatch, end_stopwatch
start_stopwatch()
Alias for: run_stopwatch
stats() click to toggle source

Based on the registered information, get various statistics.

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/get-graph-stats

@example

client.graph("test-graph").stats
# File lib/pixela/graph.rb, line 179
def stats
  client.get_graph_stats(graph_id: graph_id)
end
update(name: nil, unit: nil, color: nil, timezone: nil, purge_cache_urls: nil, self_sufficient: nil, is_secret: nil, publish_optional_data: nil) click to toggle source

Update predefined pixelation graph definitions.

@param name [String] @param unit [String] @param color [String] @param timezone [String] @param self_sufficient [String] If SVG graph with this field `increment` or `decrement` is referenced, Pixel of this graph itself will be incremented or decremented @param purge_cache_urls [String,Array<String>] @param is_secret [Boolean] @param publish_optional_data [Boolean]

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/put-graph

@example

client.graph("test-graph").update(name: "graph-name", unit: "commit", color: "shibafu", timezone: "Asia/Tokyo", purge_cache_urls: ["https://camo.githubusercontent.com/xxx/xxxx"])
# File lib/pixela/graph.rb, line 86
def update(name: nil, unit: nil, color: nil, timezone: nil, purge_cache_urls: nil, self_sufficient: nil, is_secret: nil, publish_optional_data: nil)
  client.update_graph(
    graph_id: graph_id, name: name, unit: unit, color: color, timezone: timezone, self_sufficient: self_sufficient,
    purge_cache_urls: purge_cache_urls, is_secret: is_secret, publish_optional_data: publish_optional_data,
  )
end
url(date: nil, mode: nil) click to toggle source

Get graph url

@param date [Date,Time] @param mode [String] e.g) `short`

@return [String]

@see docs.pixe.la/entry/get-graph

@example

client.graph("test-graph").url
client.graph("test-graph").url(date: Date.new(2018, 3, 31), mode: "short")
# File lib/pixela/graph.rb, line 63
def url(date: nil, mode: nil)
  client.graph_url(graph_id: graph_id, date: date, mode: mode)
end