• 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

25.0
/lib/pixela/client/pixel_methods.rb
1
module Pixela::Client::PixelMethods
1✔
2
  # It records the quantity of the specified date as a "Pixel".
3
  #
4
  # @param graph_id      [String]
5
  # @param date          [Date,Time]
6
  # @param quantity      [Integer,Float]
7
  # @param optional_data [Object] Additional information other than quantity
8
  #
9
  # @return [Pixela::Response]
10
  #
11
  # @raise [Pixela::PixelaError] API is failed
12
  #
13
  # @see https://docs.pixe.la/entry/post-pixel
14
  #
15
  # @example
16
  #   client.create_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15), quantity: 5, optional_data: {key: "value"})
17
  def create_pixel(graph_id:, date: Date.today, quantity:, optional_data: nil)
1✔
18
    params = {
19
      date:         to_ymd(date),
×
20
      quantity:     quantity.to_s,
21
      optionalData: optional_data&.to_json,
22
    }
23

24
    with_error_handling do
×
25
      connection.post("users/#{username}/graphs/#{graph_id}", params.compact).body
×
26
    end
27
  end
28

29
  # This API is used to register multiple Pixels (quantities for a specific day) at a time.
30
  #
31
  # @param graph_id [String]
32
  # @param pixels   [Array<Hash>] key: date, quantity, optional_data
33
  #
34
  # @return [Pixela::Response]
35
  #
36
  # @raise [Pixela::PixelaError] API is failed
37
  #
38
  # @see https://docs.pixe.la/entry/batch-post-pixels
39
  #
40
  # @example
41
  #   client.create_pixels(graph_id: "test-graph", pixels: [{date: Date.new(2018, 9, 15), quantity: 5, optional_data: {key: "value"}}])
42
  def create_pixels(graph_id:, pixels:)
1✔
43
    pixels = pixels.map do |pixel|
×
44
      {
45
        date:         to_ymd(pixel[:date]),
×
46
        quantity:     pixel[:quantity].to_s,
47
        optionalData: pixel[:optional_data]&.to_json,
48
      }.compact
49
    end
50

51
    with_error_handling do
×
52
      connection.post("users/#{username}/graphs/#{graph_id}/pixels", pixels).body
×
53
    end
54
  end
55

56
  # Get registered quantity as "Pixel".
57
  #
58
  # @param graph_id [String]
59
  # @param date     [Date,Time]
60
  #
61
  # @return [Pixela::Response]
62
  #
63
  # @raise [Pixela::PixelaError] API is failed
64
  #
65
  # @see https://docs.pixe.la/entry/get-pixel
66
  #
67
  # @example
68
  #   client.get_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15))
69
  def get_pixel(graph_id:, date: Date.today)
1✔
70
    res =
71
      with_error_handling do
×
72
        connection.get("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}").body
×
73
      end
74

75
    if res.key?(:optionalData)
×
76
      res[:optional_data] =
×
77
        begin
78
          JSON.parse(res[:optionalData])
×
79
        rescue JSON::ParserError
80
          res[:optionalData]
×
81
        end
82
      res.delete(:optionalData)
×
83
    end
84

85
    res
×
86
  end
87

88
  # Update the quantity already registered as a "Pixel".
89
  #
90
  # @param graph_id      [String]
91
  # @param date          [Date,Time]
92
  # @param quantity      [Integer,Float]
93
  # @param optional_data [Object] Additional information other than quantity
94
  #
95
  # @return [Pixela::Response]
96
  #
97
  # @raise [Pixela::PixelaError] API is failed
98
  #
99
  # @see https://docs.pixe.la/entry/put-pixel
100
  #
101
  # @example
102
  #   client.update_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15), quantity: 7, optional_data: {key: "value"})
103
  def update_pixel(graph_id:, date: Date.today, quantity:, optional_data: nil)
1✔
104
    params = {
105
      quantity:     quantity.to_s,
×
106
      optionalData: optional_data&.to_json
107
    }
108

109
    with_error_handling do
×
110
      connection.put("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}", params.compact).body
×
111
    end
112
  end
113

114
  # Delete the registered "Pixel".
115
  #
116
  # @param graph_id [String]
117
  # @param date     [Date,Time]
118
  #
119
  # @return [Pixela::Response]
120
  #
121
  # @raise [Pixela::PixelaError] API is failed
122
  #
123
  # @see https://docs.pixe.la/entry/delete-pixel
124
  #
125
  # @example
126
  #   client.delete_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15))
127
  def delete_pixel(graph_id:, date: Date.today)
1✔
128
    with_error_handling do
×
129
      connection.delete("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}").body
×
130
    end
131
  end
132

133
  # Increment quantity "Pixel" of the day (UTC).
134
  #
135
  # @param graph_id [String]
136
  #
137
  # @return [Pixela::Response]
138
  #
139
  # @raise [Pixela::PixelaError] API is failed
140
  #
141
  # @see https://docs.pixe.la/entry/increment-pixel
142
  #
143
  # @example
144
  #   client.increment_pixel(graph_id: "test-graph")
145
  def increment_pixel(graph_id:)
1✔
146
    with_error_handling do
×
147
      connection.put("users/#{username}/graphs/#{graph_id}/increment").body
×
148
    end
149
  end
150

151
  # Decrement quantity "Pixel" of the day (UTC).
152
  #
153
  # @param graph_id [String]
154
  #
155
  # @return [Pixela::Response]
156
  #
157
  # @raise [Pixela::PixelaError] API is failed
158
  #
159
  # @see https://docs.pixe.la/entry/decrement-pixel
160
  #
161
  # @example
162
  #   client.decrement_pixel(graph_id: "test-graph")
163
  def decrement_pixel(graph_id:)
1✔
164
    with_error_handling do
×
165
      connection.put("users/#{username}/graphs/#{graph_id}/decrement").body
×
166
    end
167
  end
168

169
  # Add quantity to the "Pixel" of the day
170
  #
171
  # @param graph_id [String]
172
  # @param quantity [String]
173
  #
174
  # @return [Pixela::Response]
175
  #
176
  # @raise [Pixela::PixelaError] API is failed
177
  #
178
  # @see https://docs.pixe.la/entry/add-pixel
179
  #
180
  # @example
181
  #   client.add_pixel(graph_id: "test-graph", quantity: "1")
182
  def add_pixel(graph_id:, quantity:)
1✔
183
    params = {
184
      quantity: quantity.to_s,
×
185
    }
186

187
    with_error_handling do
×
188
      connection.put("users/#{username}/graphs/#{graph_id}/add", params.compact).body
×
189
    end
190
  end
191

192
  # Subtract quantity from the "Pixel" of the day
193
  #
194
  # @param graph_id [String]
195
  # @param quantity [String]
196
  #
197
  # @return [Pixela::Response]
198
  #
199
  # @raise [Pixela::PixelaError] API is failed
200
  #
201
  # @see https://docs.pixe.la/entry/subtract-pixel
202
  #
203
  # @example
204
  #   client.subtract_pixel(graph_id: "test-graph", quantity: "1")
205
  def subtract_pixel(graph_id:, quantity:)
1✔
206
    params = {
207
      quantity: quantity.to_s,
×
208
    }
209

210
    with_error_handling do
×
211
      connection.put("users/#{username}/graphs/#{graph_id}/subtract", params.compact).body
×
212
    end
213
  end
214
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