gyaazle 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/README.md +3 -0
- data/gyaazle.gemspec +3 -0
- data/lib/gyaazle/cli.rb +24 -15
- data/lib/gyaazle/client.rb +20 -27
- data/lib/gyaazle/config.rb +8 -4
- data/lib/gyaazle/version.rb +1 -1
- data/spec/gyaazle_cli_spec.rb +115 -0
- data/spec/gyaazle_client_spec.rb +143 -0
- data/spec/gyaazle_config_spec.rb +57 -0
- data/spec/spec_helper.rb +31 -0
- metadata +54 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9fcb4b5a8c115bc19de388ee9a16611d396208a
|
4
|
+
data.tar.gz: dcb1e78fdd812a5c080ec784c799c0a2bb398ed2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7432d5148cbb9d3e868dc1877d777270f15007f588665a233b6b4cc215b22d16660c67718cc286b94165b29c41ca6cc6619c94c3e66d7fdb4f66123b8fa83364
|
7
|
+
data.tar.gz: 1d19d6a111e70dc291fbca2b8b26d6288ce39e7e4bccb0d02a053a7695c11c9cea843797a569408cc3af4f32f28274438d6bb9d32d9a1e12f09331af9cecbf2e
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/uu59/gyaazle.png?branch=master)](https://travis-ci.org/uu59/gyaazle)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/uu59/gyaazle/badge.png?branch=master)](https://coveralls.io/r/uu59/gyaazle)
|
3
|
+
|
1
4
|
# Gyaazle
|
2
5
|
|
3
6
|
Gyazo like image uploader that upload image(s) to Google Drive.
|
data/gyaazle.gemspec
CHANGED
@@ -26,4 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "pry"
|
27
27
|
spec.add_development_dependency "bundler", "~> 1.3"
|
28
28
|
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
spec.add_development_dependency "simplecov"
|
31
|
+
spec.add_development_dependency "webmock"
|
29
32
|
end
|
data/lib/gyaazle/cli.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Gyaazle
|
2
2
|
class CLI
|
3
|
+
attr_reader :config, :client
|
4
|
+
|
3
5
|
def initialize(argv)
|
4
6
|
@argv = argv
|
5
7
|
@opts = Trollop.options(@argv) do
|
@@ -35,19 +37,19 @@ TEXT
|
|
35
37
|
end
|
36
38
|
|
37
39
|
def upload
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
@client.refresh_token!
|
42
|
-
credentials = @client.credentials
|
43
|
-
end
|
40
|
+
check_credentials!
|
41
|
+
|
44
42
|
@argv.each do |file|
|
45
|
-
fileobj =
|
46
|
-
puts "#{file}:
|
43
|
+
fileobj = client.upload(file)
|
44
|
+
puts "#{file}:"
|
45
|
+
puts " * url: #{fileobj[:alternateLink]}"
|
46
|
+
puts " * download: #{fileobj[:downloadUrl]}"
|
47
|
+
puts " * deep link: https://drive.google.com/uc?export=view&id=#{fileobj[:id]}"
|
48
|
+
puts
|
47
49
|
if @opts[:open]
|
48
50
|
Launchy.open fileobj[:alternateLink]
|
49
51
|
end
|
50
|
-
|
52
|
+
client.set_permissions(fileobj[:id])
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
@@ -64,21 +66,28 @@ TEXT
|
|
64
66
|
end
|
65
67
|
|
66
68
|
def edit_config
|
67
|
-
system(ENV["EDITOR"],
|
68
|
-
puts "Updated!"
|
69
|
+
system(ENV["EDITOR"], config.file)
|
69
70
|
end
|
70
71
|
|
71
|
-
def initialize_tokens
|
72
|
-
tokens =
|
73
|
-
|
72
|
+
def initialize_tokens(verifier = nil)
|
73
|
+
tokens = client.get_tokens(verifier || authorize)
|
74
|
+
config.save(tokens)
|
74
75
|
tokens
|
75
76
|
end
|
76
77
|
|
77
78
|
def authorize
|
78
79
|
puts "Open this link by your browser, and authorize"
|
79
|
-
puts
|
80
|
+
puts client.authorize_url
|
80
81
|
print "Paste code here: "
|
81
82
|
STDIN.gets.strip
|
82
83
|
end
|
84
|
+
|
85
|
+
def check_credentials!
|
86
|
+
if config.load.nil? || config.load[:refresh_token].nil?
|
87
|
+
initialize_tokens(authorize)
|
88
|
+
else
|
89
|
+
client.refresh_token!
|
90
|
+
end
|
91
|
+
end
|
83
92
|
end
|
84
93
|
end
|
data/lib/gyaazle/client.rb
CHANGED
@@ -1,30 +1,19 @@
|
|
1
1
|
module Gyaazle
|
2
2
|
class Client
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :agent, :config
|
4
4
|
|
5
5
|
def initialize(config)
|
6
6
|
@config = config
|
7
|
-
@
|
8
|
-
end
|
9
|
-
|
10
|
-
def authorize(code)
|
11
|
-
json = client.post_content("https://accounts.google.com/o/oauth2/token", {
|
12
|
-
:code => code,
|
13
|
-
:client_id => config.id,
|
14
|
-
:client_secret => config.secret,
|
15
|
-
:redirect_uri => "urn:ietf:wg:oauth:2.0:oob",
|
16
|
-
:grant_type => "authorization_code",
|
17
|
-
})
|
18
|
-
MultiJson.load(json, :symbolize_keys => true)
|
7
|
+
@agent = HTTPClient.new
|
19
8
|
end
|
20
9
|
|
21
10
|
def authorize_url
|
22
11
|
url = "https://accounts.google.com/o/oauth2/auth?client_id=#{config.id}&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/drive"
|
23
|
-
Nokogiri::HTML.parse(
|
12
|
+
Nokogiri::HTML.parse(agent.get(url).body).at('a').attributes["href"].to_s
|
24
13
|
end
|
25
14
|
|
26
15
|
def get_tokens(verifier)
|
27
|
-
|
16
|
+
agent.post_content("https://accounts.google.com/o/oauth2/token",{
|
28
17
|
:code => verifier,
|
29
18
|
:client_id => config.id,
|
30
19
|
:client_secret => config.secret,
|
@@ -34,7 +23,7 @@ module Gyaazle
|
|
34
23
|
end
|
35
24
|
|
36
25
|
def refresh_token!
|
37
|
-
json =
|
26
|
+
json = agent.post("https://accounts.google.com/o/oauth2/token", {
|
38
27
|
:refresh_token => credentials[:refresh_token],
|
39
28
|
:client_id => config.id,
|
40
29
|
:client_secret => config.secret,
|
@@ -59,11 +48,11 @@ module Gyaazle
|
|
59
48
|
},
|
60
49
|
]
|
61
50
|
|
62
|
-
response =
|
51
|
+
response = agent.post(
|
63
52
|
'https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart',
|
64
53
|
body,
|
65
54
|
{
|
66
|
-
"Authorization" =>
|
55
|
+
"Authorization" => authorization_header_value,
|
67
56
|
"Content-Type" => "multipart/related; boundary=___#{Time.now.to_f}___",
|
68
57
|
}
|
69
58
|
)
|
@@ -81,33 +70,37 @@ module Gyaazle
|
|
81
70
|
:additionalRoles => ["commenter"],
|
82
71
|
}
|
83
72
|
)
|
84
|
-
|
73
|
+
agent.post_content(
|
85
74
|
"https://www.googleapis.com/drive/v2/files/#{file_id}/permissions",
|
86
75
|
json,
|
87
76
|
{
|
88
|
-
"Authorization" =>
|
77
|
+
"Authorization" => authorization_header_value,
|
89
78
|
'Content-Type' => 'application/json;charset=utf-8',
|
90
79
|
}
|
91
80
|
)
|
92
81
|
end
|
93
82
|
|
94
|
-
def
|
95
|
-
json =
|
83
|
+
def get_file_info(file_id)
|
84
|
+
json = agent.get(
|
96
85
|
"https://www.googleapis.com/drive/v2/files/#{file_id}",
|
97
|
-
|
86
|
+
nil,
|
98
87
|
{
|
99
|
-
"Authorization" =>
|
88
|
+
"Authorization" => authorization_header_value,
|
100
89
|
}
|
101
90
|
).body
|
102
91
|
|
103
92
|
MultiJson.load(json, :symbolize_keys => true)
|
104
93
|
end
|
105
94
|
|
95
|
+
def authorization_header_value
|
96
|
+
"#{credentials[:token_type]} #{credentials[:access_token]}"
|
97
|
+
end
|
98
|
+
|
106
99
|
def folder_id
|
107
100
|
id = credentials[:folder_id]
|
108
101
|
return create_folder("Gyaazle") unless id
|
109
102
|
|
110
|
-
folder =
|
103
|
+
folder = get_file_info(id)
|
111
104
|
if !folder[:id] || folder[:labels][:trashed]
|
112
105
|
create_folder("Gyaazle")
|
113
106
|
else
|
@@ -116,7 +109,7 @@ module Gyaazle
|
|
116
109
|
end
|
117
110
|
|
118
111
|
def create_folder(name)
|
119
|
-
json =
|
112
|
+
json = agent.post_content(
|
120
113
|
"https://www.googleapis.com/drive/v2/files",
|
121
114
|
MultiJson.dump({
|
122
115
|
:title => name,
|
@@ -124,7 +117,7 @@ module Gyaazle
|
|
124
117
|
:parents => [{:id => "root"}],
|
125
118
|
}),
|
126
119
|
{
|
127
|
-
"Authorization" =>
|
120
|
+
"Authorization" => authorization_header_value,
|
128
121
|
'Content-Type' => 'application/json;charset=utf-8',
|
129
122
|
}
|
130
123
|
)
|
data/lib/gyaazle/config.rb
CHANGED
@@ -3,15 +3,12 @@ module Gyaazle
|
|
3
3
|
CLIENT_ID = "810975313441.apps.googleusercontent.com"
|
4
4
|
CLIENT_SECRET = "0CJJ4jT2jcUsCWDrsHvXmARs"
|
5
5
|
|
6
|
-
attr_reader :id, :secret
|
6
|
+
attr_reader :id, :secret
|
7
7
|
|
8
8
|
def initialize(file = nil)
|
9
9
|
@id = CLIENT_ID
|
10
10
|
@secret = CLIENT_SECRET
|
11
11
|
@file = file
|
12
|
-
dir = File.dirname(@file)
|
13
|
-
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
14
|
-
FileUtils.touch(file) unless File.exists?(file)
|
15
12
|
end
|
16
13
|
|
17
14
|
def save(json)
|
@@ -27,5 +24,12 @@ module Gyaazle
|
|
27
24
|
def load
|
28
25
|
MultiJson.load(File.read(file), :symbolize_keys => true) rescue nil
|
29
26
|
end
|
27
|
+
|
28
|
+
def file
|
29
|
+
dir = File.dirname(@file)
|
30
|
+
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
31
|
+
FileUtils.touch(@file) unless File.exists?(@file)
|
32
|
+
@file
|
33
|
+
end
|
30
34
|
end
|
31
35
|
end
|
data/lib/gyaazle/version.rb
CHANGED
@@ -0,0 +1,115 @@
|
|
1
|
+
# -- coding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Gyaazle::CLI do
|
6
|
+
let(:cli) { Gyaazle::CLI.new([]) }
|
7
|
+
|
8
|
+
describe "ensure oauth token" do
|
9
|
+
before do
|
10
|
+
cli.stub(:authorize).and_return("verification code")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "invoke #check_credentials! before #upload" do
|
14
|
+
cli.should_receive(:check_credentials!)
|
15
|
+
cli.run!
|
16
|
+
end
|
17
|
+
|
18
|
+
context "config file does not exists" do
|
19
|
+
before do
|
20
|
+
cli.config.stub(:load).and_return(nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "invoke #initialize_tokens" do
|
24
|
+
cli.should_receive(:initialize_tokens)
|
25
|
+
cli.run!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "config file is sane" do
|
30
|
+
before do
|
31
|
+
cli.config.stub(:load).and_return(:client_id => "id", :client_secret => "secret", :refresh_token => "refresh")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "invoke #refresh_token!" do
|
35
|
+
cli.client.should_receive(:refresh_token!)
|
36
|
+
cli.run!
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "options" do
|
42
|
+
context "-e" do
|
43
|
+
let(:cli) { Gyaazle::CLI.new(%w!-e!) }
|
44
|
+
before do
|
45
|
+
cli.stub(:edit_config)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "invoke #edit_config" do
|
49
|
+
cli.should_receive(:edit_config)
|
50
|
+
cli.run!
|
51
|
+
end
|
52
|
+
|
53
|
+
it "not invoke #upload and #check_credentials!" do
|
54
|
+
cli.should_not_receive(:check_credentials!)
|
55
|
+
cli.should_not_receive(:upload)
|
56
|
+
cli.run!
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "--config filepath" do
|
61
|
+
let(:file) { File.join("/tmp", rand.to_s) }
|
62
|
+
let(:cli) { Gyaazle::CLI.new(%W!--config #{file}!) }
|
63
|
+
|
64
|
+
it "set config file" do
|
65
|
+
cli.config.file.should == file
|
66
|
+
File.unlink(file) if File.exists?(file)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "--capture" do
|
71
|
+
let(:cli) { Gyaazle::CLI.new(%W!--capture!) }
|
72
|
+
before do
|
73
|
+
cli.stub(:upload)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "invoke #capture" do
|
77
|
+
cli.should_receive(:capture)
|
78
|
+
cli.run!
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#initialize_tokens" do
|
84
|
+
let(:token) { {:foo => 1, :bar => 44} }
|
85
|
+
|
86
|
+
it "save response to config file" do
|
87
|
+
cli.client.stub(:get_tokens).and_return(token)
|
88
|
+
cli.initialize_tokens("code")
|
89
|
+
cli.config.load.should == token
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#upload" do
|
94
|
+
let(:files) { %w!foo.jpg! }
|
95
|
+
let(:cli) { Gyaazle::CLI.new(files) }
|
96
|
+
|
97
|
+
before do
|
98
|
+
cli.stub(:check_credentials!)
|
99
|
+
|
100
|
+
@orig_stdout = $stdout
|
101
|
+
$stdout = File.new("/dev/null", "w")
|
102
|
+
end
|
103
|
+
|
104
|
+
after do
|
105
|
+
$stdout = @orig_stdout
|
106
|
+
end
|
107
|
+
|
108
|
+
it "invoke client.upload" do
|
109
|
+
cli.client.should_receive(:upload).with(files.first).and_return(:alternateLink => "dummy")
|
110
|
+
cli.client.should_receive(:set_permissions)
|
111
|
+
cli.upload
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# -- coding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Gyaazle::Client do
|
6
|
+
let(:file) { File.expand_path("../tmp/dummy_conf.json", __FILE__) }
|
7
|
+
let(:config) { Gyaazle::Config.new(file) }
|
8
|
+
let(:client) { Gyaazle::Client.new(config) }
|
9
|
+
let(:folder_id) { "ididid" }
|
10
|
+
|
11
|
+
before do
|
12
|
+
config.save(:foo => 1)
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
File.unlink(file) if File.exists?(file)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#credentials" do
|
20
|
+
it "return hash with symbol key" do
|
21
|
+
client.credentials.class.should == Hash
|
22
|
+
client.credentials.keys.all?{|key| key.class == Symbol}.should be_true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#folder_id" do
|
27
|
+
context "Gyaazle folder does exists" do
|
28
|
+
before do
|
29
|
+
config.update(:folder_id => folder_id)
|
30
|
+
client.stub(:get_file_info).and_return({
|
31
|
+
:id => folder_id,
|
32
|
+
:labels => {
|
33
|
+
:trashed => false
|
34
|
+
}
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
it "invoke #create_folder" do
|
39
|
+
client.should_not_receive(:create_folder)
|
40
|
+
client.folder_id.should == folder_id
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "Gyaazle folder does not exists" do
|
45
|
+
before do
|
46
|
+
config.update(:folder_id => nil)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "invoke #create_folder" do
|
50
|
+
client.should_receive(:create_folder)
|
51
|
+
client.folder_id
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "Gyaazle folder is in trash" do
|
56
|
+
before do
|
57
|
+
config.update(:folder_id => folder_id)
|
58
|
+
client.stub(:get_file_info).and_return({
|
59
|
+
:id => folder_id,
|
60
|
+
:labels => {
|
61
|
+
:trashed => true
|
62
|
+
}
|
63
|
+
})
|
64
|
+
end
|
65
|
+
|
66
|
+
it "invoke #create_folder" do
|
67
|
+
client.should_receive(:create_folder)
|
68
|
+
client.folder_id
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#get_file_info" do
|
74
|
+
let(:response) { {:folder_id => folder_id, :labels => {:trashed => false}} }
|
75
|
+
before do
|
76
|
+
@requset = stub_request(:get, "https://www.googleapis.com/drive/v2/files/#{folder_id}").with(
|
77
|
+
:headers => {
|
78
|
+
"Authorization" => client.authorization_header_value
|
79
|
+
}
|
80
|
+
).to_return(
|
81
|
+
:body => MultiJson.dump(response)
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "GET www.googleapis.com with folder_id" do
|
86
|
+
client.get_file_info(folder_id)
|
87
|
+
WebMock.should have_requested(:get, "https://www.googleapis.com/drive/v2/files/#{folder_id}")
|
88
|
+
end
|
89
|
+
|
90
|
+
it "return response as object" do
|
91
|
+
client.get_file_info(folder_id).should == response
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#create_folder" do
|
96
|
+
let(:new_folder_id) { "foobardir" }
|
97
|
+
let(:new_folder_name) { "Gyaazle" }
|
98
|
+
|
99
|
+
before do
|
100
|
+
@request = stub_request(:post, "https://www.googleapis.com/drive/v2/files").with(
|
101
|
+
:headers => {
|
102
|
+
"Authorization" => client.authorization_header_value
|
103
|
+
}
|
104
|
+
).to_return(
|
105
|
+
:body => MultiJson.dump(:id => new_folder_id)
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "POST www.googleapis.com with new_folder_name" do
|
110
|
+
client.create_folder(new_folder_name)
|
111
|
+
WebMock.should have_requested(:post, "https://www.googleapis.com/drive/v2/files").with{|req| req.body[new_folder_name] }
|
112
|
+
end
|
113
|
+
|
114
|
+
it "config[:folder_id] should update" do
|
115
|
+
client.create_folder(new_folder_name)
|
116
|
+
config.load[:folder_id].should == new_folder_id
|
117
|
+
end
|
118
|
+
|
119
|
+
it "return new folder_id" do
|
120
|
+
client.create_folder(new_folder_name).should == new_folder_id
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "#refresh_token!" do
|
125
|
+
let(:access_token) { "ACCESS_TOKEN" }
|
126
|
+
before do
|
127
|
+
@request = stub_request(:post, "https://accounts.google.com/o/oauth2/token").to_return(
|
128
|
+
:body => MultiJson.dump(:access_token => access_token)
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "POST accounts.google.com" do
|
133
|
+
client.refresh_token!
|
134
|
+
WebMock.should have_requested(:post, "https://accounts.google.com/o/oauth2/token")
|
135
|
+
end
|
136
|
+
|
137
|
+
it "update access token" do
|
138
|
+
client.refresh_token!
|
139
|
+
config.load[:access_token].should == access_token
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -- coding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Gyaazle::Config do
|
6
|
+
let(:file) { File.expand_path("../tmp/dummy_conf.json", __FILE__) }
|
7
|
+
let(:config) { Gyaazle::Config.new(file) }
|
8
|
+
|
9
|
+
after do
|
10
|
+
File.unlink(file) if File.exists?(file)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#load" do
|
14
|
+
it "return nil if config file does not exists" do
|
15
|
+
File.unlink(file) if File.exists?(file)
|
16
|
+
config.load.should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "return nil if config file invalid json" do
|
20
|
+
File.open(file, "w"){|f| f.write "invalid json here" }
|
21
|
+
config.load.should be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "return object with symbol keys" do
|
25
|
+
obj = {"foo" => 1, :bar => 2}
|
26
|
+
File.open(file, "w"){|f| f.write MultiJson.dump(obj) }
|
27
|
+
config.load.should == {:foo => 1, :bar => 2}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#save" do
|
32
|
+
it "write string to config file" do
|
33
|
+
str = "str"
|
34
|
+
config.save(str)
|
35
|
+
File.read(file).should == str
|
36
|
+
end
|
37
|
+
|
38
|
+
it "dump object to config file" do
|
39
|
+
obj = {"foo" => "bar"}
|
40
|
+
config.save(obj)
|
41
|
+
File.read(file).should == MultiJson.dump(obj, :pretty => true)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#update" do
|
46
|
+
before do
|
47
|
+
@obj = {:foo => 1, :bar => 2}
|
48
|
+
config.save(@obj)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "save an object that merged" do
|
52
|
+
diff = {:foo => 66, :baz => 3}
|
53
|
+
config.update(diff)
|
54
|
+
config.load.should == {:foo => 66, :bar => 2, :baz => 3}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -- coding: utf-8
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler/setup"
|
5
|
+
|
6
|
+
require "simplecov"
|
7
|
+
require 'coveralls'
|
8
|
+
Coveralls.wear!
|
9
|
+
|
10
|
+
if ENV["COVERAGE"]
|
11
|
+
# Coveralls overwrite NilFomatter
|
12
|
+
SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
|
13
|
+
SimpleCov.start do
|
14
|
+
add_filter "/spec/"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
Bundler.require :default, :test
|
18
|
+
require "rspec-expectations"
|
19
|
+
require "rspec/matchers/built_in/be"
|
20
|
+
require "webmock/rspec"
|
21
|
+
|
22
|
+
Dir["./spec/support/**/*.rb"].each{|file| require file }
|
23
|
+
|
24
|
+
|
25
|
+
require File.expand_path("../../lib/gyaazle.rb", __FILE__)
|
26
|
+
|
27
|
+
RSpec.configure do |config|
|
28
|
+
end
|
29
|
+
# -- coding: utf-8
|
30
|
+
|
31
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gyaazle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- uu59
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -122,6 +122,48 @@ dependencies:
|
|
122
122
|
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
125
167
|
description: Gyazo like image uploader to Google Drive
|
126
168
|
email:
|
127
169
|
- k@uu59.org
|
@@ -131,6 +173,7 @@ extensions: []
|
|
131
173
|
extra_rdoc_files: []
|
132
174
|
files:
|
133
175
|
- .gitignore
|
176
|
+
- .travis.yml
|
134
177
|
- Gemfile
|
135
178
|
- LICENSE.txt
|
136
179
|
- README.md
|
@@ -142,6 +185,10 @@ files:
|
|
142
185
|
- lib/gyaazle/client.rb
|
143
186
|
- lib/gyaazle/config.rb
|
144
187
|
- lib/gyaazle/version.rb
|
188
|
+
- spec/gyaazle_cli_spec.rb
|
189
|
+
- spec/gyaazle_client_spec.rb
|
190
|
+
- spec/gyaazle_config_spec.rb
|
191
|
+
- spec/spec_helper.rb
|
145
192
|
homepage: https://github.com/uu59/gyaazle
|
146
193
|
licenses:
|
147
194
|
- MIT
|
@@ -166,5 +213,9 @@ rubygems_version: 2.0.2
|
|
166
213
|
signing_key:
|
167
214
|
specification_version: 4
|
168
215
|
summary: Gyazo like image uploader to Google Drive
|
169
|
-
test_files:
|
216
|
+
test_files:
|
217
|
+
- spec/gyaazle_cli_spec.rb
|
218
|
+
- spec/gyaazle_client_spec.rb
|
219
|
+
- spec/gyaazle_config_spec.rb
|
220
|
+
- spec/spec_helper.rb
|
170
221
|
has_rdoc:
|