Module: Pixela::Client::PixelMethods
- Included in:
- Pixela::Client
- Defined in:
- lib/pixela/client/pixel_methods.rb
Instance Method Summary collapse
-
#create_pixel(graph_id:, date: Date.today, quantity:, optional_data: nil) ⇒ Pixela::Response
It records the quantity of the specified date as a "Pixel".
-
#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).
-
#update_pixel(graph_id:, date: Date.today, quantity:, optional_data: nil) ⇒ Pixela::Response
Update the quantity already registered as a "Pixel".
Instance Method Details
#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}", compact_hash(params)).body end end |
#decrement_pixel(graph_id:) ⇒ Pixela::Response
Decrement quantity "Pixel" of the day (UTC).
136 137 138 139 140 |
# File 'lib/pixela/client/pixel_methods.rb', line 136 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".
100 101 102 103 104 |
# File 'lib/pixela/client/pixel_methods.rb', line 100 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".
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pixela/client/pixel_methods.rb', line 42 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).
118 119 120 121 122 |
# File 'lib/pixela/client/pixel_methods.rb', line 118 def increment_pixel(graph_id:) with_error_handling do connection.put("users/#{username}/graphs/#{graph_id}/increment").body end end |
#update_pixel(graph_id:, date: Date.today, quantity:, optional_data: nil) ⇒ Pixela::Response
Update the quantity already registered as a "Pixel".
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/pixela/client/pixel_methods.rb', line 76 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)}", compact_hash(params)).body end end |