imgurr 0.0.1 → 0.0.3

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: d4544fad3819e0f8c9d81e8a59e1be7435a78296
4
- data.tar.gz: 890d54d33ea441afd7970d73ea1d937d0df4dde9
3
+ metadata.gz: dc5e24675f0306b5d0f9c1068599acc4ffd6de29
4
+ data.tar.gz: 62ffec32123b2d2d9e306f98bcc5d0c2440e5780
5
5
  SHA512:
6
- metadata.gz: 99eb2135ac23a07d1a23333aaf0db10564a4e347c70cb54b12acf8e8f51538236a2685372ad93ed2eb0eea4317536315785ef6ab34d5753578258b4ba153131f
7
- data.tar.gz: 1b807e4cb0ab03b55b0582376dd23c307edba8d3c919f176f3f3cf7caafdcb4beceb0bb3a7f94f73753b31ebece59c9468f3ca01311a7f49a7ae6e20047fb86c
6
+ metadata.gz: 5af7a7c4f701d72132e6aed3e8577420de2e7508d4efe3eec9b83573da91b07d325c843e9fad8f0023c3516626fb492ac64cae2dd0e4fbc2afa8c99b97b946b1
7
+ data.tar.gz: ef8c4dd81a8bb18f6d259b966963235d4298a7b1377202bba889b59d44db9a8a06588d754476da6a261fac476e6559cc85e57eeb65e75618750bb029d38fa3c3
data/Gemfile.lock CHANGED
@@ -1,16 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- imgurr (0.0.1)
4
+ imgurr (0.0.2)
5
5
  json (~> 1.7.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
10
  json (1.7.7)
11
+ rake (0.9.6)
11
12
 
12
13
  PLATFORMS
13
14
  ruby
14
15
 
15
16
  DEPENDENCIES
16
17
  imgurr!
18
+ rake (~> 0.9.2)
data/README.md CHANGED
@@ -5,9 +5,22 @@ Command line utility for Imgur in ruby
5
5
 
6
6
 
7
7
  ## Install
8
+ **Warning:** This gem is still in early development and might not work on your system. Please report any bugs.
9
+
8
10
  gem install imgurr
9
11
 
10
12
  ## Usage
11
13
  imgurr upload image.jpg
12
14
  Copied http://i.imgur.com/PLWGJlc.gif to clipboard
15
+
16
+ imgurr info 2KxrTAK
17
+ Image ID : 2KxrTAK
18
+ Views : 14717
19
+ Bandwidth : 2.296 GiB
20
+ Title :
21
+ Desc :
22
+ Animated : false
23
+ Width : 960 px
24
+ Height : 540 px
25
+ Link : http://i.imgur.com/2KxrTAK.jpg
13
26
 
data/imgurr.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'imgurr'
3
- s.version = '0.0.1'
4
- s.date = '2013-04-06'
3
+ s.version = '0.0.3'
4
+ s.date = '2013-04-07'
5
5
  s.summary = "Imgurr lets you upload images to imgur from the command line"
6
6
  s.description = "Imgurr is a ruby gem that lets you upload images to Imgur and manage your account"
7
7
  s.authors = ["Christophe Naud-Dulude"]
@@ -10,7 +10,7 @@
10
10
  module Imgurr
11
11
  class Command
12
12
  class << self
13
- #include Imgurup::Color
13
+ #include Imgurr::Color
14
14
 
15
15
  # Public: executes a command.
16
16
  #
@@ -25,16 +25,6 @@ module Imgurr
25
25
  delegate(command, major, minor)
26
26
  end
27
27
 
28
- # Public: prints any given string.
29
- #
30
- # s = String output
31
- #
32
- # Prints to STDOUT and returns. This method exists to standardize output
33
- # and for easy mocking or overriding.
34
- def output(s)
35
- puts(s)
36
- end
37
-
38
28
  # Public: gets $stdin.
39
29
  #
40
30
  # Returns the $stdin object. This method exists to help with easy mocking
@@ -47,12 +37,14 @@ module Imgurr
47
37
  #
48
38
  # Returns output based on method calls.
49
39
  def delegate(command, major, minor)
50
- return version if command == '-v'
40
+ return help unless command
41
+ return no_internet unless self.internet_connection?
42
+
51
43
  return version if command == '--version'
52
44
  return help if command == 'help'
53
45
  return help if command[0] == 45 || command[0] == '-' # any - dash options are pleas for help
54
- return echo(major,minor) if command == 'echo' || command == 'e'
55
46
  return upload(major) if command == 'upload' || command == 'up' || command == 'u'
47
+ return info(major) if command == 'info' || command == 'i'
56
48
 
57
49
  end
58
50
 
@@ -60,23 +52,53 @@ module Imgurr
60
52
  #
61
53
  # Returns nothing
62
54
  def upload(major)
55
+ unless File.exist?(major)
56
+ puts "File #{major} not found."
57
+ return
58
+ end
63
59
  response = ImgurAPI.upload(major)
64
- puts response if response.start_with?('Error')
60
+ puts response if response.start_with?('Imgur Error')
65
61
  puts "Copied #{Platform.copy(response)} to clipboard" if response.start_with?('http')
66
62
  end
67
63
 
64
+ # Public: Get image info
65
+ #
66
+ # Returns nothing
67
+ def info(major)
68
+ response = ImgurAPI.get_info(major)
69
+ puts response
70
+ end
71
+
68
72
  # Public: the version of boom that you're currently running.
69
73
  #
70
74
  # Returns a String identifying the version number.
71
75
  def version
72
- output "You're running imgurup #{Imgurup::VERSION}."
76
+ puts "You're running imgurr #{Imgurr::VERSION}."
73
77
  end
74
78
 
75
79
  # Public: launches preferences JSON file in an editor for you to edit manually.
76
80
  #
77
81
  # Returns nothing.
78
82
  def edit
79
- Platform.edit(account.json_file)
83
+ #Platform.edit(account.json_file)
84
+ end
85
+
86
+ # Public: Checks is there's an active internet connection
87
+ #
88
+ # Returns true or false
89
+ def internet_connection?
90
+ begin
91
+ true if open("http://www.google.com/")
92
+ rescue
93
+ false
94
+ end
95
+ end
96
+
97
+ # Public: No internet error
98
+ #
99
+ # Returns nothing
100
+ def no_internet
101
+ puts "An Internet connection is required to use this command."
80
102
  end
81
103
 
82
104
  # Public: prints all the commands of boom.
@@ -84,16 +106,19 @@ module Imgurr
84
106
  # Returns nothing.
85
107
  def help
86
108
  text = '
87
- - imgurup: help ---------------------------------------------------
109
+ - imgurr: help ---------------------------------------------------
88
110
 
89
- imgurup upload <image> Upload image and copy link to clipboard
111
+ imgurr help This help text
112
+ imgurr version Print current version
90
113
 
114
+ imgurr upload <image> Upload image and copy link to clipboard
115
+ imgurr info <id> Print image information
91
116
 
92
117
  all other documentation is located at:
93
- https://github.com/Chris911/imgurup
118
+ https://github.com/Chris911/imgurr
94
119
  '.gsub(/^ {8}/, '') # strip the first eight spaces of every line
95
120
 
96
- output text
121
+ puts text
97
122
  end
98
123
 
99
124
  end
@@ -11,8 +11,8 @@ module Imgurr
11
11
  API_PUBLIC_KEY = 'Client-ID 70ff50b8dfc3a53'
12
12
 
13
13
  ENDPOINTS = {
14
- :image => '/3/image',
15
- :gallery => '/3/gallery'
14
+ :image => '/3/image/',
15
+ :gallery => '/3/gallery/'
16
16
  }
17
17
 
18
18
  # HTTP Client used for API requests
@@ -35,17 +35,55 @@ module Imgurr
35
35
  request.add_field('Authorization', API_PUBLIC_KEY)
36
36
 
37
37
  response = web_client.request(request)
38
- handle_response(response.body)
38
+ handle_upload_response(response.body)
39
+ end
40
+
41
+ # Public: Get info about an image
42
+ #
43
+ # args - The image imgur id
44
+ #
45
+ def get_info(image_id)
46
+ request = Net::HTTP::Get.new(API_URI.request_uri + ENDPOINTS[:image] + image_id)
47
+ request.add_field('Authorization', API_PUBLIC_KEY)
48
+
49
+ response = web_client.request(request)
50
+ handle_info_response(response.body)
39
51
  end
40
52
 
41
53
  # Public: Handle API Response
42
54
  #
43
55
  # args - Response data
44
56
  #
45
- def handle_response(response)
57
+ def handle_upload_response(response)
58
+ data = JSON.parse(response)
59
+ puts JSON.pretty_unparse(data) if Imgurr::DEBUG
60
+ if data['success']
61
+ return data['data']['link']
62
+ end
63
+ ImgurErrors.handle_error(response)
64
+ end
65
+
66
+ # Public: Handle API Response
67
+ #
68
+ # args - Response data
69
+ #
70
+ def handle_info_response(response)
46
71
  data = JSON.parse(response)
47
- #puts JSON.pretty_unparse(data)
48
- data['data']['link'] if(data['success'])
72
+ puts JSON.pretty_unparse(data) if Imgurr::DEBUG
73
+ if data['success']
74
+ return "
75
+ Image ID : #{data['data']['id']}
76
+ Views : #{data['data']['views']}
77
+ Bandwidth : #{Numbers.to_human(data['data']['bandwidth'])}
78
+ Title : #{data['data']['title']}
79
+ Desc : #{data['data']['description']}
80
+ Animated : #{data['data']['animated']}
81
+ Width : #{data['data']['width']} px
82
+ Height : #{data['data']['height']} px
83
+ Link : #{data['data']['link']}
84
+ ".gsub(/^ {8}/, '')
85
+ end
86
+ ImgurErrors.handle_error(response)
49
87
  end
50
88
 
51
89
  end
@@ -8,17 +8,9 @@ module Imgurr
8
8
  class ImgurErrors
9
9
  class << self
10
10
 
11
- ERROR_CODES = {
12
- 400 => 'Missing Parameters',
13
- 401 => 'Auth Required',
14
- 403 => 'Forbidden',
15
- 404 => 'Resource does not exist',
16
- 429 => 'Rate Limiting',
17
- 500 => 'Internal Error'
18
- }
19
-
20
11
  def handle_error(response)
21
-
12
+ data = JSON.parse(response)
13
+ "Imgur Error: #{data['data']['error']} (#{data['status']})"
22
14
  end
23
15
 
24
16
  end
@@ -0,0 +1,14 @@
1
+ module Imgurr
2
+ class Numbers
3
+ class << self
4
+ def to_human(number)
5
+ units = %W(B KiB MiB GiB TiB)
6
+
7
+ size, unit = units.reduce(number.to_f) do |(fsize, _), utype|
8
+ fsize > 512 ? [fsize / 1024, utype] : (break [fsize, utype])
9
+ end
10
+ return "#{"%.3f" % size} #{unit}"
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/imgurr.rb CHANGED
@@ -8,18 +8,20 @@ end
8
8
  # External require
9
9
  require 'net/http'
10
10
  require 'net/https'
11
+ require 'open-uri'
11
12
  require 'json'
12
- require 'openssl'
13
13
 
14
14
  $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
15
15
 
16
16
  # Internal require
17
- require 'imgurr/command'
18
17
  require 'imgurr/color'
18
+ require 'imgurr/numbers'
19
19
  require 'imgurr/imgurAPI'
20
20
  require 'imgurr/platform'
21
21
  require 'imgurr/imgurErrors'
22
+ require 'imgurr/command'
22
23
 
23
24
  module Imgurr
24
- VERSION = '0.0.1'
25
+ VERSION = '0.0.2'
26
+ DEBUG = false
25
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imgurr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christophe Naud-Dulude
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-06 00:00:00.000000000 Z
11
+ date: 2013-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -58,6 +58,7 @@ files:
58
58
  - lib/imgurr/command.rb
59
59
  - lib/imgurr/imgurAPI.rb
60
60
  - lib/imgurr/imgurErrors.rb
61
+ - lib/imgurr/numbers.rb
61
62
  - lib/imgurr/platform.rb
62
63
  - lib/imgurr.rb
63
64
  - test/run