• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sue445 / pixela / #12148

26 Dec 2025 11:22AM UTC coverage: 44.444% (-53.8%) from 98.195%
#12148

push

web-flow
Merge b4c2c510f into 6f2b98fd6

120 of 270 relevant lines covered (44.44%)

0.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.59
/lib/pixela/client/graph_methods.rb
1
module Pixela::Client::GraphMethods
1✔
2
  # Create a new pixelation graph definition.
3
  #
4
  # @param graph_id              [String]
5
  # @param name                  [String]
6
  # @param unit                  [String]
7
  # @param type                  [String]
8
  # @param color                 [String]
9
  # @param timezone              [String]
10
  # @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
11
  # @param is_secret             [Boolean]
12
  # @param publish_optional_data [Boolean]
13
  #
14
  # @return [Pixela::Response]
15
  #
16
  # @raise [Pixela::PixelaError] API is failed
17
  #
18
  # @see https://docs.pixe.la/entry/post-graph
19
  #
20
  # @example
21
  #   client.create_graph(graph_id: "test-graph", name: "graph-name", unit: "commit", type: "int", color: "shibafu", timezone: "Asia/Tokyo", self_sufficient: "increment", is_secret: true, publish_optional_data: true)
22
  def create_graph(graph_id:, name:, unit:, type:, color:, timezone: nil, self_sufficient: nil, is_secret: nil, publish_optional_data: nil)
1✔
23
    params = {
24
      id:                  graph_id,
×
25
      name:                name,
26
      unit:                unit,
27
      type:                type,
28
      color:               color,
29
      timezone:            timezone,
30
      selfSufficient:      self_sufficient,
31
      isSecret:            is_secret,
32
      publishOptionalData: publish_optional_data
33
    }
34

35
    with_error_handling do
×
36
      connection.post("users/#{username}/graphs", params.compact).body
×
37
    end
38
  end
39

40
  # Get all predefined pixelation graph definitions.
41
  #
42
  # @return [Array<Hashie::Mash>]
43
  #
44
  # @raise [Pixela::PixelaError] API is failed
45
  #
46
  # @see https://docs.pixe.la/entry/get-graph
47
  #
48
  # @example
49
  #   client.get_graphs
50
  def get_graphs
1✔
51
    with_error_handling do
×
52
      connection.get("users/#{username}/graphs").body.graphs
×
53
    end
54
  end
55

56
  # Get graph url
57
  #
58
  # @param graph_id     [String]
59
  # @param date         [Date,Time]
60
  # @param mode         [String] e.g) `short`
61
  # @param appearance   [String] e.g) `dark`
62
  # @param less_than    [String]
63
  # @param greater_than [String]
64
  #
65
  # @return [String]
66
  #
67
  # @see https://docs.pixe.la/entry/get-svg
68
  #
69
  # @example
70
  #   client.graph_url(graph_id: "test-graph")
71
  #   client.graph_url(graph_id: "test-graph", date: Date.new(2018, 3, 31), mode: "short")
72
  def graph_url(graph_id:, date: nil, mode: nil, appearance: nil, less_than: nil, greater_than: nil)
1✔
73
    url = "#{Pixela::Client::API_ENDPOINT}/users/#{username}/graphs/#{graph_id}"
×
74

75
    params = Faraday::Utils::ParamsHash.new
×
76
    params[:date] = to_ymd(date) if date
×
77
    params[:mode] = mode if mode
×
78
    params[:appearance] = appearance if appearance
×
79
    params[:lessThan] = less_than if less_than
×
80
    params[:greaterThan] = greater_than if greater_than
×
81

82
    url << "?#{params.to_query}" unless params.empty?
×
83

84
    url
×
85
  end
86

87
  # Displays graph list by detail in html format.
88
  #
89
  # @return [String]
90
  #
91
  # @see https://docs.pixe.la/entry/get-graph-list-html
92
  #
93
  # @example
94
  #   client.graphs_url
95
  def graphs_url
1✔
96
    "https://pixe.la/v1/users/#{username}/graphs.html"
×
97
  end
98

99
  # Update predefined pixelation graph definitions.
100
  #
101
  # @param graph_id              [String]
102
  # @param name                  [String]
103
  # @param unit                  [String]
104
  # @param color                 [String]
105
  # @param timezone              [String]
106
  # @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
107
  # @param purge_cache_urls      [String,Array<String>]
108
  # @param is_secret             [Boolean]
109
  # @param publish_optional_data [Boolean]
110
  #
111
  # @return [Pixela::Response]
112
  #
113
  # @raise [Pixela::PixelaError] API is failed
114
  #
115
  # @see https://docs.pixe.la/entry/put-graph
116
  #
117
  # @example
118
  #   client.update_graph(graph_id: "test-graph", name: "graph-name", unit: "commit", color: "shibafu", timezone: "Asia/Tokyo", self_sufficient: "increment", purge_cache_urls: ["https://camo.githubusercontent.com/xxx/xxxx"])
119
  def update_graph(graph_id:, name: nil, unit: nil, color: nil, timezone: nil, self_sufficient: nil, purge_cache_urls: nil, is_secret: nil, publish_optional_data: nil)
1✔
120
    params = {
121
      name:                name,
×
122
      unit:                unit,
123
      color:               color,
124
      timezone:            timezone,
125
      selfSufficient:      self_sufficient,
126
      isSecret:            is_secret,
127
      publishOptionalData: publish_optional_data
128
    }
129

130
    if purge_cache_urls
×
131
      params[:purgeCacheURLs] = Array(purge_cache_urls)
×
132
    end
133

134
    with_error_handling do
×
135
      connection.put("users/#{username}/graphs/#{graph_id}", params.compact).body
×
136
    end
137
  end
138

139
  # Delete the predefined pixelation graph definition.
140
  #
141
  # @param graph_id [String]
142
  #
143
  # @return [Pixela::Response]
144
  #
145
  # @raise [Pixela::PixelaError] API is failed
146
  #
147
  # @see https://docs.pixe.la/entry/delete-graph
148
  #
149
  # @example
150
  #   client.delete_graph("test-graph")
151
  def delete_graph(graph_id)
1✔
152
    with_error_handling do
×
153
      connection.delete("users/#{username}/graphs/#{graph_id}").body
×
154
    end
155
  end
156

157
  # Get a Date list of Pixel registered in the graph specified by graphID.
158
  #
159
  # @param graph_id [String]
160
  # @param from [Date] Specify the start position of the period.
161
  # @param to   [Date] Specify the end position of the period.
162
  #
163
  # @return [Array<Date>]
164
  #
165
  # @raise [Pixela::PixelaError] API is failed
166
  #
167
  # @see https://docs.pixe.la/entry/get-graph-pixels
168
  #
169
  # @example
170
  #   client.get_pixel_dates(graph_id: "test-graph", from: Date.new(2018, 1, 1), to: Date.new(2018, 12, 31))
171
  def get_pixel_dates(graph_id:, from: nil, to: nil)
1✔
172
    params = {
173
      from: to_ymd(from),
×
174
      to:   to_ymd(to),
175
    }
176

177
    res =
178
      with_error_handling do
×
179
        connection.get("users/#{username}/graphs/#{graph_id}/pixels", params.compact).body
×
180
      end
181

182
    res.pixels.map { |ymd| Date.parse(ymd) }
×
183
  end
184

185
  # Get a Date list of Pixel registered in the graph specified by graphID.
186
  #
187
  # @param graph_id [String]
188
  # @param from [Date] Specify the start position of the period.
189
  # @param to   [Date] Specify the end position of the period.
190
  #
191
  # @return [Array<Hashie::Mash>]
192
  #
193
  # @raise [Pixela::PixelaError] API is failed
194
  #
195
  # @see https://docs.pixe.la/entry/get-graph-pixels
196
  #
197
  # @example
198
  #   client.get_pixels(graph_id: "test-graph", from: Date.new(2018, 1, 1), to: Date.new(2018, 12, 31))
199
  def get_pixels(graph_id:, from: nil, to: nil)
1✔
200
    params = {
201
      from:     to_ymd(from),
×
202
      to:       to_ymd(to),
203
      withBody: true,
204
    }
205

206
    with_error_handling do
×
207
      connection.get("users/#{username}/graphs/#{graph_id}/pixels", params.compact).body.pixels
×
208
    end
209
  end
210

211
  # Based on the registered information, get various statistics.
212
  #
213
  # @param graph_id [String]
214
  #
215
  # @return [Pixela::Response]
216
  #
217
  # @raise [Pixela::PixelaError] API is failed
218
  #
219
  # @see https://docs.pixe.la/entry/get-graph-stats
220
  #
221
  # @example
222
  #   client.get_graph_stats(graph_id: "test-graph")
223
  def get_graph_stats(graph_id:)
1✔
224
    with_error_handling do
×
225
      connection.get("users/#{username}/graphs/#{graph_id}/stats").body
×
226
    end
227
  end
228

229
  # This will start and end the measurement of the time.
230
  #
231
  # @param graph_id [String]
232
  #
233
  # @return [Pixela::Response]
234
  #
235
  # @raise [Pixela::PixelaError] API is failed
236
  #
237
  # @see https://docs.pixe.la/entry/post-stopwatch
238
  #
239
  # @example
240
  #   client.run_stopwatch(graph_id: "test-graph")
241
  def run_stopwatch(graph_id:)
1✔
242
    with_error_handling do
×
243
      connection.post("users/#{username}/graphs/#{graph_id}/stopwatch").body
×
244
    end
245
  end
246

247
  alias_method :start_stopwatch, :run_stopwatch
1✔
248
  alias_method :end_stopwatch,   :run_stopwatch
1✔
249

250
  # Get a predefined pixelation graph definition.
251
  #
252
  # @param graph_id [String]
253
  #
254
  # @return [Pixela::Response]
255
  #
256
  # @raise [Pixela::PixelaError] API is failed
257
  #
258
  # @see https://docs.pixe.la/entry/get-a-graph-def
259
  #
260
  # @example
261
  #   client.get_graph_def(graph_id: "test-graph")
262
  def get_graph_def(graph_id:)
1✔
263
    with_error_handling do
×
264
      connection.get("users/#{username}/graphs/#{graph_id}/graph-def").body
×
265
    end
266
  end
267

268
  # This API is used to get latest Pixel of the graph which specified by <graphID> .
269
  #
270
  # @param graph_id [String]
271
  #
272
  # @return [Pixela::Response]
273
  #
274
  # @raise [Pixela::PixelaError] API is failed
275
  #
276
  # @see https://docs.pixe.la/entry/get-latest-pixel
277
  #
278
  # @example
279
  #   client.get_graph_latest(graph_id: "test-graph")
280
  def get_graph_latest(graph_id:)
1✔
281
    with_error_handling do
×
282
      connection.get("users/#{username}/graphs/#{graph_id}/latest").body
×
283
    end
284
  end
285

286
  # This is an endpoint that responds with the Pixel of the day you requested this API.
287
  #
288
  # @param graph_id [String]
289
  # @param return_empty [Boolean] 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.
290
  #
291
  # @return [Pixela::Response]
292
  #
293
  # @raise [Pixela::PixelaError] API is failed
294
  #
295
  # @see https://docs.pixe.la/entry/get-today-pixel
296
  #
297
  # @example
298
  #   client.get_graph_today(graph_id: "test-graph", return_empty: true)
299
  def get_graph_today(graph_id:, return_empty: false)
1✔
300
    params = {}
×
301
    if return_empty
×
302
      params[:returnEmpty] = return_empty
×
303
    end
304

305
    with_error_handling do
×
306
      connection.get("users/#{username}/graphs/#{graph_id}/today", params.compact).body
×
307
    end
308
  end
309
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc