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:



147
148
149
# File 'lib/pixela/graph.rb', line 147

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:



131
132
133
# File 'lib/pixela/graph.rb', line 131

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:



242
243
244
# File 'lib/pixela/graph.rb', line 242

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:



103
104
105
# File 'lib/pixela/graph.rb', line 103

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:



117
118
119
# File 'lib/pixela/graph.rb', line 117

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 <graphID> .

Examples:

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

Returns:

Raises:

See Also:



258
259
260
# File 'lib/pixela/graph.rb', line 258

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:



180
181
182
# File 'lib/pixela/graph.rb', line 180

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:



197
198
199
# File 'lib/pixela/graph.rb', line 197

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:



225
226
227
# File 'lib/pixela/graph.rb', line 225

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:



211
212
213
# File 'lib/pixela/graph.rb', line 211

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:



163
164
165
# File 'lib/pixela/graph.rb', line 163

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:



86
87
88
89
90
91
# 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) ⇒ 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

Returns:

  • (String)

See Also:



63
64
65
# 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