pixela 1.5.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c390c81b40e7d104a1e81987394e6111e0f80fe5d1556340f7a3116dc8b0e5d
4
- data.tar.gz: 1869873ca527f4990a34bf148a44634109e6d4a2ae6b7cbc1cedd16281236539
3
+ metadata.gz: 39c681c4cb1fce393df5c86cc50123e29da258cc585b27bf9bcfc84374b33236
4
+ data.tar.gz: 6f2fc270dbff077f6b1dd3ec071df8e02d7651f9ef9a25613cd905d7f0f5bc8d
5
5
  SHA512:
6
- metadata.gz: b18dbd0f05991d21b51b92845d02bb6f14577d80b8a29202f44da5cac7920cff2f5d33e7c2581d9ed9658561138be95c071e551fff6680b27cbd60ed85370a01
7
- data.tar.gz: fb7cfff2961cfb02a2c4a8c4ddab1c81e90402af6e388333c8b3ba6a861334a8f384feee2879e3e22c706a0b9469665d74987a82ec2f89e65ca52dfc0cb75efc
6
+ metadata.gz: 16f3dd6d558ec9d052e835059f06d3279e3dbec925c81cc0dd355c333974f4859a36ededa0990fca2be55a6d9216ea21bb95a004b212f904b28734182f8e2218
7
+ data.tar.gz: ae7de882f2425ff12d002eb42015ae941bea73387ccb49a546a36b7b57d17413aa67df7f5ed78516e701a94a16d43d18f9546ee500ff5afd59e426e790b74b2f
@@ -12,9 +12,6 @@ on:
12
12
  schedule:
13
13
  - cron: "0 10 * * 5" # JST 19:00 (Fri)
14
14
 
15
- env:
16
- CI: "true"
17
-
18
15
  jobs:
19
16
  test:
20
17
  runs-on: ubuntu-latest
@@ -22,22 +19,21 @@ jobs:
22
19
  container: ${{ matrix.ruby }}
23
20
 
24
21
  env:
25
- BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
22
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
26
23
 
27
24
  strategy:
28
25
  fail-fast: false
29
26
 
30
27
  matrix:
31
28
  ruby:
32
- - ruby:2.3
33
29
  - ruby:2.4
34
30
  - ruby:2.5
35
31
  - ruby:2.6
36
32
  - ruby:2.7
33
+ - ruby:3.0
37
34
  - rubylang/ruby:master-nightly-bionic
38
35
  gemfile:
39
- - faraday_0.gemfile
40
- - faraday_1.gemfile
36
+ - faraday_1
41
37
  include:
42
38
  - ruby: rubylang/ruby:master-nightly-bionic
43
39
  allow_failures: "true"
@@ -45,7 +41,6 @@ jobs:
45
41
  steps:
46
42
  - uses: actions/checkout@v2
47
43
 
48
-
49
44
  - name: Cache gemfiles/vendor/bundle
50
45
  uses: actions/cache@v1
51
46
  id: cache_gem
@@ -94,7 +89,7 @@ jobs:
94
89
  continue-on-error: true
95
90
 
96
91
  - name: Slack Notification (not success)
97
- uses: homoluctus/slatify@master
92
+ uses: lazy-actions/slatify@master
98
93
  if: "! success()"
99
94
  continue-on-error: true
100
95
  with:
@@ -112,7 +107,7 @@ jobs:
112
107
 
113
108
  steps:
114
109
  - name: Slack Notification (success)
115
- uses: homoluctus/slatify@master
110
+ uses: lazy-actions/slatify@master
116
111
  if: always()
117
112
  continue-on-error: true
118
113
  with:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  ## Unreleased
2
- [full changelog](http://github.com/sue445/pixela/compare/v1.5.0...master)
2
+ [full changelog](http://github.com/sue445/pixela/compare/v2.2.1...master)
3
+
4
+ ## v2.2.1
5
+ [full changelog](http://github.com/sue445/pixela/compare/v2.2.0...v2.2.1)
6
+
7
+ * Enable MFA requirement for gem releasing
8
+ * https://github.com/sue445/pixela/pull/88
9
+
10
+ ## v2.2.0
11
+ [full changelog](http://github.com/sue445/pixela/compare/v2.1.0...v2.2.0)
12
+
13
+ * Add `Pixela::Client#get_graph_def` and `Pixela::Graph#def`
14
+ * https://github.com/sue445/pixela/pull/83
15
+ * https://github.com/a-know/Pixela/releases/tag/v1.21.0
16
+ * Add `Pixela::Client#get_pixels` and `Pixela::Graph#pixels`
17
+ * https://github.com/sue445/pixela/pull/84
18
+ * https://github.com/a-know/Pixela/releases/tag/v1.21.0
19
+
20
+ ## v2.1.0
21
+ [full changelog](http://github.com/sue445/pixela/compare/v2.0.0...v2.1.0)
22
+
23
+ * Add `Pixela::Client#update_profile`
24
+ * https://github.com/sue445/pixela/pull/81
25
+ * https://github.com/a-know/Pixela/releases/tag/v1.20.0
26
+
27
+ ## v2.0.0
28
+ [full changelog](http://github.com/sue445/pixela/compare/v1.5.0...v2.0.0)
29
+
30
+ ### :warning: Breaking changes :warning:
31
+ * Remove Channel and Notification
32
+ * https://github.com/sue445/pixela/pull/75
33
+ * https://github.com/a-know/Pixela/releases/tag/v1.19.0
34
+ * Drop support for faraday v0.x
35
+ * https://github.com/sue445/pixela/pull/77
36
+ * Drop support for ruby 2.3
37
+ * https://github.com/sue445/pixela/pull/78
3
38
 
4
39
  ## v1.5.0
5
40
  [full changelog](http://github.com/sue445/pixela/compare/v1.4.2...v1.5.0)
@@ -33,7 +33,7 @@ module Pixela::Client::GraphMethods
33
33
  }
34
34
 
35
35
  with_error_handling do
36
- connection.post("users/#{username}/graphs", compact_hash(params)).body
36
+ connection.post("users/#{username}/graphs", params.compact).body
37
37
  end
38
38
  end
39
39
 
@@ -126,7 +126,7 @@ module Pixela::Client::GraphMethods
126
126
  end
127
127
 
128
128
  with_error_handling do
129
- connection.put("users/#{username}/graphs/#{graph_id}", compact_hash(params)).body
129
+ connection.put("users/#{username}/graphs/#{graph_id}", params.compact).body
130
130
  end
131
131
  end
132
132
 
@@ -170,12 +170,38 @@ module Pixela::Client::GraphMethods
170
170
 
171
171
  res =
172
172
  with_error_handling do
173
- connection.get("users/#{username}/graphs/#{graph_id}/pixels", compact_hash(params)).body
173
+ connection.get("users/#{username}/graphs/#{graph_id}/pixels", params.compact).body
174
174
  end
175
175
 
176
176
  res.pixels.map { |ymd| Date.parse(ymd) }
177
177
  end
178
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)
194
+ params = {
195
+ from: to_ymd(from),
196
+ to: to_ymd(to),
197
+ withBody: true,
198
+ }
199
+
200
+ with_error_handling do
201
+ connection.get("users/#{username}/graphs/#{graph_id}/pixels", params.compact).body.pixels
202
+ end
203
+ end
204
+
179
205
  # Based on the registered information, get various statistics.
180
206
  #
181
207
  # @param graph_id [String]
@@ -214,4 +240,22 @@ module Pixela::Client::GraphMethods
214
240
 
215
241
  alias_method :start_stopwatch, :run_stopwatch
216
242
  alias_method :end_stopwatch, :run_stopwatch
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:)
257
+ with_error_handling do
258
+ connection.get("users/#{username}/graphs/#{graph_id}/graph-def").body
259
+ end
260
+ end
217
261
  end
@@ -22,7 +22,7 @@ module Pixela::Client::PixelMethods
22
22
  }
23
23
 
24
24
  with_error_handling do
25
- connection.post("users/#{username}/graphs/#{graph_id}", compact_hash(params)).body
25
+ connection.post("users/#{username}/graphs/#{graph_id}", params.compact).body
26
26
  end
27
27
  end
28
28
 
@@ -80,7 +80,7 @@ module Pixela::Client::PixelMethods
80
80
  }
81
81
 
82
82
  with_error_handling do
83
- connection.put("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}", compact_hash(params)).body
83
+ connection.put("users/#{username}/graphs/#{graph_id}/#{to_ymd(date)}", params.compact).body
84
84
  end
85
85
  end
86
86
 
@@ -0,0 +1,40 @@
1
+ module Pixela::Client::ProfileMethods
2
+ # Updates the profile information for the user corresponding to username
3
+ #
4
+ # @param display_name [String]
5
+ # @param gravatar_icon_email [String]
6
+ # @param title [String]
7
+ # @param timezone [String]
8
+ # @param about_url [String]
9
+ # @param contribute_urls [Array<String>]
10
+ # @param pinned_graph_id [String]
11
+ #
12
+ # @return [Pixela::Response]
13
+ #
14
+ # @raise [Pixela::PixelaError] API is failed
15
+ #
16
+ # @see https://docs.pixe.la/entry/put-profile
17
+ #
18
+ # @example
19
+ # client.update_profile(display_name: "a-know", gravatar_icon_email: "user@example.com", title: "my title", timezone: "Asia/Tokyo", about_url: "https://home.a-know.me", contribute_urls: ["https://pixe.la/","https://github.com/a-know/pi","https://blog.a-know.me/archive/category/Pixela"])
20
+ def update_profile(display_name: nil, gravatar_icon_email: nil, title: nil, timezone: nil,
21
+ about_url: nil, contribute_urls: [], pinned_graph_id: nil)
22
+
23
+ params = {
24
+ displayName: display_name,
25
+ gravatarIconEmail: gravatar_icon_email,
26
+ title: title,
27
+ timezone: timezone,
28
+ aboutURL: about_url,
29
+ pinnedGraphID: pinned_graph_id
30
+ }
31
+
32
+ unless contribute_urls.empty?
33
+ params[:contributeURLs] = contribute_urls
34
+ end
35
+
36
+ with_error_handling do
37
+ connection(endpoint: Pixela::Client::TOP_ENDPOINT).put("@#{username}", params.compact).body
38
+ end
39
+ end
40
+ end
@@ -21,7 +21,7 @@ module Pixela::Client::UserMethods
21
21
  }
22
22
 
23
23
  with_error_handling do
24
- connection(default_headers).post("users", params).body
24
+ connection(request_headers: default_headers).post("users", params).body
25
25
  end
26
26
  end
27
27
 
@@ -53,7 +53,7 @@ module Pixela::Client::WebhookMethods
53
53
  # client.invoke_webhook(webhook_hash: "<webhookHash>")
54
54
  def invoke_webhook(webhook_hash:)
55
55
  with_error_handling do
56
- connection(default_headers).post("users/#{username}/webhooks/#{webhook_hash}").body
56
+ connection(request_headers: default_headers).post("users/#{username}/webhooks/#{webhook_hash}").body
57
57
  end
58
58
  end
59
59
 
data/lib/pixela/client.rb CHANGED
@@ -1,20 +1,19 @@
1
1
  module Pixela
2
2
  class Client
3
- autoload :ChannelMethods, "pixela/client/channel_methods"
4
3
  autoload :GraphMethods, "pixela/client/graph_methods"
5
- autoload :NotificationMethods, "pixela/client/notificaton_methods"
6
4
  autoload :PixelMethods, "pixela/client/pixel_methods"
5
+ autoload :ProfileMethods, "pixela/client/profile_methods"
7
6
  autoload :UserMethods, "pixela/client/user_methods"
8
7
  autoload :WebhookMethods, "pixela/client/webhook_methods"
9
8
 
10
- include ChannelMethods
11
9
  include GraphMethods
12
- include NotificationMethods
13
10
  include PixelMethods
11
+ include ProfileMethods
14
12
  include UserMethods
15
13
  include WebhookMethods
16
14
 
17
15
  API_ENDPOINT = "https://pixe.la/v1"
16
+ TOP_ENDPOINT = "https://pixe.la"
18
17
 
19
18
  # @!attribute [r] username
20
19
  # @return [String]
@@ -47,13 +46,6 @@ module Pixela
47
46
  Webhook.new(client: self, webhook_hash: webhook_hash)
48
47
  end
49
48
 
50
- # @param channel_id [String]
51
- #
52
- # @return [Pixela::Channel]
53
- def channel(channel_id)
54
- Channel.new(client: self, channel_id: channel_id)
55
- end
56
-
57
49
  private
58
50
 
59
51
  # @!attribute [r] token
@@ -63,8 +55,8 @@ module Pixela
63
55
  # @param request_headers [Hash]
64
56
  #
65
57
  # @return [Faraday::Connection]
66
- def connection(request_headers = user_token_headers)
67
- Faraday.new(url: API_ENDPOINT, headers: request_headers) do |conn|
58
+ def connection(request_headers: user_token_headers, endpoint: API_ENDPOINT)
59
+ Faraday.new(url: endpoint, headers: request_headers) do |conn|
68
60
  conn.request :json
69
61
  conn.response :mashify, mash_class: Pixela::Response
70
62
  conn.response :json
@@ -81,7 +73,7 @@ module Pixela
81
73
 
82
74
  def with_error_handling
83
75
  yield
84
- rescue *faraday_errors => error
76
+ rescue Faraday::ClientError, Faraday::ServerError => error
85
77
  begin
86
78
  body = JSON.parse(error.response[:body])
87
79
  raise PixelaError, body["message"]
@@ -90,14 +82,6 @@ module Pixela
90
82
  end
91
83
  end
92
84
 
93
- def faraday_errors
94
- if Gem::Version.create(Faraday::VERSION) >= Gem::Version.create("1.0.0")
95
- return [Faraday::ClientError, Faraday::ServerError]
96
- end
97
-
98
- [Faraday::Error::ClientError]
99
- end
100
-
101
85
  def default_headers
102
86
  {
103
87
  "User-Agent" => "Pixela v#{Pixela::VERSION} (https://github.com/sue445/pixela)",
@@ -118,10 +102,5 @@ module Pixela
118
102
 
119
103
  date.strftime("%Y%m%d")
120
104
  end
121
-
122
- def compact_hash(hash)
123
- # NOTE: Hash#compact is available since MRI 2.4+
124
- hash.reject { |_, v| v.nil? }
125
- end
126
105
  end
127
106
  end
data/lib/pixela/graph.rb CHANGED
@@ -22,13 +22,6 @@ module Pixela
22
22
  Pixel.new(client: client, graph_id: graph_id, date: date)
23
23
  end
24
24
 
25
- # @param notification_id [String]
26
- #
27
- # @return [Pixela::Notification]
28
- def notification(notification_id)
29
- Notification.new(client: client, graph_id: graph_id, notification_id: notification_id)
30
- end
31
-
32
25
  # Create a new pixelation graph definition.
33
26
  #
34
27
  # @param name [String]
@@ -156,6 +149,23 @@ module Pixela
156
149
  client.get_pixel_dates(graph_id: graph_id, from: from, to: to)
157
150
  end
158
151
 
152
+ # Get a Date list of Pixel registered in the graph specified by graphID.
153
+ #
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<Hashie::Mash>]
158
+ #
159
+ # @raise [Pixela::PixelaError] API is failed
160
+ #
161
+ # @see https://docs.pixe.la/entry/get-graph-pixels
162
+ #
163
+ # @example
164
+ # client.graph("test-graph").pixels(from: Date.new(2018, 1, 1), to: Date.new(2018, 12, 31))
165
+ def pixels(from: nil, to: nil)
166
+ client.get_pixels(graph_id: graph_id, from: from, to: to)
167
+ end
168
+
159
169
  # Based on the registered information, get various statistics.
160
170
  #
161
171
  # @return [Pixela::Response]
@@ -186,5 +196,21 @@ module Pixela
186
196
 
187
197
  alias_method :start_stopwatch, :run_stopwatch
188
198
  alias_method :end_stopwatch, :run_stopwatch
199
+
200
+ # Get a predefined pixelation graph definition.
201
+ #
202
+ # @return [Pixela::Response]
203
+ #
204
+ # @raise [Pixela::PixelaError] API is failed
205
+ #
206
+ # @see https://docs.pixe.la/entry/get-a-graph-def
207
+ #
208
+ # @example
209
+ # client.graph("test-graph").def
210
+ def def
211
+ client.get_graph_def(graph_id: graph_id)
212
+ end
213
+
214
+ alias_method :definition, :def
189
215
  end
190
216
  end
@@ -1,3 +1,3 @@
1
1
  module Pixela
2
- VERSION = "1.5.0"
2
+ VERSION = "2.2.1"
3
3
  end
data/lib/pixela.rb CHANGED
@@ -5,11 +5,9 @@ require "faraday_curl"
5
5
  require "date"
6
6
 
7
7
  module Pixela
8
- autoload :Channel, "pixela/channel"
9
8
  autoload :Client, "pixela/client"
10
9
  autoload :Configuration, "pixela/configuration"
11
10
  autoload :Graph, "pixela/graph"
12
- autoload :Notification, "pixela/notification"
13
11
  autoload :Pixel, "pixela/pixel"
14
12
  autoload :Response, "pixela/response"
15
13
  autoload :Webhook, "pixela/webhook"
data/pixela.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.metadata["homepage_uri"] = spec.homepage
21
21
  spec.metadata["source_code_uri"] = spec.homepage
22
22
  spec.metadata["changelog_uri"] = spec.homepage + "/blob/master/CHANGELOG.md"
23
+ spec.metadata["rubygems_mfa_required"] = "true"
23
24
  else
24
25
  raise "RubyGems 2.0 or newer is required to protect against " \
25
26
  "public gem pushes."
@@ -34,9 +35,9 @@ Gem::Specification.new do |spec|
34
35
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
36
  spec.require_paths = ["lib"]
36
37
 
37
- spec.required_ruby_version = ">= 2.3.0"
38
+ spec.required_ruby_version = ">= 2.4.0"
38
39
 
39
- spec.add_dependency "faraday"
40
+ spec.add_dependency "faraday", ">= 1.0.0"
40
41
  spec.add_dependency "faraday_curl"
41
42
  spec.add_dependency "faraday_middleware"
42
43
  spec.add_dependency "hashie"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixela
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-06 00:00:00.000000000 Z
11
+ date: 2021-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday_curl
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -240,20 +240,16 @@ files:
240
240
  - Rakefile
241
241
  - bin/console
242
242
  - bin/setup
243
- - gemfiles/faraday_0.gemfile
244
243
  - gemfiles/faraday_1.gemfile
245
244
  - lib/pixela.rb
246
- - lib/pixela/channel.rb
247
245
  - lib/pixela/client.rb
248
- - lib/pixela/client/channel_methods.rb
249
246
  - lib/pixela/client/graph_methods.rb
250
- - lib/pixela/client/notificaton_methods.rb
251
247
  - lib/pixela/client/pixel_methods.rb
248
+ - lib/pixela/client/profile_methods.rb
252
249
  - lib/pixela/client/user_methods.rb
253
250
  - lib/pixela/client/webhook_methods.rb
254
251
  - lib/pixela/configuration.rb
255
252
  - lib/pixela/graph.rb
256
- - lib/pixela/notification.rb
257
253
  - lib/pixela/pixel.rb
258
254
  - lib/pixela/response.rb
259
255
  - lib/pixela/version.rb
@@ -266,7 +262,8 @@ metadata:
266
262
  homepage_uri: https://github.com/sue445/pixela
267
263
  source_code_uri: https://github.com/sue445/pixela
268
264
  changelog_uri: https://github.com/sue445/pixela/blob/master/CHANGELOG.md
269
- post_install_message:
265
+ rubygems_mfa_required: 'true'
266
+ post_install_message:
270
267
  rdoc_options: []
271
268
  require_paths:
272
269
  - lib
@@ -274,15 +271,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
274
271
  requirements:
275
272
  - - ">="
276
273
  - !ruby/object:Gem::Version
277
- version: 2.3.0
274
+ version: 2.4.0
278
275
  required_rubygems_version: !ruby/object:Gem::Requirement
279
276
  requirements:
280
277
  - - ">="
281
278
  - !ruby/object:Gem::Version
282
279
  version: '0'
283
280
  requirements: []
284
- rubygems_version: 3.1.2
285
- signing_key:
281
+ rubygems_version: 3.2.22
282
+ signing_key:
286
283
  specification_version: 4
287
284
  summary: Pixela API client for Ruby
288
285
  test_files: []
@@ -1,8 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in pixela.gemspec
6
- gemspec path: "../"
7
-
8
- gem "faraday", "~> 0.17"
@@ -1,106 +0,0 @@
1
- module Pixela
2
- class Channel
3
- # @!attribute [r] client
4
- # @return [Pixela::Client]
5
- attr_reader :client
6
-
7
- # @!attribute [r] id
8
- # @return [String]
9
- attr_reader :channel_id
10
-
11
- # @param client [Pixela::Client]
12
- # @param graph_id [String]
13
- def initialize(client:, channel_id:)
14
- @client = client
15
- @channel_id = channel_id
16
- end
17
-
18
- # Create a new channel settings for notification.
19
- #
20
- # @param name [String]
21
- # @param type [String]
22
- # @param detail [Hash]
23
- #
24
- # @return [Pixela::Response]
25
- #
26
- # @raise [Pixela::PixelaError] API is failed
27
- #
28
- # @see https://docs.pixe.la/entry/post-channel
29
- #
30
- # @example
31
- # client.channel("my-channel").create(name: "My slack channel", type: "slack", detail: {url: "https://hooks.slack.com/services/T035DA4QD/B06LMAV40/xxxx", userName: "Pixela Notification", channelName: "pixela-notify"})
32
- def create(name:, type:, detail:)
33
- client.create_channel(channel_id: channel_id, name: name, type: type, detail: detail)
34
- end
35
-
36
- # Create a new channel settings for slack notification.
37
- #
38
- # @param name [String]
39
- # @param url [String]
40
- # @param user_name [String]
41
- # @param channel_name [String]
42
- #
43
- # @return [Pixela::Response]
44
- #
45
- # @raise [Pixela::PixelaError] API is failed
46
- #
47
- # @see https://docs.pixe.la/entry/post-channel
48
- #
49
- # @example
50
- # client.channel("my-channel").create_with_slack(name: "My slack channel", url: "https://hooks.slack.com/services/T035DA4QD/B06LMAV40/xxxx", user_name: "Pixela Notification", channel_name: "pixela-notify")
51
- def create_with_slack(name:, url:, user_name:, channel_name:)
52
- client.create_slack_channel(channel_id: channel_id, name: name, url: url, user_name: user_name, channel_name: channel_name)
53
- end
54
-
55
- # Update predefined channel settings.
56
- #
57
- # @param name [String]
58
- # @param type [String]
59
- # @param detail [Hash]
60
- #
61
- # @return [Pixela::Response]
62
- #
63
- # @raise [Pixela::PixelaError] API is failed
64
- #
65
- # @see https://docs.pixe.la/entry/put-channel
66
- #
67
- # @example
68
- # client.channel("my-channel").update(name: "My slack channel", type: "slack", detail: {url: "https://hooks.slack.com/services/T035DA4QD/B06LMAV40/xxxx", userName: "Pixela Notification", channelName: "pixela-notify"})
69
- def update(name:, type:, detail:)
70
- client.update_channel(channel_id: channel_id, name: name, type: type, detail: detail)
71
- end
72
-
73
- # Update predefined slack channel settings.
74
- #
75
- # @param name [String]
76
- # @param url [String]
77
- # @param user_name [String]
78
- # @param channel_name [String]
79
- #
80
- # @return [Pixela::Response]
81
- #
82
- # @raise [Pixela::PixelaError] API is failed
83
- #
84
- # @see https://docs.pixe.la/entry/post-channel
85
- #
86
- # @example
87
- # client.channel("my-channel").update_with_slack(name: "My slack channel", url: "https://hooks.slack.com/services/T035DA4QD/B06LMAV40/xxxx", user_name: "Pixela Notification", channel_name: "pixela-notify")
88
- def update_with_slack(name:, url:, user_name:, channel_name:)
89
- client.update_slack_channel(channel_id: channel_id, name: name, url: url, user_name: user_name, channel_name: channel_name)
90
- end
91
-
92
- # Delete predefined channel settings.
93
- #
94
- # @see https://docs.pixe.la/entry/delete-channel
95
- #
96
- # @return [Pixela::Response]
97
- #
98
- # @raise [Pixela::PixelaError] API is failed
99
- #
100
- # @example
101
- # client.channel("my-channel").delete
102
- def delete
103
- client.delete_channel(channel_id: channel_id)
104
- end
105
- end
106
- end
@@ -1,148 +0,0 @@
1
- module Pixela::Client::ChannelMethods
2
- # Create a new channel settings for notification.
3
- #
4
- # @param channel_id [String]
5
- # @param name [String]
6
- # @param type [String]
7
- # @param detail [Hash]
8
- #
9
- # @return [Pixela::Response]
10
- #
11
- # @raise [Pixela::PixelaError] API is failed
12
- #
13
- # @see https://docs.pixe.la/entry/post-channel
14
- #
15
- # @example
16
- # client.create_channel(channel_id: "my-channel", name: "My slack channel", type: "slack", detail: {url: "https://hooks.slack.com/services/T035DA4QD/B06LMAV40/xxxx", userName: "Pixela Notification", channelName: "pixela-notify"})
17
- def create_channel(channel_id:, name:, type:, detail:)
18
- params = {
19
- id: channel_id,
20
- name: name,
21
- type: type,
22
- detail: detail,
23
- }
24
-
25
- with_error_handling do
26
- connection.post("users/#{username}/channels", compact_hash(params)).body
27
- end
28
- end
29
-
30
- # Create a new channel settings for slack notification.
31
- #
32
- # @param channel_id [String]
33
- # @param name [String]
34
- # @param url [String]
35
- # @param user_name [String]
36
- # @param channel_name [String]
37
- #
38
- # @return [Pixela::Response]
39
- #
40
- # @raise [Pixela::PixelaError] API is failed
41
- #
42
- # @see https://docs.pixe.la/entry/post-channel
43
- #
44
- # @example
45
- # client.create_slack_channel(channel_id: "my-channel", name: "My slack channel", url: "https://hooks.slack.com/services/T035DA4QD/B06LMAV40/xxxx", user_name: "Pixela Notification", channel_name: "pixela-notify")
46
- def create_slack_channel(channel_id:, name:, url:, user_name:, channel_name:)
47
- create_channel(
48
- channel_id: channel_id,
49
- name: name,
50
- type: "slack",
51
- detail: {
52
- url: url,
53
- userName: user_name,
54
- channelName: channel_name,
55
- },
56
- )
57
- end
58
-
59
- # Get all predefined channels.
60
- #
61
- # @see https://docs.pixe.la/entry/get-channels
62
- #
63
- # @return [Array<Pixela::Response>]
64
- #
65
- # @raise [Pixela::PixelaError] API is failed
66
- #
67
- # @example
68
- # client.get_channels
69
- def get_channels
70
- with_error_handling do
71
- connection.get("users/#{username}/channels").body.channels
72
- end
73
- end
74
-
75
- # Update predefined channel settings.
76
- #
77
- # @param channel_id [String]
78
- # @param name [String]
79
- # @param type [String]
80
- # @param detail [Hash]
81
- #
82
- # @return [Pixela::Response]
83
- #
84
- # @raise [Pixela::PixelaError] API is failed
85
- #
86
- # @see https://docs.pixe.la/entry/put-channel
87
- #
88
- # @example
89
- # client.update_channel(channel_id: "my-channel", name: "My slack channel", type: "slack", detail: {url: "https://hooks.slack.com/services/T035DA4QD/B06LMAV40/xxxx", userName: "Pixela Notification", channelName: "pixela-notify"})
90
- def update_channel(channel_id:, name:, type:, detail:)
91
- params = {
92
- name: name,
93
- type: type,
94
- detail: detail,
95
- }
96
-
97
- with_error_handling do
98
- connection.put("users/#{username}/channels/#{channel_id}", compact_hash(params)).body
99
- end
100
- end
101
-
102
- # Update predefined slack channel settings.
103
- #
104
- # @param channel_id [String]
105
- # @param name [String]
106
- # @param url [String]
107
- # @param user_name [String]
108
- # @param channel_name [String]
109
- #
110
- # @return [Pixela::Response]
111
- #
112
- # @raise [Pixela::PixelaError] API is failed
113
- #
114
- # @see https://docs.pixe.la/entry/post-channel
115
- #
116
- # @example
117
- # client.update_slack_channel(channel_id: "my-channel", name: "My slack channel", url: "https://hooks.slack.com/services/T035DA4QD/B06LMAV40/xxxx", user_name: "Pixela Notification", channel_name: "pixela-notify")
118
- def update_slack_channel(channel_id:, name:, url:, user_name:, channel_name:)
119
- update_channel(
120
- channel_id: channel_id,
121
- name: name,
122
- type: "slack",
123
- detail: {
124
- url: url,
125
- userName: user_name,
126
- channelName: channel_name,
127
- },
128
- )
129
- end
130
-
131
- # Delete predefined channel settings.
132
- #
133
- # @param channel_id [String]
134
- #
135
- # @see https://docs.pixe.la/entry/delete-channel
136
- #
137
- # @return [Pixela::Response]
138
- #
139
- # @raise [Pixela::PixelaError] API is failed
140
- #
141
- # @example
142
- # client.delete_channel(channel_id: "my-channel")
143
- def delete_channel(channel_id:)
144
- with_error_handling do
145
- connection.delete("users/#{username}/channels/#{channel_id}").body
146
- end
147
- end
148
- end
@@ -1,105 +0,0 @@
1
- module Pixela::Client::NotificationMethods
2
- # Create a notification rule.
3
- #
4
- # @param graph_id [String]
5
- # @param notification_id [String]
6
- # @param name [String]
7
- # @param target [String]
8
- # @param condition [String]
9
- # @param threshold [String]
10
- # @param remind_by [String]
11
- # @param channel_id [String]
12
- #
13
- # @return [Pixela::Response]
14
- #
15
- # @raise [Pixela::PixelaError] API is failed
16
- #
17
- # @see https://docs.pixe.la/entry/post-notification
18
- #
19
- # @example
20
- # client.create_notification(graph_id: "test-graph", notification_id: "my-notification-rule", name: "my notification rule", target: "quantity", condition: ">", threshold: "5", remind_by: "21", channel_id: "my-channel")
21
- def create_notification(graph_id:, notification_id:, name:, target:, condition:, threshold:, remind_by: nil, channel_id:)
22
- params = {
23
- id: notification_id,
24
- name: name,
25
- target: target,
26
- condition: condition,
27
- threshold: threshold,
28
- remindBy: remind_by,
29
- channelID: channel_id,
30
- }
31
-
32
- with_error_handling do
33
- connection.post("users/#{username}/graphs/#{graph_id}/notifications", compact_hash(params)).body
34
- end
35
- end
36
-
37
- # Get all predefined notifications.
38
- #
39
- # @param graph_id [String]
40
- #
41
- # @return [Array<Pixela::Response>]
42
- #
43
- # @raise [Pixela::PixelaError] API is failed
44
- #
45
- # @see https://docs.pixe.la/entry/get-notifications
46
- #
47
- # @example
48
- # client.get_notifications(graph_id: "test-graph")
49
- def get_notifications(graph_id:)
50
- with_error_handling do
51
- connection.get("users/#{username}/graphs/#{graph_id}/notifications").body.notifications
52
- end
53
- end
54
-
55
- # Update predefined notification rule.
56
- #
57
- # @param graph_id [String]
58
- # @param notification_id [String]
59
- # @param name [String]
60
- # @param target [String]
61
- # @param condition [String]
62
- # @param threshold [String]
63
- # @param channel_id [String]
64
- #
65
- # @return [Pixela::Response]
66
- #
67
- # @raise [Pixela::PixelaError] API is failed
68
- #
69
- # @see https://docs.pixe.la/entry/put-notification
70
- #
71
- # @example
72
- # client.update_notification(graph_id: "test-graph", notification_id: "my-notification-rule", name: "my notification rule", target: "quantity", condition: ">", threshold: "5", channel_id: "my-channel")
73
- def update_notification(graph_id:, notification_id:, name:, target:, condition:, threshold:, channel_id:)
74
- params = {
75
- name: name,
76
- target: target,
77
- condition: condition,
78
- threshold: threshold,
79
- channelID: channel_id,
80
- }
81
-
82
- with_error_handling do
83
- connection.put("users/#{username}/graphs/#{graph_id}/notifications/#{notification_id}", compact_hash(params)).body
84
- end
85
- end
86
-
87
- # Delete predefined notification settings.
88
- #
89
- # @param graph_id [String]
90
- # @param notification_id [String]
91
- #
92
- # @return [Pixela::Response]
93
- #
94
- # @raise [Pixela::PixelaError] API is failed
95
- #
96
- # @see https://docs.pixe.la/entry/delete-notification
97
- #
98
- # @example
99
- # client.delete_notification(graph_id: "test-graph", notification_id: "my-notification-rule")
100
- def delete_notification(graph_id:, notification_id:)
101
- with_error_handling do
102
- connection.delete("users/#{username}/graphs/#{graph_id}/notifications/#{notification_id}").body
103
- end
104
- end
105
- end
@@ -1,79 +0,0 @@
1
- module Pixela
2
- class Notification
3
- # @!attribute [r] client
4
- # @return [Pixela::Client]
5
- attr_reader :client
6
-
7
- # @!attribute [r] graph_id
8
- # @return [String]
9
- attr_reader :graph_id
10
-
11
- # @!attribute [r] notification_id
12
- # @return [String]
13
- attr_reader :notification_id
14
-
15
- # @param client [Pixela::Client]
16
- # @param graph_id [String]
17
- # @param notification_id [String]
18
- def initialize(client:, graph_id:, notification_id:)
19
- @client = client
20
- @graph_id = graph_id
21
- @notification_id = notification_id
22
- end
23
-
24
- # Create a notification rule.
25
- #
26
- # @param name [String]
27
- # @param target [String]
28
- # @param condition [String]
29
- # @param threshold [String]
30
- # @param remind_by [String]
31
- # @param channel_id [String]
32
- #
33
- # @return [Pixela::Response]
34
- #
35
- # @raise [Pixela::PixelaError] API is failed
36
- #
37
- # @see https://docs.pixe.la/entry/post-notification
38
- #
39
- # @example
40
- # client.graph("test-graph").notification("my-notification-rule").create(name: "my notification rule", target: "quantity", condition: ">", threshold: "5", remind_by: "21", channel_id: "my-channel")
41
- def create(name:, target:, condition:, threshold:, remind_by: nil, channel_id:)
42
- client.create_notification(graph_id: graph_id, notification_id: notification_id, name: name, target: target, condition: condition, threshold: threshold, remind_by: remind_by, channel_id: channel_id)
43
- end
44
-
45
- # Update predefined notification rule.
46
- #
47
- # @param name [String]
48
- # @param target [String]
49
- # @param condition [String]
50
- # @param threshold [String]
51
- # @param channel_id [String]
52
- #
53
- # @return [Pixela::Response]
54
- #
55
- # @raise [Pixela::PixelaError] API is failed
56
- #
57
- # @see https://docs.pixe.la/entry/put-notification
58
- #
59
- # @example
60
- # client.graph("test-graph").notification("my-notification-rule").update(name: "my notification rule", target: "quantity", condition: ">", threshold: "5", channel_id: "my-channel")
61
- def update(name:, target:, condition:, threshold:, channel_id:)
62
- client.update_notification(graph_id: graph_id, notification_id: notification_id, name: name, target: target, condition: condition, threshold: threshold, channel_id: channel_id)
63
- end
64
-
65
- # Delete predefined notification settings.
66
- #
67
- # @return [Pixela::Response]
68
- #
69
- # @raise [Pixela::PixelaError] API is failed
70
- #
71
- # @see https://docs.pixe.la/entry/delete-notification
72
- #
73
- # @example
74
- # client.graph("test-graph").notification("my-notification-rule").delete
75
- def delete
76
- client.delete_notification(graph_id: graph_id, notification_id: notification_id)
77
- end
78
- end
79
- end