flckr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0b810058504821e930cc4a79b667587c39f065c0
4
+ data.tar.gz: ac21cf5474456b2104c08aa7db46debdd8ba2ff7
5
+ SHA512:
6
+ metadata.gz: cef5f99129368cbb0aa1c729dd16aa72ec010bf97df7dbe78aa654b1e11342fc5525e7e4ee702e541528401e13637c80b2131cde5c867d3d469f24352e2f9d68
7
+ data.tar.gz: 28eb3e8065f36dd2e3d4adf3051bafdb3a07ba8c5ba9fbf6fbf065be8bb1c39ae53ef125caa4307718415d87ade42e18f87641dfda66614d67109c23cd00e87a
@@ -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
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at coddeys@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flckr.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dima Sukhikh
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,55 @@
1
+ # Flckr
2
+
3
+ This gem makes a collage for given keywords from Flickr.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'flckr'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install flckr
20
+
21
+ ## Usage
22
+
23
+ Getting help
24
+
25
+ ```bash
26
+ flckrcli help
27
+ ```
28
+
29
+ Create a collage
30
+
31
+ ```bash
32
+ flckrcli create FILENAME -a, --api-key=API_KEY -k, --keywords=one two three # Make a collage for given keywords from Flick
33
+ ```
34
+
35
+ Example
36
+
37
+ ```bash
38
+ flckrcli collage my_collage -k porshe lexus honda ford volkswagen mercedes audi honda ferrari maserati -a bb8fa6cd487eb07a509356acd2fe6113
39
+ ```
40
+
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bundle` to install dependencies. Then, run `rake spec` to run the tests. You can also run `exe/flckrcli` for an interactive prompt that will allow you to experiment.
45
+ 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).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on BitBucket at https://bitbucket.org/pozitive/flckr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
50
+
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
55
+
@@ -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
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ require 'thor'
3
+ require_relative '../lib/flckr'
4
+ require_relative '../lib/flckr/collage'
5
+ require_relative '../lib/flckr/api'
6
+
7
+ class FlckrCLI < Thor
8
+ desc 'create FILENAME', 'Make a collage for given keywords from Flick'
9
+ option :api_key, aliases: '-a', desc: 'Specify an API key', required: true
10
+ option :keywords, aliases: '-k', type: :array, desc: 'Specify a file name', required: true
11
+
12
+ def collage(name = 'collage')
13
+ api = Flckr::Api.new(options[:api_key])
14
+ Dir.mktmpdir do |dir|
15
+ api.download_by(options[:keywords], dir)
16
+ Flckr::Collage.create(dir, name)
17
+ end
18
+ end
19
+ end
20
+
21
+ FlckrCLI.start
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flckr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'flckr'
8
+ spec.version = Flckr::VERSION
9
+ spec.authors = ['Dima Sukhikh']
10
+ spec.email = ['coddeys@gmail.com']
11
+
12
+ spec.summary = 'Create collage from 10 top-rated Flickr images'
13
+ spec.homepage = 'https://bitbucket.org/pozitive/flckr'
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
+
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 'thor', '~> 0.19.1'
25
+ spec.add_runtime_dependency 'faraday', '~> 0.10.0'
26
+ spec.add_runtime_dependency 'faraday_middleware', '~> 0.10.0'
27
+ spec.add_runtime_dependency 'typhoeus', '~> 1.1.0', '>= 1.1.0'
28
+ spec.add_runtime_dependency 'rmagick-screwdrivers', '~> 0.2.0'
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.13'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.0'
33
+ spec.add_development_dependency 'vcr', '~> 3.0.3', '>= 3.0.3'
34
+ spec.add_development_dependency 'webmock', '~> 2.1.0', '>= 2.1.0'
35
+ end
@@ -0,0 +1,15 @@
1
+ require 'flckr/version'
2
+
3
+ module Flckr
4
+ def self.silent_warnings
5
+ old_stderr = $stderr
6
+ $stderr = StringIO.new
7
+ yield
8
+ ensure
9
+ $stderr = old_stderr
10
+ end
11
+
12
+ def self.collage(_keywords, _name)
13
+ true
14
+ end
15
+ end
@@ -0,0 +1,81 @@
1
+ require_relative 'dict'
2
+ require 'json'
3
+ require 'faraday'
4
+ require 'typhoeus'
5
+ require 'typhoeus/adapters/faraday'
6
+ require 'securerandom'
7
+
8
+ module Flckr
9
+ class Api
10
+ def initialize(api_key)
11
+ @api_key = api_key
12
+ end
13
+
14
+ def download_by(keywords, dir)
15
+ ten_keywords = Dict.make_ten_words keywords
16
+ urls = search_all ten_keywords
17
+ urls.map do |url|
18
+ download(url, dir)
19
+ end
20
+ end
21
+
22
+ def download(url, dir)
23
+ response = conn.get url
24
+ File.open("#{dir}/#{SecureRandom.hex(5)}.jpg", 'wb') { |fp| fp.write(response.body) }
25
+ end
26
+
27
+ def generate_url(photo_id:, server_id:, farm_id:, secret:)
28
+ "https://farm#{farm_id}.staticflickr.com/#{server_id}/#{photo_id}_#{secret}_m.jpg"
29
+ end
30
+
31
+ def search_all(keywords)
32
+ search(keywords)
33
+ .map { |r| parse r }
34
+ .reject(&:nil?)
35
+ .map { |e| generate_url e }
36
+ end
37
+
38
+ def search(keywords)
39
+ [].tap do |responses|
40
+ client = conn
41
+ client.in_parallel do
42
+ keywords.each do |keyword|
43
+ responses << client.get('/services/rest', params(@api_key, keyword))
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def parse(response)
52
+ hash = JSON.parse response.body
53
+ return $stderr.puts hash['message'] if hash['stat'] == 'fail'
54
+ photo = hash['photos']['photo'].first
55
+ to_hash photo unless photo.nil?
56
+ end
57
+
58
+ def to_hash(photo)
59
+ { photo_id: photo['id'],
60
+ farm_id: photo['farm'],
61
+ secret: photo['secret'],
62
+ server_id: photo['server'] }
63
+ end
64
+
65
+ def conn
66
+ Faraday.new(url: 'https://api.flickr.com') do |faraday|
67
+ faraday.adapter :typhoeus
68
+ end
69
+ end
70
+
71
+ def params(api_key, keyword)
72
+ { method: 'flickr.photos.search',
73
+ api_key: api_key,
74
+ text: keyword,
75
+ format: 'json',
76
+ nojsoncallback: 1,
77
+ page: 1,
78
+ per_page: 1 }
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,15 @@
1
+ Flckr.silent_warnings do
2
+ require 'rmagick/screwdrivers'
3
+ end
4
+
5
+ module Flckr
6
+ module Collage
7
+ def self.create(dir, name)
8
+ options = {
9
+ columns: 5,
10
+ thumb_width: 100
11
+ }
12
+ Magick::Screwdrivers.collage(dir, options).write("#{name}.jpeg")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module Flckr
2
+ module Dict
3
+ DEFAULT_DICT = '/usr/share/dict/words'.freeze
4
+ def self.random_line
5
+ File.readlines(DEFAULT_DICT).sample.strip
6
+ end
7
+
8
+ def self.make_ten_words(words)
9
+ ten_words = words.take(10)
10
+ count = ten_words.count
11
+ return ten_words if count == 10
12
+ (10 - count).times { ten_words << Dict.random_line }
13
+ ten_words
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Flckr
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,218 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flckr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dima Sukhikh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.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.10.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.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.10.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: typhoeus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.1.0
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: 1.1.0
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.1.0
75
+ - !ruby/object:Gem::Dependency
76
+ name: rmagick-screwdrivers
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.2.0
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.2.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: bundler
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.13'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.13'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '10.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '10.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rspec
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '3.0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '3.0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: vcr
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 3.0.3
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: 3.0.3
141
+ type: :development
142
+ prerelease: false
143
+ version_requirements: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: 3.0.3
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: 3.0.3
151
+ - !ruby/object:Gem::Dependency
152
+ name: webmock
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: 2.1.0
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 2.1.0
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: 2.1.0
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: 2.1.0
171
+ description:
172
+ email:
173
+ - coddeys@gmail.com
174
+ executables:
175
+ - flckrcli
176
+ extensions: []
177
+ extra_rdoc_files: []
178
+ files:
179
+ - ".gitignore"
180
+ - ".rspec"
181
+ - ".travis.yml"
182
+ - CODE_OF_CONDUCT.md
183
+ - Gemfile
184
+ - LICENSE.txt
185
+ - README.md
186
+ - Rakefile
187
+ - exe/flckrcli
188
+ - flckr.gemspec
189
+ - lib/flckr.rb
190
+ - lib/flckr/api.rb
191
+ - lib/flckr/collage.rb
192
+ - lib/flckr/dict.rb
193
+ - lib/flckr/version.rb
194
+ homepage: https://bitbucket.org/pozitive/flckr
195
+ licenses:
196
+ - MIT
197
+ metadata: {}
198
+ post_install_message:
199
+ rdoc_options: []
200
+ require_paths:
201
+ - lib
202
+ required_ruby_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ required_rubygems_version: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - ">="
210
+ - !ruby/object:Gem::Version
211
+ version: '0'
212
+ requirements: []
213
+ rubyforge_project:
214
+ rubygems_version: 2.5.1
215
+ signing_key:
216
+ specification_version: 4
217
+ summary: Create collage from 10 top-rated Flickr images
218
+ test_files: []