Module: Pixela::Client::PixelMethods
- Included in:
- Pixela::Client
- Defined in:
- lib/pixela/client/pixel_methods.rb
Instance Method Summary collapse
-
#add_pixel(graph_id:, quantity:) ⇒ Pixela::Response
Add quantity to the “Pixel” of the day.
-
#create_pixel(graph_id:, date: Date.today, quantity:, optional_data: nil) ⇒ Pixela::Response
It records the quantity of the specified date as a “Pixel”.
-
#create_pixels(graph_id:, pixels:) ⇒ Pixela::Response
This API is used to register multiple Pixels (quantities for a specific day) at a time.
-
#decrement_pixel(graph_id:) ⇒ Pixela::Response
Decrement quantity “Pixel” of the day (UTC).
-
#delete_pixel(graph_id:, date: Date.today) ⇒ Pixela::Response
Delete the registered “Pixel”.
-
#get_pixel(graph_id:, date: Date.today) ⇒ Pixela::Response
Get registered quantity as “Pixel”.
-
#increment_pixel(graph_id:) ⇒ Pixela::Response
Increment quantity “Pixel” of the day (UTC).
-
#subtract_pixel(graph_id:, quantity:) ⇒ Pixela::Response
Subtract quantity from the “Pixel” of the day.
-
#update_pixel(graph_id:, date: Date.today, quantity:, optional_data: nil) ⇒ Pixela::Response
Update the quantity already registered as a “Pixel”.
Instance Method Details
#add_pixel(graph_id:, quantity:) ⇒ Pixela::Response
Add quantity to the “Pixel” of the day
182 183 184 185 186 187 188 189 190 |
# File 'lib/pixela/client/pixel_methods.rb', line 182 def add_pixel(graph_id:, quantity:) params = { quantity: quantity.to_s, } with_error_handling do connection.put("users/#{username}/graphs/#{graph_id}/add", params.compact).body end end |
#create_pixel(graph_id:, date: Date.today, quantity:, optional_data: nil) ⇒ Pixela::Response
It records the quantity of the specified date as a “Pixel”.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pixela/client/pixel_methods.rb', line 17 def create_pixel(graph_id:, date: Date.today, quantity:, optional_data: nil) params = { date: to_ymd(date), quantity: quantity.to_s, optionalData: optional_data&.to_json, } with_error_handling do connection.post("users/#{username}/graphs/#{graph_id}", params.compact).body end end |
#create_pixels(graph_id:, pixels:) ⇒ Pixela::Response
This API is used to register multiple Pixels (quantities for a specific day) at a time.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pixela/client/pixel_methods.rb', line 42 def create_pixels(graph_id:, pixels:) pixels = pixels.map do |pixel| { date: to_ymd(pixel[:date]), quantity: pixel[:quantity].to_s, optionalData: pixel[:optional_data]&.to_json, }.compact end with_error_handling do connection.post("users/#{username}/graphs/#{graph_id}/pixels", pixels).body end end |
#decrement_pixel(graph_id:) ⇒ Pixela::Response
Decrement quantity “Pixel” of the day (UTC).
163 164 165 166 167 |
# File 'lib/pixela/client/pixel_methods.rb', line 163 def decrement_pixel(graph_id:) with_error_handling do connection.put("users/#{username}/graphs/#{graph_id}/decrement").body end end |
#delete_pixel(graph_id:, date: Date.today) ⇒ Pixela::Response
Delete the registered “Pixel”.
127 128 129 130 131 |
# File 'lib/pixela/client/pixel_methods.rb', line 127 def delete_pixel(graph_id:, date: Date.today) with_error_handling do connection.delete("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}").body end end |
#get_pixel(graph_id:, date: Date.today) ⇒ Pixela::Response
Get registered quantity as “Pixel”.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/pixela/client/pixel_methods.rb', line 69 def get_pixel(graph_id:, date: Date.today) res = with_error_handling do connection.get("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}").body end if res.key?(:optionalData) res[:optional_data] = begin JSON.parse(res[:optionalData]) rescue JSON::ParserError res[:optionalData] end res.delete(:optionalData) end res end |
#increment_pixel(graph_id:) ⇒ Pixela::Response
Increment quantity “Pixel” of the day (UTC).
145 146 147 148 149 |
# File 'lib/pixela/client/pixel_methods.rb', line 145 def increment_pixel(graph_id:) with_error_handling do connection.put("users/#{username}/graphs/#{graph_id}/increment").body end end |
#subtract_pixel(graph_id:, quantity:) ⇒ Pixela::Response
Subtract quantity from the “Pixel” of the day
205 206 207 208 209 210 211 212 213 |
# File 'lib/pixela/client/pixel_methods.rb', line 205 def subtract_pixel(graph_id:, quantity:) params = { quantity: quantity.to_s, } with_error_handling do connection.put("users/#{username}/graphs/#{graph_id}/subtract", params.compact).body end end |
#update_pixel(graph_id:, date: Date.today, quantity:, optional_data: nil) ⇒ Pixela::Response
Update the quantity already registered as a “Pixel”.
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/pixela/client/pixel_methods.rb', line 103 def update_pixel(graph_id:, date: Date.today, quantity:, optional_data: nil) params = { quantity: quantity.to_s, optionalData: optional_data&.to_json } with_error_handling do connection.put("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}", params.compact).body end end |