metallica_logo 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9b9dd2594b61bf96029f0752f269a955a28dc2ea8d1867b62a9e03d42c7ef286
4
+ data.tar.gz: 99c9bc0e8a2534ba03cd3c2891a27ad8f65b6347b684613f2fa7d369caee6f0f
5
+ SHA512:
6
+ metadata.gz: 2f233c55773d5d78cfd44d870bbcce6f0ea6b08d1a31829122ddeea316117bbce9bf3b7b3c7c1a81efbdbd6a598fa7f3c4c0e419e188763edc8c2904ffc4d1ec
7
+ data.tar.gz: 908f05a5ddb7bc93ceb15f495684351a9d30c09df6f9e534e8e08465552e2868fa6a33cc29a39935d09e842e64ced8cb044c7e83bce4b845055086095f3d92f8
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.7
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in metallica_logo.gemspec
8
+ gemspec
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ metallica_logo (0.0.1)
5
+ rest-client (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ crack (0.4.3)
13
+ safe_yaml (~> 1.0.0)
14
+ domain_name (0.5.20190701)
15
+ unf (>= 0.0.5, < 1.0.0)
16
+ hashdiff (1.0.0)
17
+ http-accept (1.7.0)
18
+ http-cookie (1.0.3)
19
+ domain_name (~> 0.5)
20
+ mime-types (3.3.1)
21
+ mime-types-data (~> 3.2015)
22
+ mime-types-data (3.2019.1009)
23
+ minitest (5.11.3)
24
+ minitest-spec-context (0.0.4)
25
+ netrc (0.11.0)
26
+ public_suffix (4.0.3)
27
+ rake (10.5.0)
28
+ rest-client (2.1.0)
29
+ http-accept (>= 1.7.0, < 2.0)
30
+ http-cookie (>= 1.0.2, < 2.0)
31
+ mime-types (>= 1.16, < 4.0)
32
+ netrc (~> 0.8)
33
+ safe_yaml (1.0.5)
34
+ unf (0.1.4)
35
+ unf_ext
36
+ unf_ext (0.0.7.6)
37
+ vcr (5.0.0)
38
+ webmock (3.8.0)
39
+ addressable (>= 2.3.6)
40
+ crack (>= 0.3.2)
41
+ hashdiff (>= 0.4.0, < 2.0.0)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bundler (~> 2.0)
48
+ metallica_logo!
49
+ minitest (~> 5.0)
50
+ minitest-spec-context (~> 0.0.3)
51
+ rake (~> 10.0)
52
+ vcr (~> 5.0)
53
+ webmock (~> 3.0)
54
+
55
+ BUNDLED WITH
56
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 john_farrell
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.
@@ -0,0 +1,59 @@
1
+ # MetallicaLogo
2
+
3
+ ![Metallica Logo](https://raw.githubusercontent.com/johnmfarrell1/metallica_logo/master/examples/metallica_logo_example_cropped.png)
4
+
5
+ Get any provided text as a Metallica image logo.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'metallica_logo'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install metallica_logo
22
+
23
+ ## Usage
24
+
25
+ You can initialize a new client for fetching logos as follows:
26
+ ```ruby
27
+ client = MetallicaLogo::Client.new
28
+ ```
29
+
30
+ The client has 2 public methods depending on how you wish to use it.
31
+ To fetch a logo result without downloading the image, use the following:
32
+
33
+ ```ruby
34
+ logo = client.generate_logo('some test to generate')
35
+ #=> #<MetallicaLogo::Result:0x0000000000000000 @file="<url to image>", @token="token", @result="result">
36
+ ```
37
+
38
+ If you wish to also save the image locally, use the following:
39
+
40
+ ```ruby
41
+ logo = client.generate_and_download_logo('some test to generate', 'file.jpg')
42
+ #=> #<Pathname:file.jpg>
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ 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).
50
+
51
+ Note: This gem uses a 3rd party API. I do not own this 3rd party API.
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/johnmfarrell1/metallica_logo.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'metallica_logo'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -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,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'metallica_logo/version'
4
+ require 'metallica_logo/result'
5
+ require 'metallica_logo/client'
6
+ require 'rest-client'
7
+ require 'json'
8
+ require 'pathname'
9
+
10
+ module MetallicaLogo
11
+ class Error < StandardError; end
12
+ class ServerError < Error; end
13
+ class RequestError < Error; end
14
+
15
+ BASE_URL = 'http://metallica.alwaysdata.net'
16
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MetallicaLogo
4
+ # HTTP client for requesting logo generation and also
5
+ # if desired, downloading to a local destination
6
+ class Client
7
+ attr_reader :rest_klass, :base_url
8
+
9
+ MAX_CHARACTERS = 25
10
+
11
+ def initialize(base_url: MetallicaLogo::BASE_URL, rest_klass: RestClient)
12
+ @rest_klass = rest_klass
13
+ @base_url = base_url
14
+ end
15
+
16
+ def generate_logo(text)
17
+ if text.size > MAX_CHARACTERS
18
+ raise RequestError, "Too many characters, limit is #{MAX_CHARACTERS}"
19
+ end
20
+
21
+ response = post("#{@base_url}/creation/", 'the_text': text)
22
+ MetallicaLogo::Result.new(JSON.parse(response))
23
+ end
24
+
25
+ def generate_and_download_logo(text, destination_file)
26
+ result = generate_logo(text)
27
+ destination_file = Pathname(destination_file)
28
+ destination_file.dirname.mkpath
29
+ response = download(result.file)
30
+ IO.binwrite(destination_file, response.body)
31
+ destination_file
32
+ end
33
+
34
+ private
35
+
36
+ def download(url)
37
+ rest_klass.get(url)
38
+ rescue rest_klass::ExceptionWithResponse => e
39
+ validate_response(e.response)
40
+ end
41
+
42
+ def post(url, payload)
43
+ response = rest_klass.post(url, payload)
44
+ validate_response(response)
45
+ rescue rest_klass::ExceptionWithResponse => e
46
+ validate_response(e.response)
47
+ end
48
+
49
+ def validate_response(response)
50
+ unless valid_json?(response.body)
51
+ raise ServerError, 'Invalid JSON returned'
52
+ end
53
+
54
+ case response.code.to_s
55
+ when /2\d\d/ then response
56
+ when /5\d\d/ then raise ServerError, response.body
57
+ else
58
+ raise RequestError, response.body
59
+ end
60
+ end
61
+
62
+ def valid_json?(value)
63
+ result = JSON.parse(value)
64
+ result.is_a?(Hash)
65
+ rescue JSON::ParserError
66
+ false
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MetallicaLogo
4
+ # value object for storing the response of a logo
5
+ # generation request
6
+ class Result
7
+ attr_reader :file, :token, :result
8
+
9
+ def initialize(data)
10
+ @file = "#{MetallicaLogo::BASE_URL}/#{data['file']}"
11
+ @token = data['token']
12
+ @result = data['result']
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MetallicaLogo
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'metallica_logo/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'metallica_logo'
9
+ spec.version = MetallicaLogo::VERSION
10
+ spec.authors = ['john_farrell']
11
+ spec.email = ['john_farrell@symantec.com']
12
+
13
+ spec.summary = 'Small gem for generating a Metallica '\
14
+ 'like logo for some provided string'
15
+ spec.description = 'This gem uses an existing logo generation API '\
16
+ 'to generate a Metallica like logo for a given string'
17
+ spec.homepage = 'https://github.com/johnmfarrell1'
18
+ spec.license = 'MIT'
19
+
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = 'https://github.com/johnmfarrell1/metallica_logo'
23
+ spec.metadata['changelog_uri'] = 'https://github.com/johnmfarrell1/metallica_logo'
24
+ else
25
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
26
+ 'public gem pushes.'
27
+ end
28
+
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
+ `git ls-files -z`.split("\x0").reject do |f|
31
+ f.match(%r{^(test|spec|features)/})
32
+ end
33
+ end
34
+ spec.bindir = 'exe'
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ['lib']
37
+
38
+ spec.add_development_dependency 'bundler', '~> 2.0'
39
+ spec.add_development_dependency 'minitest', '~> 5.0'
40
+ spec.add_development_dependency 'minitest-spec-context', '~> 0.0.3'
41
+ spec.add_development_dependency 'rake', '~> 10.0'
42
+ spec.add_development_dependency 'vcr', '~> 5.0'
43
+ spec.add_development_dependency 'webmock', '~> 3.0'
44
+ spec.add_dependency 'rest-client', '~> 2.0'
45
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metallica_logo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - john_farrell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-spec-context
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rest-client
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
111
+ description: This gem uses an existing logo generation API to generate a Metallica
112
+ like logo for a given string
113
+ email:
114
+ - john_farrell@symantec.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - examples/metallica_logo_example.jpg
129
+ - examples/metallica_logo_example_cropped.png
130
+ - lib/metallica_logo.rb
131
+ - lib/metallica_logo/client.rb
132
+ - lib/metallica_logo/result.rb
133
+ - lib/metallica_logo/version.rb
134
+ - metallica_logo.gemspec
135
+ homepage: https://github.com/johnmfarrell1
136
+ licenses:
137
+ - MIT
138
+ metadata:
139
+ homepage_uri: https://github.com/johnmfarrell1
140
+ source_code_uri: https://github.com/johnmfarrell1/metallica_logo
141
+ changelog_uri: https://github.com/johnmfarrell1/metallica_logo
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubygems_version: 3.0.3
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Small gem for generating a Metallica like logo for some provided string
161
+ test_files: []