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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7448318fcf34b51979ba1c1e91fb96fc4409e81f
4
- data.tar.gz: 400af06a1fd0f1c9aa09a4db4e841bcb662d3b63
3
+ metadata.gz: a4ccbcb111bab108ce0af65e9bfbd701e8fa89a4
4
+ data.tar.gz: 25df7e074c26a58b78196ca6f6c8106c4a65a53a
5
5
  SHA512:
6
- metadata.gz: 77a3d9fd1d90ffa9ec84ce0ce173a4482b521789196095a5046590381212ffc5627cfafa1a2e6ed9daa85f8195a183682b83df8ca84492ada2cbcf551eb333f1
7
- data.tar.gz: 6abc18a284872a389be281e966ff7b6db660097aa05a6625852ad569523a3991c7549c988d7596b4372857ef9e2b9d144e6a78bf093bde68c7fc0c73a6863c61
6
+ metadata.gz: 46b9a6bfc10a4550dd997af2273296ff4b7b1d3c08b2f374644ae669f0e4dbf97584c4d359f6fe2ea5e608943b80b9dd6d272826642537c63139829abf3fc058
7
+ data.tar.gz: b230e8742bd4178cf8ebf2d2e8e073892d27a76949b13bdda68740cf1d316af54c07d48d8194300b7f0acefb82f2ed5126cdf0a4b37cc9ee7f68b1c142f0cacc
data/.travis.yml CHANGED
@@ -1,5 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.5
4
- - 2.1.6
5
- - 2.2.2
3
+ - 2.3.0
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.client_id = "ID of Client"
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.2"
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.}
@@ -8,7 +8,7 @@ module Google
8
8
 
9
9
  module Calendar
10
10
  class << self
11
- attr_accessor :id, :client_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(client_id)
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
- CLIENT_ID_SUFFIX = ".apps.googleusercontent.com"
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(client_id)
15
- @id = client_id.include?(CLIENT_ID_SUFFIX) ? scan_id(client_id) : client_id
16
- @auth_uri = ACCOUNTS_GOOGLE_COM_BASE_URI + "/o/oauth2/auth"
17
- @token_uri = ACCOUNTS_GOOGLE_COM_BASE_URI + "/o/oauth2/token"
18
- @client_id = @id + CLIENT_ID_SUFFIX
19
- @client_email = @id + "@" + CLIENT_EMAIL_DOMAIN
20
- @auth_provider_x509_cert_url = WWW_GOOGLEAPIS_COM_BASE_URI + "/oauth2/v1/certs"
21
- @client_x509_cert_url = WWW_GOOGLEAPIS_COM_BASE_URI + "/robot/v1/metadata/x509" + @client_email
22
- @scope = WWW_GOOGLEAPIS_COM_BASE_URI + "/auth/calendar"
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.client_id = client_id
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
- let(:client_id_suffix) { ".apps.googleusercontent.com" }
5
- let(:client_email_domain) { "developer.gserviceaccount.com" }
6
- let(:accounts_google_com_base_uri) { "https://accounts.google.com" }
7
- let(:www_googleapis_com_base_uri) { "https://www.googleapis.com" }
8
-
9
- let(:id) { "1000000000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }
10
- let(:client_id) { id + ".apps.googleusercontent.com" }
11
- let(:auth_uri) { accounts_google_com_base_uri + "/o/oauth2/auth" }
12
- let(:token_uri) { accounts_google_com_base_uri + "/o/oauth2/token" }
13
- let(:client_email) { id + "@" + client_email_domain }
14
- let(:auth_provider_x509_cert_url) { www_googleapis_com_base_uri + "/oauth2/v1/certs" }
15
- let(:client_x509_cert_url) { www_googleapis_com_base_uri + "/robot/v1/metadata/x509" + client_email }
16
- let(:scope) { www_googleapis_com_base_uri + "/auth/calendar" }
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
- service_account = Google::ServiceAccount.new(client_id)
42
- expect(service_account.id).to eq id
43
- expect(service_account.auth_uri).to eq auth_uri
44
- expect(service_account.token_uri).to eq token_uri
45
- expect(service_account.client_id).to eq client_id
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.2
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: 2016-02-19 00:00:00.000000000 Z
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.4.8
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.