lotus_notes_calendar 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2@lotus_notes_calendar --create
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'nokogiri'
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "shoulda", ">= 0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.0"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ nokogiri (1.5.0)
10
+ rake (0.9.2)
11
+ rcov (0.9.10)
12
+ shoulda (2.11.3)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.0.0)
19
+ jeweler (~> 1.6.0)
20
+ nokogiri
21
+ rcov
22
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 David Radcliffe
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.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = lotus_notes_calendar
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to lotus_notes_calendar
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 David Radcliffe. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "lotus_notes_calendar"
18
+ gem.homepage = "http://github.com/dwradcliffe/lotus_notes_calendar"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Read and parse Lotus Notes calendars}
21
+ gem.description = %Q{Given a Lotus Notes calendar url, parse events into ruby class. Includes basic query options.}
22
+ gem.email = "david@etchdev.com"
23
+ gem.authors = ["David Radcliffe"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "lotus_notes_calendar #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1.pre
@@ -0,0 +1,2 @@
1
+ require 'lotus_notes_calendar/calendar'
2
+ require 'lotus_notes_calendar/event'
@@ -0,0 +1,68 @@
1
+ require 'nokogiri'
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ module LotusNotesCalendar
6
+ class Calendar
7
+
8
+ attr_reader :name, :url
9
+
10
+ def initialize(url, name = "")
11
+ @name = name
12
+ @url = url
13
+ @results = {}
14
+ end
15
+
16
+ def find(id)
17
+ url = "#{@url}/#{id}?OpenDocument"
18
+ return @results[url] if @results.has_key?(url)
19
+ doc = Nokogiri::HTML(open_url(url))
20
+ event = Event.from_html(self, id, doc)
21
+ @results[url] = event
22
+ return event
23
+ end
24
+
25
+ def all
26
+ where
27
+ end
28
+
29
+ def where(options = {})
30
+ url = build_url(options)
31
+ return @results[url] if @results.has_key?(url)
32
+ doc = Nokogiri::XML(open_url(url))
33
+ events = []
34
+ doc.xpath('//viewentries/viewentry').each do |event_xml|
35
+ events << Event.from_xml(self, event_xml)
36
+ end
37
+ @results[url] = events
38
+ return events
39
+ end
40
+
41
+ private
42
+ def build_url(options = {})
43
+ url = "#{@url}?ReadViewEntries&PreFormat"
44
+ if options[:start] and options[:end]
45
+ url += "&KeyType=time"
46
+ url += "&StartKey=#{options[:start]}"
47
+ url += "&UntilKey=#{options[:end]}"
48
+ elsif options[:date]
49
+ url += "&Date=#{options[:date]}"
50
+ end
51
+ url
52
+ end
53
+ def open_url(url)
54
+ begin
55
+ Rails.logger.info url
56
+ uri = URI.parse(url)
57
+ http = Net::HTTP.new(uri.host, uri.port)
58
+ http.use_ssl = uri.is_a? URI::HTTPS
59
+ # http.ca_file = "/etc/ssl/certs/ca-certificate.crt"
60
+ request = Net::HTTP::Get.new(uri.request_uri)
61
+ http.request(request).body
62
+ rescue Errno::ETIMEDOUT
63
+ ""
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,59 @@
1
+ module LotusNotesCalendar
2
+ class Event
3
+
4
+ attr_accessor :id, :at, :text, :calendar
5
+
6
+
7
+ def self.from_xml(calendar, xml_node)
8
+ # xml_node is 'viewentry' node
9
+
10
+ e = Event.new
11
+ e.id = xml_node['unid']
12
+ e.calendar = calendar
13
+ date_str = xml_node.xpath('entrydata[@name="$6"]/text')[0].content
14
+ e.at = Date.strptime date_str, '%m/%d/%Y'
15
+ e.text = xml_node.xpath('entrydata[@name="$7"]/text')[0].content
16
+
17
+ return e
18
+
19
+ end
20
+
21
+ def self.from_html(calendar, id, html)
22
+
23
+ e = Event.new
24
+ e.id = id
25
+ e.calendar = calendar
26
+ next_attr = nil
27
+
28
+ html.xpath('//html/body/form/table/tr/td/font').each do |el|
29
+
30
+ if next_attr.nil?
31
+ case el.content
32
+ when "Date"
33
+ next_attr = :at
34
+ when "Description"
35
+ next_attr = :text
36
+ end
37
+ else
38
+ case next_attr
39
+ when :at
40
+ e.at = Date.strptime el.content, '%m/%d/%Y'
41
+ when :text
42
+ e.text = el.content
43
+ end
44
+ next_attr = nil
45
+ end
46
+
47
+ end
48
+
49
+ # e.id = xml_node['unid']
50
+ # date_str = xml_node.xpath('entrydata[@name="$6"]/text')[0].content
51
+ # e.at = Date.strptime date_str, '%m/%d/%Y'
52
+ # e.text = xml_node.xpath('entrydata[@name="$7"]/text')[0].content
53
+
54
+ return e
55
+
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{lotus_notes_calendar}
8
+ s.version = "0.0.1.pre"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{David Radcliffe}]
12
+ s.date = %q{2012-01-17}
13
+ s.description = %q{Given a Lotus Notes calendar url, parse events into ruby class. Includes basic query options.}
14
+ s.email = %q{david@etchdev.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rvmrc",
22
+ ".travis.yml",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/lotus_notes_calendar.rb",
30
+ "lib/lotus_notes_calendar/calendar.rb",
31
+ "lib/lotus_notes_calendar/event.rb",
32
+ "lotus_notes_calendar.gemspec",
33
+ "test/helper.rb",
34
+ "test/test_lotus_notes_calendar.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/dwradcliffe/lotus_notes_calendar}
37
+ s.licenses = [%q{MIT}]
38
+ s.require_paths = [%q{lib}]
39
+ s.rubygems_version = %q{1.8.8}
40
+ s.summary = %q{Read and parse Lotus Notes calendars}
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
47
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
50
+ s.add_development_dependency(%q<rcov>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<nokogiri>, [">= 0"])
53
+ s.add_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
56
+ s.add_dependency(%q<rcov>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<nokogiri>, [">= 0"])
60
+ s.add_dependency(%q<shoulda>, [">= 0"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
63
+ s.add_dependency(%q<rcov>, [">= 0"])
64
+ end
65
+ end
66
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'lotus_notes_calendar'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+
3
+ class TestLotusNotesCalendar < Test::Unit::TestCase
4
+
5
+ should "get current events" do
6
+ calendar = LotusNotesCalendar::Calendar.new("https://harmony.mcsc.k12.in.us/msstudent.nsf/school+calendar")
7
+ results = calendar.where
8
+ assert_equal 26, results.count
9
+ assert_equal "7th Gr. First Football Practice - 9-11am", results[0].text
10
+ assert_equal "Monday, Aug 1", results[0].at.strftime('%A, %b %e')
11
+ end
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lotus_notes_calendar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - David Radcliffe
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-17 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: &70357415994860 !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: *70357415994860
25
+ - !ruby/object:Gem::Dependency
26
+ name: shoulda
27
+ requirement: &70357415993820 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70357415993820
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70357415992680 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70357415992680
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &70357415991580 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70357415991580
58
+ - !ruby/object:Gem::Dependency
59
+ name: rcov
60
+ requirement: &70357415990700 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70357415990700
69
+ description: Given a Lotus Notes calendar url, parse events into ruby class. Includes
70
+ basic query options.
71
+ email: david@etchdev.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - LICENSE.txt
76
+ - README.rdoc
77
+ files:
78
+ - .document
79
+ - .rvmrc
80
+ - .travis.yml
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.rdoc
85
+ - Rakefile
86
+ - VERSION
87
+ - lib/lotus_notes_calendar.rb
88
+ - lib/lotus_notes_calendar/calendar.rb
89
+ - lib/lotus_notes_calendar/event.rb
90
+ - lotus_notes_calendar.gemspec
91
+ - test/helper.rb
92
+ - test/test_lotus_notes_calendar.rb
93
+ homepage: http://github.com/dwradcliffe/lotus_notes_calendar
94
+ licenses:
95
+ - MIT
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ segments:
107
+ - 0
108
+ hash: -301071999928766116
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>'
113
+ - !ruby/object:Gem::Version
114
+ version: 1.3.1
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.8
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Read and parse Lotus Notes calendars
121
+ test_files: []