hexapic 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/hexapic +4 -4
- data/hexapic.gemspec +1 -1
- data/lib/hexapic/api.rb +34 -0
- data/lib/hexapic/repository.rb +4 -11
- data/lib/hexapic/version.rb +1 -1
- data/lib/hexapic.rb +1 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8c9ad56c1964298f5438c95706490aac86ec9a5
|
4
|
+
data.tar.gz: 788ab3ddb258ecec61d5b4c50afa9ff5f67bde34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 930acfb7a2ada5168f13bb92dadc64756bdda060f9278c2cdcfb6fbb51bc2e0f3c246a62286028d61fbfb07cb5a29521ca7c8d920595a68d8ae24048ec664c16
|
7
|
+
data.tar.gz: 434a5f583f8c9b035f3a7bd44ba3b328d74cb01492a9d6a1121074081a61fb81182a4b334c62339b4b58d7140d7303a8a393a1c2db6464787eb1b09cfa324054
|
data/bin/hexapic
CHANGED
@@ -50,11 +50,11 @@ Choice.options do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
if Choice.choices[:tags]
|
53
|
-
begin
|
53
|
+
#begin
|
54
54
|
set_wallpaper
|
55
|
-
rescue Exception => e
|
56
|
-
|
57
|
-
end
|
55
|
+
#rescue Exception => e
|
56
|
+
# puts e.message
|
57
|
+
#end
|
58
58
|
elsif Choice.choices[:version]
|
59
59
|
print_version
|
60
60
|
else
|
data/hexapic.gemspec
CHANGED
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'minitest', '~> 5.4'
|
26
26
|
spec.add_runtime_dependency 'choice', '~> 0.1'
|
27
27
|
spec.add_runtime_dependency 'flickr.rb', '~> 1.2'
|
28
|
-
spec.add_runtime_dependency '
|
28
|
+
spec.add_runtime_dependency 'faraday', '~> 0.9'
|
29
29
|
spec.add_runtime_dependency 'mini_magick', '~> 4.0'
|
30
30
|
end
|
data/lib/hexapic/api.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Hexapic
|
6
|
+
module API
|
7
|
+
class Instagram
|
8
|
+
INSTAGRAM_API_URL = 'https://api.instagram.com/v1/'
|
9
|
+
|
10
|
+
def initialize(client_id)
|
11
|
+
@client_id = client_id
|
12
|
+
@conn = Faraday.new(url: INSTAGRAM_API_URL) do |faraday|
|
13
|
+
faraday.request :url_encoded
|
14
|
+
faraday.adapter :net_http
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def search(tag, count = 20)
|
19
|
+
tag = URI.encode(tag)
|
20
|
+
res = @conn.get("tags/#{tag}/media/recent",{client_id: @client_id, count: count})
|
21
|
+
data = JSON.parse(res.body)
|
22
|
+
|
23
|
+
data['data'].map do |img|
|
24
|
+
{
|
25
|
+
id: img['id'],
|
26
|
+
likes: img['likes']['count'],
|
27
|
+
link: img['link'],
|
28
|
+
url: img['images']['standard_resolution']['url']
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/hexapic/repository.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'flickr'
|
2
|
-
require 'instagram'
|
3
|
-
require 'uri'
|
4
2
|
module Hexapic
|
5
3
|
module Repository
|
6
4
|
COUNT = 6
|
@@ -20,22 +18,19 @@ module Hexapic
|
|
20
18
|
CLIENT_ID = '417c3ee8c9544530b83aa1c24de2abb3'
|
21
19
|
|
22
20
|
def initialize
|
23
|
-
@instagram = Instagram.
|
21
|
+
@instagram = API::Instagram.new(CLIENT_ID)
|
24
22
|
puts 'Using Instagram'
|
25
23
|
end
|
26
24
|
|
27
25
|
def find_pictures(tag)
|
28
|
-
tag
|
26
|
+
tag.delete(',')
|
29
27
|
puts "Getting last images by tag #{tag}"
|
30
|
-
pics = @instagram.
|
31
|
-
url
|
32
|
-
Picture.new(url, url, url.split('/').last)
|
28
|
+
pics = @instagram.search(tag).sample(COUNT).map do |r|
|
29
|
+
Picture.new(r[:url], r[:link], r[:id])
|
33
30
|
end
|
34
31
|
|
35
32
|
raise ImagesNotFound.new("Found only #{pics.size} images. Need #{COUNT}.") if pics.size < COUNT
|
36
33
|
pics
|
37
|
-
rescue Exception => e
|
38
|
-
raise NoInternet.new(e.message)
|
39
34
|
end
|
40
35
|
end
|
41
36
|
|
@@ -61,8 +56,6 @@ module Hexapic
|
|
61
56
|
|
62
57
|
raise ImagesNotFound.new("Found only #{pics.size} images. Need #{COUNT}.") if pics.size < COUNT
|
63
58
|
pics
|
64
|
-
rescue Exception => e
|
65
|
-
raise NoInternet.new(e.message)
|
66
59
|
end
|
67
60
|
end
|
68
61
|
|
data/lib/hexapic/version.rb
CHANGED
data/lib/hexapic.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hexapic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Siganov
|
@@ -81,19 +81,19 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.2'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: faraday
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '0.9'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '0.9'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: mini_magick
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- bin/hexapic
|
127
127
|
- hexapic.gemspec
|
128
128
|
- lib/hexapic.rb
|
129
|
+
- lib/hexapic/api.rb
|
129
130
|
- lib/hexapic/collage.rb
|
130
131
|
- lib/hexapic/desktop_environment.rb
|
131
132
|
- lib/hexapic/downloader.rb
|