Module: Pixela::Client::GraphMethods
- Included in:
- Pixela::Client
- Defined in:
- lib/pixela/client/graph_methods.rb
Instance Method Summary collapse
-
#create_graph(graph_id:, name:, unit:, type:, color:, timezone: nil, description: nil, start_on_monday: nil, self_sufficient: nil, is_secret: nil, publish_optional_data: nil) ⇒ Pixela::Response
Create a new pixelation graph definition.
-
#delete_graph(graph_id) ⇒ Pixela::Response
Delete the predefined pixelation graph definition.
-
#get_graph_def(graph_id:) ⇒ Pixela::Response
Get a predefined pixelation graph definition.
-
#get_graph_latest(graph_id:) ⇒ Pixela::Response
This API is used to get latest Pixel of the graph which specified by <graphID> .
-
#get_graph_stats(graph_id:) ⇒ Pixela::Response
Based on the registered information, get various statistics.
-
#get_graph_today(graph_id:, return_empty: false) ⇒ Pixela::Response
This is an endpoint that responds with the Pixel of the day you requested this API.
-
#get_graphs ⇒ Array<Hashie::Mash>
Get all predefined pixelation graph definitions.
-
#get_pixel_dates(graph_id:, from: nil, to: nil) ⇒ Array<Date>
Get a Date list of Pixel registered in the graph specified by graphID.
-
#get_pixels(graph_id:, from: nil, to: nil) ⇒ Array<Hashie::Mash>
Get a Date list of Pixel registered in the graph specified by graphID.
-
#graph_url(graph_id:, date: nil, mode: nil, appearance: nil, less_than: nil, greater_than: nil) ⇒ String
Get graph url.
-
#graphs_url ⇒ String
Displays graph list by detail in html format.
-
#run_stopwatch(graph_id:) ⇒ Pixela::Response
(also: #start_stopwatch, #end_stopwatch)
This will start and end the measurement of the time.
-
#update_graph(graph_id:, name: nil, unit: nil, color: nil, timezone: nil, description: nil, start_on_monday: nil, self_sufficient: nil, purge_cache_urls: nil, is_secret: nil, publish_optional_data: nil) ⇒ Pixela::Response
Update predefined pixelation graph definitions.
Instance Method Details
#create_graph(graph_id:, name:, unit:, type:, color:, timezone: nil, description: nil, start_on_monday: nil, self_sufficient: nil, is_secret: nil, publish_optional_data: nil) ⇒ Pixela::Response
Create a new pixelation graph definition.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pixela/client/graph_methods.rb', line 24 def create_graph(graph_id:, name:, unit:, type:, color:, timezone: nil, description: nil, start_on_monday: nil, self_sufficient: nil, is_secret: nil, publish_optional_data: nil) params = { id: graph_id, name: name, unit: unit, type: type, color: color, timezone: timezone, description: description, startOnMonday: start_on_monday, selfSufficient: self_sufficient, isSecret: is_secret, publishOptionalData: publish_optional_data } with_error_handling do connection.post("users/#{username}/graphs", params.compact).body end end |
#delete_graph(graph_id) ⇒ Pixela::Response
Delete the predefined pixelation graph definition.
159 160 161 162 163 |
# File 'lib/pixela/client/graph_methods.rb', line 159 def delete_graph(graph_id) with_error_handling do connection.delete("users/#{username}/graphs/#{graph_id}").body end end |
#get_graph_def(graph_id:) ⇒ Pixela::Response
Get a predefined pixelation graph definition.
270 271 272 273 274 |
# File 'lib/pixela/client/graph_methods.rb', line 270 def get_graph_def(graph_id:) with_error_handling do connection.get("users/#{username}/graphs/#{graph_id}/graph-def").body end end |
#get_graph_latest(graph_id:) ⇒ Pixela::Response
This API is used to get latest Pixel of the graph which specified by <graphID> .
288 289 290 291 292 |
# File 'lib/pixela/client/graph_methods.rb', line 288 def get_graph_latest(graph_id:) with_error_handling do connection.get("users/#{username}/graphs/#{graph_id}/latest").body end end |
#get_graph_stats(graph_id:) ⇒ Pixela::Response
Based on the registered information, get various statistics.
231 232 233 234 235 |
# File 'lib/pixela/client/graph_methods.rb', line 231 def get_graph_stats(graph_id:) with_error_handling do connection.get("users/#{username}/graphs/#{graph_id}/stats").body end end |
#get_graph_today(graph_id:, return_empty: false) ⇒ Pixela::Response
This is an endpoint that responds with the Pixel of the day you requested this API.
307 308 309 310 311 312 313 314 315 316 |
# File 'lib/pixela/client/graph_methods.rb', line 307 def get_graph_today(graph_id:, return_empty: false) params = {} if return_empty params[:returnEmpty] = return_empty end with_error_handling do connection.get("users/#{username}/graphs/#{graph_id}/today", params.compact).body end end |
#get_graphs ⇒ Array<Hashie::Mash>
Get all predefined pixelation graph definitions.
54 55 56 57 58 |
# File 'lib/pixela/client/graph_methods.rb', line 54 def get_graphs with_error_handling do connection.get("users/#{username}/graphs").body.graphs end end |
#get_pixel_dates(graph_id:, from: nil, to: nil) ⇒ Array<Date>
Get a Date list of Pixel registered in the graph specified by graphID.
179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/pixela/client/graph_methods.rb', line 179 def get_pixel_dates(graph_id:, from: nil, to: nil) params = { from: to_ymd(from), to: to_ymd(to), } res = with_error_handling do connection.get("users/#{username}/graphs/#{graph_id}/pixels", params.compact).body end res.pixels.map { |ymd| Date.parse(ymd) } end |
#get_pixels(graph_id:, from: nil, to: nil) ⇒ Array<Hashie::Mash>
Get a Date list of Pixel registered in the graph specified by graphID.
207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/pixela/client/graph_methods.rb', line 207 def get_pixels(graph_id:, from: nil, to: nil) params = { from: to_ymd(from), to: to_ymd(to), withBody: true, } with_error_handling do connection.get("users/#{username}/graphs/#{graph_id}/pixels", params.compact).body.pixels end end |
#graph_url(graph_id:, date: nil, mode: nil, appearance: nil, less_than: nil, greater_than: nil) ⇒ String
Get graph url
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pixela/client/graph_methods.rb', line 76 def graph_url(graph_id:, date: nil, mode: nil, appearance: nil, less_than: nil, greater_than: nil) url = "#{Pixela::Client::API_ENDPOINT}/users/#{username}/graphs/#{graph_id}" params = Faraday::Utils::ParamsHash.new params[:date] = to_ymd(date) if date params[:mode] = mode if mode params[:appearance] = appearance if appearance params[:lessThan] = less_than if less_than params[:greaterThan] = greater_than if greater_than url << "?#{params.to_query}" unless params.empty? url end |
#graphs_url ⇒ String
Displays graph list by detail in html format.
99 100 101 |
# File 'lib/pixela/client/graph_methods.rb', line 99 def graphs_url "https://pixe.la/v1/users/#{username}/graphs.html" end |
#run_stopwatch(graph_id:) ⇒ Pixela::Response Also known as: start_stopwatch, end_stopwatch
This will start and end the measurement of the time.
249 250 251 252 253 |
# File 'lib/pixela/client/graph_methods.rb', line 249 def run_stopwatch(graph_id:) with_error_handling do connection.post("users/#{username}/graphs/#{graph_id}/stopwatch").body end end |
#update_graph(graph_id:, name: nil, unit: nil, color: nil, timezone: nil, description: nil, start_on_monday: nil, self_sufficient: nil, purge_cache_urls: nil, is_secret: nil, publish_optional_data: nil) ⇒ Pixela::Response
Update predefined pixelation graph definitions.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/pixela/client/graph_methods.rb', line 125 def update_graph(graph_id:, name: nil, unit: nil, color: nil, timezone: nil, description: nil, start_on_monday: nil, self_sufficient: nil, purge_cache_urls: nil, is_secret: nil, publish_optional_data: nil) params = { name: name, unit: unit, color: color, timezone: timezone, description: description, startOnMonday: start_on_monday, selfSufficient: self_sufficient, isSecret: is_secret, publishOptionalData: publish_optional_data } if purge_cache_urls params[:purgeCacheURLs] = Array(purge_cache_urls) end with_error_handling do connection.put("users/#{username}/graphs/#{graph_id}", params.compact).body end end |