gyaazle 0.2.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bf8c6b6d331040b41feb688abb4d2f1bb43e424
4
- data.tar.gz: 99a4581ba42a3641727235d0d2173916e0c13a12
3
+ metadata.gz: 6b888572168c7b80285d8843e723817669c8b28c
4
+ data.tar.gz: 20beb96d0312b5e07135ff01d45877e56b88c868
5
5
  SHA512:
6
- metadata.gz: 64fa2b8d4dde26d1172a82a7eb2b05226b212676cf104622547f9c2899464587887b9bbca16778dc3b1c49af54927c3bd0e44a94f35b53bc02bfb3c3c7aeb28d
7
- data.tar.gz: 1ccc3ae4c85ea328d9c941add3e3ed111c35dc1a780a47a4e90faf98716173a8bc187dac835a68e647a31920c53216041d882493c9ddcac24a2cc4a6baa83412
6
+ metadata.gz: 0275fe6ec8712ec12c002ad5ef3e237ef1998651a038a79525b236e8d44b3f1c8a5003718a7ec1af896e65f5d4cc4d2510e62229e6cf964d27693cf29d94bb8f
7
+ data.tar.gz: 52ddc12e566a8a1be32f0e5845dd1a7dc09b69e0a5db607373803b5987bf6857b9f255403d294b2e84fa599500e26834bccd5b895915ad484cbdcb769a769767
data/.travis.yml CHANGED
@@ -5,4 +5,4 @@ rvm:
5
5
  - 2.0.0
6
6
 
7
7
  script:
8
- - bundle exec rspec -c
8
+ - bundle exec rspec -c -f d
data/lib/gyaazle.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require "fileutils"
2
+ require "tempfile"
3
+
1
4
  require "httpclient"
2
5
  require "multi_json"
3
6
  require "nokogiri"
data/lib/gyaazle/cli.rb CHANGED
@@ -60,7 +60,17 @@ TEXT
60
60
  end
61
61
 
62
62
  def edit_config
63
- system(ENV["EDITOR"], config.file)
63
+ tmpfile = Tempfile.new("gyaazle-")
64
+ tmpfile.close
65
+ FileUtils.cp(config.file, tmpfile.path)
66
+ system(ENV["EDITOR"], tmpfile.path)
67
+ begin
68
+ MultiJson.load File.read(tmpfile.path)
69
+ FileUtils.cp(tmpfile.path, config.file)
70
+ rescue MultiJson::LoadError => e
71
+ $stderr.puts e.message
72
+ $stderr.puts "Does not saved"
73
+ end
64
74
  end
65
75
 
66
76
  def initialize_tokens(verifier = nil)
@@ -61,23 +61,28 @@ module Gyaazle
61
61
  end
62
62
 
63
63
  def set_permissions(file_id, permissions = nil)
64
- json = MultiJson.dump(
65
- permissions || credentials[:permissions] || {
66
- :role => "reader",
67
- :type => "#{"anyone"}",
68
- :value => "#{"me"}",
69
- :withLink => "true",
70
- :additionalRoles => ["commenter"],
71
- }
72
- )
73
- agent.post_content(
74
- "https://www.googleapis.com/drive/v2/files/#{file_id}/permissions",
75
- json,
76
- {
77
- "Authorization" => authorization_header_value,
78
- 'Content-Type' => 'application/json;charset=utf-8',
79
- }
80
- )
64
+ permissions ||= credentials[:permissions] || {
65
+ # Reference:
66
+ # * https://developers.google.com/drive/manage-sharing
67
+ # * https://developers.google.com/drive/v2/reference/permissions#resource
68
+ :role => "reader",
69
+ :type => "anyone",
70
+ :value => "me",
71
+ :withLink => "true",
72
+ :additionalRoles => ["commenter"],
73
+ }
74
+ permissions = [permissions] if permissions.class != Array
75
+ permissions.each do |perm|
76
+ json = MultiJson.dump(perm)
77
+ agent.post_content(
78
+ "https://www.googleapis.com/drive/v2/files/#{file_id}/permissions",
79
+ json,
80
+ {
81
+ "Authorization" => authorization_header_value,
82
+ 'Content-Type' => 'application/json;charset=utf-8',
83
+ }
84
+ )
85
+ end
81
86
  end
82
87
 
83
88
  def get_file_info(file_id)
@@ -1,3 +1,3 @@
1
1
  module Gyaazle
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -114,19 +114,14 @@ describe Gyaazle::CLI do
114
114
 
115
115
  before do
116
116
  cli.stub(:check_credentials!)
117
-
118
- @orig_stdout = $stdout
119
- $stdout = File.new("/dev/null", "w")
120
- end
121
-
122
- after do
123
- $stdout = @orig_stdout
124
117
  end
125
118
 
126
119
  it "invoke client.upload" do
127
120
  cli.client.should_receive(:upload).with(files.first).and_return(:alternateLink => "dummy")
128
121
  cli.client.should_receive(:set_permissions)
129
- cli.upload
122
+ silence do
123
+ cli.upload
124
+ end
130
125
  end
131
126
  end
132
127
 
@@ -135,8 +130,10 @@ describe Gyaazle::CLI do
135
130
  let(:cli) { Gyaazle::CLI.new(%W!-e --config #{conf}!) }
136
131
 
137
132
  it "invoke #system with $EDITOR" do
138
- cli.should_receive(:system).with(ENV["EDITOR"], conf)
139
- cli.edit_config
133
+ cli.should_receive(:system).at_least(1).with(ENV["EDITOR"], anything)
134
+ silence do
135
+ cli.edit_config
136
+ end
140
137
  File.unlink(conf) if File.exists?(conf)
141
138
  end
142
139
  end
@@ -24,7 +24,7 @@ describe Gyaazle::Client do
24
24
  end
25
25
 
26
26
  describe "#folder_id" do
27
- context "Gyaazle folder does exists" do
27
+ context "folder_id given" do
28
28
  before do
29
29
  config.update(:folder_id => folder_id)
30
30
  client.stub(:get_file_info).and_return({
@@ -35,13 +35,13 @@ describe Gyaazle::Client do
35
35
  })
36
36
  end
37
37
 
38
- it "invoke #create_folder" do
38
+ it "not invoke #create_folder" do
39
39
  client.should_not_receive(:create_folder)
40
40
  client.folder_id.should == folder_id
41
41
  end
42
42
  end
43
43
 
44
- context "Gyaazle folder does not exists" do
44
+ context "folder_id does not given" do
45
45
  before do
46
46
  config.update(:folder_id => nil)
47
47
  end
@@ -52,7 +52,7 @@ describe Gyaazle::Client do
52
52
  end
53
53
  end
54
54
 
55
- context "Gyaazle folder is in trash" do
55
+ context "folder_id given but its in trash" do
56
56
  before do
57
57
  config.update(:folder_id => folder_id)
58
58
  client.stub(:get_file_info).and_return({
data/spec/spec_helper.rb CHANGED
@@ -25,6 +25,16 @@ Dir["./spec/support/**/*.rb"].each{|file| require file }
25
25
  require File.expand_path("../../lib/gyaazle.rb", __FILE__)
26
26
 
27
27
  RSpec.configure do |config|
28
+ def silence
29
+ @orig_stdout = $stdout
30
+ @orig_stderr = $stderr
31
+ $stdout = File.new("/dev/null", "w")
32
+ $stderr = File.new("/dev/null", "w")
33
+ yield
34
+ ensure
35
+ $stdout = @orig_stdout
36
+ $stderr = @orig_stderr
37
+ end
28
38
  end
29
39
  # -- coding: utf-8
30
40
 
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.2.0
4
+ version: 0.2.1
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-26 00:00:00.000000000 Z
11
+ date: 2013-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient