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, 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_stats(graph_id:) ⇒ Pixela::Response
Based on the registered information, get various statistics.
-
#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.
-
#graph_url(graph_id:, date: nil, mode: 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, 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, self_sufficient: nil, is_secret: nil, publish_optional_data: nil) ⇒ Pixela::Response
Create a new pixelation graph definition.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pixela/client/graph_methods.rb', line 22 def create_graph(graph_id:, name:, unit:, type:, color:, timezone: 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, selfSufficient: self_sufficient, isSecret: is_secret, publishOptionalData: publish_optional_data } with_error_handling do connection.post("users/#{username}/graphs", compact_hash(params)).body end end |
#delete_graph(graph_id) ⇒ Pixela::Response
Delete the predefined pixelation graph definition.
145 146 147 148 149 |
# File 'lib/pixela/client/graph_methods.rb', line 145 def delete_graph(graph_id) with_error_handling do connection.delete("users/#{username}/graphs/#{graph_id}").body end end |
#get_graph_stats(graph_id:) ⇒ Pixela::Response
Based on the registered information, get various statistics.
191 192 193 194 195 |
# File 'lib/pixela/client/graph_methods.rb', line 191 def get_graph_stats(graph_id:) with_error_handling do connection.get("users/#{username}/graphs/#{graph_id}/stats").body end end |
#get_graphs ⇒ Array<Hashie::Mash>
Get all predefined pixelation graph definitions.
50 51 52 53 54 |
# File 'lib/pixela/client/graph_methods.rb', line 50 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.
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/pixela/client/graph_methods.rb', line 165 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", compact_hash(params)).body end res.pixels.map { |ymd| Date.parse(ymd) } end |
#graph_url(graph_id:, date: nil, mode: nil) ⇒ String
Get graph url
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/pixela/client/graph_methods.rb', line 69 def graph_url(graph_id:, date: nil, mode: 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 url << "?#{params.to_query}" unless params.empty? url end |
#graphs_url ⇒ String
Displays graph list by detail in html format.
89 90 91 |
# File 'lib/pixela/client/graph_methods.rb', line 89 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.
209 210 211 212 213 |
# File 'lib/pixela/client/graph_methods.rb', line 209 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, self_sufficient: nil, purge_cache_urls: nil, is_secret: nil, publish_optional_data: nil) ⇒ Pixela::Response
Update predefined pixelation graph definitions.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/pixela/client/graph_methods.rb', line 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) params = { name: name, unit: unit, color: color, timezone: timezone, 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}", compact_hash(params)).body end end |