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

sue445 / pixela / #11453

23 Jan 2023 12:17PM UTC coverage: 39.357% (-58.6%) from 97.934%
#11453

push

web-flow
Merge pull request #100 from sue445/dependabot/github_actions/actions/configure-pages-3

Bump actions/configure-pages from 2 to 3

98 of 249 relevant lines covered (39.36%)

0.39 hits per line

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

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

24
    with_error_handling do
×
25
      connection.post("users/#{username}/graphs/#{graph_id}", params.compact).body
×
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)
1✔
43
    res =
44
      with_error_handling do
×
45
        connection.get("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}").body
×
46
      end
47

48
    if res.key?(:optionalData)
×
49
      res[:optional_data] =
×
50
        begin
51
          JSON.parse(res[:optionalData])
×
52
        rescue JSON::ParserError
53
          res[:optionalData]
×
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
71
  #
72
  # @see https://docs.pixe.la/entry/put-pixel
73
  #
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)
1✔
77
    params = {
78
      quantity:     quantity.to_s,
×
79
      optionalData: optional_data&.to_json
80
    }
81

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

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)
1✔
101
    with_error_handling do
×
102
      connection.delete("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}").body
×
103
    end
104
  end
105

106
  # Increment quantity "Pixel" of the day (UTC).
107
  #
108
  # @param graph_id [String]
109
  #
110
  # @return [Pixela::Response]
111
  #
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:)
1✔
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]
129
  #
130
  # @raise [Pixela::PixelaError] API is failed
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:)
1✔
137
    with_error_handling do
×
138
      connection.put("users/#{username}/graphs/#{graph_id}/decrement").body
×
139
    end
140
  end
141
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