Module: Pixela::Client::PixelMethods

Included in:
Pixela::Client
Defined in:
lib/pixela/client/pixel_methods.rb

Instance Method Summary collapse

Instance Method Details

#create_pixel(graph_id:, date: Date.today, quantity:) ⇒ Hashie::Mash

It records the quantity of the specified date as a "Pixel".

Examples:

client.create_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15), quantity: 5)

Parameters:

  • graph_id (String)
  • date (Date, Time) (defaults to: Date.today)
  • quantity (Integer, Float)

Returns:

  • (Hashie::Mash)

Raises:

See Also:



16
17
18
19
20
21
22
23
24
25
# File 'lib/pixela/client/pixel_methods.rb', line 16

def create_pixel(graph_id:, date: Date.today, quantity:)
  params = {
    date:     to_ymd(date),
    quantity: quantity.to_s,
  }

  with_error_handling do
    connection.post("users/#{username}/graphs/#{graph_id}", params, user_token_headers).body
  end
end

#decrement_pixel(graph_id:) ⇒ Hashie::Mash

Decrement quantity "Pixel" of the day (UTC).

Examples:

client.decrement_pixel(graph_id: "test-graph")

Parameters:

  • graph_id (String)

Returns:

  • (Hashie::Mash)

Raises:

See Also:



119
120
121
122
123
# File 'lib/pixela/client/pixel_methods.rb', line 119

def decrement_pixel(graph_id:)
  with_error_handling do
    connection.put("users/#{username}/graphs/#{graph_id}/decrement", nil, user_token_headers).body
  end
end

#delete_pixel(graph_id:, date: Date.today) ⇒ Hashie::Mash

Delete the registered "Pixel".

Examples:

client.delete_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15))

Parameters:

  • graph_id (String)
  • date (Date, Time) (defaults to: Date.today)

Returns:

  • (Hashie::Mash)

Raises:

See Also:



83
84
85
86
87
# File 'lib/pixela/client/pixel_methods.rb', line 83

def delete_pixel(graph_id:, date: Date.today)
  with_error_handling do
    connection.delete("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}", nil, user_token_headers).body
  end
end

#get_pixel(graph_id:, date: Date.today) ⇒ Hashie::Mash

Get registered quantity as "Pixel".

Examples:

client.get_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15))

Parameters:

  • graph_id (String)
  • date (Date, Time) (defaults to: Date.today)

Returns:

  • (Hashie::Mash)

Raises:

See Also:



40
41
42
43
44
# File 'lib/pixela/client/pixel_methods.rb', line 40

def get_pixel(graph_id:, date: Date.today)
  with_error_handling do
    connection.get("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}", nil, user_token_headers).body
  end
end

#increment_pixel(graph_id:) ⇒ Hashie::Mash

Increment quantity "Pixel" of the day (UTC).

Examples:

client.increment_pixel(graph_id: "test-graph")

Parameters:

  • graph_id (String)

Returns:

  • (Hashie::Mash)

Raises:

See Also:



101
102
103
104
105
# File 'lib/pixela/client/pixel_methods.rb', line 101

def increment_pixel(graph_id:)
  with_error_handling do
    connection.put("users/#{username}/graphs/#{graph_id}/increment", nil, user_token_headers).body
  end
end

#update_pixel(graph_id:, date: Date.today, quantity:) ⇒ Hashie::Mash

Update the quantity already registered as a "Pixel".

Examples:

client.update_pixel(graph_id: "test-graph", date: Date.new(2018, 9, 15), quantity: 7)

Parameters:

  • graph_id (String)
  • date (Date, Time) (defaults to: Date.today)
  • quantity (Integer, Float)

Returns:

  • (Hashie::Mash)

Raises:

See Also:



60
61
62
63
64
65
66
67
68
# File 'lib/pixela/client/pixel_methods.rb', line 60

def update_pixel(graph_id:, date: Date.today, quantity:)
  params = {
    quantity: quantity.to_s,
  }

  with_error_handling do
    connection.put("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}", params, user_token_headers).body
  end
end