Class: CloudKit

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cloud_kit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token, container, environment = "production", database = "public", version = 1) ⇒ CloudKit

Returns a new instance of CloudKit.



16
17
18
19
20
21
22
# File 'lib/cloud_kit.rb', line 16

def initialize(api_token, container, environment = "production", database = "public", version = 1)
  @api_token = api_token
  @container = container
  @environment = environment
  @database = database
  @version = version
end

Instance Attribute Details

#session_token=(value) ⇒ Object (writeonly)

debug_output $stdout



14
15
16
# File 'lib/cloud_kit.rb', line 14

def session_token=(value)
  @session_token = value
end

Instance Method Details

#lookup(record_names, user_options = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/cloud_kit.rb', line 47

def lookup(record_names, user_options = {})
  records = []
  record_names.each do |record_name|
    records << {:recordName => record_name}
  end
  
  options = {:body => {:records => records}.to_json, :query => auth_options}
  options.merge! user_options
  self.class.post("#{uri_base}/records/lookup", options)    
end

#modify(operations, user_options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cloud_kit.rb', line 24

def modify(operations, user_options = {})    
  options = {:body => {:operations => operations}.to_json, :query => auth_options}
  options.merge! user_options
  response = self.class.post("#{uri_base}/records/modify", options)
  
  # Requires authentication
  if response.code == 421
    puts "Authentication required: #{response.parsed_response["redirectURL"]}"
  end
  
  response
end

#query(record_type, filter_by = nil, sort_by = nil, user_options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/cloud_kit.rb', line 37

def query(record_type, filter_by = nil, sort_by = nil, user_options = {})
  query_options = {:recordType => record_type}
  query_options[:filterBy] = filter_by if filter_by
  query_options[:sortBy] = sort_by if sort_by
  
  options = {:body => {:query => query_options}.to_json, :query => auth_options}
  options.merge! user_options
  self.class.post("#{uri_base}/records/query", options)    
end