lita-phraseapp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +33 -0
- data/lib/lita-phraseapp.rb +4 -0
- data/lib/lita/phraseapp.rb +22 -0
- data/lib/lita/phraseapp_event.rb +24 -0
- data/lib/lita/phraseapp_gateway.rb +39 -0
- data/lib/lita/phraseapp_stats.rb +51 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c6f9231b81cf251462c73a668bfc06f0e956f673
|
4
|
+
data.tar.gz: 85cf24b953cbb981c2b3622f105c659c417dde04
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 41d77c6c87bd85846e83903054dc88394eee920613523109bb86fc3e0aae746fb06d22deb431f0c242027e7cee58035da15fb20d1817408dbf308c803ee645a3
|
7
|
+
data.tar.gz: 0f0d7d473503a9bb942b0fbe2980c6772d38f1303571a86f8afa3cd1b1652a5a931293c59ffe559e6760ef314d9a0e64de4cba2d4d83a19ecae59bc063904db2
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 James Healy
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# lita-phraseapp
|
2
|
+
|
3
|
+
A lita plugin for interacting with phraseapp.com, a translation management app.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this gem to your lita installation by including the following line in your Gemfile:
|
8
|
+
|
9
|
+
gem "lita-phraseapp"
|
10
|
+
|
11
|
+
## Externally triggered events
|
12
|
+
|
13
|
+
This handler can phraseapp events and trigger a variety of activities as appropriate. To
|
14
|
+
get started, use the phraseapp web interface to configure a webhook that POSTs events to:
|
15
|
+
|
16
|
+
http://your-lita-bot.com/phraseapp
|
17
|
+
|
18
|
+
### Locale Stats
|
19
|
+
|
20
|
+
To print a summary of locale stats to a channel each time a file is uploaded to a project,
|
21
|
+
edit your lita\_config.rb to include the following line.
|
22
|
+
|
23
|
+
config.handlers.phraseapp_stats.channel_name = "channel-name"
|
24
|
+
|
25
|
+
## Chat commands
|
26
|
+
|
27
|
+
This handler provides no additional chat commands. Yet.
|
28
|
+
|
29
|
+
## TODO
|
30
|
+
|
31
|
+
Possible ideas for new features, either via chat commands or externally triggered events:
|
32
|
+
|
33
|
+
* more specs
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "lita"
|
2
|
+
require_relative 'phraseapp_event'
|
3
|
+
|
4
|
+
module Lita
|
5
|
+
module Handlers
|
6
|
+
# Interact with phraseapp via our slack team
|
7
|
+
class Phraseapp < Handler
|
8
|
+
|
9
|
+
config :api_key
|
10
|
+
|
11
|
+
http.post "/phraseapp", :phraseapp_event
|
12
|
+
|
13
|
+
def phraseapp_event(request, response)
|
14
|
+
event = PhraseappEvent.new(request.body.read)
|
15
|
+
robot.trigger(:phraseapp_event, event: event, api_key: config.api_key)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
Lita.register_handler(Phraseapp)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
# Value object that wraps raw phraseapp webhook data and provides convenience
|
4
|
+
# methods for querying it
|
5
|
+
class PhraseappEvent
|
6
|
+
attr_reader :data
|
7
|
+
|
8
|
+
def initialize(data)
|
9
|
+
@data = JSON.load(data)
|
10
|
+
end
|
11
|
+
|
12
|
+
def name
|
13
|
+
@data.fetch("event")
|
14
|
+
end
|
15
|
+
|
16
|
+
def message
|
17
|
+
@data.fetch("message")
|
18
|
+
end
|
19
|
+
|
20
|
+
def project_name
|
21
|
+
@data.fetch("project", {}).fetch("name", nil)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'phraseapp-ruby'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
class PhraseappGateway
|
5
|
+
def initialize(api_key)
|
6
|
+
@api_key = api_key
|
7
|
+
end
|
8
|
+
|
9
|
+
def project_name_to_id(name)
|
10
|
+
projects_list, err = phraseapp_client.projects_list(1, 20)
|
11
|
+
projects_list.select { |project|
|
12
|
+
project.name.downcase == name.downcase
|
13
|
+
}.map { |project|
|
14
|
+
project.id
|
15
|
+
}.first
|
16
|
+
end
|
17
|
+
|
18
|
+
def locales(project_id)
|
19
|
+
locales_list, err = phraseapp_client.locales_list(project_id, 1, 20)
|
20
|
+
locales = locales_list.flatten.map { |abbreviated_locale|
|
21
|
+
phraseapp_client.locale_show(project_id, abbreviated_locale.id)
|
22
|
+
}.flatten.compact.map { |locale|
|
23
|
+
OpenStruct.new(
|
24
|
+
name: locale.name,
|
25
|
+
total: locale.statistics['keys_total_count'],
|
26
|
+
completed: locale.statistics['translations_completed_count'],
|
27
|
+
percent: (BigDecimal.new(locale.statistics['translations_completed_count'].to_f / locale.statistics['keys_total_count'], 5) * 100).round(2)
|
28
|
+
)
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def phraseapp_client
|
35
|
+
@phraseapp_client ||= PhraseApp::Client.new(
|
36
|
+
PhraseApp::Auth::Credentials.new(token: @api_key)
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "lita"
|
2
|
+
require_relative 'phraseapp_event'
|
3
|
+
require_relative 'phraseapp_gateway'
|
4
|
+
|
5
|
+
module Lita
|
6
|
+
module Handlers
|
7
|
+
# Print phraseapp project stats to a channel
|
8
|
+
class PhraseappStats < Handler
|
9
|
+
config :channel_name
|
10
|
+
|
11
|
+
on :phraseapp_event, :print_event
|
12
|
+
|
13
|
+
def print_event(payload)
|
14
|
+
event = payload[:event]
|
15
|
+
print_stats(event) if event.name == "uploads:create"
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def print_stats(event)
|
21
|
+
project_id = phraseapp_gateway.project_name_to_id(event.project_name)
|
22
|
+
if project_id
|
23
|
+
robot.send_message(target, "[phraseapp] #{event.message}")
|
24
|
+
robot.send_message(target, locale_stats_message(project_id))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def locale_stats_message(project_id)
|
29
|
+
locales = phraseapp_gateway.locales(project_id)
|
30
|
+
locales_to_message(locales)
|
31
|
+
end
|
32
|
+
|
33
|
+
def locales_to_message(locales)
|
34
|
+
"Locales:\n" + locales.map { |locale|
|
35
|
+
"- #{locale.name}: #{locale.completed}/#{locale.total} (#{locale.percent.to_s("F")}%)"
|
36
|
+
}.join("\n")
|
37
|
+
end
|
38
|
+
|
39
|
+
def target
|
40
|
+
Source.new(room: Lita::Room.find_by_name(config.channel_name) || "general")
|
41
|
+
end
|
42
|
+
|
43
|
+
def phraseapp_gateway
|
44
|
+
@gateway ||= PhraseappGateway.new(Lita.config.handlers.phraseapp.api_key)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
Lita.register_handler(PhraseappStats)
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-phraseapp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Healy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: lita
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: phraseapp-ruby
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.1.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.1.0
|
97
|
+
description: Lita handler for interacting with phraseapp.com, a translation management
|
98
|
+
application
|
99
|
+
email:
|
100
|
+
- james.healy@theconversation.edu.au
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files:
|
104
|
+
- README.md
|
105
|
+
- MIT-LICENSE
|
106
|
+
files:
|
107
|
+
- MIT-LICENSE
|
108
|
+
- README.md
|
109
|
+
- lib/lita-phraseapp.rb
|
110
|
+
- lib/lita/phraseapp.rb
|
111
|
+
- lib/lita/phraseapp_event.rb
|
112
|
+
- lib/lita/phraseapp_gateway.rb
|
113
|
+
- lib/lita/phraseapp_stats.rb
|
114
|
+
homepage: http://github.com/conversation/lita-phraseapp
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata:
|
118
|
+
lita_plugin_type: handler
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 1.9.3
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.5.1
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Lita handler for interacting with phraseapp.com, a translation management
|
139
|
+
application
|
140
|
+
test_files: []
|