filmot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/filmot +95 -0
  2. metadata +48 -0
data/bin/filmot ADDED
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'highline/import'
4
+ require 'fileutils'
5
+ require 'rubygems'
6
+ require 'etc'
7
+ require 'rest-client'
8
+ require 'json'
9
+
10
+ HOME_DIRECTORY = Etc.getpwuid.dir
11
+ CONFIG_FILE_PATH = "#{HOME_DIRECTORY}/.imgur"
12
+
13
+ def main
14
+ if check_if_file_exists(CONFIG_FILE_PATH) == false
15
+ ask_for_api_key
16
+ create_new_config_file
17
+ end
18
+ check_number_of_arguments
19
+ check_if_file_is_an_image @file_to_be_uploaded.to_s
20
+ get_api_key
21
+ self.post_to_imgur(@api_key, @file_to_be_uploaded)
22
+ end
23
+
24
+ def check_number_of_arguments
25
+ if ARGV.length != 1
26
+ puts "Please specify one image."
27
+ exit 0
28
+ end
29
+ @file_to_be_uploaded = ARGV[0]
30
+ end
31
+
32
+ def check_if_file_is_an_image file_path
33
+ return true if file_path.downcase.match("\.(png|jpg|gif|jpeg)$")
34
+
35
+ puts "Please enter an image ending in either:\npng,gif,jpeg,jpg"
36
+ return false #if the image is not a regex match.
37
+ exit 0
38
+ end
39
+
40
+ def ask_for_api_key
41
+ puts "1. Please go to http://imgur.com/register/api_anon and register for an API key. \n"
42
+ puts "2. Copy and paste the special \"secret key\" they give you and paste it below."
43
+
44
+ puts "Your browser will open to the page in"
45
+ countdown(3,1)
46
+ puts "Blast off! Make sure to paste it below!"
47
+
48
+ system('open "http://imgur.com/register/api_anon"')
49
+ @api_key = ask("API Key: ") { |q|
50
+ q.default = nil
51
+ }
52
+ end
53
+
54
+ def countdown(total,sleep_amount)
55
+ total.downto(1) do |y|
56
+ puts "#{y}..."
57
+ sleep(sleep_amount)
58
+ end
59
+ end
60
+
61
+
62
+ def get_api_key
63
+ FileUtils.cd(HOME_DIRECTORY)
64
+ File.open(CONFIG_FILE_PATH).each_line{ |line|
65
+ @api_key = line
66
+ }
67
+ end
68
+
69
+ def create_new_config_file
70
+ FileUtils.cd(HOME_DIRECTORY)
71
+ File.open(CONFIG_FILE_PATH, 'w') do |file|
72
+ file.print @api_key
73
+ end
74
+ end
75
+
76
+ def check_if_file_exists file_path
77
+ if File.exist?(file_path) == false
78
+ puts "A config file has not been found. I'll create one now."
79
+ return false
80
+ end
81
+ return true
82
+ end
83
+
84
+ def self.post_to_imgur(key, file_path)
85
+ url = "http://imgur.com/api/upload.json"
86
+ data = {
87
+ :key => key,
88
+ :image => File.open(file_path),
89
+ }
90
+
91
+ response = RestClient.post(url, data)
92
+ json = JSON.parse(response.body)["rsp"]["image"]["imgur_page"] rescue nil
93
+ puts "Uploading #{@file_to_be_uploaded}... #{json}"
94
+ end
95
+ main
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: filmot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Roher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-18 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'Uploads images to http://imgur.com. Filmot is an alternative URL for
15
+ imgur. '
16
+ email: roher4@gmail.com
17
+ executables:
18
+ - filmot
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/filmot
23
+ homepage: http://rubygems.org/gems/filmot
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.15
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: filmot!
47
+ test_files: []
48
+ has_rdoc: