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

sue445 / pixela / #11406

23 Jan 2023 12:17PM UTC coverage: 97.287% (-0.6%) from 97.934%
#11406

push

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

Bump actions/configure-pages from 2 to 3

251 of 258 relevant lines covered (97.29%)

6.93 hits per line

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

96.0
/lib/pixela/client/graph_methods.rb
1
module Pixela::Client::GraphMethods
1✔
2
  # Create a new pixelation graph definition.
3
  #
4
  # @param graph_id              [String]
5
  # @param name                  [String]
6
  # @param unit                  [String]
7
  # @param type                  [String]
8
  # @param color                 [String]
9
  # @param timezone              [String]
10
  # @param self_sufficient       [String] If SVG graph with this field `increment` or `decrement` is referenced, Pixel of this graph itself will be incremented or decremented
11
  # @param is_secret             [Boolean]
12
  # @param publish_optional_data [Boolean]
13
  #
14
  # @return [Pixela::Response]
15
  #
16
  # @raise [Pixela::PixelaError] API is failed
17
  #
18
  # @see https://docs.pixe.la/entry/post-graph
19
  #
20
  # @example
21
  #   client.create_graph(graph_id: "test-graph", name: "graph-name", unit: "commit", type: "int", color: "shibafu", timezone: "Asia/Tokyo", self_sufficient: "increment", is_secret: true, publish_optional_data: true)
22
  def create_graph(graph_id:, name:, unit:, type:, color:, timezone: nil, self_sufficient: nil, is_secret: nil, publish_optional_data: nil)
1✔
23
    params = {
24
      id:                  graph_id,
2✔
25
      name:                name,
26
      unit:                unit,
27
      type:                type,
28
      color:               color,
29
      timezone:            timezone,
30
      selfSufficient:      self_sufficient,
31
      isSecret:            is_secret,
32
      publishOptionalData: publish_optional_data
33
    }
34

35
    with_error_handling do
2✔
36
      connection.post("users/#{username}/graphs", params.compact).body
2✔
37
    end
38
  end
39

40
  # Get all predefined pixelation graph definitions.
41
  #
42
  # @return [Array<Hashie::Mash>]
43
  #
44
  # @raise [Pixela::PixelaError] API is failed
45
  #
46
  # @see https://docs.pixe.la/entry/get-graph
47
  #
48
  # @example
49
  #   client.get_graphs
50
  def get_graphs
1✔
51
    with_error_handling do
7✔
52
      connection.get("users/#{username}/graphs").body.graphs
7✔
53
    end
54
  end
55

56
  # Get graph url
57
  #
58
  # @param graph_id [String]
59
  # @param date     [Date,Time]
60
  # @param mode     [String] e.g) `short`
61
  #
62
  # @return [String]
63
  #
64
  # @see https://docs.pixe.la/entry/get-svg
65
  #
66
  # @example
67
  #   client.graph_url(graph_id: "test-graph")
68
  #   client.graph_url(graph_id: "test-graph", date: Date.new(2018, 3, 31), mode: "short")
69
  def graph_url(graph_id:, date: nil, mode: nil)
1✔
70
    url = "#{Pixela::Client::API_ENDPOINT}/users/#{username}/graphs/#{graph_id}"
6✔
71

72
    params = Faraday::Utils::ParamsHash.new
6✔
73
    params[:date] = to_ymd(date) if date
6✔
74
    params[:mode] = mode if mode
6✔
75

76
    url << "?#{params.to_query}" unless params.empty?
6✔
77

78
    url
6✔
79
  end
80

81
  # Displays graph list by detail in html format.
82
  #
83
  # @return [String]
84
  #
85
  # @see https://docs.pixe.la/entry/get-graph-list-html
86
  #
87
  # @example
88
  #   client.graphs_url
89
  def graphs_url
1✔
90
    "https://pixe.la/v1/users/#{username}/graphs.html"
1✔
91
  end
92

93
  # Update predefined pixelation graph definitions.
94
  #
95
  # @param graph_id              [String]
96
  # @param name                  [String]
97
  # @param unit                  [String]
98
  # @param color                 [String]
99
  # @param timezone              [String]
100
  # @param self_sufficient       [String] If SVG graph with this field `increment` or `decrement` is referenced, Pixel of this graph itself will be incremented or decremented
101
  # @param purge_cache_urls      [String,Array<String>]
102
  # @param is_secret             [Boolean]
103
  # @param publish_optional_data [Boolean]
104
  #
105
  # @return [Pixela::Response]
106
  #
107
  # @raise [Pixela::PixelaError] API is failed
108
  #
109
  # @see https://docs.pixe.la/entry/put-graph
110
  #
111
  # @example
112
  #   client.update_graph(graph_id: "test-graph", name: "graph-name", unit: "commit", color: "shibafu", timezone: "Asia/Tokyo", self_sufficient: "increment", purge_cache_urls: ["https://camo.githubusercontent.com/xxx/xxxx"])
113
  def update_graph(graph_id:, name: nil, unit: nil, color: nil, timezone: nil, self_sufficient: nil, purge_cache_urls: nil, is_secret: nil, publish_optional_data: nil)
1✔
114
    params = {
115
      name:                name,
14✔
116
      unit:                unit,
117
      color:               color,
118
      timezone:            timezone,
119
      selfSufficient:      self_sufficient,
120
      isSecret:            is_secret,
121
      publishOptionalData: publish_optional_data
122
    }
123

124
    if purge_cache_urls
14✔
125
      params[:purgeCacheURLs] = Array(purge_cache_urls)
12✔
126
    end
127

128
    with_error_handling do
14✔
129
      connection.put("users/#{username}/graphs/#{graph_id}", params.compact).body
14✔
130
    end
131
  end
132

133
  # Delete the predefined pixelation graph definition.
134
  #
135
  # @param graph_id [String]
136
  #
137
  # @return [Pixela::Response]
138
  #
139
  # @raise [Pixela::PixelaError] API is failed
140
  #
141
  # @see https://docs.pixe.la/entry/delete-graph
142
  #
143
  # @example
144
  #   client.delete_graph("test-graph")
145
  def delete_graph(graph_id)
1✔
146
    with_error_handling do
2✔
147
      connection.delete("users/#{username}/graphs/#{graph_id}").body
2✔
148
    end
149
  end
150

151
  # Get a Date list of Pixel registered in the graph specified by graphID.
152
  #
153
  # @param graph_id [String]
154
  # @param from [Date] Specify the start position of the period.
155
  # @param to   [Date] Specify the end position of the period.
156
  #
157
  # @return [Array<Date>]
158
  #
159
  # @raise [Pixela::PixelaError] API is failed
160
  #
161
  # @see https://docs.pixe.la/entry/get-graph-pixels
162
  #
163
  # @example
164
  #   client.get_pixel_dates(graph_id: "test-graph", from: Date.new(2018, 1, 1), to: Date.new(2018, 12, 31))
165
  def get_pixel_dates(graph_id:, from: nil, to: nil)
1✔
166
    params = {
167
      from: to_ymd(from),
1✔
168
      to:   to_ymd(to),
169
    }
170

171
    res =
172
      with_error_handling do
1✔
173
        connection.get("users/#{username}/graphs/#{graph_id}/pixels", params.compact).body
1✔
174
      end
175

176
    res.pixels.map { |ymd| Date.parse(ymd) }
6✔
177
  end
178

179
  # Get a Date list of Pixel registered in the graph specified by graphID.
180
  #
181
  # @param graph_id [String]
182
  # @param from [Date] Specify the start position of the period.
183
  # @param to   [Date] Specify the end position of the period.
184
  #
185
  # @return [Array<Hashie::Mash>]
186
  #
187
  # @raise [Pixela::PixelaError] API is failed
188
  #
189
  # @see https://docs.pixe.la/entry/get-graph-pixels
190
  #
191
  # @example
192
  #   client.get_pixels(graph_id: "test-graph", from: Date.new(2018, 1, 1), to: Date.new(2018, 12, 31))
193
  def get_pixels(graph_id:, from: nil, to: nil)
1✔
194
    params = {
195
      from:     to_ymd(from),
7✔
196
      to:       to_ymd(to),
197
      withBody: true,
198
    }
199

200
    with_error_handling do
7✔
201
      connection.get("users/#{username}/graphs/#{graph_id}/pixels", params.compact).body.pixels
7✔
202
    end
203
  end
204

205
  # Based on the registered information, get various statistics.
206
  #
207
  # @param graph_id [String]
208
  #
209
  # @return [Pixela::Response]
210
  #
211
  # @raise [Pixela::PixelaError] API is failed
212
  #
213
  # @see https://docs.pixe.la/entry/get-graph-stats
214
  #
215
  # @example
216
  #   client.get_graph_stats(graph_id: "test-graph")
217
  def get_graph_stats(graph_id:)
1✔
218
    with_error_handling do
1✔
219
      connection.get("users/#{username}/graphs/#{graph_id}/stats").body
1✔
220
    end
221
  end
222

223
  # This will start and end the measurement of the time.
224
  #
225
  # @param graph_id [String]
226
  #
227
  # @return [Pixela::Response]
228
  #
229
  # @raise [Pixela::PixelaError] API is failed
230
  #
231
  # @see https://docs.pixe.la/entry/post-stopwatch
232
  #
233
  # @example
234
  #   client.run_stopwatch(graph_id: "test-graph")
235
  def run_stopwatch(graph_id:)
1✔
236
    with_error_handling do
2✔
237
      connection.post("users/#{username}/graphs/#{graph_id}/stopwatch").body
2✔
238
    end
239
  end
240

241
  alias_method :start_stopwatch, :run_stopwatch
1✔
242
  alias_method :end_stopwatch,   :run_stopwatch
1✔
243

244
  # Get a predefined pixelation graph definition.
245
  #
246
  # @param graph_id [String]
247
  #
248
  # @return [Pixela::Response]
249
  #
250
  # @raise [Pixela::PixelaError] API is failed
251
  #
252
  # @see https://docs.pixe.la/entry/get-a-graph-def
253
  #
254
  # @example
255
  #   client.get_graph_def(graph_id: "test-graph")
256
  def get_graph_def(graph_id:)
1✔
257
    with_error_handling do
10✔
258
      connection.get("users/#{username}/graphs/#{graph_id}/graph-def").body
10✔
259
    end
260
  end
261
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