slackup 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 217865baf5660d9ee09b17a815f9849c8f714f1e
4
+ data.tar.gz: 27907d862fd07bbb93b7aa1cc4bdaa8f7ea4133b
5
+ SHA512:
6
+ metadata.gz: 5e83bd95a1104f5a24eb818f2554163af2ac4218ba595ed876558b7a72f776948b54062b78c054e52dbff76d4b84d2a0f1ec4f32a1d9927d1a6207559578285b
7
+ data.tar.gz: 69a6419c81695b8a83d62e239881b7843278181558058fa46405494a8c99cb9a26d90367e1aa30545f0f6209367e2827dda3c90e1ffe9052f9a91011f44bb340
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ slackup (0.0.2)
5
+ slack-api (~> 1.1, >= 1.1.3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ eventmachine (1.0.7)
11
+ faraday (0.9.1)
12
+ multipart-post (>= 1.2, < 3)
13
+ faraday_middleware (0.9.1)
14
+ faraday (>= 0.7.4, < 0.10)
15
+ faye-websocket (0.9.2)
16
+ eventmachine (>= 0.12.0)
17
+ websocket-driver (>= 0.5.1)
18
+ multi_json (1.11.0)
19
+ multipart-post (2.0.0)
20
+ rake (10.4.2)
21
+ slack-api (1.1.3)
22
+ faraday (>= 0.7, < 0.10)
23
+ faraday_middleware (~> 0.8)
24
+ faye-websocket (~> 0.9.2)
25
+ multi_json (~> 1.0, >= 1.0.3)
26
+ websocket-driver (0.5.4)
27
+ websocket-extensions (>= 0.1.0)
28
+ websocket-extensions (0.1.2)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.9)
35
+ rake (~> 10.0)
36
+ slackup!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Benjamin Fleischer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # slackup
2
+ backup my slacks
3
+
4
+ ## Installation
5
+
6
+ `gem install slackup`
7
+
8
+ ## Usage
9
+
10
+ 1. Get token for each team from https://api.slack.com/web
11
+
12
+ 2. Configure a file in the backup directory called `slack_teams.yml`,
13
+ though `slack_teams.yaml` and `slack_teams.json` will also work.
14
+
15
+ The config file must contain a dictionary (hash) of
16
+ team names (backup directories) and associated tokens.
17
+
18
+ e.g.
19
+
20
+ slack_teams.yml
21
+
22
+ ```yaml
23
+ ---
24
+ some-team: xxxp-some-token
25
+ another-team: xxxp-different-token
26
+ ```
27
+
28
+ slack_teams.json
29
+
30
+ ```json
31
+ {
32
+ "some-team": "xxxp-some-token",
33
+ "another-team": "xxxp-different-token"
34
+ }
35
+ ```
36
+
37
+ 3. Run `slackup` in your terminal
38
+
39
+ Each key/value team pair will be run in a local directory named by the key
40
+ using only the token for auth. Thus, the key (team) name can be whatever you want.
41
+
42
+ ## Development
43
+
44
+ This gem is does the bare basics of backup and works for me.
45
+
46
+ It has no tests.
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it ( https://github.com/[my-github-username]/slackup/fork )
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create a new Pull Request
55
+
56
+ MIT License
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/exe/slackup ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby --disable-gems
2
+ require_relative "../lib/slackup"
3
+ Slackup.backup
@@ -0,0 +1,3 @@
1
+ module Slackup
2
+ VERSION = "0.0.2"
3
+ end
data/lib/slackup.rb ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "pathname"
4
+ require "yaml"
5
+ require "fileutils"
6
+ gem "slack-api", "= 1.1.3"
7
+ require "slack"
8
+
9
+ class Slackup
10
+ Error = Class.new(StandardError)
11
+ RUN_ROOT = Pathname Dir.pwd
12
+ def self.run_root
13
+ RUN_ROOT
14
+ end
15
+
16
+ SEMAPHORE = Mutex.new
17
+ attr_reader :name
18
+ def initialize(name, token)
19
+ @name = name
20
+ @token = token
21
+ FileUtils.mkdir_p(name)
22
+ end
23
+
24
+ def self.team_token_pairs_file
25
+ Pathname.glob(run_root.join("slack_teams.{json,yml,yaml}")).first
26
+ end
27
+
28
+ def self.team_token_pairs
29
+ if team_token_pairs_file.readable?
30
+ YAML.load(team_token_pairs_file.read)
31
+ else
32
+ fail Error, "No team token pairs file found. See README for instructions."
33
+ end
34
+ end
35
+
36
+ def self.backup(team_token_pairs = team_token_pairs())
37
+ team_token_pairs.each do |name, token|
38
+ new(name, token).execute
39
+ end
40
+ end
41
+
42
+ def execute
43
+ SEMAPHORE.synchronize do
44
+ authorize! &&
45
+ Dir.chdir(name) do
46
+ channels.each do |channel|
47
+ write_channel_messages(channel)
48
+ end
49
+ write_stars
50
+ end
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def authorize!
57
+ Slack.configure do |config|
58
+ config.token = @token
59
+ end
60
+ auth_test = Slack.auth_test
61
+ if auth_test["ok"] === true
62
+ p [name]
63
+ true
64
+ else
65
+ p [name, auth_test]
66
+ false
67
+ end
68
+ end
69
+
70
+ def users
71
+ @users ||= Slack.users_list["members"]
72
+ end
73
+
74
+ def channels
75
+ @channels ||= Slack.channels_list["channels"]
76
+ end
77
+
78
+ def write_channel_messages(channel)
79
+ messages = Slack.channels_history({channel: channel["id"], count: "1000"})["messages"]
80
+ File.open(backup_filename(channel['name']),"w") do |f|
81
+ f.write format_channel_messages(messages)
82
+ end
83
+ end
84
+
85
+ def format_channel_messages(messages)
86
+ messages.reverse.map { |msg|
87
+ if (msg.has_key?("text") && msg.has_key?("user"))
88
+ users.each do |user|
89
+ if user["id"] == msg["user"]
90
+ break msg["user"] = user["name"]
91
+ end
92
+ end
93
+ msg
94
+ else
95
+ nil
96
+ end
97
+ }.compact.to_yaml
98
+ end
99
+
100
+ def write_stars
101
+ File.open(backup_filename("stars"),"w") do |f|
102
+ stars = Slack.stars_list(count: "1000", page: "1")
103
+ f.write(format_stars(stars))
104
+ end
105
+ end
106
+
107
+ def format_stars(stars)
108
+ stars.to_yaml
109
+ end
110
+
111
+ def backup_filename(name)
112
+ "#{name}.yml"
113
+ end
114
+ end
115
+
116
+ if $0 == __FILE__
117
+ Slackup.backup
118
+ end
data/slackup.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'slackup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "slackup"
8
+ spec.version = Slackup::VERSION
9
+ spec.authors = ["Benjamin Fleischer"]
10
+ spec.email = ["dev@benjaminfleischer.com"]
11
+
12
+ spec.summary = %q{A simple tool to backup slack channels}
13
+ spec.description = %q{Backup slack channels with just a name and a token}
14
+ spec.homepage = "https://github.com/bf4/slackup"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "slack-api", "~> 1.1", ">= 1.1.3"
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slackup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin Fleischer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slack-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.1.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.9'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.9'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ description: Backup slack channels with just a name and a token
62
+ email:
63
+ - dev@benjaminfleischer.com
64
+ executables:
65
+ - slackup
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - ".gitignore"
70
+ - CODE_OF_CONDUCT.md
71
+ - Gemfile
72
+ - Gemfile.lock
73
+ - LICENSE
74
+ - README.md
75
+ - Rakefile
76
+ - exe/slackup
77
+ - lib/slackup.rb
78
+ - lib/slackup/version.rb
79
+ - slackup.gemspec
80
+ homepage: https://github.com/bf4/slackup
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.6
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: A simple tool to backup slack channels
104
+ test_files: []