• 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

57.14
/lib/pixela/graph.rb
1
module Pixela
1✔
2
  class Graph
1✔
3
    # @!attribute [r] client
4
    # @return [Pixela::Client]
5
    attr_reader :client
1✔
6

7
    # @!attribute [r] graph_id
8
    # @return [String]
9
    attr_reader :graph_id
1✔
10

11
    # @param client [Pixela::Client]
12
    # @param graph_id [String]
13
    def initialize(client:, graph_id:)
1✔
14
      @client   = client
×
15
      @graph_id = graph_id
×
16
    end
17

18
    # @param date [Date,Time]
19
    #
20
    # @return [Pixela::Pixel]
21
    def pixel(date = Date.today)
1✔
22
      Pixel.new(client: client, graph_id: graph_id, date: date)
×
23
    end
24

25
    # Create a new pixelation graph definition.
26
    #
27
    # @param name                  [String]
28
    # @param unit                  [String]
29
    # @param type                  [String]
30
    # @param color                 [String]
31
    # @param timezone              [String]
32
    # @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
33
    # @param is_secret             [Boolean]
34
    # @param publish_optional_data [Boolean]
35
    #
36
    # @return [Pixela::Response]
37
    #
38
    # @raise [Pixela::PixelaError] API is failed
39
    #
40
    # @see https://docs.pixe.la/entry/post-graph
41
    #
42
    # @example
43
    #   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)
44
    def create(name:, unit:, type:, color:, timezone: nil, self_sufficient: nil, is_secret: nil, publish_optional_data: nil)
1✔
45
      client.create_graph(
×
46
        graph_id: graph_id, name: name, unit: unit, type: type, color: color, timezone: timezone, self_sufficient: self_sufficient,
47
        is_secret: is_secret, publish_optional_data: publish_optional_data,
48
      )
49
    end
50

51
    # Get graph url
52
    #
53
    # @param date         [Date,Time]
54
    # @param mode         [String] e.g) `short`
55
    # @param appearance   [String] e.g) `dark`
56
    # @param less_than    [String]
57
    # @param greater_than [String]
58
    #
59
    # @return [String]
60
    #
61
    # @see https://docs.pixe.la/entry/get-graph
62
    #
63
    # @example
64
    #   client.graph("test-graph").url
65
    #   client.graph("test-graph").url(date: Date.new(2018, 3, 31), mode: "short")
66
    def url(date: nil, mode: nil, appearance: nil, less_than: nil, greater_than: nil)
1✔
67
      client.graph_url(graph_id: graph_id, date: date, mode: mode, appearance: appearance, less_than: less_than, greater_than: greater_than)
×
68
    end
69

70
    # Update predefined pixelation graph definitions.
71
    #
72
    # @param name                  [String]
73
    # @param unit                  [String]
74
    # @param color                 [String]
75
    # @param timezone              [String]
76
    # @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
77
    # @param purge_cache_urls      [String,Array<String>]
78
    # @param is_secret             [Boolean]
79
    # @param publish_optional_data [Boolean]
80
    #
81
    # @return [Pixela::Response]
82
    #
83
    # @raise [Pixela::PixelaError] API is failed
84
    #
85
    # @see https://docs.pixe.la/entry/put-graph
86
    #
87
    # @example
88
    #   client.graph("test-graph").update(name: "graph-name", unit: "commit", color: "shibafu", timezone: "Asia/Tokyo", purge_cache_urls: ["https://camo.githubusercontent.com/xxx/xxxx"])
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)
1✔
90
      client.update_graph(
×
91
        graph_id: graph_id, name: name, unit: unit, color: color, timezone: timezone, self_sufficient: self_sufficient,
92
        purge_cache_urls: purge_cache_urls, is_secret: is_secret, publish_optional_data: publish_optional_data,
93
      )
94
    end
95

96
    # Delete the predefined pixelation graph definition.
97
    #
98
    # @return [Pixela::Response]
99
    #
100
    # @raise [Pixela::PixelaError] API is failed
101
    #
102
    # @see https://docs.pixe.la/entry/put-graph
103
    #
104
    # @example
105
    #   client.graph("test-graph").delete
106
    def delete
1✔
107
      client.delete_graph(graph_id)
×
108
    end
109

110
    # Increment quantity "Pixel" of the day (UTC).
111
    #
112
    # @return [Pixela::Response]
113
    #
114
    # @raise [Pixela::PixelaError] API is failed
115
    #
116
    # @see https://docs.pixe.la/entry/increment-pixel
117
    #
118
    # @example
119
    #   client.graph("test-graph").increment
120
    def increment
1✔
121
      client.increment_pixel(graph_id: graph_id)
×
122
    end
123

124
    # Decrement quantity "Pixel" of the day (UTC).
125
    #
126
    # @return [Pixela::Response]
127
    #
128
    # @raise [Pixela::PixelaError] API is failed
129
    #
130
    # @see https://docs.pixe.la/entry/decrement-pixel
131
    #
132
    # @example
133
    #   client.graph("test-graph").decrement
134
    def decrement
1✔
135
      client.decrement_pixel(graph_id: graph_id)
×
136
    end
137

138
    # Add quantity to the "Pixel" of the day
139
    #
140
    # @param quantity [String]
141
    #
142
    # @return [Pixela::Response]
143
    #
144
    # @raise [Pixela::PixelaError] API is failed
145
    #
146
    # @see https://docs.pixe.la/entry/add-pixel
147
    #
148
    # @example
149
    #   client.graph("test-graph").add(quantity: "1")
150
    def add(quantity:)
1✔
151
      client.add_pixel(graph_id: graph_id, quantity: quantity)
×
152
    end
153

154
    # Subtract quantity from the "Pixel" of the day
155
    #
156
    # @param quantity [String]
157
    #
158
    # @return [Pixela::Response]
159
    #
160
    # @raise [Pixela::PixelaError] API is failed
161
    #
162
    # @see https://docs.pixe.la/entry/subtract-pixel
163
    #
164
    # @example
165
    #   client.graph("test-graph").subtract(quantity: "1")
166
    def subtract(quantity:)
1✔
167
      client.subtract_pixel(graph_id: graph_id, quantity: quantity)
×
168
    end
169

170
    # Get a Date list of Pixel registered in the graph specified by graphID.
171
    #
172
    # @param from [Date] Specify the start position of the period.
173
    # @param to   [Date] Specify the end position of the period.
174
    #
175
    # @return [Array<Date>]
176
    #
177
    # @raise [Pixela::PixelaError] API is failed
178
    #
179
    # @see https://docs.pixe.la/entry/get-graph-pixels
180
    #
181
    # @example
182
    #   client.graph("test-graph").pixel_dates(from: Date.new(2018, 1, 1), to: Date.new(2018, 12, 31))
183
    def pixel_dates(from: nil, to: nil)
1✔
184
      client.get_pixel_dates(graph_id: graph_id, from: from, to: to)
×
185
    end
186

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

204
    # Based on the registered information, get various statistics.
205
    #
206
    # @return [Pixela::Response]
207
    #
208
    # @raise [Pixela::PixelaError] API is failed
209
    #
210
    # @see https://docs.pixe.la/entry/get-graph-stats
211
    #
212
    # @example
213
    #   client.graph("test-graph").stats
214
    def stats
1✔
215
      client.get_graph_stats(graph_id: graph_id)
×
216
    end
217

218
    # This will start and end the measurement of the time.
219
    #
220
    # @return [Pixela::Response]
221
    #
222
    # @raise [Pixela::PixelaError] API is failed
223
    #
224
    # @see https://docs.pixe.la/entry/post-stopwatch
225
    #
226
    # @example
227
    #   client.graph("test-graph").run_stopwatch
228
    def run_stopwatch
1✔
229
      client.run_stopwatch(graph_id: graph_id)
×
230
    end
231

232
    alias_method :start_stopwatch, :run_stopwatch
1✔
233
    alias_method :end_stopwatch,   :run_stopwatch
1✔
234

235
    # Get a predefined pixelation graph definition.
236
    #
237
    # @return [Pixela::Response]
238
    #
239
    # @raise [Pixela::PixelaError] API is failed
240
    #
241
    # @see https://docs.pixe.la/entry/get-a-graph-def
242
    #
243
    # @example
244
    #   client.graph("test-graph").def
245
    def def
1✔
246
      client.get_graph_def(graph_id: graph_id)
×
247
    end
248

249
    alias_method :definition, :def
1✔
250

251
    # This API is used to get latest Pixel of the graph which specified by <graphID> .
252
    #
253
    # @return [Pixela::Response]
254
    #
255
    # @raise [Pixela::PixelaError] API is failed
256
    #
257
    # @see https://docs.pixe.la/entry/get-latest-pixel
258
    #
259
    # @example
260
    #   client.graph("test-graph").latest
261
    def latest
1✔
262
      client.get_graph_latest(graph_id: graph_id)
×
263
    end
264

265
    # This is an endpoint that responds with the Pixel of the day you requested this API.
266
    #
267
    # @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.
268
    #
269
    # @return [Pixela::Response]
270
    #
271
    # @raise [Pixela::PixelaError] API is failed
272
    #
273
    # @see https://docs.pixe.la/entry/get-today-pixel
274
    #
275
    # @example
276
    #   client.graph("test-graph").today(return_empty: true)
277
    def today(return_empty: false)
1✔
278
      client.get_graph_today(graph_id: graph_id, return_empty: return_empty)
×
279
    end
280
  end
281
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