Module: Pixela::Client::GraphMethods

Included in:
Pixela::Client
Defined in:
lib/pixela/client/graph_methods.rb

Instance Method Summary collapse

Instance Method Details

#create_graph(graph_id:, name:, unit:, type:, color:) ⇒ Hashie::Mash

Create a new pixelation graph definition.

Examples:

client.create_graph(graph_id: "test-graph", name: "graph-name", unit: "commit", type: "int", color: "shibafu")

Parameters:

  • graph_id (String)
  • name (String)
  • unit (String)
  • type (String)
  • color (String)

Returns:

  • (Hashie::Mash)

Raises:

See Also:



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pixela/client/graph_methods.rb', line 18

def create_graph(graph_id:, name:, unit:, type:, color:)
  params = {
    id:    graph_id,
    name:  name,
    unit:  unit,
    type:  type,
    color: color,
  }

  with_error_handling do
    connection.post("users/#{username}/graphs", params, user_token_headers).body
  end
end

#delete_graph(graph_id) ⇒ Hashie::Mash

Delete the predefined pixelation graph definition.

Examples:

client.delete_graph("test-graph")

Parameters:

  • graph_id (String)

Returns:

  • (Hashie::Mash)

Raises:

See Also:



107
108
109
110
111
# File 'lib/pixela/client/graph_methods.rb', line 107

def delete_graph(graph_id)
  with_error_handling do
    connection.delete("users/#{username}/graphs/#{graph_id}", nil, user_token_headers).body
  end
end

#get_graphsArray<Hashie::Mash>

Get all predefined pixelation graph definitions.

Examples:

client.get_graphs

Returns:

  • (Array<Hashie::Mash>)

Raises:

See Also:



42
43
44
45
46
# File 'lib/pixela/client/graph_methods.rb', line 42

def get_graphs
  with_error_handling do
    connection.get("users/#{username}/graphs", nil, user_token_headers).body.graphs
  end
end

#graph_url(graph_id:, date: nil) ⇒ String

Get graph url

Examples:

client.graph_url(graph_id: "test-graph")
client.graph_url(graph_id: "test-graph", date: Date.new(2018, 3, 31))

Parameters:

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

Returns:

  • (String)

See Also:



60
61
62
63
64
65
66
# File 'lib/pixela/client/graph_methods.rb', line 60

def graph_url(graph_id:, date: nil)
  url = "#{Pixela::Client::API_ENDPOINT}/users/#{username}/graphs/#{graph_id}"

  url << "?date=#{to_ymd(date)}" if date

  url
end

#update_graph(graph_id:, name:, unit:, color:) ⇒ Hashie::Mash

Update predefined pixelation graph definitions.

Examples:

client.update_graph(graph_id: "test-graph", name: "graph-name", unit: "commit", color: "shibafu")

Parameters:

  • graph_id (String)
  • name (String)
  • unit (String)
  • color (String)

Returns:

  • (Hashie::Mash)

Raises:

See Also:



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/pixela/client/graph_methods.rb', line 83

def update_graph(graph_id:, name:, unit:, color:)
  params = {
    name:  name,
    unit:  unit,
    color: color,
  }

  with_error_handling do
    connection.put("users/#{username}/graphs/#{graph_id}", params, user_token_headers).body
  end
end