adn_hashtag_photos 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/adn_hashtag_photos.gemspec +32 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/adn_hashtag_photos.rb +11 -0
- data/lib/adn_hashtag_photos/gallery_builder.rb +44 -0
- data/lib/adn_hashtag_photos/posts_loader.rb +52 -0
- data/lib/adn_hashtag_photos/uploader.rb +17 -0
- data/lib/adn_hashtag_photos/uploader/base.rb +15 -0
- data/lib/adn_hashtag_photos/uploader/climber.rb +18 -0
- data/lib/adn_hashtag_photos/uploader/core.rb +18 -0
- data/lib/adn_hashtag_photos/version.rb +3 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f788843eb7358bbe7ef79a57a1e1aaf37b55045c
|
4
|
+
data.tar.gz: 994a242c2fe47111d01090a109dc9161ea15f41e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26bb5cef6933630bc8f43af0b6ad4dd0115adf7466b2a38123bbaa3ed83c9f3d537bb961dc9f237b603d6a4c56f2ea514f9e7874f5f17e47b834612c85190956
|
7
|
+
data.tar.gz: 0a6e92e8493e258c535d5e568daa0af81467425f167e51300334ca98fa1675f6fb7a3b28483fed9e37a5c142b0e91538260d7e60bd7e2203db61c28c5a9a8fb7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Mailo Svetel
|
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,51 @@
|
|
1
|
+
# AdnHashtagPhotos
|
2
|
+
|
3
|
+
This gem creates photo gallery where all photos has one hashtag in common.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'adn_hashtag_photos'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install adn_hashtag_photos
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Let's say we wan't make gallery for hashtag IguanaLister
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'rubygems'
|
27
|
+
require 'bundler/setup'
|
28
|
+
require 'adn_hashtag_photos'
|
29
|
+
|
30
|
+
# Initialize Gallery
|
31
|
+
builder = AdnHashtagPhotos::GalleryBuilder.new 'IguanaLister'
|
32
|
+
|
33
|
+
# Get the photos data
|
34
|
+
builder.photos
|
35
|
+
```
|
36
|
+
|
37
|
+
[Screenshot from example Sinatra app](https://files.app.net/jz4mp52py.png)
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it ( https://github.com/[my-github-username]/adn_hashtag_photos/fork )
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'adn_hashtag_photos/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'adn_hashtag_photos'
|
8
|
+
spec.version = AdnHashtagPhotos::VERSION
|
9
|
+
spec.authors = ['Mailo Svetel']
|
10
|
+
spec.email = ['development@rooland.cz']
|
11
|
+
|
12
|
+
spec.summary = %q{This gem creates photo gallery data where all photos has one hashtag in common.}
|
13
|
+
spec.homepage = 'https://github.com/roolo/adn_hashtag_photos'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.add_runtime_dependency 'rest-client', '~> 1.8.0'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.2.0'
|
30
|
+
spec.add_development_dependency 'webmock', '~> 1.21.0'
|
31
|
+
spec.add_development_dependency 'vcr', '~> 2.9.3'
|
32
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'adn_hashtag_photos'
|
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,11 @@
|
|
1
|
+
require 'adn_hashtag_photos/version'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
|
5
|
+
module AdnHashtagPhotos
|
6
|
+
autoload :GalleryBuilder, 'adn_hashtag_photos/gallery_builder'
|
7
|
+
autoload :PostsLoader, 'adn_hashtag_photos/posts_loader'
|
8
|
+
|
9
|
+
# Modules
|
10
|
+
autoload :Uploader, 'adn_hashtag_photos/uploader'
|
11
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
|
3
|
+
module AdnHashtagPhotos
|
4
|
+
# This class prepares simple objects from ADN posts
|
5
|
+
class GalleryBuilder
|
6
|
+
# @param [String] hashtag Hashtag to filter posts by
|
7
|
+
def initialize hashtag
|
8
|
+
@posts_loader = PostsLoader.new hashtag
|
9
|
+
@hashtag = hashtag
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Array]
|
13
|
+
def photos
|
14
|
+
posts = @posts_loader.posts.reject do |item|
|
15
|
+
item[:annotations].empty? || item[:annotations].any?{|annotation|
|
16
|
+
annotation[:type] == 'net.app.core.language'
|
17
|
+
}
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
posts.inject([]) do |memo, post|
|
22
|
+
memo << {
|
23
|
+
content: post[:html],
|
24
|
+
thumbnail_url: detect_data(post[:annotations], :thumbnail_url)
|
25
|
+
}
|
26
|
+
|
27
|
+
memo
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param [Array] annotations
|
32
|
+
# @param [Symbol] key_name
|
33
|
+
def detect_data annotations, key_name
|
34
|
+
detected_uploader = Uploader.detect_uploader annotations
|
35
|
+
|
36
|
+
begin
|
37
|
+
detected_uploader.send key_name
|
38
|
+
rescue
|
39
|
+
raise annotations.inspect
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
|
3
|
+
module AdnHashtagPhotos
|
4
|
+
# This class loads all posts for given hashtag
|
5
|
+
class PostsLoader
|
6
|
+
# @param [String] hashtag Hashtag to filter posts by
|
7
|
+
def initialize hashtag
|
8
|
+
@posts_data = []
|
9
|
+
@posts_url = 'https://api.app.net/posts/tag/%s?include_annotations=1&count=20'%[
|
10
|
+
hashtag
|
11
|
+
]
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Array]
|
16
|
+
def posts
|
17
|
+
if @posts_data.empty?
|
18
|
+
@posts_data = load_posts
|
19
|
+
end
|
20
|
+
|
21
|
+
@posts_data
|
22
|
+
end
|
23
|
+
|
24
|
+
# This method recursively loads older posts as long as there are any
|
25
|
+
#
|
26
|
+
# @param [Nil, Integer] before_id Id of oldest post we have so far
|
27
|
+
# @param [Array] loaded_posts
|
28
|
+
#
|
29
|
+
# @return [Array]
|
30
|
+
def load_posts before_id = nil, loaded_posts = []
|
31
|
+
posts_url = @posts_url
|
32
|
+
posts_url += '&before_id=' + before_id.to_s if before_id
|
33
|
+
|
34
|
+
the_response = RestClient.get(posts_url)
|
35
|
+
|
36
|
+
this_load = JSON.parse( the_response,
|
37
|
+
symbolize_names: true
|
38
|
+
)
|
39
|
+
|
40
|
+
loaded_posts.push(this_load[:data]).flatten!
|
41
|
+
|
42
|
+
if this_load[:meta][:more]
|
43
|
+
load_posts(
|
44
|
+
this_load[:data].last[:id],
|
45
|
+
loaded_posts
|
46
|
+
)
|
47
|
+
else
|
48
|
+
loaded_posts
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative './uploader/base'
|
2
|
+
require_relative './uploader/climber'
|
3
|
+
require_relative './uploader/core'
|
4
|
+
|
5
|
+
module AdnHashtagPhotos
|
6
|
+
module Uploader
|
7
|
+
# Detects uploader of photo / annotations structure
|
8
|
+
#
|
9
|
+
# @param [Array] annotations
|
10
|
+
# @return [Uploader::Base]
|
11
|
+
def self.detect_uploader annotations
|
12
|
+
[Climber, Core].map do |provider|
|
13
|
+
provider.new annotations if provider.detected? annotations
|
14
|
+
end.compact.first
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module AdnHashtagPhotos
|
2
|
+
module Uploader
|
3
|
+
class Base
|
4
|
+
# @param [Array] annotations
|
5
|
+
def initialize annotations
|
6
|
+
@annotations = annotations
|
7
|
+
end
|
8
|
+
|
9
|
+
# @param [Array] annotations
|
10
|
+
def self.detected?
|
11
|
+
raise NotImplementedError
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module AdnHashtagPhotos
|
2
|
+
module Uploader
|
3
|
+
class Climber < Base
|
4
|
+
# @param [Array] annotations
|
5
|
+
def self.detected? annotations
|
6
|
+
annotations.any?{|item|
|
7
|
+
item[:type] == 'com.alwaysallthetime.climber.poster'
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def thumbnail_url
|
12
|
+
@annotations.detect{|annotation|
|
13
|
+
annotation[:type] == 'com.alwaysallthetime.climber.poster'
|
14
|
+
}[:value][:url]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module AdnHashtagPhotos
|
2
|
+
module Uploader
|
3
|
+
class Core < Base
|
4
|
+
# @param [Array] annotations
|
5
|
+
def self.detected? annotations
|
6
|
+
annotations.any?{|item|
|
7
|
+
item[:type] == 'net.app.core.oembed'
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def thumbnail_url
|
12
|
+
@annotations.detect{|annotation|
|
13
|
+
annotation[:type] == 'net.app.core.oembed'
|
14
|
+
}[:value][:thumbnail_url]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adn_hashtag_photos
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mailo Svetel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.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.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.2.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.21.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.21.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.9.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.9.3
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- development@rooland.cz
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- adn_hashtag_photos.gemspec
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- lib/adn_hashtag_photos.rb
|
115
|
+
- lib/adn_hashtag_photos/gallery_builder.rb
|
116
|
+
- lib/adn_hashtag_photos/posts_loader.rb
|
117
|
+
- lib/adn_hashtag_photos/uploader.rb
|
118
|
+
- lib/adn_hashtag_photos/uploader/base.rb
|
119
|
+
- lib/adn_hashtag_photos/uploader/climber.rb
|
120
|
+
- lib/adn_hashtag_photos/uploader/core.rb
|
121
|
+
- lib/adn_hashtag_photos/version.rb
|
122
|
+
homepage: https://github.com/roolo/adn_hashtag_photos
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata:
|
126
|
+
allowed_push_host: https://rubygems.org
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.4.6
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: This gem creates photo gallery data where all photos has one hashtag in common.
|
147
|
+
test_files: []
|