Class: ICloudReader
- Inherits:
-
Object
- Object
- ICloudReader
- Defined in:
- lib/icloud-reader.rb,
lib/icloud-reader/version.rb
Constant Summary collapse
- PRINCIPAL_URL_XML =
%Q{<A:propfind xmlns:A='DAV:'> <A:prop> <A:current-user-principal/> </A:prop> </A:propfind> }
- CALENDARS_XML =
%Q{ <A:propfind xmlns:A='DAV:'> <A:prop> <A:displayname/> </A:prop> </A:propfind> }
- VERSION =
"1.0.0"
Instance Attribute Summary collapse
-
#calendars ⇒ Object
readonly
Returns the value of attribute calendars.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Instance Method Summary collapse
- #base_calendars_url ⇒ Object
- #base_contacts_url ⇒ Object
- #calendars_url ⇒ Object
- #contacts_url ⇒ Object
-
#initialize(options = {}) ⇒ ICloudReader
constructor
A new instance of ICloudReader.
- #load_calendars ⇒ Object
- #load_user_id ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ICloudReader
Returns a new instance of ICloudReader.
25 26 27 28 29 30 31 32 |
# File 'lib/icloud-reader.rb', line 25 def initialize( = {}) @server_number = [:server_number] || 1 @client = HTTPClient.new @username = [:username] @password = [:password] @user_id = load_user_id @calendars = load_calendars end |
Instance Attribute Details
#calendars ⇒ Object (readonly)
Returns the value of attribute calendars.
23 24 25 |
# File 'lib/icloud-reader.rb', line 23 def calendars @calendars end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
23 24 25 |
# File 'lib/icloud-reader.rb', line 23 def user_id @user_id end |
Instance Method Details
#base_calendars_url ⇒ Object
34 35 36 |
# File 'lib/icloud-reader.rb', line 34 def base_calendars_url "https://p0#{@server_number}-caldav.icloud.com" end |
#base_contacts_url ⇒ Object
38 39 40 |
# File 'lib/icloud-reader.rb', line 38 def base_contacts_url "https://p0#{@server_number}-contacts.icloud.com" end |
#calendars_url ⇒ Object
42 43 44 |
# File 'lib/icloud-reader.rb', line 42 def calendars_url URI.join(base_calendars_url, "#{user_id}/calendars/").to_s end |
#contacts_url ⇒ Object
46 47 48 |
# File 'lib/icloud-reader.rb', line 46 def contacts_url URI.join(base_contacts_url, "#{user_id}/carddavhome/card/").to_s end |
#load_calendars ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/icloud-reader.rb', line 55 def load_calendars document = xml_request(calendars_url, CALENDARS_XML) calendars = {} document.search("response").each do |response| path = response.search("href").first.text url = URI.join(calendars_url, path) displayName = response.search("displayname").first calendars[displayName.text] = url.to_s if displayName end calendars end |
#load_user_id ⇒ Object
50 51 52 53 |
# File 'lib/icloud-reader.rb', line 50 def load_user_id document = xml_request(base_calendars_url, PRINCIPAL_URL_XML) document.search("current-user-principal href").first.text.split("/")[1] end |