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:



156
157
158
# File 'lib/pixela/graph.rb', line 156

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

#add_specific(quantity:, date:) ⇒ Pixela::Response

Add quantity to a specific “Pixel”

Examples:

client.graph("test-graph").add_specific(date: Date.today, quantity: "1")

Parameters:

  • quantity (Integer, Float)
  • date (Date, Time)

Returns:

Raises:

See Also:



300
301
302
# File 'lib/pixela/graph.rb', line 300

def add_specific(quantity:, date:)
  client.add_specific_pixel(graph_id: graph_id, date: date, quantity: quantity)
end

#create(name:, unit:, type:, color:, timezone: nil, description: nil, start_on_monday: 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)
  • description (String) (defaults to: nil)
  • start_on_monday (Boolean) (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:



46
47
48
49
50
51
52
# File 'lib/pixela/graph.rb', line 46

def create(name:, unit:, type:, color:, timezone: nil, description: nil, start_on_monday: 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,
    description: description, start_on_monday: start_on_monday, 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:



140
141
142
# File 'lib/pixela/graph.rb', line 140

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:



251
252
253
# File 'lib/pixela/graph.rb', line 251

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:



112
113
114
# File 'lib/pixela/graph.rb', line 112

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:



126
127
128
# File 'lib/pixela/graph.rb', line 126

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:



267
268
269
# File 'lib/pixela/graph.rb', line 267

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:



189
190
191
# File 'lib/pixela/graph.rb', line 189

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:

Raises:

See Also:



206
207
208
# File 'lib/pixela/graph.rb', line 206

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:



234
235
236
# File 'lib/pixela/graph.rb', line 234

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:



220
221
222
# File 'lib/pixela/graph.rb', line 220

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:



172
173
174
# File 'lib/pixela/graph.rb', line 172

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

#subtract_specific(quantity:, date:) ⇒ Pixela::Response

Subtract quantity to a specific “Pixel”

Examples:

client.graph("test-graph").subtract_specific(date: Date.today, quantity: "1")

Parameters:

  • quantity (Integer, Float)
  • date (Date, Time)

Returns:

Raises:

See Also:



317
318
319
# File 'lib/pixela/graph.rb', line 317

def subtract_specific(quantity:, date:)
  client.subtract_specific_pixel(graph_id: graph_id, date: date, quantity: quantity)
end

#today(return_empty: false) ⇒ Pixela::Response

This is an endpoint that responds with the Pixel of the day you requested this API.

Examples:

client.graph("test-graph").today(return_empty: true)

Parameters:

  • return_empty (Boolean) (defaults to: false)

    Specifying true for this param will return an empty Pixel instead of 404 Not Found if the Pixel is unregistered on the day of the request.

Returns:

Raises:

See Also:



283
284
285
# File 'lib/pixela/graph.rb', line 283

def today(return_empty: false)
  client.get_graph_today(graph_id: graph_id, return_empty: return_empty)
end

#update(name: nil, unit: nil, color: nil, timezone: nil, description: nil, start_on_monday: 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)
  • description (String) (defaults to: nil)
  • start_on_monday (Boolean) (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:



94
95
96
97
98
99
100
# File 'lib/pixela/graph.rb', line 94

def update(name: nil, unit: nil, color: nil, timezone: nil, description: nil, start_on_monday: 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,
    description: description, start_on_monday: start_on_monday, 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:



69
70
71
# File 'lib/pixela/graph.rb', line 69

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