gitpic 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/gitpic +10 -0
- data/bin/gp +10 -0
- data/lib/gitpic.rb +8 -0
- data/lib/gitpic/auth.rb +33 -0
- data/lib/gitpic/command.rb +37 -0
- data/lib/gitpic/uploader.rb +51 -0
- metadata +85 -0
data/bin/gitpic
ADDED
data/bin/gp
ADDED
data/lib/gitpic.rb
ADDED
data/lib/gitpic/auth.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
class Gitpic::Auth
|
3
|
+
def self.login(email, password)
|
4
|
+
token = RestClient.post( "#{Gitpic::HOST}/api/tokens", {
|
5
|
+
:email => email,
|
6
|
+
:password => password
|
7
|
+
})
|
8
|
+
|
9
|
+
return false if token.strip == ''
|
10
|
+
|
11
|
+
config_dir = File.expand_path('~/.gitpic')
|
12
|
+
Dir.mkdir config_dir unless Dir.exists?(config_dir)
|
13
|
+
|
14
|
+
token_path = config_dir + "/token"
|
15
|
+
File.delete token_path if File.exists? token_path
|
16
|
+
|
17
|
+
token_file = File.new(token_path, "w+")
|
18
|
+
token_file.write(token)
|
19
|
+
token_file.write("\n")
|
20
|
+
token_file.close
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.read_token
|
25
|
+
token_path = File.expand_path("~/.gitpic/token")
|
26
|
+
if File.exists?(token_path)
|
27
|
+
File.new(token_path).read
|
28
|
+
else
|
29
|
+
puts "Please login with `gitpic login` before attempting to upload"
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
class Gitpic::Command < Thor
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
desc "upload", "recursively upload directory"
|
8
|
+
def upload(dir)
|
9
|
+
token = Gitpic::Auth.read_token || return
|
10
|
+
Gitpic::Uploader.new(dir, token).upload!
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "watch", "upload the directory, then watch the directory and upload new or changed files"
|
14
|
+
def watch(dir)
|
15
|
+
puts "watching #{dir}"
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "login", "enter your credentials to fetch and store your account token"
|
19
|
+
def login
|
20
|
+
email = ask("email:")
|
21
|
+
system "stty -echo"
|
22
|
+
trap("INT") do
|
23
|
+
system "stty echo"
|
24
|
+
puts("\n ! Command cancelled.")
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
password = ask("password:")
|
28
|
+
puts
|
29
|
+
system "stty echo"
|
30
|
+
|
31
|
+
if Gitpic::Auth.login(email, password)
|
32
|
+
puts "Authentication Successful."
|
33
|
+
else
|
34
|
+
puts "Authentication Failed."
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'gitpic'
|
3
|
+
class Gitpic::Uploader
|
4
|
+
attr_accessor :base_path, :token
|
5
|
+
|
6
|
+
def initialize(directory, token)
|
7
|
+
@base_path = File.expand_path(directory)
|
8
|
+
@token = token
|
9
|
+
end
|
10
|
+
|
11
|
+
def upload!(this_path=nil)
|
12
|
+
this_path ||= @base_path
|
13
|
+
puts "Scanning #{this_path}"
|
14
|
+
this_dir = Dir.new(this_path)
|
15
|
+
this_dir.each do |file_name|
|
16
|
+
next if black_list.include?(file_name)
|
17
|
+
path = File.expand_path(file_name, this_path)
|
18
|
+
if File.directory?(path)
|
19
|
+
upload!(path)
|
20
|
+
else
|
21
|
+
checksum = Digest::MD5.file(path).hexdigest
|
22
|
+
if check_file(checksum)
|
23
|
+
puts "Uploading #{path}"
|
24
|
+
post_file(path)
|
25
|
+
else
|
26
|
+
puts "Already Uploaded #{path}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def check_file(checksum)
|
33
|
+
response = RestClient.get "#{Gitpic::HOST}/api/checksums/#{checksum}?auth_token=#{token}"
|
34
|
+
response.code == 204
|
35
|
+
end
|
36
|
+
|
37
|
+
def post_file(path)
|
38
|
+
file = File.new(path, 'rb')
|
39
|
+
RestClient.post( "#{Gitpic::HOST}/api/file_blobs?auth_token=#{token}", :file_blob => {
|
40
|
+
:data => file,
|
41
|
+
:path => path,
|
42
|
+
:filesystem_created_at => file.ctime,
|
43
|
+
:filesystem_modified_at => file.mtime
|
44
|
+
})
|
45
|
+
end
|
46
|
+
|
47
|
+
def black_list
|
48
|
+
[".", "..", ".DS_Store"]
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitpic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ross Hale
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: term-ansicolor
|
16
|
+
requirement: &2156246360 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.7
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2156246360
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rest-client
|
27
|
+
requirement: &2156245820 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.6.7
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2156245820
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: thor
|
38
|
+
requirement: &2156245320 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.14.6
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2156245320
|
47
|
+
description: A ruby command line interface for uploading to GitPic
|
48
|
+
email: rosshale@gmail.com
|
49
|
+
executables:
|
50
|
+
- gitpic
|
51
|
+
- gp
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- lib/gitpic/auth.rb
|
56
|
+
- lib/gitpic/command.rb
|
57
|
+
- lib/gitpic/uploader.rb
|
58
|
+
- lib/gitpic.rb
|
59
|
+
- bin/gitpic
|
60
|
+
- bin/gp
|
61
|
+
homepage: http://gitpic.com
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.3.6
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.6
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: GitPic CLI
|
85
|
+
test_files: []
|