twitpic 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +3 -2
  2. data/Rakefile +5 -3
  3. data/bin/twitpic +46 -0
  4. data/lib/twitpic.rb +4 -2
  5. metadata +15 -4
data/README.rdoc CHANGED
@@ -16,16 +16,17 @@ Library for TwitPic API.
16
16
  == REQUIREMENTS:
17
17
 
18
18
  * mime-types
19
+ * highline
19
20
 
20
21
  == TODO:
21
22
 
22
- * Create twitpic command
23
+ * Error handling
23
24
 
24
25
  == LICENSE:
25
26
 
26
27
  (The MIT License)
27
28
 
28
- Copyright (c) 2008-2009 The Termtter Development Team
29
+ Copyright (c) 2008-2009 jugyo
29
30
 
30
31
  Permission is hereby granted, free of charge, to any person obtaining
31
32
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,20 +1,22 @@
1
1
  $:.unshift File.dirname(__FILE__) + '/lib'
2
-
2
+ require 'twitpic'
3
3
  require 'spec/rake/spectask'
4
4
  require 'rake/clean'
5
5
  require 'rake/gempackagetask'
6
6
  require 'rake/rdoctask'
7
7
 
8
8
  name = 'twitpic'
9
- version = '0.1.0'
9
+ version = TwitPic::VERSION
10
10
 
11
11
  spec = Gem::Specification.new do |s|
12
12
  s.name = name
13
13
  s.version = version
14
14
  s.summary = "Library for TwitPic API."
15
15
  s.description = "Library for TwitPic API."
16
- s.files = %w(Rakefile README.rdoc History.txt) + Dir.glob("{lib,spec}/**/*")
16
+ s.files = %w(Rakefile README.rdoc History.txt) + Dir.glob("{bin,lib,spec}/**/*")
17
17
  s.add_dependency("mime-types", ">= 1.15")
18
+ s.add_dependency("highline", ">= 1.5.1")
19
+ s.executables = ["twitpic"]
18
20
  s.authors = %w(jugyo)
19
21
  s.email = 'jugyo.org@gmail.com'
20
22
  s.homepage = 'http://github.com/jugyo/twitpic'
data/bin/twitpic ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'twitpic'
5
+ require 'optparse'
6
+ require "highline"
7
+
8
+ username = nil
9
+ password = nil
10
+ message = nil
11
+ file = nil
12
+ screencapture = nil
13
+
14
+ OptionParser.new do |o|
15
+ o.version = TwitPic::VERSION
16
+ o.banner = "Usage: #{o.program_name} [-u USERNAME -p PASSWORD -m MESSAGE] [FILE | -s]"
17
+ o.on('-u', '--username=USERNAME') {|v| username = v}
18
+ o.on('-p', '--password=PASSWORD') {|v| password = v}
19
+ o.on('-m', '--message=MESSAGE') {|v| message = v}
20
+ o.on('-s', '--screencapture') {|v| screencapture = true}
21
+ o.permute!(ARGV)
22
+ file = ARGV.first
23
+ if file.nil? && screencapture.nil?
24
+ puts o.help
25
+ exit!
26
+ end
27
+ end
28
+
29
+ if file.nil? && screencapture
30
+ file = '/tmp/twitpic_screencapture.png'
31
+ File.delete(file) if File.exists?(file)
32
+ puts 'Please capture screen...'
33
+ system 'screencapture', '-i', '-f', file
34
+ unless File.exists?(file)
35
+ puts 'Aboat!'
36
+ exit!
37
+ end
38
+ end
39
+
40
+ highline = HighLine.new
41
+ username = highline.ask('USERNAME: ') unless username
42
+ password = highline.ask('PASSWORD: ') {|q| q.echo = '*'} unless password
43
+ message = highline.ask('MESSAGE: ') unless message
44
+
45
+ puts 'Uploading...'
46
+ TwitPic.new(username, password).upload(file, message)
data/lib/twitpic.rb CHANGED
@@ -3,6 +3,8 @@ require "uri"
3
3
  require 'mime/types'
4
4
 
5
5
  class TwitPic
6
+ VERSION = '0.2.0'
7
+
6
8
  def initialize(username, password)
7
9
  @username = username
8
10
  @password = password
@@ -13,12 +15,12 @@ class TwitPic
13
15
  :username => @username,
14
16
  :password => @password
15
17
  }
16
- parts[:message] = message if message
18
+ parts[:message] = message if message && !message.empty?
17
19
 
18
20
  body = create_body(parts, file_path, boundary)
19
21
 
20
22
  url =
21
- if message
23
+ if parts[:message]
22
24
  'http://twitpic.com/api/uploadAndPost'
23
25
  else
24
26
  'http://twitpic.com/api/upload'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitpic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-19 00:00:00 +09:00
12
+ date: 2009-06-20 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,10 +22,20 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "1.15"
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: highline
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.1
34
+ version:
25
35
  description: Library for TwitPic API.
26
36
  email: jugyo.org@gmail.com
27
- executables: []
28
-
37
+ executables:
38
+ - twitpic
29
39
  extensions: []
30
40
 
31
41
  extra_rdoc_files:
@@ -35,6 +45,7 @@ files:
35
45
  - Rakefile
36
46
  - README.rdoc
37
47
  - History.txt
48
+ - bin/twitpic
38
49
  - lib/twitpic.rb
39
50
  - spec/test.txt
40
51
  - spec/twitpic_spec.rb