dingtalk-client 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9bfd72745e2e87e8bf338fa656d911879121f390179fd1627241f951c85c8e02
4
- data.tar.gz: 502532b3b827eb0da21fd3560b679ac1f91f5d27f9beafa664f71810d0745f8b
3
+ metadata.gz: eaaf81ec39e4791acf07d6ec576a1f7d4e1642150d76287db4ce8b0923e4f632
4
+ data.tar.gz: 51e7d96894aa96882eefbeb4085cb637da3db2d0bf8bd3b1811500edc1dd25c5
5
5
  SHA512:
6
- metadata.gz: aa1d0e914f5d267f41e4fbd2d118dbee9ece415a4f886bc32870bf6b91b197a3ce5acfd300f1847204fef74298b4105ce652d52c9897694ed8f8ee0f9c137cb7
7
- data.tar.gz: 629963615bee02162628f74f85fb85f1b3444e0a2a965d6c6e23506db9050dcb6b617694d9de1ee95191a4d4aae1c871a0ec5c9849b6c0157871d35b1a04dbfc
6
+ metadata.gz: ddac72dcf29874c2fdedd1fafc0a7612b046b61ed278a5b55813725baf554cde61a09e7c576d6fa7e6e2bf030f0e4d67ac976110d5f5844a266bd5a1f69b8a15
7
+ data.tar.gz: c4cbd1f9b659b3c8a461c91ab822867c63e0dab546fe0ee879342c9db7ccbbea747486725d43159fab919a420e8d959455c938c969cda996085d5efacbd4e614
@@ -14,3 +14,5 @@ Metrics/BlockLength:
14
14
  - "**/*_spec.rb"
15
15
  Style/BlockDelimiters:
16
16
  EnforcedStyle: braces_for_chaining
17
+ Style/ModuleFunction:
18
+ EnforcedStyle: extend_self
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dingtalk-client (0.2.0)
4
+ dingtalk-client (0.2.1)
5
5
  activesupport (~> 5.2.1)
6
6
  httparty (~> 0.16.2)
7
7
 
@@ -12,4 +12,5 @@ require 'dingtalk/client'
12
12
  # Pry.start
13
13
 
14
14
  require 'irb'
15
+ require 'byebug'
15
16
  IRB.start(__FILE__)
@@ -4,18 +4,16 @@ require 'httparty'
4
4
  require 'active_support/all'
5
5
  require 'dingtalk/client/errors'
6
6
  require 'dingtalk/client/result'
7
- require 'dingtalk/client/configurable'
8
7
 
9
8
  module Dingtalk
10
9
  # DingTalk Client
11
10
  # @see https://open-doc.dingtalk.com/
12
11
  module Client
13
12
  extend ActiveSupport::Autoload
13
+ autoload :Configurable
14
14
  autoload :GroupRobotClient
15
15
  include Configurable
16
-
17
- def self.included(base)
18
- base.include GroupRobotClient
19
- end
16
+ include GroupRobotClient
17
+ extend self
20
18
  end
21
19
  end
@@ -28,10 +28,12 @@ module Dingtalk
28
28
  # @see Configurable
29
29
  class Configuration
30
30
  attr_writer :group_robot_tokens, :group_robot_webhook_prefix, :template_dir
31
+ attr_accessor :is_debugging
31
32
 
32
33
  def initialize
33
34
  @group_robot_webhook_prefix = 'https://oapi.dingtalk.com/robot/send?access_token='
34
35
  @template_dir = '.'
36
+ @is_debugging = false
35
37
  end
36
38
 
37
39
  def group_robot_tokens
@@ -16,7 +16,7 @@ module Dingtalk
16
16
  include NotifyFeedcard
17
17
  base_uri Dingtalk::Client.config.group_robot_webhook_prefix
18
18
  headers 'Content-Type' => 'application/json'
19
- logger ::Logger.new($stdout), :debug, :curl
19
+ logger ::Logger.new($stdout), :debug, :curl if Dingtalk::Client.config.is_debugging
20
20
  end
21
21
  end
22
22
  end
@@ -10,7 +10,8 @@ module Dingtalk
10
10
  # @option options [String] template_file (code) without file suffix
11
11
  # @option options [Boolean] is_at_all (false)
12
12
  # @option options [Array] at_mobiles ([])
13
- def notify_markdown(code, title, **options)
13
+ # @yield a block which will execute in template locale environment
14
+ def notify_markdown(code, title, **options, &block)
14
15
  options.with_defaults!(
15
16
  template_file: code,
16
17
  is_at_all: false,
@@ -22,7 +23,7 @@ module Dingtalk
22
23
  template_file = String(options[:template_file])
23
24
  is_at_all = is_at_all != false
24
25
  at_mobiles = Array(at_mobiles)
25
- content = get_markdown_content(template_file)
26
+ content = get_markdown_content(template_file, &block)
26
27
  body = get_markdown_body(title, content, is_at_all, at_mobiles)
27
28
  notify(token, body)
28
29
  end
@@ -30,7 +31,9 @@ module Dingtalk
30
31
  private
31
32
 
32
33
  # @param template_file [String]
33
- def get_markdown_content(template_file)
34
+ # @yield a block which will execute in template locale environment
35
+ def get_markdown_content(template_file, &block)
36
+ instance_eval(&block) if block
34
37
  path = "#{Dingtalk::Client.config.template_dir}/#{template_file}.markdown.erb"
35
38
  ERB.new(File.read(path)).result(binding)
36
39
  rescue Errno::ENOENT
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dingtalk
4
4
  module Client
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dingtalk-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pine Wong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-30 00:00:00.000000000 Z
11
+ date: 2018-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler