imgurapi 2.0.2 → 3.0.0

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: c69afc57eef5284296e36c8b5836e69011b015fc
4
- data.tar.gz: 7fb7e32ee6c569746ef56d29f80dadaead0ea1e1
3
+ metadata.gz: 6d77b29707bea1234b6841d315a016b0b16f955d
4
+ data.tar.gz: d6b760ffe9a4619495f1856ded2260c14a6309ac
5
5
  SHA512:
6
- metadata.gz: e6977d3bb8ef0296b2ff178507b6f669fb0914dd47948bc6c95d9a7a590622fa4ec7ab297d4c8b2eca0604f73255b86c38e232e0d945560028a8ead62870443b
7
- data.tar.gz: caed10efce8328a7ba2109ead917bb18af4045b503cbcaf45f06dcf68559e5130d12708039fe5c7604511c5deb8c6c926f68ee16485da15e76f817f1dda0508b
6
+ metadata.gz: 6b234a644136409006effbc608543020632d2a9065f208f284fd2d5199f98829b47186470ed920c80b0ef95e59063e538e7c6f5083bd67916dff509befb1ebb7
7
+ data.tar.gz: c6b19d8891c344136ad0de716e39efb4310933dfd94cde38265b7e557227bb8227d64d7fcab81fac0cf49c5fa3ef3f21c4fe1109c87391b6a566e7d9e8403a7b
data/README.md CHANGED
@@ -47,13 +47,13 @@ refresh_token: REFRESH_TOKEN
47
47
 
48
48
  Create a session object to communicate to Imgur.
49
49
  ```ruby
50
- imgur_session = Imgur::Session.new(client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET', refresh_token: 'REFRESH_TOKEN')
50
+ imgur_session = Imgurapi::Session.new(client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET', refresh_token: 'REFRESH_TOKEN')
51
51
  ```
52
52
 
53
53
  Your account:
54
54
  ```ruby
55
55
  account = imgur_session.account.account
56
- => #<Imgur::Account:0x007fd399b6b678 @id=123, @url="my_account", @bio=nil, @reputation=7, @created=1352279501, @pro_expiration=false>
56
+ => #<Imgurapi::Account:0x007fd399b6b678 @id=123, @url="my_account", @bio=nil, @reputation=7, @created=1352279501, @pro_expiration=false>
57
57
  ```
58
58
 
59
59
  How many images you have:
@@ -66,7 +66,7 @@ Upload your first image. Argument can be either a String or a File:
66
66
  image = imgur_session.image.image.upload('portrait.jpg')
67
67
  ```
68
68
 
69
- image is now an instance of Imgur::Image, a convenient way to manage all the attributes of your image (at least more convenient than a multilevel dictionary):
69
+ image is now an instance of Imgurapi::Image, a convenient way to manage all the attributes of your image (at least more convenient than a multilevel dictionary):
70
70
  ```ruby
71
71
  name = nil
72
72
  title = nil
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
+ #!/usr/bin/env rake
1
2
  require 'bundler/gem_tasks'
2
3
 
3
- load 'imgur/tasks/tasks.rake'
4
+ Bundler.setup
4
5
 
5
- require 'rspec/core/rake_task'
6
- RSpec::Core::RakeTask.new
7
- task :default => :spec
6
+ load 'imgurapi/tasks/tasks.rake'
@@ -1,16 +1,16 @@
1
- module Imgur
1
+ module Imgurapi
2
2
  module Api
3
3
  class Account < Base
4
4
 
5
5
  # https://api.imgur.com/endpoints/account#account
6
6
  def account
7
- Imgur::Account.new communication.call(:get, 'account/me')
7
+ Imgurapi::Account.new communication.call(:get, 'account/me')
8
8
  end
9
9
 
10
10
  # https://api.imgur.com/endpoints/account#images
11
11
  def images(page = 0)
12
12
  communication.call(:get, "account/me/images/#{page}").map do |image|
13
- Imgur::Image.new image
13
+ Imgurapi::Image.new image
14
14
  end
15
15
  end
16
16
 
@@ -1,4 +1,4 @@
1
- module Imgur
1
+ module Imgurapi
2
2
  module Api
3
3
  Base = Struct.new(:session) do
4
4
 
@@ -1,4 +1,4 @@
1
- module Imgur
1
+ module Imgurapi
2
2
  module Api
3
3
  class Image < Base
4
4
 
@@ -6,7 +6,7 @@ module Imgur
6
6
  def image(id)
7
7
  raise 'Please provide a valid image identificator' if id.nil? or !id.kind_of? String or id == '' or !!(id =~ /[^\w]/)
8
8
 
9
- Imgur::Image.new communication.call(:get, "image/#{id}")
9
+ Imgurapi::Image.new communication.call(:get, "image/#{id}")
10
10
  end
11
11
 
12
12
  # https://api.imgur.com/endpoints/image#image-upload
@@ -19,12 +19,12 @@ module Imgur
19
19
  raise 'Must provide a File or file path'
20
20
  end
21
21
 
22
- Imgur::Image.new communication.call(:post, 'image', image: Base64.encode64(file.read))
22
+ Imgurapi::Image.new communication.call(:post, 'image', image: Base64.encode64(file.read))
23
23
  end
24
24
 
25
25
  # https://api.imgur.com/endpoints/image#image-delete
26
26
  def image_delete(id)
27
- if id.kind_of? Imgur::Image
27
+ if id.kind_of? Imgurapi::Image
28
28
  id = id.id
29
29
  end
30
30
 
@@ -1,4 +1,4 @@
1
- module Imgur
1
+ module Imgurapi
2
2
  Communication = Struct.new(:session) do
3
3
 
4
4
  API_VERSION = 3
File without changes
File without changes
File without changes
@@ -1,3 +1,3 @@
1
- module Imgur
1
+ module Imgurapi
2
2
  class Account < Base; end
3
3
  end
@@ -1,4 +1,4 @@
1
- module Imgur
1
+ module Imgurapi
2
2
  class Base
3
3
  def initialize(hsh = {})
4
4
  hsh.each do |k, v|
@@ -1,4 +1,4 @@
1
- module Imgur
1
+ module Imgurapi
2
2
  class Image < Base
3
3
 
4
4
  IMAGE_URL = 'http://i.imgur.com/'
@@ -9,7 +9,7 @@ module Imgur
9
9
  end
10
10
 
11
11
  # Provides the download URL in case you know a valid imgur hash and don't want to make a network trip with .find
12
- # Just in case you don't need the full Imgur::Image object
12
+ # Just in case you don't need the full Imgurapi::Image object
13
13
  def url(size)
14
14
  size = case size
15
15
  when :small_square, :small, :s
@@ -1,4 +1,4 @@
1
- module Imgur
1
+ module Imgurapi
2
2
  class Session
3
3
  HOST = 'https://api.imgur.com'
4
4
 
@@ -21,7 +21,7 @@ module Imgur
21
21
 
22
22
  %w(Account Image).each do |clazz|
23
23
  define_method clazz.downcase do
24
- Imgur::Api.const_get(clazz).new(self)
24
+ Imgurapi::Api.const_get(clazz).new(self)
25
25
  end
26
26
  end
27
27
 
@@ -1,8 +1,8 @@
1
- module Imgur
1
+ module Imgurapi
2
2
  module Tasks
3
3
  class Railtie < Rails::Railtie
4
4
  rake_tasks do
5
- load 'imgur/tasks/tasks.rake'
5
+ load 'imgurapi/tasks/tasks.rake'
6
6
  end
7
7
  end
8
8
  end
@@ -0,0 +1,37 @@
1
+ require 'imgurapi/session'
2
+
3
+ module Imgurapi
4
+
5
+ module Rake
6
+ extend self
7
+
8
+ AUTHORIZE_ENDPOINT = '/oauth2/authorize'
9
+ TOKEN_ENDPOINT = '/oauth2/token'
10
+
11
+ def authorize(client_id, client_secret)
12
+ puts "\nVisit this URL: #{Imgurapi::Session::HOST}#{AUTHORIZE_ENDPOINT}?client_id=#{client_id}&response_type=pin"
13
+ print 'And after you approved the authorization please enter your verification code: '
14
+
15
+ pin = STDIN.gets.strip
16
+
17
+ begin
18
+ response = Faraday.new(Imgurapi::Session::HOST).post(TOKEN_ENDPOINT, pin: pin, client_id: client_id, client_secret: client_secret, grant_type: 'pin')
19
+
20
+ raise "HTTP #{response.status}" if response.status != 200
21
+ credentials = JSON.parse response.body
22
+ rescue => e
23
+ puts "Authorization failed: #{e.message}\nPlease try again."
24
+ exit
25
+ end
26
+
27
+ puts <<-MESSAGE
28
+
29
+ Authorization was successful. Use these credentials to initialize the library:
30
+
31
+ access_token: #{credentials['access_token']}
32
+ refresh_secret: #{credentials['refresh_token']}
33
+
34
+ MESSAGE
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,4 @@
1
- require 'imgur' # We need HOST to be available
2
- require 'imgur/tasks/rake'
1
+ require 'imgurapi/tasks/rake'
3
2
 
4
3
  namespace :imgur do
5
4
  desc 'Obtain your Imgur tokens'
@@ -9,6 +8,6 @@ namespace :imgur do
9
8
  exit
10
9
  end
11
10
 
12
- Imgur::Rake.authorize(ENV['CLIENT_ID'], ENV['CLIENT_SECRET'])
11
+ Imgurapi::Rake.authorize(ENV['CLIENT_ID'], ENV['CLIENT_SECRET'])
13
12
  end
14
13
  end
@@ -0,0 +1,5 @@
1
+ module Imgurapi
2
+
3
+ VERSION = '3.0.0'
4
+
5
+ end
data/lib/imgurapi.rb ADDED
@@ -0,0 +1,23 @@
1
+ # Gem dependencies
2
+ require 'faraday'
3
+ require 'json'
4
+ require 'base64'
5
+
6
+ # Some nice extensions to base classes
7
+ require 'imgurapi/extensions/array'
8
+ require 'imgurapi/extensions/hash'
9
+ require 'imgurapi/extensions/string'
10
+
11
+ # This gem real code
12
+ require 'imgurapi/version'
13
+ require 'imgurapi/api/base'
14
+ require 'imgurapi/api/account'
15
+ require 'imgurapi/api/image'
16
+ require 'imgurapi/communication'
17
+ require 'imgurapi/session'
18
+ require 'imgurapi/models/base'
19
+ require 'imgurapi/models/account'
20
+ require 'imgurapi/models/image'
21
+
22
+ # Rails integration
23
+ require 'imgurapi/tasks/railtie' if defined? Rails
@@ -1,20 +1,20 @@
1
1
  require_relative '../spec_helper'
2
2
  require 'imgur'
3
3
 
4
- describe Imgur::Session do
4
+ describe Imgurapiapi::Session do
5
5
 
6
6
  context 'incorrect credentials' do
7
- it { expect { Imgur::Session.new }.to raise_error }
8
- it { expect { Imgur::Session.new(random_key: nil) }.to raise_error }
9
- it { expect { Imgur::Session.new(client_id: nil, random_key: nil) }.to raise_error }
10
- it { expect { Imgur::Session.new({}) }.to raise_error }
7
+ it { expect { Imgurapi::Session.new }.to raise_error }
8
+ it { expect { Imgurapi::Session.new(random_key: nil) }.to raise_error }
9
+ it { expect { Imgurapi::Session.new(client_id: nil, random_key: nil) }.to raise_error }
10
+ it { expect { Imgurapi::Session.new({}) }.to raise_error }
11
11
  end
12
12
 
13
13
  context 'correct credentials' do
14
14
  it do
15
15
  expect(
16
- Imgur::Session.new(client_id: 'ID', client_secret: 'SECRET', refresh_token: 'TOKEN')
17
- ).to be_an_instance_of Imgur::Session
16
+ Imgurapi::Session.new(client_id: 'ID', client_secret: 'SECRET', refresh_token: 'TOKEN')
17
+ ).to be_an_instance_of Imgurapi::Session
18
18
  end
19
19
  end
20
20
  end
data/spec/imgur_spec.rb CHANGED
@@ -1,28 +1,28 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
  require 'imgur'
3
3
 
4
- describe Imgur do
4
+ describe Imgurapi do
5
5
 
6
6
  describe 'placeholder classes' do
7
7
 
8
8
  it 'should create an Image with the fields provided' do
9
- image = Imgur::Image.new
10
- image.should be_an_instance_of Imgur::Image
9
+ image = Imgurapi::Image.new
10
+ image.should be_an_instance_of Imgurapi::Image
11
11
 
12
12
  fields = {:a => 1, :b => 2}
13
- image = Imgur::Image.new(fields)
14
- image.should be_an_instance_of Imgur::Image
13
+ image = Imgurapi::Image.new(fields)
14
+ image.should be_an_instance_of Imgurapi::Image
15
15
  image.a.should eq(1)
16
16
  image.b.should eq(2)
17
17
  end
18
18
 
19
19
  it 'should create a Link with the fields provided' do
20
- links = Imgur::Links.new
21
- links.should be_an_instance_of Imgur::Links
20
+ links = Imgurapi::Links.new
21
+ links.should be_an_instance_of Imgurapi::Links
22
22
 
23
23
  fields = {:a => 1, :b => 2}
24
- links = Imgur::Links.new(fields)
25
- links.should be_an_instance_of Imgur::Links
24
+ links = Imgurapi::Links.new(fields)
25
+ links.should be_an_instance_of Imgurapi::Links
26
26
  links.a.should eq(1)
27
27
  links.b.should eq(2)
28
28
  end
@@ -48,7 +48,7 @@ describe Imgur do
48
48
 
49
49
  before(:all) do
50
50
  credentials = read_credentials_file
51
- @session = Imgur::Session.new(credentials)
51
+ @session = Imgurapi::Session.new(credentials)
52
52
  end
53
53
 
54
54
  it 'should parse_message' do
@@ -84,8 +84,8 @@ describe Imgur do
84
84
  @session.send(:compose_image, {:images => {}}).should eq(nil)
85
85
 
86
86
  from_hash = {:images => {:image => {}, :links => {}}}
87
- @session.send(:compose_image, from_hash).should be_an_instance_of Imgur::Image
88
- @session.send(:compose_image, from_hash).links.should be_an_instance_of Imgur::Links
87
+ @session.send(:compose_image, from_hash).should be_an_instance_of Imgurapi::Image
88
+ @session.send(:compose_image, from_hash).links.should be_an_instance_of Imgurapi::Links
89
89
  end
90
90
 
91
91
  end
@@ -94,7 +94,7 @@ describe Imgur do
94
94
 
95
95
  before(:all) do
96
96
  credentials = read_credentials_file
97
- @session = Imgur::Session.new(credentials)
97
+ @session = Imgurapi::Session.new(credentials)
98
98
  @upload_path, @upload_file = my_sample_image
99
99
  end
100
100
 
@@ -111,10 +111,10 @@ describe Imgur do
111
111
  expect { @session.upload(:not_the_expected_object) }.to raise_error
112
112
 
113
113
  @@image_by_path = @session.upload(@upload_path) #FIXME I know this is horrible, but I need to share the same image between tests http://brentlavelle.wordpress.com/2011/04/04/rspec-and-instance-variables/
114
- @@image_by_path.should be_an_instance_of Imgur::Image
114
+ @@image_by_path.should be_an_instance_of Imgurapi::Image
115
115
 
116
116
  @@image_by_file = @session.upload(@upload_file)
117
- @@image_by_file.should be_an_instance_of Imgur::Image
117
+ @@image_by_file.should be_an_instance_of Imgurapi::Image
118
118
  end
119
119
 
120
120
  it 'should retrieve the image' do
@@ -125,7 +125,7 @@ describe Imgur do
125
125
  image.should be_nil
126
126
 
127
127
  image = @session.find(@@image_by_path.hash)
128
- image.should be_an_instance_of Imgur::Image
128
+ image.should be_an_instance_of Imgurapi::Image
129
129
 
130
130
  image.hash.should eq(@@image_by_path.hash)
131
131
  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: 2.0.2
4
+ version: 3.0.0
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: 2015-07-06 00:00:00.000000000 Z
11
+ date: 2015-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -61,22 +61,22 @@ files:
61
61
  - LICENSE.txt
62
62
  - README.md
63
63
  - Rakefile
64
- - lib/imgur.rb
65
- - lib/imgur/api/account.rb
66
- - lib/imgur/api/base.rb
67
- - lib/imgur/api/image.rb
68
- - lib/imgur/communication.rb
69
- - lib/imgur/extensions/array.rb
70
- - lib/imgur/extensions/hash.rb
71
- - lib/imgur/extensions/string.rb
72
- - lib/imgur/models/account.rb
73
- - lib/imgur/models/base.rb
74
- - lib/imgur/models/image.rb
75
- - lib/imgur/session.rb
76
- - lib/imgur/tasks/railtie.rb
77
- - lib/imgur/tasks/rake.rb
78
- - lib/imgur/tasks/tasks.rake
79
- - lib/imgur/version.rb
64
+ - lib/imgurapi.rb
65
+ - lib/imgurapi/api/account.rb
66
+ - lib/imgurapi/api/base.rb
67
+ - lib/imgurapi/api/image.rb
68
+ - lib/imgurapi/communication.rb
69
+ - lib/imgurapi/extensions/array.rb
70
+ - lib/imgurapi/extensions/hash.rb
71
+ - lib/imgurapi/extensions/string.rb
72
+ - lib/imgurapi/models/account.rb
73
+ - lib/imgurapi/models/base.rb
74
+ - lib/imgurapi/models/image.rb
75
+ - lib/imgurapi/session.rb
76
+ - lib/imgurapi/tasks/railtie.rb
77
+ - lib/imgurapi/tasks/rake.rb
78
+ - lib/imgurapi/tasks/tasks.rake
79
+ - lib/imgurapi/version.rb
80
80
  - spec/imgur/session_spec.rb
81
81
  - spec/imgur_spec.rb
82
82
  - spec/spec_helper.rb
@@ -1,36 +0,0 @@
1
- module Imgur
2
-
3
- module Rake
4
- extend self
5
-
6
- AUTHORIZE_ENDPOINT = '/oauth2/authorize'
7
- TOKEN_ENDPOINT = '/oauth2/token'
8
-
9
- def authorize(client_id, client_secret)
10
- connection = Faraday.new(HOST)
11
-
12
- puts "\nVisit this URL: #{HOST}#{AUTHORIZE_ENDPOINT}?client_id=#{client_id}&response_type=pin"
13
- print 'And after you approved the authorization please enter your verification code: '
14
-
15
- pin = STDIN.gets.strip
16
-
17
- begin
18
- response = JSON.parse connection.post(TOKEN_ENDPOINT, pin: pin, client_id: client_id, client_secret: client_secret, grant_type: 'pin').body
19
- rescue
20
- puts "Authorization failed.\nPlease try again."
21
- exit
22
- end
23
-
24
- puts <<-MESSAGE
25
-
26
- Authorization was successful. Use these credentials to initialize the library:
27
-
28
- access_token: #{response['access_token']}
29
- refresh_secret: #{response['refresh_token']}
30
-
31
- MESSAGE
32
- end
33
-
34
- end
35
-
36
- end
data/lib/imgur/version.rb DELETED
@@ -1,5 +0,0 @@
1
- module Imgur
2
-
3
- VERSION = '2.0.2'
4
-
5
- end
data/lib/imgur.rb DELETED
@@ -1,20 +0,0 @@
1
- # Gem dependencies
2
- require 'faraday'
3
- require 'json'
4
- require 'base64'
5
-
6
- # Some nice extensions to base classes
7
- require 'imgur/extensions/array'
8
- require 'imgur/extensions/hash'
9
- require 'imgur/extensions/string'
10
-
11
- # This gem real code
12
- require 'imgur/version'
13
- require 'imgur/api/base'
14
- require 'imgur/api/account'
15
- require 'imgur/api/image'
16
- require 'imgur/communication'
17
- require 'imgur/session'
18
- require 'imgur/models/base'
19
- require 'imgur/models/account'
20
- require 'imgur/models/image'