ruboty-mtgcard 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: 43d1ac7ed68e8ea3d429e435062a0ec81f3c3305
4
+ data.tar.gz: 4cc70cf8622414cf6ea367e0c9cbcce7bc063803
5
+ SHA512:
6
+ metadata.gz: 8008fa7934ac28f8fb821aaf8c29a93075377d73c8fb794d4382f60c8d65430bd8321c8b0fef41f87bd7e87eaa867af49f96ba697744c15a4dac5e897e1e90f6
7
+ data.tar.gz: 25fef3fe8fa07a74f641952dc91e0ec4f6d2c72e334aa410e6048e72430687ee98a57d5250597deb7e0d4d8e9cfc791bc62255fba2a3553ece8b9d31af74d762
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ruboty-mtgcard.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 TAGAWA Takao
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.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Ruboty::Mtgcard
2
+
3
+ A Ruboty plugin that returns MTG card illustration url.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruboty-mtgcard'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```
22
+ $ gem install ruboty-mtgcard
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```
28
+ > ruboty mtgcard [keyword]
29
+ ```
30
+
31
+ ## ENV
32
+
33
+ ```
34
+ MTGCARD_LANGUAGE - MTG card language (default: english)
35
+ MTGCARD_MESSAGE_WHEN_NOT_FOUND - Message when not found (default: No cards found.)
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dounokouno/ruboty-mtgcard.
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,59 @@
1
+ require 'ruboty'
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ module Ruboty
6
+ module Handlers
7
+ class Mtgcard < Base
8
+ API_URL = 'https://api.magicthegathering.io/v1/cards?'
9
+ DEFAULT_MTGCARD_LANGUAGE = 'english'
10
+ DEFAULT_MTGCARD_MESSAGE_WHEN_NOT_FOUND = 'No cards found.'
11
+
12
+ env :MTGCARD_LANGUAGE, 'MTG card language (default: english)', optional: true
13
+ env :MTGCARD_MESSAGE_WHEN_NOT_FOUND, 'Message when not found (default: No cards found.)', optional: true
14
+
15
+ LANGUAGE = ENV['MTGCARD_LANGUAGE'] || DEFAULT_MTGCARD_LANGUAGE
16
+ MESSAGE_WHEN_NOT_FOUND = ENV['MTGCARD_MESSAGE_WHEN_NOT_FOUND'] || DEFAULT_MTGCARD_MESSAGE_WHEN_NOT_FOUND
17
+
18
+ on(
19
+ /(mtgcard) (?<keyword>.+)/,
20
+ name: 'mtgcard',
21
+ description: 'Returns MTG card illustration url that matches the keyword'
22
+ )
23
+
24
+ def mtgcard(message)
25
+ image_url = nil
26
+
27
+ begin
28
+ res = open "#{api_url}&name=#{URI.escape(message[:keyword])}"
29
+ rescue => e
30
+ return message.reply e
31
+ end
32
+
33
+ cards = JSON.parse(res.read)['cards']
34
+ return message.reply MESSAGE_WHEN_NOT_FOUND if cards.length == 0
35
+
36
+ if LANGUAGE == 'english'
37
+ while image_url.nil? || image_url.length == 0
38
+ image_url = cards.sample['imageUrl']
39
+ end
40
+ else
41
+ while image_url.nil? || image_url.length == 0
42
+ card = cards.sample['foreignNames'].find { |foreig_name| foreig_name['language'] == LANGUAGE.capitalize }
43
+ image_url = card['imageUrl']
44
+ end
45
+ end
46
+
47
+ message.reply image_url
48
+ end
49
+
50
+ private
51
+
52
+ def api_url
53
+ url = API_URL
54
+ url += "language=#{LANGUAGE}" if LANGUAGE != 'english'
55
+ url
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,2 @@
1
+ require 'ruboty/mtgcard/version'
2
+ require 'ruboty/handlers/mtgcard'
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Mtgcard
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/mtgcard/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ruboty-mtgcard'
8
+ spec.version = Ruboty::Mtgcard::VERSION
9
+ spec.authors = ['TAGAWA Takao']
10
+ spec.email = ['dounokouno@gmail.com']
11
+
12
+ spec.summary = 'A Ruboty plugin that returns MTG card illustration url.'
13
+ spec.homepage = 'https://github.com/dounokouno/ruboty-mtgcard'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'ruboty'
24
+ spec.add_development_dependency 'bundler', '~> 1.15'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-mtgcard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - TAGAWA Takao
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - dounokouno@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/ruboty/handlers/mtgcard.rb
68
+ - lib/ruboty/mtgcard.rb
69
+ - lib/ruboty/mtgcard/version.rb
70
+ - ruboty-mtgcard.gemspec
71
+ homepage: https://github.com/dounokouno/ruboty-mtgcard
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.6.13
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: A Ruboty plugin that returns MTG card illustration url.
95
+ test_files: []