icloud-reader 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/bin/icloud-reader +3 -0
- data/icloud-reader.gemspec +25 -0
- data/lib/icloud-reader.rb +132 -0
- data/lib/icloud-reader/version.rb +3 -0
- metadata +135 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrew Eberbach
|
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,44 @@
|
|
1
|
+
# The iCloud Reader
|
2
|
+
|
3
|
+
Want to use your iCloud accounts with a third-party app (like your android phone or Thunderbird Lightning)? Well, here's a simple tool to figure out what your URLs are.
|
4
|
+
|
5
|
+
This is just a rewrite, in Ruby, of http://icloud.niftyside.com/. Props go there for the original.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'icloud-reader'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install icloud-reader
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
The command is `icloud-reader`
|
24
|
+
|
25
|
+
Without any args:
|
26
|
+
|
27
|
+
Usage:
|
28
|
+
[] [OPTIONS] SUBCOMMAND [ARGS] ...
|
29
|
+
|
30
|
+
Subcommands:
|
31
|
+
calendars list the calendars and their URLs (as YAML)
|
32
|
+
contacts get your CardDAV url
|
33
|
+
|
34
|
+
Options:
|
35
|
+
-s, --server-number SERVER_NUMBER the number of the server to use
|
36
|
+
-h, --help print help
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/icloud-reader
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'icloud-reader/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "icloud-reader"
|
8
|
+
gem.version = ICloudReader::VERSION
|
9
|
+
gem.authors = ["Andrew Eberbach"]
|
10
|
+
gem.email = ["andrew@ebertech.ca"]
|
11
|
+
gem.description = %q{Get your CalDAV and CardDAV urls from iCloud}
|
12
|
+
gem.summary = %q{Get your CalDAV and CardDAV urls from iCloud}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency 'httpclient'
|
21
|
+
gem.add_runtime_dependency 'pry'
|
22
|
+
gem.add_runtime_dependency 'nokogiri'
|
23
|
+
gem.add_runtime_dependency 'clamp'
|
24
|
+
gem.add_runtime_dependency 'highline'
|
25
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'httpclient'
|
3
|
+
require 'clamp'
|
4
|
+
require 'highline'
|
5
|
+
|
6
|
+
class ICloudReader
|
7
|
+
PRINCIPAL_URL_XML =
|
8
|
+
%Q{<A:propfind xmlns:A='DAV:'>
|
9
|
+
<A:prop>
|
10
|
+
<A:current-user-principal/>
|
11
|
+
</A:prop>
|
12
|
+
</A:propfind>
|
13
|
+
}
|
14
|
+
|
15
|
+
CALENDARS_XML =
|
16
|
+
%Q{ <A:propfind xmlns:A='DAV:'>
|
17
|
+
<A:prop>
|
18
|
+
<A:displayname/>
|
19
|
+
</A:prop>
|
20
|
+
</A:propfind>
|
21
|
+
}
|
22
|
+
|
23
|
+
attr_reader :calendars, :user_id
|
24
|
+
|
25
|
+
def initialize(options = {})
|
26
|
+
@server_number = options[:server_number] || 1
|
27
|
+
@client = HTTPClient.new
|
28
|
+
@username = options[:username]
|
29
|
+
@password = options[:password]
|
30
|
+
@user_id = load_user_id
|
31
|
+
@calendars = load_calendars
|
32
|
+
end
|
33
|
+
|
34
|
+
def base_calendars_url
|
35
|
+
"https://p0#{@server_number}-caldav.icloud.com"
|
36
|
+
end
|
37
|
+
|
38
|
+
def base_contacts_url
|
39
|
+
"https://p0#{@server_number}-contacts.icloud.com"
|
40
|
+
end
|
41
|
+
|
42
|
+
def calendars_url
|
43
|
+
URI.join(base_calendars_url, "#{user_id}/calendars/").to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
def contacts_url
|
47
|
+
URI.join(base_contacts_url, "#{user_id}/carddavhome/card/").to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
def load_user_id
|
51
|
+
document = xml_request(base_calendars_url, PRINCIPAL_URL_XML)
|
52
|
+
document.search("current-user-principal href").first.text.split("/")[1]
|
53
|
+
end
|
54
|
+
|
55
|
+
def load_calendars
|
56
|
+
document = xml_request(calendars_url, CALENDARS_XML)
|
57
|
+
calendars = {}
|
58
|
+
|
59
|
+
document.search("response").each do |response|
|
60
|
+
path = response.search("href").first.text
|
61
|
+
url = URI.join(calendars_url, path)
|
62
|
+
displayName = response.search("displayname").first
|
63
|
+
calendars[displayName.text] = url.to_s if displayName
|
64
|
+
end
|
65
|
+
|
66
|
+
calendars
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def xml_request(*args)
|
72
|
+
response = request(*args)
|
73
|
+
raise "Authentication failed! Check your username and password! #{response.code}" if response.code == 401
|
74
|
+
raise "Invalid Response! I have no idea how to handle this... #{response.code}" unless response.code == 207
|
75
|
+
Nokogiri::XML(response.body)
|
76
|
+
end
|
77
|
+
|
78
|
+
def request(url, xml)
|
79
|
+
domain = url
|
80
|
+
@client.set_auth(domain, @username, @password)
|
81
|
+
result = @client.request("PROPFIND", url, nil, xml, headers)
|
82
|
+
result
|
83
|
+
end
|
84
|
+
|
85
|
+
def headers
|
86
|
+
{
|
87
|
+
"Depth" => "1",
|
88
|
+
"Content-Type" => "text/xml; charset='UTF-8'"
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
class ICloudReaderCommand < Clamp::Command
|
95
|
+
option ["-s", "--server-number"], "SERVER_NUMBER", "the number of the server to use", :default_value => "8"
|
96
|
+
|
97
|
+
def reader
|
98
|
+
unless @reader
|
99
|
+
username = ask_for_username
|
100
|
+
password = ask_for_password
|
101
|
+
@reader = ICloudReader.new(:server_number => server_number, :username => username, :password => password)
|
102
|
+
end
|
103
|
+
@reader
|
104
|
+
end
|
105
|
+
|
106
|
+
def asker
|
107
|
+
HighLine.new
|
108
|
+
end
|
109
|
+
|
110
|
+
def ask_for_username
|
111
|
+
asker.ask("Username: ")
|
112
|
+
end
|
113
|
+
|
114
|
+
def ask_for_password
|
115
|
+
asker.ask("Password (will be masked with x's): ") { |q| q.echo = "x" }
|
116
|
+
end
|
117
|
+
|
118
|
+
subcommand "calendars", "list the calendars and their URLs (as YAML)" do
|
119
|
+
def execute
|
120
|
+
puts reader.calendars.to_yaml
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
subcommand "contacts", "get your CardDAV url" do
|
125
|
+
def execute
|
126
|
+
puts reader.contacts_url
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: icloud-reader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Eberbach
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httpclient
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: pry
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: nokogiri
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: clamp
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: highline
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Get your CalDAV and CardDAV urls from iCloud
|
95
|
+
email:
|
96
|
+
- andrew@ebertech.ca
|
97
|
+
executables:
|
98
|
+
- icloud-reader
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- bin/icloud-reader
|
108
|
+
- icloud-reader.gemspec
|
109
|
+
- lib/icloud-reader.rb
|
110
|
+
- lib/icloud-reader/version.rb
|
111
|
+
homepage: ''
|
112
|
+
licenses: []
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 1.8.23
|
132
|
+
signing_key:
|
133
|
+
specification_version: 3
|
134
|
+
summary: Get your CalDAV and CardDAV urls from iCloud
|
135
|
+
test_files: []
|