medicine_shield 0.1.0

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: bd1d40117ba6c4e86986a6f1ebd7cfb73a97231b
4
+ data.tar.gz: 1ac80886d78e14e59e50bda54ff94fcb218cde09
5
+ SHA512:
6
+ metadata.gz: 24f9dbf4899af004e0fd88f181d72b19e824d02f073150503f4e31431510dd7ae8809b5d5312cec8efe8cbb16eaa6c7c9c2ac8f89325bfdd1672e195ba7cb143
7
+ data.tar.gz: 3a642c6d39fc869068278848574d5fcfe312f489f7c60ea87671e3ba83139f47e701c3b6fc584d772e3b316ff46712eb6b30fd4a98bc2f1c89299976622d76f2
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in medicine_shield.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Shugo Maeda
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # MedicineShield
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/medicine_shield`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'medicine_shield'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install medicine_shield
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Shugo Maeda/medicine_shield.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "medicine_shield"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "medicine_shield/version"
2
+
3
+ module MedicineShield
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mastodon"
4
+ require "oauth2"
5
+ require "fileutils"
6
+
7
+ module MedicineShield
8
+ APP_NAME = "medicine_shield"
9
+ SCOPE = "read write follow"
10
+
11
+ module_function
12
+
13
+ def config_path
14
+ File.expand_path("config.json", CONFIG[:medicine_shield_directory])
15
+ end
16
+
17
+ def get_config
18
+ path = config_path
19
+ begin
20
+ JSON.load(File.read(path))
21
+ rescue Errno::ENOENT
22
+ config = create_config
23
+ FileUtils.mkdir_p(File.dirname(path))
24
+ old_umask = File.umask
25
+ File.umask(0066)
26
+ begin
27
+ File.write(path, config.to_json)
28
+ ensure
29
+ File.umask(old_umask)
30
+ end
31
+ config
32
+ end
33
+ end
34
+
35
+ def create_config
36
+ url = read_from_minibuffer("Mastodon URL: ",
37
+ default: "https://mstdn.sanin.club")
38
+ mstdn_client = Mastodon::REST::Client.new(base_url: url)
39
+ app = mstdn_client.create_app(APP_NAME, "urn:ietf:wg:oauth:2.0:oob", SCOPE)
40
+ oauth_client = OAuth2::Client.new(app.client_id,
41
+ app.client_secret,
42
+ site: url)
43
+ email = read_from_minibuffer("Mastodon user e-mail: ")
44
+ password = read_from_minibuffer("Mastodon password: ")
45
+ token = oauth_client.password.get_token(email, password, scope: SCOPE)
46
+ {
47
+ "url" => url,
48
+ "client_id" => app.client_id,
49
+ "client_secret" => app.client_secret,
50
+ "email" => email,
51
+ "access_token" => token.token
52
+ }
53
+ end
54
+ end
55
+
56
+ define_command(:toot) do
57
+ |msg = read_from_minibuffer("Toot: ")|
58
+ config = MedicineShield.get_config
59
+ client = Mastodon::REST::Client.new(base_url: config["url"],
60
+ bearer_token: config["access_token"])
61
+ response = client.create_status(msg)
62
+ message("Tooted")
63
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ CONFIG[:medicine_shield_directory] = File.expand_path("~/.medicine_shield")
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MedicineShield
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "medicine_shield/version"
4
+ require_relative "medicine_shield/config"
5
+ require_relative "medicine_shield/commands"
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'medicine_shield/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "medicine_shield"
8
+ spec.version = MedicineShield::VERSION
9
+ spec.authors = ["Shugo Maeda"]
10
+ spec.email = ["shugo@ruby-lang.org"]
11
+
12
+ spec.summary = "A Mastodon client for Textbringer."
13
+ spec.description = "A Mastodon client for Textbringer."
14
+ spec.homepage = "https://github.com/shugo/medicine_shield"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "textbringer"
25
+ spec.add_runtime_dependency "mastodon-api"
26
+ spec.add_runtime_dependency "oauth2"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.14"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: medicine_shield
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shugo Maeda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: textbringer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: mastodon-api
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: oauth2
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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: A Mastodon client for Textbringer.
84
+ email:
85
+ - shugo@ruby-lang.org
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/setup
97
+ - lib/medicine_shield.rb
98
+ - lib/medicine_shield/commands.rb
99
+ - lib/medicine_shield/config.rb
100
+ - lib/medicine_shield/version.rb
101
+ - lib/textbringer_plugin.rb
102
+ - medicine_shield.gemspec
103
+ homepage: https://github.com/shugo/medicine_shield
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.6.11
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: A Mastodon client for Textbringer.
127
+ test_files: []
128
+ has_rdoc: