Class: Pixela::Graph

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, graph_id:) ⇒ Graph

Returns a new instance of Graph.

Parameters:



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

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

Instance Attribute Details

#clientPixela::Client (readonly)

Returns:



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

def client
  @client
end

#graph_idString (readonly)

Returns:

  • (String)


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

def graph_id
  @graph_id
end

Instance Method Details

#add(quantity:) ⇒ Pixela::Response

Add quantity to the "Pixel" of the day

Examples:

client.graph("test-graph").add(quantity: "1")

Parameters:

  • quantity (String)

Returns:

Raises:

See Also:



150
151
152
# File 'lib/pixela/graph.rb', line 150

def add(quantity:)
  client.add_pixel(graph_id: graph_id, quantity: quantity)
end

#create(name:, unit:, type:, color:, timezone: nil, self_sufficient: nil, is_secret: nil, publish_optional_data: nil) ⇒ Pixela::Response

Create a new pixelation graph definition.

Examples:

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)

Parameters:

  • name (String)
  • unit (String)
  • type (String)
  • color (String)
  • timezone (String) (defaults to: nil)
  • self_sufficient (String) (defaults to: nil)

    If SVG graph with this field increment or decrement is referenced, Pixel of this graph itself will be incremented or decremented

  • is_secret (Boolean) (defaults to: nil)
  • publish_optional_data (Boolean) (defaults to: nil)

Returns:

Raises:

See Also:



44
45
46
47
48
49
# 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

#decrementPixela::Response

Decrement quantity "Pixel" of the day (UTC).

Examples:

client.graph("test-graph").decrement

Returns:

Raises:

See Also:



134
135
136
# File 'lib/pixela/graph.rb', line 134

def decrement
  client.decrement_pixel(graph_id: graph_id)
end

#defPixela::Response Also known as: definition

Get a predefined pixelation graph definition.

Examples:

client.graph("test-graph").def

Returns:

Raises:

See Also:



245
246
247
# File 'lib/pixela/graph.rb', line 245

def def
  client.get_graph_def(graph_id: graph_id)
end

#deletePixela::Response

Delete the predefined pixelation graph definition.

Examples:

client.graph("test-graph").delete

Returns:

Raises:

See Also:



106
107
108
# File 'lib/pixela/graph.rb', line 106

def delete
  client.delete_graph(graph_id)
end

#incrementPixela::Response

Increment quantity "Pixel" of the day (UTC).

Examples:

client.graph("test-graph").increment

Returns:

Raises:

See Also:



120
121
122
# File 'lib/pixela/graph.rb', line 120

def increment
  client.increment_pixel(graph_id: graph_id)
end

#latestPixela::Response

This API is used to get latest Pixel of the graph which specified by .

Examples:

client.graph("test-graph").latest

Returns:

Raises:

See Also:



261
262
263
# File 'lib/pixela/graph.rb', line 261

def latest
  client.get_graph_latest(graph_id: graph_id)
end

#pixel(date = Date.today) ⇒ Pixela::Pixel

Parameters:

  • date (Date, Time) (defaults to: Date.today)

Returns:



21
22
23
# 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) ⇒ Array<Date>

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

Examples:

client.graph("test-graph").pixel_dates(from: Date.new(2018, 1, 1), to: Date.new(2018, 12, 31))

Parameters:

  • from (Date) (defaults to: nil)

    Specify the start position of the period.

  • to (Date) (defaults to: nil)

    Specify the end position of the period.

Returns:

  • (Array<Date>)

Raises:

See Also:



183
184
185
# File 'lib/pixela/graph.rb', line 183

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) ⇒ Array<Hashie::Mash>

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

Examples:

client.graph("test-graph").pixels(from: Date.new(2018, 1, 1), to: Date.new(2018, 12, 31))

Parameters:

  • from (Date) (defaults to: nil)

    Specify the start position of the period.

  • to (Date) (defaults to: nil)

    Specify the end position of the period.

Returns:

  • (Array<Hashie::Mash>)

Raises:

See Also:



200
201
202
# File 'lib/pixela/graph.rb', line 200

def pixels(from: nil, to: nil)
  client.get_pixels(graph_id: graph_id, from: from, to: to)
end

#run_stopwatchPixela::Response Also known as: start_stopwatch, end_stopwatch

This will start and end the measurement of the time.

Examples:

client.graph("test-graph").run_stopwatch

Returns:

Raises:

See Also:



228
229
230
# File 'lib/pixela/graph.rb', line 228

def run_stopwatch
  client.run_stopwatch(graph_id: graph_id)
end

#statsPixela::Response

Based on the registered information, get various statistics.

Examples:

client.graph("test-graph").stats

Returns:

Raises:

See Also:



214
215
216
# File 'lib/pixela/graph.rb', line 214

def stats
  client.get_graph_stats(graph_id: graph_id)
end

#subtract(quantity:) ⇒ Pixela::Response

Subtract quantity from the "Pixel" of the day

Examples:

client.graph("test-graph").subtract(quantity: "1")

Parameters:

  • quantity (String)

Returns:

Raises:

See Also:



166
167
168
# File 'lib/pixela/graph.rb', line 166

def subtract(quantity:)
  client.subtract_pixel(graph_id: graph_id, quantity: quantity)
end

#update(name: nil, unit: nil, color: nil, timezone: nil, purge_cache_urls: nil, self_sufficient: nil, is_secret: nil, publish_optional_data: nil) ⇒ Pixela::Response

Update predefined pixelation graph definitions.

Examples:

client.graph("test-graph").update(name: "graph-name", unit: "commit", color: "shibafu", timezone: "Asia/Tokyo", purge_cache_urls: ["https://camo.githubusercontent.com/xxx/xxxx"])

Parameters:

  • name (String) (defaults to: nil)
  • unit (String) (defaults to: nil)
  • color (String) (defaults to: nil)
  • timezone (String) (defaults to: nil)
  • self_sufficient (String) (defaults to: nil)

    If SVG graph with this field increment or decrement is referenced, Pixel of this graph itself will be incremented or decremented

  • purge_cache_urls (String, Array<String>) (defaults to: nil)
  • is_secret (Boolean) (defaults to: nil)
  • publish_optional_data (Boolean) (defaults to: nil)

Returns:

Raises:

See Also:



89
90
91
92
93
94
# File 'lib/pixela/graph.rb', line 89

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, appearance: nil, less_than: nil, greater_than: nil) ⇒ String

Get graph url

Examples:

client.graph("test-graph").url
client.graph("test-graph").url(date: Date.new(2018, 3, 31), mode: "short")

Parameters:

  • date (Date, Time) (defaults to: nil)
  • mode (String) (defaults to: nil)

    e.g) short

  • appearance (String) (defaults to: nil)

    e.g) dark

  • less_than (String) (defaults to: nil)
  • greater_than (String) (defaults to: nil)

Returns:

  • (String)

See Also:



66
67
68
# File 'lib/pixela/graph.rb', line 66

def url(date: nil, mode: nil, appearance: nil, less_than: nil, greater_than: nil)
  client.graph_url(graph_id: graph_id, date: date, mode: mode, appearance: appearance, less_than: less_than, greater_than: greater_than)
end