caly 0.0.0

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
+ SHA256:
3
+ metadata.gz: 945baa4c6e37c1db04ff8c816f41043aaba3d97b5e1cafcf74075ce44b0cbf49
4
+ data.tar.gz: 480b5c3b07087fc3109672b8022609e9075a52b894c2a82305651ed020a52ad4
5
+ SHA512:
6
+ metadata.gz: 6f1fc8b1328a3fe5b44735ab251e48de461f6dccacd5ecfde4a9ea6aea4ce78135b2e89e3f29917259b7ec410b8a206d8f9431a6dfcf75ba3f3f1905a6cd5345
7
+ data.tar.gz: 62a2de9963b1d22bd77033b9894f92ffb08bd1738804aefe255c4ec2de187473f3aa3b883710665289b3ed19d864cb2d80017f228be9dd6fb53c0b85bf706c7a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2024 lucashudson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Caly - One API, any Calendar
2
+ [![Coverage](badge.svg)](https://github.com/Lucas-Hudson/caly)
3
+
4
+ Caly unifies endpoints and object data models across many calendar APIs, helping you instantly integrate your app with
5
+ [Google Calendar](https://developers.google.com/calendar/api/guides/overview) and
6
+ [Microsoft Outlook](https://learn.microsoft.com/en-us/graph/api/resources/calendar?view=graph-rest-1.0) in one go.
7
+
8
+ ## Installation
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem "caly"
13
+ ```
14
+
15
+ And then execute:
16
+ ```bash
17
+ $ bundle
18
+ ```
19
+
20
+ Or install it yourself as:
21
+ ```bash
22
+ $ gem install caly
23
+ ```
24
+
25
+ ## Usage
26
+ ```ruby
27
+ account = Caly::Account.new(provider, token)
28
+
29
+ account.list_calendars #=> Array of Caly::Calendar instances
30
+ ```
31
+
32
+ ## Contributing
33
+ Contribution directions go here.
34
+
35
+ ## License
36
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,26 @@
1
+ module Caly
2
+ class Account
3
+ attr_reader :provider, :token
4
+
5
+ def initialize(provider, token)
6
+ unless Caly::AVAILABLE_PROVIDERS.include?(provider.to_sym)
7
+ raise ArgumentError.new("#{provider} isn't a supported provider.")
8
+ end
9
+
10
+ @provider = provider
11
+ @token = token
12
+ end
13
+
14
+ def self.caly_provider_for(name)
15
+ Caly::Providers.const_get(Util.classify(name))
16
+ end
17
+
18
+ def caly_provider
19
+ @caly_provider ||= self.class.caly_provider_for(provider).new(token)
20
+ end
21
+
22
+ def list_calendars
23
+ caly_provider.list_calendars
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ module Caly
2
+ class Calendar
3
+ attr_reader :id, :name, :description, :location, :timezone, :raw
4
+
5
+ def initialize(id: nil, name: nil, description: nil, location: nil, timezone: nil, raw: nil)
6
+ @id = id
7
+ @name = name
8
+ @description = description
9
+ @location = location
10
+ @timezone = timezone
11
+ @raw = raw
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ module Caly
2
+ class Client
3
+ def initialize(url, headers)
4
+ @url = url
5
+ @headers = headers
6
+ end
7
+
8
+ def execute_request(method, path)
9
+ uri = URI.parse([@url, path].join("/"))
10
+
11
+ request = Net::HTTPGenericRequest.new(
12
+ method.to_s.upcase,
13
+ false,
14
+ true,
15
+ uri,
16
+ @headers
17
+ )
18
+
19
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
20
+ http.request(request)
21
+ end
22
+
23
+ JSON.parse(response.body).merge("code" => response.code)
24
+ end
25
+ end
26
+ end
data/lib/caly/error.rb ADDED
@@ -0,0 +1,10 @@
1
+ module Caly
2
+ class Error
3
+ attr_reader :message, :code
4
+
5
+ def initialize(message:, code:)
6
+ @message = message
7
+ @code = code
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module Caly
2
+ module Providers
3
+ class Base
4
+ extend Forwardable
5
+
6
+ def_delegator :@client, :execute_request
7
+
8
+ def initialize(token)
9
+ @headers = {Authorization: "Bearer #{token}", ContentType: "application/json"}
10
+ @client = Caly::Client.new(@url, @headers)
11
+ end
12
+
13
+ private
14
+
15
+ def error_from(response)
16
+ ::Caly::Error.new(message: response.dig("error", "message"), code: response.dig("code"))
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ module Caly
2
+ module Providers
3
+ class GoogleOauth2 < Base
4
+ def initialize(token)
5
+ @url = "https://www.googleapis.com/calendar/v3"
6
+ super
7
+ end
8
+
9
+ def list_calendars
10
+ response = execute_request(:get, "users/me/calendarList")
11
+
12
+ return error_from(response) unless response["code"] == "200"
13
+
14
+ response["items"].map do |c|
15
+ if c["accessRole"] == "owner"
16
+ Caly::Calendar.new(id: c["id"], name: c["summary"], description: c["description"], location: c["location"], timezone: c["timeZone"], raw: c)
17
+ end
18
+ end.compact
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ module Caly
2
+ module Providers
3
+ class MicrosoftGraph < Base
4
+ def initialize(token)
5
+ @url = "https://graph.microsoft.com/v1.0/me"
6
+ super
7
+ end
8
+
9
+ def list_calendars
10
+ response = execute_request(:get, "calendars")
11
+
12
+ return error_from(response) unless response["code"] == "200"
13
+
14
+ response["value"].map do |c|
15
+ Caly::Calendar.new(id: c["id"], name: c["name"], raw: c) if c["canEdit"] == true
16
+ end.compact
17
+ end
18
+ end
19
+ end
20
+ end
data/lib/caly/util.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Caly
2
+ class Util
3
+ def self.classify(str)
4
+ str.to_s.split("_").collect!(&:capitalize).join
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Caly
2
+ VERSION = "0.0.0"
3
+ end
data/lib/caly.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "net/http"
2
+ require "json"
3
+ require "forwardable"
4
+
5
+ require "caly/version"
6
+
7
+ require "caly/providers/base"
8
+ require "caly/providers/google_oauth2"
9
+ require "caly/providers/microsoft_graph"
10
+
11
+ require "caly/account"
12
+ require "caly/calendar"
13
+ require "caly/client"
14
+ require "caly/error"
15
+
16
+ require "caly/util"
17
+
18
+ module Caly
19
+ AVAILABLE_PROVIDERS = [:google_oauth2, :microsoft_graph].freeze
20
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: caly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Hudson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-04-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Integrate easily with Google Calendar and Microsoft Outlook calendars.
14
+ email: lucashudson.contact@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - MIT-LICENSE
20
+ - README.md
21
+ - lib/caly.rb
22
+ - lib/caly/account.rb
23
+ - lib/caly/calendar.rb
24
+ - lib/caly/client.rb
25
+ - lib/caly/error.rb
26
+ - lib/caly/providers/base.rb
27
+ - lib/caly/providers/google_oauth2.rb
28
+ - lib/caly/providers/microsoft_graph.rb
29
+ - lib/caly/util.rb
30
+ - lib/caly/version.rb
31
+ homepage: https://rubygems.org/gems/caly
32
+ licenses:
33
+ - MIT
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.2.33
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Caly - One API, any Calendar
54
+ test_files: []