cat_generator 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05eec0edcf45ca5becca9fd63a76ca5bf1b24ada
4
+ data.tar.gz: 3041115667fd77376a0c475fc9e919619ff08bd4
5
+ SHA512:
6
+ metadata.gz: d51e3097cef3ebb6c01285acf40ccfac85ec65c17ea6b9fa5e003376cef73a1adaf7d149de42a2c3100154ed0e59c0a77cc85043fc1176115f195f555cc3101c
7
+ data.tar.gz: 6c788168450d56e1ac417667e1a57903bfd4093a71fb2bc45822a6c63c681a7fba9eb24981feb19f34d578089dce36e559b17a1821a6584a3d569a426e33e94b
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cat_generator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Basel Farah
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,74 @@
1
+ # CatGenerator
2
+ CatGenerator generates random cat photos and facts about cat. It communicates with:
3
+ ```
4
+ http://thecatapi.com/
5
+ http://catfacts-api.appspot.com/
6
+ ```
7
+
8
+ ## Installation
9
+
10
+ The gem is not yet available on rubygems so to use it clone the project:
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Build the gem:
17
+
18
+ $ gem build cat_generator.gemspec
19
+
20
+ This will generate a gem file
21
+ ```
22
+ cat_generator-x.x.x.gem
23
+ ```
24
+
25
+ Then run:
26
+
27
+ $ gem install cat_generator-x.x.x.gem
28
+
29
+ ## Usage
30
+
31
+ To get the next cat photo url:
32
+ ```ruby
33
+ CatGenerator::Photo.url
34
+ ```
35
+
36
+ To open the next cat photo in a browser:
37
+ ```ruby
38
+ CatGenerator::Photo.open_in_browser
39
+ ```
40
+
41
+ To save the next cat photo on your desktop:
42
+ ```ruby
43
+ CatGenerator::Photo.write_to_desktop
44
+ ```
45
+
46
+ To get the next cat fact:
47
+ ```ruby
48
+ CatGenerator::Fact.next
49
+ ```
50
+
51
+ You can run the executable in terminal:
52
+ ```bash
53
+ bundle exec cat_generator [browser|file|fact]
54
+ ```
55
+
56
+ * browser (default): will open the photo in the default browser
57
+ * file: will save the photo on your desktop
58
+ * fact: will print the next cat fact
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ 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).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/baz44/cat_generator.
69
+
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
74
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/cat_generator ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cat_generator"
5
+
6
+ CatGenerator::Cli.run(ARGV[0] || 'browser')
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cat_generator"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cat_generator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cat_generator"
8
+ spec.version = CatGenerator::VERSION
9
+ spec.authors = ["Basel Farah"]
10
+ spec.email = ["baself@gmail.com"]
11
+
12
+ spec.summary = %q{Generates cat photos and facts}
13
+ spec.description = %q{Use this gem to generate cat photos and cats, it interacts with http://thecatapi.com/ and http://catfacts-api.appspot.com/}
14
+ spec.homepage = "https://github.com/baz44/cat_generator"
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 = "bin"
19
+ spec.executables = ["cat_generator"]
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "webmock"
26
+
27
+ spec.add_dependency 'excon'
28
+ end
@@ -0,0 +1,9 @@
1
+ require "cat_generator/version"
2
+ require 'cat_generator/photo'
3
+ require 'cat_generator/fact'
4
+ require 'cat_generator/cli'
5
+
6
+ require 'excon'
7
+
8
+ module CatGenerator
9
+ end
@@ -0,0 +1,16 @@
1
+ module CatGenerator
2
+ class Cli
3
+ def self.run(option = 'browser')
4
+ case option
5
+ when 'browser'
6
+ CatGenerator::Photo.open_in_browser
7
+ when 'file'
8
+ CatGenerator::Photo.write_to_desktop
9
+ when 'fact'
10
+ puts CatGenerator::Fact.next
11
+ else
12
+ warn 'Usage: cat_generator [browser|file|fact]'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'json'
2
+
3
+ module CatGenerator
4
+ class Fact
5
+ CAT_FACTS_API = 'http://catfacts-api.appspot.com/api/facts'
6
+
7
+ def self.next
8
+ response = Excon.get(CAT_FACTS_API)
9
+
10
+ if response.status == 200
11
+ json_response = JSON.parse(response.body)
12
+ json_response["facts"].first
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ module CatGenerator
2
+ class Photo
3
+ CAT_PHOTOS_API = 'http://thecatapi.com/api/images/get'
4
+
5
+ # returns the next photo url from thecatapi.com
6
+ def self.url
7
+ response = Excon.get(CAT_PHOTOS_API)
8
+
9
+ if response.status == 302
10
+ response.headers["location"]
11
+ end
12
+ end
13
+
14
+ # downloads the next photo and saves to Desktop
15
+ def self.write_to_desktop
16
+ photo_url = url
17
+
18
+ if photo_url
19
+ filename = photo_url.split('/').last
20
+ target = File.expand_path("~/Desktop/#{filename}")
21
+
22
+ File.open(target, 'w') do |file|
23
+ file.write(Excon.get(photo_url).body)
24
+ end
25
+ end
26
+ end
27
+
28
+ # opens the photo in the default browser
29
+ def self.open_in_browser
30
+ photo_url = url
31
+ `open #{photo_url}` if photo_url
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module CatGenerator
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cat_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Basel Farah
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-24 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: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: webmock
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: excon
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
+ description: Use this gem to generate cat photos and cats, it interacts with http://thecatapi.com/
84
+ and http://catfacts-api.appspot.com/
85
+ email:
86
+ - baself@gmail.com
87
+ executables:
88
+ - cat_generator
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - .gitignore
93
+ - .rspec
94
+ - .travis.yml
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/cat_generator
100
+ - bin/console
101
+ - bin/setup
102
+ - cat_generator.gemspec
103
+ - lib/cat_generator.rb
104
+ - lib/cat_generator/cli.rb
105
+ - lib/cat_generator/fact.rb
106
+ - lib/cat_generator/photo.rb
107
+ - lib/cat_generator/version.rb
108
+ homepage: https://github.com/baz44/cat_generator
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.0.14
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Generates cat photos and facts
132
+ test_files: []