discourse_imgur 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 717530e929774ab425c96253db8d68b1512ff905
4
+ data.tar.gz: ea69ac8967546d9a8e6ba4fc3097bf661b7a2d82
5
+ SHA512:
6
+ metadata.gz: 117d9a099780d4ea55ced96c794adeba7d2a641c544e4d46cec91f826bfb36ea99354d20dd495922eb60426781e4ad1b8c3aebdfbd2b1382705dfe59c2964758
7
+ data.tar.gz: 9aaa1cd0005ed2e9b1363aadf4566981c18e953696b572cb8c52a83af363ccd39e5cbd50090a3e4f510395704d72714a04b03aae4e89a348155934018b09da0e
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'rails'
5
+ gem 'rspec'
6
+ gem 'mocha'
7
+ end
8
+
9
+ # TODO: We need our own gem server
10
+ gem 'discourse_plugin', path: '../discourse_plugin'
11
+
12
+ # Specify your gem's dependencies in rails_multisite.gemspec
13
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Régis Hanol
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # DiscourseImgur
2
+
3
+ Add support for Imgur storage
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:test) do |spec|
6
+ spec.pattern = 'spec/*_spec.rb'
7
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'discourse_imgur/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "discourse_imgur"
8
+ spec.version = DiscourseImgur::VERSION
9
+ spec.authors = ["Régis Hanol"]
10
+ spec.email = ["regis@hanol.fr"]
11
+ spec.description = %q{Add support for Imgur}
12
+ spec.summary = %q{Add support for Imgur}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,2 @@
1
+ require "discourse_imgur/version"
2
+ require 'discourse_imgur/engine' if defined?(Rails) && (!Rails.env.test?)
@@ -0,0 +1,19 @@
1
+ require 'discourse_imgur/plugin'
2
+
3
+ module DiscourseImgur
4
+
5
+ class Engine < Rails::Engine
6
+
7
+ engine_name 'discourse_imgur'
8
+
9
+ initializer "discourse_imgur.configure_rails_initialization" do |app|
10
+
11
+ app.config.after_initialize do
12
+ DiscoursePluginRegistry.setup(DiscourseImgur::Plugin)
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,31 @@
1
+ require 'rest_client'
2
+
3
+ # /!\ WARNING /!\
4
+ # This plugin has been extracted from the Discourse source code and has not been tested.
5
+ # It really needs some love <3
6
+ # /!\ WARNING /!\
7
+
8
+
9
+ module Imgur
10
+
11
+ def self.store_file(file, image_info, upload_id)
12
+ raise Discourse::SiteSettingMissing.new("imgur_endpoint") if SiteSetting.imgur_endpoint.blank?
13
+ raise Discourse::SiteSettingMissing.new("imgur_client_id") if SiteSetting.imgur_client_id.blank?
14
+
15
+ @imgur_loaded = require 'imgur' unless @imgur_loaded
16
+
17
+ blob = file.read
18
+
19
+ response = RestClient.post(
20
+ SiteSetting.imgur_endpoint,
21
+ { image: Base64.encode64(blob) },
22
+ { 'Authorization' => "ClientID #{SiteSetting.imgur_client_id}" }
23
+ )
24
+
25
+ json = JSON.parse(response.body)['data'] rescue nil
26
+
27
+ return nil if json.blank?
28
+ return json['link']
29
+ end
30
+
31
+ end
@@ -0,0 +1,5 @@
1
+ cs:
2
+ site_settings:
3
+ enable_imgur: "Používat imgur pro ukládání obrázků, nehostovat obrázky lokálně"
4
+ imgur_client_id: "Přístupový klíč 'client ID' pro imgur.com - vyžadováno pro upload obrázků"
5
+ imgur_client_secret: "Přístupový klíč 'client secret' pro imgur.com - vyžadováno pro upload obrázků"
@@ -0,0 +1,5 @@
1
+ de:
2
+ site_settings:
3
+ enable_imgur: "Aktiviere die Imgur API zum Hochladen, so dass Dateien nicht lokal gehostet werden."
4
+ imgur_client_id: "Deine imgur.com Client-ID. Wird benötigt, um Bilder hochzuladen."
5
+ imgur_client_secret: "Dein imgur.com Geheimniss. Wird zur Zeit für das Hochladen der Bilder nicht benötigt, könnte aber in Zukunft benötigt werden."
@@ -0,0 +1,5 @@
1
+ en:
2
+ site_settings:
3
+ enable_imgur: "Enable imgur api for uploading, don't host files locally"
4
+ imgur_client_id: "Your imgur.com client ID, required for image upload to function"
5
+ imgur_client_secret: "Your imgur.com client secret. Not currently required for image upload to function, but may be at some point."
@@ -0,0 +1,5 @@
1
+ es:
2
+ site_settings:
3
+ enable_imgur: "Activar imgur api para subidas, no almacenes ficheros localmente"
4
+ imgur_api_key: "Tu imgur.com api key, requerida para la función de subida de imágenes"
5
+ imgur_endpoint: "End point para la subida de imagenes de imgur.com"
@@ -0,0 +1,5 @@
1
+ fr:
2
+ site_settings:
3
+ enable_imgur: "utiliser l'envoi des images avec l'API imgur, ne pas stocker les fichiers localement"
4
+ imgur_client_id: "Votre ID client imgur.com. Requis pour que l'envoi d'images fonctionne."
5
+ imgur_client_secret: "Votre secret imgur.com. Pas nécessaire pour que l'envoi d'image fonctionne, mais pourrais le devenir."
@@ -0,0 +1,5 @@
1
+ it:
2
+ site_settings:
3
+ enable_imgur: "Utilizza le api imgur per l'upload, non salvare file in locale"
4
+ imgur_client_id: "Your imgur.com client ID, required for image upload to function"
5
+ imgur_client_secret: "Your imgur.com client secret. Not currently required for image upload to function, but may be at some point."
@@ -0,0 +1,5 @@
1
+ nl:
2
+ site_settings:
3
+ enable_imgur: "Gebruik de imgur API voor uploads en sla afbeeldingen niet lokaal op"
4
+ imgur_client_id: "Je imgur.com client ID, nodig om afbeeldingen te kunnen uploaden naar imgur"
5
+ imgur_client_secret: "Je imgur.com client secret. Is nog niet nodig voor het uploaden van afbeeldingen, maar dat zou in de toekomst kunnen veranderen."
@@ -0,0 +1,5 @@
1
+ pt:
2
+ site_settings:
3
+ enable_imgur: "permitir imgur api para uploading, não guardar ficheiros localmente"
4
+ imgur_api_key: "chave para imgur.com api - necessária para image upload"
5
+ imgur_endpoint: "end point para uploading imgur.com images"
@@ -0,0 +1,5 @@
1
+ sv:
2
+ site_settings:
3
+ enable_imgur: "Aktivera imgur.coms API för uppladdning, sparar inte filer lokalt"
4
+ imgur_api_key: "Din API-nyckel för imgur.com, krävs för att bilduppladdningen ska funka"
5
+ imgur_endpoint: "Ändpunkt för uppladdning av bilder till imgur.com"
@@ -0,0 +1,5 @@
1
+ zs_CN:
2
+ site_settings:
3
+ enable_imgur: "启用 Imgur API 来上传文件,不在本地(站点服务器)保存文件"
4
+ imgur_client_id: "你的imgur.com的客户端ID,以便图片上传能正常工作。"
5
+ imgur_client_secret: "你的imgur.com的客户端secret。 目前图片上传功能并不需要这项信息,但是将来的某天可能需要。"
@@ -0,0 +1,5 @@
1
+ zh_TW:
2
+ site_settings:
3
+ enable_imgur: "啓用 Imgur API 來上傳文件,不在本地(站點服務器)保存文件"
4
+ imgur_client_id: "你的imgur.com的客戶端ID,以便圖片上傳能正常工作。"
5
+ imgur_client_secret: "你的imgur.com的客戶端secret。 目前圖片上傳功能並不需要這項信息,但是將來的某天可能需要。"
@@ -0,0 +1,23 @@
1
+ require 'discourse_plugin'
2
+
3
+ # /!\ WARNING /!\
4
+ # This plugin has been extracted from the Discourse source code and has not been tested.
5
+ # It really needs some love <3
6
+ # /!\ WARNING /!\
7
+
8
+ module DiscourseImgur
9
+
10
+ class Plugin < DiscoursePlugin
11
+
12
+ def setup
13
+ # add_setting(:enable_imgur, false)
14
+ # add_setting(:imgur_client_id, '')
15
+ # add_setting(:imgur_endpoint, "https://api.imgur.com/3/image.json")
16
+
17
+ # TODO: Mix the following logic in Upload#store_file
18
+ # return Imgur.store_file(file, image_info, upload_id) if SiteSetting.enable_imgur?
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ module DiscourseImgur
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'discourse_imgur/imgur'
3
+
4
+ # /!\ WARNING /!\
5
+ # This plugin has been extracted from the Discourse source code and has not been tested.
6
+ # It really needs some love <3
7
+ # /!\ WARNING /!\
8
+
9
+ describe Imgur do
10
+
11
+ describe "store_file" do
12
+
13
+ let(:file) { Rails.root.join('app', 'assets', 'images', 'logo.png') }
14
+ let(:image_info) { FastImage.new(file) }
15
+ let(:params) { [SiteSetting.imgur_endpoint, { image: Base64.encode64(file.read) }, { 'Authorization' => "ClientID #{SiteSetting.imgur_client_id}" }] }
16
+
17
+ before(:each) do
18
+ SiteSetting.stubs(:imgur_endpoint).returns("imgur_endpoint")
19
+ SiteSetting.stubs(:imgur_client_id).returns("imgur_client_id")
20
+ end
21
+
22
+ it 'returns the url of the Imgur upload if successful' do
23
+ json = {
24
+ data: {
25
+ id: 'fake',
26
+ link: 'http://imgur.com/fake.png',
27
+ deletehash: 'a3kaoad30'
28
+ },
29
+ success: true,
30
+ status: 200
31
+ }.to_json
32
+
33
+ response = mock
34
+ response.expects(:body).returns(json)
35
+ RestClient.expects(:post).with(*params).returns(response)
36
+
37
+ Imgur.store_file(file, image_info, 1).should == 'http://imgur.com/fake.png'
38
+ end
39
+
40
+ it 'returns nil if the request fails' do
41
+ json = {
42
+ success: false,
43
+ status: 400
44
+ }.to_json
45
+
46
+ response = mock
47
+ response.expects(:body).returns(json)
48
+ RestClient.expects(:post).with(*params).returns(response)
49
+
50
+ Imgur.store_file(file, image_info, 1).should be_nil
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'rails'
3
+
4
+ ENV["RAILS_ENV"] ||= 'test'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ config.mock_framework = :mocha
9
+ config.color_enabled = true
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: discourse_imgur
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Régis Hanol
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Add support for Imgur
42
+ email:
43
+ - regis@hanol.fr
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - LICENSE.txt
50
+ - README.md
51
+ - Rakefile
52
+ - discourse_imgur.gemspec
53
+ - lib/discourse_imgur.rb
54
+ - lib/discourse_imgur/engine.rb
55
+ - lib/discourse_imgur/imgur.rb
56
+ - lib/discourse_imgur/locale/server.cs.yml
57
+ - lib/discourse_imgur/locale/server.de.yml
58
+ - lib/discourse_imgur/locale/server.en.yml
59
+ - lib/discourse_imgur/locale/server.es.yml
60
+ - lib/discourse_imgur/locale/server.fr.yml
61
+ - lib/discourse_imgur/locale/server.it.yml
62
+ - lib/discourse_imgur/locale/server.nl.yml
63
+ - lib/discourse_imgur/locale/server.pt.yml
64
+ - lib/discourse_imgur/locale/server.sv.yml
65
+ - lib/discourse_imgur/locale/server.zh_CN.yml
66
+ - lib/discourse_imgur/locale/server.zh_TW.yml
67
+ - lib/discourse_imgur/plugin.rb
68
+ - lib/discourse_imgur/version.rb
69
+ - spec/imgur_spec.rb
70
+ - spec/spec_helper.rb
71
+ homepage: ''
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.0
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Add support for Imgur
95
+ test_files:
96
+ - spec/imgur_spec.rb
97
+ - spec/spec_helper.rb
98
+ has_rdoc: