googlecal 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cab9c7f838cca955077ddff4aa3ddcf189ba0ca9
4
+ data.tar.gz: 2af1ecce263af3e2e6c0213c9f37961d144d30ae
5
+ SHA512:
6
+ metadata.gz: f365f52c1322924c5a0ae3017e2431c3a030266d89105a883dd38750378a7c5d6018d3c33cf6b58c331082610199f197c64072b87fcd959844849bb9e420f95d
7
+ data.tar.gz: cb3c59e515fdb61a13c2352fa6ee6da483ab8836f98a6601b73c580205d63a296daa8556ba6dd534d4b8b4ac92f39d4491078b73ef74dd308c31902eb9572d0a
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ # dont keep your client_secrets in git
11
+ client_secret.json
12
+ /doc/
13
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in googlecal.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,31 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Ennovar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy
7
+ of this software and associated documentation files (the "Software"), to
8
+ deal
9
+ in the Software without restriction, including without limitation the
10
+ rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
+ sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included
17
+ in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21
+ OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
+ THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27
+ FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29
+ IN THE
30
+ SOFTWARE.
31
+
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ [![Build
2
+ Status](https://travis-ci.org/Ennovar/googlecal.svg?branch=master)](https://travis-ci.org/Ennovar/googlecal)
3
+ # Googlecal
4
+ _simple wrapper for google calendar api for ruby_
5
+
6
+ ## This project is in Alpha!!!
7
+
8
+
9
+ ## Testing Setup
10
+ Before you are ready to start developing on the project there are a
11
+ couple steps to follow
12
+
13
+ 1. make sure you have a google account... **DUH**
14
+ 2. make sure you enable the account to access your google calendar, you
15
+ can find directions for that
16
+ [here](https://developers.google.com/google-apps/calendar/quickstart/ruby)
17
+ 3. download your client_secret.json file into the project directory,
18
+ these will authenticate you. Dont worry the .gitignore will ignore
19
+ this file
20
+ 4. run your tests with the following command inside the directory `rake
21
+ spec`
22
+
23
+ **NOTE:** if you get the following output from running your tests
24
+
25
+ ```
26
+ Open the following url in the browser ............
27
+ ```
28
+ 1. you need to cancel your tests
29
+ 2. run `./bin/console`
30
+ 3. in the irb console you need to run the following
31
+ `Googlecal::Base.new('')`
32
+ 4. the url should print out to the console, open the url in your browser
33
+ and then use the code that is in the webpage and paste it into the
34
+ irb console to authenticate you.
35
+
36
+ **Then you are clear to start running tests**
37
+
38
+
39
+ ## Generating Documentation
40
+ 1. install rdoc with
41
+ ```
42
+ gem install rdoc
43
+ ```
44
+ 2. generate the docs by running this command in the project directory
45
+ ```
46
+ rdoc
47
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "googlecal"
5
+ require 'dotenv'
6
+ Dotenv.load('.env')
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require "irb"
16
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/googlecal.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'googlecal/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "googlecal"
8
+ spec.version = Googlecal::VERSION
9
+ spec.authors = ["Austin M Crane"]
10
+ spec.email = ["austin.crane@ennovar.wichita.edu"]
11
+
12
+ spec.summary = %q{Simple wrapper around google calendar api}
13
+ spec.description = %q{Simple wrapper around google calendar api}
14
+ spec.homepage = "http://github.com"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_runtime_dependency "google-api-client"
26
+
27
+ spec.add_development_dependency "dotenv"
28
+ spec.add_development_dependency "bundler", "~> 1.13"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
data/lib/googlecal.rb ADDED
@@ -0,0 +1,166 @@
1
+ require "googlecal/version"
2
+ # google api stuff
3
+ require 'google/apis/calendar_v3'
4
+ require 'googleauth'
5
+ require 'googleauth/stores/file_token_store'
6
+
7
+ # :title: Googlecal
8
+ module Googlecal
9
+ # :title: Base
10
+ class Base
11
+ attr_accessor :credentials, :default_calendar
12
+
13
+ # TODO: not sure what this is for, needs documentation
14
+ OOB_URL = 'urn:ietf:wg:oauth:2.0:oob'
15
+
16
+ # Initialize a new googlecal instance and authenticate with google with file paths
17
+ #
18
+ # ==== Attributes
19
+ #
20
+ # * +:application_name:+ - Name of application in gooogle console that you need to setup
21
+ # * +:authenticate_with_env:+ - Optionally authenticate with enviroment variables instead of client_secrets_path
22
+ # * +:credentials_path:+ - The file path to loading credentials path
23
+ # * +:client_secrets_path:+ - The file path to json file holding client secrets
24
+ # * +:scope:+ -The access scope for the use of the google api session
25
+ def initialize(application_name,
26
+ authenticate_with_env = false,
27
+ credentials_path = File.join(Dir.home, '.credentials',"calendar-ruby-quickstart.yaml"),
28
+ client_secrets_path = 'client_secret.json',
29
+ scope = Google::Apis::CalendarV3::AUTH_CALENDAR)
30
+ # authenticate with google
31
+ if authenticate_with_env
32
+ # set credentials
33
+ @credentials = authorize_with_env(scope)
34
+ else
35
+ # set credentials
36
+ @credentials = authorize(credentials_path, client_secrets_path, scope)
37
+ end
38
+ @calendar_service = setup_calendar_service(application_name, @credentials)
39
+ end
40
+
41
+ def events(calendar_id = 'primary', **opts)
42
+ @calendar_service.list_events(calendar_id,
43
+ max_results: 10)
44
+ end
45
+
46
+ def create_event(calendar_id = 'primary', **opts)
47
+ event = Google::Apis::CalendarV3::Event.new(
48
+ summary: opts[:summary] || '',
49
+ location: opts[:location] || '',
50
+ start: {
51
+ date_time: Time.now.iso8601,
52
+ time_zone: 'America/Los_Angeles',
53
+ },
54
+ end: {
55
+ date_time: (Time.now + 10*60).iso8601,
56
+ time_zone: 'America/Los_Angeles',
57
+ }
58
+ )
59
+ result = @calendar_service.insert_event(calendar_id, event)
60
+ return result
61
+ end
62
+
63
+ # Delete an even from a calendar by event id
64
+ #
65
+ # ==== Attributes
66
+ #
67
+ # * +:calendar_id:+ - Unique id of calendar
68
+ # * +:event_id:+ - Unique id of event to be deleted
69
+ def delete_event(calendar_id = 'primary', event_id)
70
+ result = @calendar_service.delete_event(calendar_id, event_id)
71
+ return result
72
+ end
73
+
74
+ # Get an event by event id
75
+ #
76
+ # ==== Attributes
77
+ #
78
+ # * +:calendar_id:+ - Unique id of calendar
79
+ # * +:event_id:+ - Unique id of event
80
+ # TODO: for some reason this part is not working with some of the tests i have tried
81
+ # with it
82
+ def get_event(calendar_id = 'primary', event_id)
83
+ result = @calendar_service.get_acl(calendar_id, event_id)
84
+ return result
85
+ end
86
+
87
+ private
88
+
89
+ # Authenticate with google with file paths and a scope
90
+ #
91
+ # ==== Attributes
92
+ #
93
+ # * +:credentials_path:+ - The file path to loading credentials path
94
+ # * +:client_secrets_path:+ - The file path to json file holding client secrets
95
+ # * +:scope:+ - The access scope for the use of the google api session
96
+ def authorize(credentials_path, client_secrets_path, scope)
97
+ FileUtils.mkdir_p(File.dirname(credentials_path))
98
+ client_id = Google::Auth::ClientId.from_file(client_secrets_path)
99
+ token_store = Google::Auth::Stores::FileTokenStore.new(file: credentials_path)
100
+ authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
101
+ user_id = 'default'
102
+ credentials = authorizer.get_credentials(user_id)
103
+ # check if loaded credentials exist
104
+ if credentials.nil?
105
+ url = authorizer.get_authorization_url(base_url: OOB_URL)
106
+ # user must verify application
107
+ puts "Open the following url in the browser"
108
+ puts url
109
+ code = gets
110
+ credentials = authorizer.get_and_store_credentials_from_code(
111
+ user_id: user_id,
112
+ code: code,
113
+ base_url: OOB_URL
114
+ )
115
+ end
116
+ # return the produced credentials
117
+ return credentials
118
+ end
119
+
120
+ # Authenticate with enviroment variables
121
+ #
122
+ # ==== Attributes
123
+ #
124
+ # * +:credentials_path:+ - The file path to store the credentials
125
+ # * +:scope:+ - The access scope for the use of the google api session
126
+ def authorize_with_env(scope)
127
+ FileUtils.mkdir_p(File.dirname(ENV['GCAL_TOKEN_STORE_PATH']))
128
+ # get values for env varibales
129
+ client_id = Google::Auth::ClientId.new(ENV['GCAL_CLIENT_ID'], ENV['GCAL_CLIENT_SECRET'])
130
+ # setup token store for the file
131
+ token_store = Google::Auth::Stores::FileTokenStore.new(file: ENV['GCAL_TOKEN_STORE_PATH'])
132
+ authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
133
+ user_id = 'default'
134
+ credentials = authorizer.get_credentials(user_id)
135
+ # check if loaded credentials exist
136
+ if credentials.nil?
137
+ url = authorizer.get_authorization_url(base_url: OOB_URL)
138
+ # user must verify application
139
+ puts "Open the following url in the browser"
140
+ puts url
141
+ code = gets
142
+ credentials = authorizer.get_and_store_credentials_from_code(
143
+ user_id: user_id,
144
+ code: code,
145
+ base_url: OOB_URL
146
+ )
147
+ end
148
+ # return the produced credentials
149
+ return credentials
150
+ end
151
+
152
+ # Setup calendar service for a session
153
+ #
154
+ # ==== Attributes
155
+ #
156
+ # * +:application_name:+ - Name of application setup in google console
157
+ # * +:credentials:+ - User authentication credentials
158
+ def setup_calendar_service(application_name, credentials)
159
+ service = Google::Apis::CalendarV3::CalendarService.new
160
+ service.client_options.application_name = application_name
161
+ service.authorization = credentials
162
+ # return service once it is setup
163
+ return service
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,3 @@
1
+ module Googlecal
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: googlecal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Austin M Crane
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: google-api-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Simple wrapper around google calendar api
84
+ email:
85
+ - austin.crane@ennovar.wichita.edu
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".DS_Store"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - googlecal.gemspec
101
+ - lib/googlecal.rb
102
+ - lib/googlecal/version.rb
103
+ homepage: http://github.com
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.1
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Simple wrapper around google calendar api
126
+ test_files: []