imgurapi 3.1.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cff8c35e8361a8f17f30d62cf865c9dfc12dbbc2
4
- data.tar.gz: a6612b4296b9ec7a33418c382cd80684cd78bab9
3
+ metadata.gz: dc8dabbb161b89c8c24be36fe0ce9229bbf95947
4
+ data.tar.gz: 8f9d4b79aac9514f49e6d3c9ff29a0a2e519091f
5
5
  SHA512:
6
- metadata.gz: e89da47ea0da8ba5c26db3a2adf7403184325dbd8dbaa9ef22050a05b590d4920c6766650e23a76d373bd48f5e5057d0e95c797fc6a7d5eea33abb832df35a83
7
- data.tar.gz: c98fcd1d38fe797f5bb0f63f8a9b8c1834b81e5e919751caf24c03f9d1e8ce4549f67d933beea88aec40c779d75fdd9e13d98e15852e8900efd48f782ca22480
6
+ metadata.gz: 73c32e9b7fda8bd7b13c9601ffa455c9fe135b11644d1f775a7a9c812c45f49856e0106c4c932a1c044906215a68458ab97753e683b11ad1ca93b40951004b80
7
+ data.tar.gz: ffbb1013112ac0e84f3f588101a07d0efe08ddef304be8f7cc8426f2be6049b9045cd5c14fd5947a357ec5e1001a509b01142d73c847b2767f585cef1d08a613
@@ -1,16 +1,22 @@
1
1
  module Imgurapi
2
2
  class Image < Base
3
3
 
4
- IMAGE_URL = 'http://i.imgur.com/'
4
+ IMGUR_HOST = 'i.imgur.com'
5
5
  IMAGE_EXTENSION = 'jpg' # jpg is the default extension for every Imgur image
6
6
 
7
- def link
8
- @link ||= "#{IMAGE_URL}#{id}.#{IMAGE_EXTENSION}"
7
+ def link(use_ssl = false)
8
+ protocol = if use_ssl
9
+ 'https://'
10
+ else
11
+ 'http://'
12
+ end
13
+
14
+ "#{protocol}#{IMGUR_HOST}/#{id}.#{IMAGE_EXTENSION}"
9
15
  end
10
16
 
11
17
  # Provides the download URL in case you know a valid imgur hash and don't want to make a network trip with .find
12
18
  # Just in case you don't need the full Imgurapi::Image object
13
- def url(size = nil)
19
+ def url(size: nil, use_ssl: false)
14
20
  size = case size
15
21
  when :small_square, :small, :s
16
22
  's'
@@ -20,7 +26,7 @@ module Imgurapi
20
26
  ''
21
27
  end
22
28
 
23
- splitted_link = link.split('.')
29
+ splitted_link = link(use_ssl).split('.')
24
30
  splitted_link[splitted_link.size - 2] << size
25
31
  splitted_link.join '.'
26
32
  end
@@ -12,6 +12,7 @@ module Imgurapi
12
12
  @client_secret = options[:client_secret]
13
13
  @access_token = options[:access_token]
14
14
  @refresh_token = options[:refresh_token]
15
+ @use_ssl = !!options[:use_ssl]
15
16
  end
16
17
 
17
18
  # Singleton initializer to allow access_token reuse
@@ -25,6 +26,10 @@ module Imgurapi
25
26
  end
26
27
  end
27
28
 
29
+ def use_ssl?
30
+ @use_ssl
31
+ end
32
+
28
33
  def access_token=(access_token)
29
34
  @access_token = access_token
30
35
 
@@ -1,5 +1,5 @@
1
1
  module Imgurapi
2
2
 
3
- VERSION = '3.1.0'
3
+ VERSION = '3.2.1'
4
4
 
5
5
  end
@@ -14,8 +14,10 @@ describe Imgurapi::Image do
14
14
  image = Imgurapi::Image.new(id: 'hash')
15
15
 
16
16
  expect(image.url).to eq "http://i.imgur.com/hash.jpg"
17
- expect(image.url(:random_size)).to eq "http://i.imgur.com/hash.jpg"
18
- expect(image.url(:small_square)).to eq "http://i.imgur.com/hashs.jpg"
19
- expect(image.url(:large_thumbnail)).to eq "http://i.imgur.com/hashl.jpg"
17
+ expect(image.url(size: :random_size)).to eq "http://i.imgur.com/hash.jpg"
18
+ expect(image.url(size: :small_square)).to eq "http://i.imgur.com/hashs.jpg"
19
+ expect(image.url(size: :large_thumbnail, use_ssl: false)).to eq "http://i.imgur.com/hashl.jpg"
20
+ expect(image.url(use_ssl: true)).to eq "https://i.imgur.com/hash.jpg"
21
+ expect(image.url(size: :large_thumbnail, use_ssl: true)).to eq "https://i.imgur.com/hashl.jpg"
20
22
  end
21
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imgurapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Cruz Horts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-10 00:00:00.000000000 Z
11
+ date: 2017-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday