ruboty-gamification 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 8a00f6fc15f0a90b1e88c9b3c9bf8a328823e336
4
- data.tar.gz: 8b1ce6e3ff56fe18f27be4ba89dc589dc421c88b
3
+ metadata.gz: d5603aa2b19a58433d82d7ad56cafd30f25ff09f
4
+ data.tar.gz: d7eed04b8668b8efcff0a732e4d151afaa337de5
5
5
  SHA512:
6
- metadata.gz: b907e46f82d29d4d229ddb4df3eeab18a2777b922b0332a28a55c67484071f7a838f0e7c2fbc7a6813bb7a2bf5e3b76798aa8ad079ceff0463cd9855a09885b3
7
- data.tar.gz: 1d91ca8ba29310b93efa2cbc0f148ded406706cc9a120d38c6a329c68617e12cfe6de4585baba3c7f6c381204c2ea57daee787b1143da3866c33d2cb2e11028a
6
+ metadata.gz: 91551b1fbceb1f7e22087f6ff28a6ceb2a8f1e8bcc93684e152991e7931bc58fff299d8d8ee4c62a07e1f391702e5c6a279ec6a3986b8eb587e9e99dc425e304
7
+ data.tar.gz: 071dbd146dcf9bea87e39b32a17ae4e62fd38c1eaf119cc0776b232297aed39cac6a3501ce5d878cc022109fcb4230582c7d2af40924783c29bc62f5bbc9a5c3
@@ -0,0 +1,47 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ module Ruboty
5
+ module Gamification
6
+ class Client
7
+ ISSUES_URL = "https://api.github.com/repos/yoshiori/ruboty-gamification/issues"
8
+
9
+ def initialize(gamification)
10
+ @gamification = gamification
11
+ end
12
+
13
+ def setup
14
+ load(:increment)
15
+ load(:decrement)
16
+ @gamification.reply_messages = reply_messages
17
+ end
18
+
19
+ private
20
+ def load(label)
21
+ get(labels: label).body.each do |data|
22
+ @gamification.on(
23
+ /#{data["title"]}$/,
24
+ name: "#{label}",
25
+ description: "#{label} score (https://github.com/yoshiori/ruboty-gamification/issues)",
26
+ )
27
+ reply_messages[label][data["title"]] = data["body"]
28
+ end
29
+ end
30
+
31
+ def reply_messages
32
+ @reply_messages ||= {increment: {}, decrement: {}}
33
+ end
34
+
35
+ def get(params)
36
+ connection.get(ISSUES_URL, params)
37
+ end
38
+
39
+ def connection
40
+ Faraday.new do |connection|
41
+ connection.adapter :net_http
42
+ connection.response :json
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Gamification
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,3 +1,4 @@
1
1
  require "ruboty"
2
+ require "ruboty/gamification/client"
2
3
  require "ruboty/gamification/version"
3
4
  require "ruboty/handlers/gamification"
@@ -1,31 +1,39 @@
1
+
2
+
1
3
  module Ruboty
2
4
  module Handlers
3
5
  class Gamification < Base
4
- NAMESPACE = "gamification"
6
+ class << self
7
+ attr_accessor :reply_messages
8
+ end
5
9
 
6
- on( /出社/,
7
- name: "increment",
8
- description: "increment score",
9
- )
10
+ NAMESPACE = "gamification"
10
11
 
11
- on( /出社失敗/,
12
- name: "decrement",
13
- description: "decrement score",
14
- )
12
+ client = Ruboty::Gamification::Client.new(self)
13
+ client.setup
15
14
 
16
15
  private
17
16
 
18
17
  def increment(message)
19
18
  name = message.from_name
20
19
  return unless name
21
- message.reply("Login mission success!\n#{name}++")
20
+ message.reply(reply_message(:increment ,message))
21
+ message.reply("#{name}++")
22
22
  end
23
23
 
24
24
  def decrement(message)
25
25
  name = message.from_name
26
26
  return unless name
27
- message.reply("Login mission failed!\n#{name}--")
27
+ message.reply(reply_message(:decrement ,message))
28
+ message.reply("#{name}--")
29
+ end
30
+
31
+ def reply_message(label, message)
32
+ if /\A@?#{Regexp.escape(robot.name)}:?\s*(.*)/ =~ message.body
33
+ Gamification.reply_messages[label][$1]
34
+ end
28
35
  end
36
+
29
37
  end
30
38
  end
31
39
  end
@@ -19,7 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "ruboty"
22
+ spec.add_dependency "faraday"
23
+ spec.add_dependency "faraday_middleware"
22
24
 
23
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "pry"
24
27
  spec.add_development_dependency "rake"
25
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-gamification
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiori SHOJI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-29 00:00:00.000000000 Z
11
+ date: 2014-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +66,20 @@ dependencies:
38
66
  - - "~>"
39
67
  - !ruby/object:Gem::Version
40
68
  version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: rake
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +108,7 @@ files:
66
108
  - README.md
67
109
  - Rakefile
68
110
  - lib/ruboty/gamification.rb
111
+ - lib/ruboty/gamification/client.rb
69
112
  - lib/ruboty/gamification/version.rb
70
113
  - lib/ruboty/handlers/gamification.rb
71
114
  - ruboty-gamification.gemspec