gcevent 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/README.md +2 -1
- data/gcevent.gemspec +1 -1
- data/lib/google/calendar.rb +2 -2
- data/lib/google/service_account.rb +11 -20
- data/spec/google/calendar/event_spec.rb +12 -2
- data/spec/google/calendar_spec.rb +2 -1
- data/spec/google/service_account_spec.rb +19 -43
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4ccbcb111bab108ce0af65e9bfbd701e8fa89a4
|
4
|
+
data.tar.gz: 25df7e074c26a58b78196ca6f6c8106c4a65a53a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46b9a6bfc10a4550dd997af2273296ff4b7b1d3c08b2f374644ae669f0e4dbf97584c4d359f6fe2ea5e608943b80b9dd6d272826642537c63139829abf3fc058
|
7
|
+
data.tar.gz: b230e8742bd4178cf8ebf2d2e8e073892d27a76949b13bdda68740cf1d316af54c07d48d8194300b7f0acefb82f2ed5126cdf0a4b37cc9ee7f68b1c142f0cacc
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -30,7 +30,8 @@ Or install it yourself as:
|
|
30
30
|
Google::Calendar.id = "Id of a target Google Calendar"
|
31
31
|
Google::Calendar.secret_key.path = "Path of xxx-privatekey.p12"
|
32
32
|
Google::Calendar.secret_key.password = "Password"
|
33
|
-
Google::Calendar.
|
33
|
+
Google::Calendar.client_secret_path = "Path of client_secret_xxx.json"
|
34
|
+
Google::Calendar.client_email = "Email address of service account"
|
34
35
|
```
|
35
36
|
|
36
37
|
### Event#get
|
data/gcevent.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "gcevent"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.3"
|
8
8
|
spec.authors = ["ogawatti"]
|
9
9
|
spec.email = ["ogawattim@gmail.com"]
|
10
10
|
spec.summary = %q{A wrapper of Google Calendar Event API.}
|
data/lib/google/calendar.rb
CHANGED
@@ -8,7 +8,7 @@ module Google
|
|
8
8
|
|
9
9
|
module Calendar
|
10
10
|
class << self
|
11
|
-
attr_accessor :id, :
|
11
|
+
attr_accessor :id, :client_secret_path, :client_email
|
12
12
|
end
|
13
13
|
|
14
14
|
extend self
|
@@ -40,7 +40,7 @@ module Google
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def service_account
|
43
|
-
Google::ServiceAccount.new(
|
43
|
+
Google::ServiceAccount.new(client_secret_path, client_email)
|
44
44
|
end
|
45
45
|
|
46
46
|
def signing_key
|
@@ -1,31 +1,22 @@
|
|
1
1
|
module Google
|
2
2
|
class ServiceAccount
|
3
|
-
|
4
|
-
CLIENT_EMAIL_DOMAIN = "developer.gserviceaccount.com"
|
5
|
-
ACCOUNTS_GOOGLE_COM_BASE_URI = "https://accounts.google.com"
|
6
|
-
WWW_GOOGLEAPIS_COM_BASE_URI = "https://www.googleapis.com"
|
3
|
+
SCOPE = 'https://www.googleapis.com/auth/calendar'
|
7
4
|
|
8
|
-
attr_reader :id
|
9
5
|
attr_reader :auth_uri, :token_uri
|
10
6
|
attr_reader :client_id, :client_email
|
11
7
|
attr_reader :auth_provider_x509_cert_url, :client_x509_cert_url
|
8
|
+
attr_reader :project_id
|
12
9
|
attr_reader :scope
|
13
10
|
|
14
|
-
def initialize(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@
|
22
|
-
@scope
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def scan_id(client_id)
|
28
|
-
client_id.scan(/^(.*)#{CLIENT_ID_SUFFIX}$/).first.first
|
11
|
+
def initialize(secret_path, email)
|
12
|
+
JSON.parse(File.read(secret_path)).each do |key, secret|
|
13
|
+
secret.each do |k, v|
|
14
|
+
instance_varialbe_name = "@#{k}".to_sym
|
15
|
+
instance_variable_set(instance_varialbe_name, v)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
@client_email ||= email
|
19
|
+
@scope = SCOPE
|
29
20
|
end
|
30
21
|
end
|
31
22
|
end
|
@@ -34,11 +34,21 @@ describe Google::Calendar::Event do
|
|
34
34
|
let(:end_date) { { date: Date.tomorrow } }
|
35
35
|
|
36
36
|
before do
|
37
|
+
Google::Calendar.id = calendar_id
|
37
38
|
allow(Google::APIClient::KeyUtils).to receive(:load_key) { OpenSSL::PKey::RSA.new }
|
38
39
|
allow(File).to receive(:exist?) { true }
|
40
|
+
allow(File).to receive(:read) {
|
41
|
+
{
|
42
|
+
installed: {
|
43
|
+
client_id: "100000000000000000000",
|
44
|
+
project_id: "test-project-000001",
|
45
|
+
auth_uri: "https://accounts.google.com/o/oauth2/auth",
|
46
|
+
token_uri: "https://accounts.google.com/o/oauth2/token",
|
47
|
+
auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs"
|
48
|
+
}
|
49
|
+
}.to_json
|
50
|
+
}
|
39
51
|
allow_any_instance_of(Signet::OAuth2::Client).to receive(:fetch_access_token!) { true }
|
40
|
-
Google::Calendar.client_id = client_id
|
41
|
-
Google::Calendar.id = calendar_id
|
42
52
|
allow(Google::Calendar).to receive(:authorize?) { true }
|
43
53
|
end
|
44
54
|
|
@@ -8,8 +8,9 @@ describe Google::Calendar do
|
|
8
8
|
before do
|
9
9
|
allow(Google::APIClient::KeyUtils).to receive(:load_key) { OpenSSL::PKey::RSA.new }
|
10
10
|
allow(File).to receive(:exist?) { true }
|
11
|
+
allow(File).to receive(:read) { { installed: { client_id: client_id } }.to_json }
|
11
12
|
allow_any_instance_of(Signet::OAuth2::Client).to receive(:fetch_access_token!) { true }
|
12
|
-
Google::Calendar.
|
13
|
+
Google::Calendar.client_secret_path = "testpath"
|
13
14
|
end
|
14
15
|
|
15
16
|
describe '.api' do
|
@@ -1,52 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Google::ServiceAccount do
|
4
|
-
|
5
|
-
let(:
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
describe '::CLIENT_ID_SUFFIX' do
|
20
|
-
subject { Google::ServiceAccount::CLIENT_ID_SUFFIX }
|
21
|
-
it { is_expected.to eq client_id_suffix }
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '::CLIENT_EMAIL_DOMAIN' do
|
25
|
-
subject { Google::ServiceAccount::CLIENT_EMAIL_DOMAIN }
|
26
|
-
it { is_expected.to eq client_email_domain }
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '::ACCOUNTS_GOOGLE_COM_BASE_URI' do
|
30
|
-
subject { Google::ServiceAccount::ACCOUNTS_GOOGLE_COM_BASE_URI }
|
31
|
-
it { is_expected.to eq accounts_google_com_base_uri }
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '::WWW_GOOGLEAPIS_COM_BASE_URI' do
|
35
|
-
subject { Google::ServiceAccount::WWW_GOOGLEAPIS_COM_BASE_URI }
|
36
|
-
it { is_expected.to eq www_googleapis_com_base_uri }
|
37
|
-
end
|
4
|
+
before { allow(File).to receive(:read) { secret.to_json } }
|
5
|
+
let(:client_secret_path) { "./testpath" }
|
6
|
+
let(:client_email) { "test@example.com" }
|
7
|
+
let(:secret) {
|
8
|
+
{
|
9
|
+
installed: {
|
10
|
+
client_id: "100000000000000000000",
|
11
|
+
project_id: "test-project-000001",
|
12
|
+
auth_uri: "https://accounts.google.com/o/oauth2/auth",
|
13
|
+
token_uri: "https://accounts.google.com/o/oauth2/token",
|
14
|
+
auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
38
18
|
|
39
19
|
describe '#initialize' do
|
40
20
|
it 'should be instance of Google::ServiceAccount' do
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
expect(service_account.client_email).to eq client_email
|
47
|
-
expect(service_account.auth_provider_x509_cert_url).to eq auth_provider_x509_cert_url
|
48
|
-
expect(service_account.client_x509_cert_url).to eq client_x509_cert_url
|
49
|
-
expect(service_account.scope).to eq scope
|
21
|
+
service_account = Google::ServiceAccount.new(client_secret_path, client_email)
|
22
|
+
secret[:installed].each do |k, v|
|
23
|
+
expect(service_account.send(k)).to eq v
|
24
|
+
end
|
25
|
+
expect(service_account.client_email).to eq client_email
|
50
26
|
end
|
51
27
|
end
|
52
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gcevent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ogawatti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-api-client
|
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
181
|
version: '0'
|
182
182
|
requirements: []
|
183
183
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.
|
184
|
+
rubygems_version: 2.5.1
|
185
185
|
signing_key:
|
186
186
|
specification_version: 4
|
187
187
|
summary: A wrapper of Google Calendar Event API.
|