hexapic 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 950bf10786d34787e3ff6792af617189d0488808
4
- data.tar.gz: 8bb93e2566e63621992045cd501821b7a8824cc2
3
+ metadata.gz: b8c9ad56c1964298f5438c95706490aac86ec9a5
4
+ data.tar.gz: 788ab3ddb258ecec61d5b4c50afa9ff5f67bde34
5
5
  SHA512:
6
- metadata.gz: 0de2939b6620e798aaa9148af6eac158ebd1b5e3817c7aca2c8ea5e4b175f4fbfc1726aea784dfd1a319722cafd68006e7df80a4a6b10af4ca497290b4f14cc5
7
- data.tar.gz: 9fdd954cae4370f51ee614be2589631a8641f1cb4d05a10d2b36440d957918a45a75b3a9b6db8be62563659331f4dba619267339e36f5d0ac0e0e74523ef1381
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
- puts e.message
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 'instagram', '~> 1.1'
28
+ spec.add_runtime_dependency 'faraday', '~> 0.9'
29
29
  spec.add_runtime_dependency 'mini_magick', '~> 4.0'
30
30
  end
@@ -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
@@ -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.client(client_id: CLIENT_ID)
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 = URI.encode(tag.split(',').first)
26
+ tag.delete(',')
29
27
  puts "Getting last images by tag #{tag}"
30
- pics = @instagram.tag_recent_media(tag).sample(COUNT).map do |r|
31
- url = r.images.standard_resolution.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
 
@@ -1,3 +1,3 @@
1
1
  module Hexapic
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/hexapic.rb CHANGED
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift File.expand_path('.')
2
2
 
3
3
  require 'hexapic/version'
4
4
  require 'hexapic/wallpaper_setter'
5
+ require 'hexapic/api'
5
6
  require 'hexapic/repository'
6
7
  require 'hexapic/downloader'
7
8
  require 'hexapic/collage'
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.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: instagram
84
+ name: faraday
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.1'
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: '1.1'
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