cronofy 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4720b62138db700e8be2fd82e56db5057a50451f
4
+ data.tar.gz: cd34dda9e376ccad7547377c0e9c5eaf0208996c
5
+ SHA512:
6
+ metadata.gz: 59bc15cefa54bcd6526de3354877f8faddbc57cf57d3772b8394623a4ff0f631e7cd09d41cc7b04799b923848c8f5cda4c2b61f78cefe5698b0eef8b418c1c85
7
+ data.tar.gz: e25078d609ad41124b6dee01cf6bb6cf7f1e1c0c621bbc85ab69fef9892e842e54b5fb13e76346ec40dd34dc8a8c53b19bdde3f889aafee6429b700cbf817c54
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sergii Paryzhskyi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Cronofy
2
+
3
+ [Cronofy](http://www.cronofy.com) - one API for all the calendars (Google, Outlook, iCloud, Exchange). This gem is an interface for easy use of [Cronofy API](http://www.cronofy.com/developers/api) with Ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cronofy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cronofy
20
+
21
+ ## Usage
22
+
23
+ You have to register on cronofy website and create an application there. You will get a client id and client secret which you will have to pass to initializer. You can also pass a token that you will get later, or leave it blank in case if you don't have it now:
24
+ ```ruby
25
+ cronofy = Cronofy.new('CLIENT_ID', 'CLIENT_SECRET', 'TOKEN')
26
+ ```
27
+
28
+ Generate a link for a user to grant access for his calendars:
29
+ ```ruby
30
+ cronofy.user_auth_link('http://localhost:3000/oauth2/callback')
31
+ ```
32
+
33
+ The specified url is a page on your website that will handle callback and get a code parameter out of it. On a callback you will have a param[:code] that you will need in order to get a token:
34
+ ```ruby
35
+ token = cronofy.get_token_from_code(code, 'http://localhost:3000/oauth2/callback')
36
+ ```
37
+ You can now save a token to pass it later to initializer.
38
+
39
+ Get a list of all the user calendars:
40
+ ```ruby
41
+ cronofy.list_calendars
42
+ ```
43
+
44
+ You will get a list of user's calendars in a json format. The example of such a response:
45
+ ```json
46
+ {
47
+ "calendars":[
48
+ {
49
+ "provider_name":"google",
50
+ "profile_name":"YYYYYYYY@gmail.com",
51
+ "calendar_id":"cal_YYYYYYYY-UNIQUE_CAL_ID_HERE-YYYYYYYY",
52
+ "calendar_name":"Office Calendar",
53
+ "calendar_readonly":false,
54
+ "calendar_deleted":false
55
+ },
56
+ {
57
+ "provider_name":"google",
58
+ "profile_name":"XXXXXXX@gmail.com",
59
+ "calendar_id":"cal_XXXXXXXX-UNIQUE_CAL_ID_HERE-XXXXXXXXX",
60
+ "calendar_name":"Home Calendar",
61
+ "calendar_readonly":false,
62
+ "calendar_deleted":false
63
+ }
64
+ ]
65
+ }
66
+ ```
67
+
68
+ To create/update an event in user's calendar:
69
+ ```ruby
70
+ event_data = {
71
+ event_id: 'uniq-id', # uniq id of event
72
+ summary: 'Event summary',
73
+ description: 'Event description',
74
+ start: Time.now + 60 * 60 * 24, # will be converted to .utc.iso8601 internally,
75
+ end: Time.now + 60 * 60 * 25, # the same convertion here
76
+ location: {
77
+ description: "Meeting room"
78
+ }
79
+ }
80
+ cronofy.create_or_update_event(calendar_id, event_data)
81
+ ```
82
+
83
+ To delete an event from user's calendar:
84
+ ```ruby
85
+ cronofy.delete_event(calendar_id, event_id)
86
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/cronofy.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cronofy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cronofy"
8
+ spec.version = Cronofy::VERSION
9
+ spec.authors = ["Sergii Paryzhskyi"]
10
+ spec.email = ["parizhskiy@gmail.com"]
11
+ spec.summary = %q{Cronofy - one API for all the calendars}
12
+ spec.homepage = "https://github.com/HeeL/cronofy"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_runtime_dependency "oauth2", "~> 1.0"
23
+ end
data/lib/cronofy.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "cronofy/version"
2
+ require "cronofy/auth"
3
+ require "cronofy/response_parser"
4
+
5
+ module Cronofy
6
+ class Cronofy
7
+
8
+ def initialize(client_id, client_secret, token = false)
9
+ @auth = Auth.new(client_id, client_secret, token)
10
+ end
11
+
12
+ def list_calendars
13
+ ResponseParser.new(request(:get, 'calendars')).parse_json
14
+ end
15
+
16
+ def create_or_update_event(calendar_id, event_data)
17
+ event_data[:start] = event_data[:start].utc.iso8601
18
+ event_data[:end] = event_data[:end].utc.iso8601
19
+ request(:post, "calendars/#{calendar_id}/events", event_data)
20
+ end
21
+
22
+ def delete_event(calendar_id, event_id)
23
+ request(:delete, "calendars/#{calendar_id}/events", event_id: event_id)
24
+ end
25
+
26
+ def user_auth_link(redirect_uri)
27
+ @auth.user_auth_link(redirect_uri)
28
+ end
29
+
30
+ def get_token_from_code(code, redirect_uri)
31
+ @auth.get_token_from_code(code, redirect_uri)
32
+ end
33
+
34
+ private
35
+
36
+ def request(method, path, params = {})
37
+ @auth.request.send(method, "/v1/#{path}", params: params)
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,29 @@
1
+ require "oauth2"
2
+
3
+ module Cronofy
4
+ class Auth
5
+ API_URL = 'https://api.cronofy.com'
6
+ APP_URL = 'https://app.cronofy.com'
7
+
8
+ def initialize(client_id, client_secret, token)
9
+ @client = OAuth2::Client.new(client_id, client_secret, site: API_URL)
10
+ @token = token
11
+ end
12
+
13
+ def user_auth_link(redirect_uri)
14
+ url = @client.auth_code.authorize_url(
15
+ :redirect_uri => redirect_uri,
16
+ :response_type => 'code'
17
+ ).gsub(API_URL, APP_URL)
18
+ "#{url}&scope=list_calendars read_events create_event delete_event"
19
+ end
20
+
21
+ def get_token_from_code(code, redirect_uri)
22
+ @client.auth_code.get_token(code, :redirect_uri => redirect_uri).token
23
+ end
24
+
25
+ def request
26
+ @request ||= OAuth2::AccessToken.new(@client, @token)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ require 'json'
2
+
3
+ module Cronofy
4
+ class ResponseParser
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def parse_json
10
+ JSON.parse @response.body
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Cronofy
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cronofy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sergii Paryzhskyi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oauth2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description:
56
+ email:
57
+ - parizhskiy@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - cronofy.gemspec
68
+ - lib/cronofy.rb
69
+ - lib/cronofy/auth.rb
70
+ - lib/cronofy/response_parser.rb
71
+ - lib/cronofy/version.rb
72
+ homepage: https://github.com/HeeL/cronofy
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.5
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Cronofy - one API for all the calendars
96
+ test_files: []