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

sue445 / pixela / #11023

11 Dec 2023 12:50PM UTC coverage: 98.084% (+0.05%) from 98.031%
#11023

push

web-flow
Merge pull request #104 from sue445/dependabot/github_actions/actions/configure-pages-4

256 of 261 relevant lines covered (98.08%)

7.08 hits per line

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

97.5
/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),
3✔
20
      quantity:     quantity.to_s,
21
      optionalData: optional_data&.to_json,
22
    }
23

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

29
  # Get registered quantity as "Pixel".
30
  #
31
  # @param graph_id [String]
32
  # @param date     [Date,Time]
33
  #
34
  # @return [Pixela::Response]
35
  #
36
  # @raise [Pixela::PixelaError] API is failed
37
  #
38
  # @see https://docs.pixe.la/entry/get-pixel
39
  #
40
  # @example
41
  #   client.get_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15))
42
  def get_pixel(graph_id:, date: Date.today)
43
    res =
1✔
44
      with_error_handling do
2✔
45
        connection.get("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}").body
46
      end
6✔
47

48
    if res.key?(:optionalData)
49
      res[:optional_data] =
50
        begin
51
          JSON.parse(res[:optionalData])
52
        rescue JSON::ParserError
2✔
53
          res[:optionalData]
2✔
54
        end
55
      res.delete(:optionalData)
56
    end
57

58
    res
59
  end
60

61
  # Update the quantity already registered as a "Pixel".
62
  #
63
  # @param graph_id      [String]
64
  # @param date          [Date,Time]
65
  # @param quantity      [Integer,Float]
66
  # @param optional_data [Object] Additional information other than quantity
67
  #
68
  # @return [Pixela::Response]
69
  #
70
  # @raise [Pixela::PixelaError] API is failed
1✔
71
  #
72
  # @see https://docs.pixe.la/entry/put-pixel
3✔
73
  #
3✔
74
  # @example
75
  #   client.update_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15), quantity: 7, optional_data: {key: "value"})
76
  def update_pixel(graph_id:, date: Date.today, quantity:, optional_data: nil)
3✔
77
    params = {
3✔
78
      quantity:     quantity.to_s,
79
      optionalData: optional_data&.to_json
3✔
80
    }
81

×
82
    with_error_handling do
83
      connection.put("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}", params.compact).body
3✔
84
    end
85
  end
86

3✔
87
  # Delete the registered "Pixel".
88
  #
89
  # @param graph_id [String]
90
  # @param date     [Date,Time]
91
  #
92
  # @return [Pixela::Response]
93
  #
94
  # @raise [Pixela::PixelaError] API is failed
95
  #
96
  # @see https://docs.pixe.la/entry/delete-pixel
97
  #
98
  # @example
99
  #   client.delete_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15))
100
  def delete_pixel(graph_id:, date: Date.today)
101
    with_error_handling do
102
      connection.delete("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}").body
103
    end
104
  end
1✔
105

106
  # Increment quantity "Pixel" of the day (UTC).
3✔
107
  #
108
  # @param graph_id [String]
109
  #
110
  # @return [Pixela::Response]
3✔
111
  #
3✔
112
  # @raise [Pixela::PixelaError] API is failed
113
  #
114
  # @see https://docs.pixe.la/entry/increment-pixel
115
  #
116
  # @example
117
  #   client.increment_pixel(graph_id: "test-graph")
118
  def increment_pixel(graph_id:)
119
    with_error_handling do
120
      connection.put("users/#{username}/graphs/#{graph_id}/increment").body
121
    end
122
  end
123

124
  # Decrement quantity "Pixel" of the day (UTC).
125
  #
126
  # @param graph_id [String]
127
  #
128
  # @return [Pixela::Response]
1✔
129
  #
2✔
130
  # @raise [Pixela::PixelaError] API is failed
2✔
131
  #
132
  # @see https://docs.pixe.la/entry/decrement-pixel
133
  #
134
  # @example
135
  #   client.decrement_pixel(graph_id: "test-graph")
136
  def decrement_pixel(graph_id:)
137
    with_error_handling do
138
      connection.put("users/#{username}/graphs/#{graph_id}/decrement").body
139
    end
140
  end
141

142
  # Add quantity to the "Pixel" of the day
143
  #
144
  # @param graph_id [String]
145
  # @param quantity [String]
146
  #
1✔
147
  # @return [Pixela::Response]
2✔
148
  #
2✔
149
  # @raise [Pixela::PixelaError] API is failed
150
  #
151
  # @see https://docs.pixe.la/entry/add-pixel
152
  #
153
  # @example
154
  #   client.add_pixel(graph_id: "test-graph", quantity: "1")
155
  def add_pixel(graph_id:, quantity:)
156
    params = {
157
      quantity: quantity.to_s,
158
    }
159

160
    with_error_handling do
161
      connection.put("users/#{username}/graphs/#{graph_id}/add", params.compact).body
162
    end
163
  end
164

1✔
165
  # Subtract quantity from the "Pixel" of the day
2✔
166
  #
2✔
167
  # @param graph_id [String]
168
  # @param quantity [String]
169
  #
170
  # @return [Pixela::Response]
171
  #
172
  # @raise [Pixela::PixelaError] API is failed
173
  #
174
  # @see https://docs.pixe.la/entry/subtract-pixel
175
  #
176
  # @example
177
  #   client.subtract_pixel(graph_id: "test-graph", quantity: "1")
178
  def subtract_pixel(graph_id:, quantity:)
179
    params = {
180
      quantity: quantity.to_s,
181
    }
182

183
    with_error_handling do
1✔
184
      connection.put("users/#{username}/graphs/#{graph_id}/subtract", params.compact).body
185
    end
2✔
186
  end
187
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