gcal-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1 @@
1
+ v0.1.0 first release
data/LICENSE ADDED
File without changes
data/Manifest ADDED
@@ -0,0 +1,9 @@
1
+ CHANGELOG
2
+ LICENSE
3
+ Manifest
4
+ README.rdoc
5
+ Rakefile
6
+ init.rb
7
+ lib/gcal.rb
8
+ lib/gcal/calendar.rb
9
+ lib/gcal/client.rb
data/README.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ == Installation
2
+ $ gem install gcal-ruby
3
+
4
+ == Using
5
+ require 'gcal'
6
+
7
+ client = GCal::Client.new(api_key, api_secret, oauth_token, oauth_secret)
8
+ client.all_calendars # returns all user calendars
9
+ client.all_calendars # returns user owned calendars
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'psych'
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'echoe'
5
+
6
+ Echoe.new('gcal-ruby', '0.1.0') do |p|
7
+ p.description = "Ruby library for Google Calendar API."
8
+ p.url = "http://github.com/23ninja/gcal-ruby"
9
+ p.author = "Iskander Haziev"
10
+ p.email = "gvalmon@gmail.com"
11
+ p.ignore_pattern = ["tmp/*", "script/*"]
12
+ p.runtime_dependencies = ['oauth', 'typhoeus', 'xml-simple']
13
+ end
data/gcal-ruby.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{gcal-ruby}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = [%q{Iskander Haziev}]
9
+ s.date = %q{2011-10-05}
10
+ s.description = %q{Ruby library for Google Calendar API.}
11
+ s.email = %q{gvalmon@gmail.com}
12
+ s.extra_rdoc_files = [%q{CHANGELOG}, %q{LICENSE}, %q{README.rdoc}, %q{lib/gcal.rb}, %q{lib/gcal/calendar.rb}, %q{lib/gcal/client.rb}]
13
+ s.files = [%q{CHANGELOG}, %q{LICENSE}, %q{Manifest}, %q{README.rdoc}, %q{Rakefile}, %q{init.rb}, %q{lib/gcal.rb}, %q{lib/gcal/calendar.rb}, %q{lib/gcal/client.rb}, %q{gcal-ruby.gemspec}]
14
+ s.homepage = %q{http://github.com/23ninja/gcal-ruby}
15
+ s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Gcal-ruby}, %q{--main}, %q{README.rdoc}]
16
+ s.require_paths = [%q{lib}]
17
+ s.rubyforge_project = %q{gcal-ruby}
18
+ s.rubygems_version = %q{1.8.6}
19
+ s.summary = %q{Ruby library for Google Calendar API.}
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ s.add_runtime_dependency(%q<oauth>, [">= 0"])
26
+ s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
27
+ s.add_runtime_dependency(%q<xml-simple>, [">= 0"])
28
+ else
29
+ s.add_dependency(%q<oauth>, [">= 0"])
30
+ s.add_dependency(%q<typhoeus>, [">= 0"])
31
+ s.add_dependency(%q<xml-simple>, [">= 0"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<oauth>, [">= 0"])
35
+ s.add_dependency(%q<typhoeus>, [">= 0"])
36
+ s.add_dependency(%q<xml-simple>, [">= 0"])
37
+ end
38
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'gcal'
data/lib/gcal.rb ADDED
@@ -0,0 +1,4 @@
1
+ module GCal
2
+ require 'gcal/client'
3
+ require 'gcal/calendar'
4
+ end
@@ -0,0 +1,5 @@
1
+ module GCal
2
+ class Calendar
3
+ attr_accessor :id, :title
4
+ end
5
+ end
@@ -0,0 +1,67 @@
1
+ require 'oauth'
2
+ require 'oauth/request_proxy/typhoeus_request'
3
+ require 'xmlsimple'
4
+ module GCal
5
+ class Client
6
+ BASE_URL = 'https://www.google.com'
7
+ API_URL = "#{BASE_URL}/calendar/feeds/default"
8
+
9
+ def initialize(api_key = nil, api_secret = nil, token = nil, secret = nil)
10
+ @api_key, @api_secret = api_key, api_secret
11
+ @client = ::Typhoeus::Hydra.new
12
+ # if api call protected, create token and consumer
13
+ if protected_api_call?
14
+ @consumer = ::OAuth::Consumer.new(api_key, api_secret, :site => BASE_URL)
15
+ @token = ::OAuth::Token.new(token, secret)
16
+ end
17
+ end
18
+
19
+ def call(uri)
20
+ request = ::Typhoeus::Request.new(API_URL + uri)
21
+ authorize_request!(request) if protected_api_call?
22
+ @client.queue(request)
23
+ @client.run
24
+ XmlSimple.xml_in(request.response.body)
25
+ end
26
+
27
+ def all_calendars
28
+ xml = call("/allcalendars/full")
29
+ calendars = []
30
+ xml['entry'].each do |entry|
31
+ calendar = GCal::Calendar.new
32
+ calendar.id = entry['id'][0]
33
+ calendar.title = entry['title'][0]['content']
34
+ calendars << calendar
35
+ end if xml['entry']
36
+ calendars
37
+ end
38
+
39
+ def own_calendars
40
+ xml = call("/owncalendars/full")
41
+ calendars = []
42
+ xml['entry'].each do |entry|
43
+ calendar = GCal::Calendar.new
44
+ calendar.id = entry['id'][0]
45
+ calendar.title = entry['title'][0]['content']
46
+ calendars << calendar
47
+ end if xml['entry']
48
+ calendars
49
+ end
50
+
51
+ protected
52
+ def protected_api_call?
53
+ !@api_key.nil?
54
+ end
55
+
56
+ def authorize_request!(request)
57
+ oauth_helper = ::OAuth::Client::Helper.new(
58
+ request, {
59
+ :consumer => @consumer,
60
+ :token => @token,
61
+ :request_uri => request.url
62
+ }
63
+ )
64
+ request.headers.merge!({"Authorization" => oauth_helper.header})
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gcal-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Iskander Haziev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-05 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oauth
16
+ requirement: &2153447540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2153447540
25
+ - !ruby/object:Gem::Dependency
26
+ name: typhoeus
27
+ requirement: &2153446140 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2153446140
36
+ - !ruby/object:Gem::Dependency
37
+ name: xml-simple
38
+ requirement: &2153445040 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2153445040
47
+ description: Ruby library for Google Calendar API.
48
+ email: gvalmon@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files:
52
+ - CHANGELOG
53
+ - LICENSE
54
+ - README.rdoc
55
+ - lib/gcal.rb
56
+ - lib/gcal/calendar.rb
57
+ - lib/gcal/client.rb
58
+ files:
59
+ - CHANGELOG
60
+ - LICENSE
61
+ - Manifest
62
+ - README.rdoc
63
+ - Rakefile
64
+ - init.rb
65
+ - lib/gcal.rb
66
+ - lib/gcal/calendar.rb
67
+ - lib/gcal/client.rb
68
+ - gcal-ruby.gemspec
69
+ homepage: http://github.com/23ninja/gcal-ruby
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --line-numbers
74
+ - --inline-source
75
+ - --title
76
+ - Gcal-ruby
77
+ - --main
78
+ - README.rdoc
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '1.2'
93
+ requirements: []
94
+ rubyforge_project: gcal-ruby
95
+ rubygems_version: 1.8.6
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Ruby library for Google Calendar API.
99
+ test_files: []