module Pixela::Client::PixelMethods
Public Instance Methods
It records the quantity of the specified date as a “Pixel”.
@param graph_id [String] @param date [Date,Time] @param quantity [Integer,Float] @param optional_data [Object] Additional information other than quantity
@return [Pixela::Response]
@raise [Pixela::PixelaError] API is failed
@see docs.pixe.la/entry/post-pixel
@example
client.create_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15), quantity: 5, optional_data: {key: "value"})
# 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
Decrement quantity “Pixel” of the day (UTC).
@param graph_id [String]
@return [Pixela::Response]
@raise [Pixela::PixelaError] API is failed
@see docs.pixe.la/entry/decrement-pixel
@example
client.decrement_pixel(graph_id: "test-graph")
# 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 the registered “Pixel”.
@param graph_id [String] @param date [Date,Time]
@return [Pixela::Response]
@raise [Pixela::PixelaError] API is failed
@see docs.pixe.la/entry/delete-pixel
@example
client.delete_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15))
# 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 registered quantity as “Pixel”.
@param graph_id [String] @param date [Date,Time]
@return [Pixela::Response]
@raise [Pixela::PixelaError] API is failed
@see docs.pixe.la/entry/get-pixel
@example
client.get_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15))
# 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 quantity “Pixel” of the day (UTC).
@param graph_id [String]
@return [Pixela::Response]
@raise [Pixela::PixelaError] API is failed
@see docs.pixe.la/entry/increment-pixel
@example
client.increment_pixel(graph_id: "test-graph")
# 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 the quantity already registered as a “Pixel”.
@param graph_id [String] @param date [Date,Time] @param quantity [Integer,Float] @param optional_data [Object] Additional information other than quantity
@return [Pixela::Response]
@raise [Pixela::PixelaError] API is failed
@see docs.pixe.la/entry/put-pixel
@example
client.update_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15), quantity: 7, optional_data: {key: "value"})
# 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)}", params.compact).body end end