cloud_kit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/cloud_kit.rb +57 -0
- data/lib/create_operation.rb +20 -0
- data/lib/modify_operation.rb +23 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8e1e25b568685009c05f6578023b56065b611196
|
4
|
+
data.tar.gz: 7c718fd1adcf65837d6ded53561264b4a8bedc13
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 362c187c54063b80e8213e4b8d518bedab73444728e0574feeed8062c456c304bfb0cd96bae1bd7875a3e24be0e5417a78a138a2c74947749b99061d23ae1899
|
7
|
+
data.tar.gz: 081ea700336e399dcd83fa3b6a068254b8624b3dade2082b6d377963628a7dc230314092ed07fb470471c4b1226707bf9cf3b100f1d91d44fa9b09b493bf4ddb
|
data/lib/cloud_kit.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'create_operation.rb'
|
3
|
+
require 'modify_operation.rb'
|
4
|
+
|
5
|
+
class CloudKit
|
6
|
+
include HTTParty
|
7
|
+
|
8
|
+
base_uri 'https://api.apple-cloudkit.com'
|
9
|
+
format :json
|
10
|
+
headers 'Content-Type' => 'application/json'
|
11
|
+
|
12
|
+
#debug_output $stdout
|
13
|
+
|
14
|
+
attr_writer :session_token
|
15
|
+
|
16
|
+
def initialize(api_token, container, environment = "production", database = "public", version = 1)
|
17
|
+
@api_token = api_token
|
18
|
+
@container = container
|
19
|
+
@environment = environment
|
20
|
+
@database = database
|
21
|
+
@version = version
|
22
|
+
end
|
23
|
+
|
24
|
+
def modify(operations, user_options = {})
|
25
|
+
options = {:body => {:operations => operations}.to_json, :query => auth_options}
|
26
|
+
options.merge! user_options
|
27
|
+
response = self.class.post("#{uri_base}/records/modify", options)
|
28
|
+
|
29
|
+
# Requires authentication
|
30
|
+
if response.code == 421
|
31
|
+
puts "Authentication required: #{response.parsed_response["redirectURL"]}"
|
32
|
+
end
|
33
|
+
|
34
|
+
response
|
35
|
+
end
|
36
|
+
|
37
|
+
def query(record_type, filter_by = nil, sort_by = nil, user_options = {})
|
38
|
+
|
39
|
+
query_options = {:recordType => record_type}
|
40
|
+
query_options[:filterBy] = filter_by if filter_by
|
41
|
+
query_options[:sortBy] = sort_by if sort_by
|
42
|
+
|
43
|
+
options = {:body => {:query => query_options}.to_json, :query => auth_options}
|
44
|
+
options.merge! user_options
|
45
|
+
self.class.post("#{uri_base}/records/query", options)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def uri_base
|
50
|
+
"/database/#{@version}/#{@container}/#{@environment}/#{@database}"
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def auth_options
|
55
|
+
{"ckAPIToken" => @api_token, "ckSession" => @session_token}
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class CreateOperation
|
2
|
+
|
3
|
+
def initialize(record_type, fields)
|
4
|
+
@record_type = record_type
|
5
|
+
@fields = fields
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_json(options = {})
|
9
|
+
hash = {operationType: "create"}
|
10
|
+
record = {recordType: @record_type}
|
11
|
+
fields = {}
|
12
|
+
@fields.each_pair do |k,v|
|
13
|
+
fields[k] = {value: v}
|
14
|
+
end
|
15
|
+
record[:fields] = fields
|
16
|
+
hash[:record] = record
|
17
|
+
hash.to_json
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class ModifyOperation
|
2
|
+
|
3
|
+
def initialize(record_type, fields = {}, record_name = nil, force = false, recordChangeTag = nil)
|
4
|
+
@record_type = record_type
|
5
|
+
@record_name = record_name
|
6
|
+
@record_change_tag = recordChangeTag
|
7
|
+
@fields = fields
|
8
|
+
@operationType = force ? "forceUpdate" : "update"
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_json(options = {})
|
12
|
+
hash = {operationType: @operationType}
|
13
|
+
record = {recordType: @record_type, recordName: @record_name, recordChangeTag: @record_change_tag}
|
14
|
+
fields = {}
|
15
|
+
@fields.each_pair do |k,v|
|
16
|
+
fields[k] = {value: v}
|
17
|
+
end
|
18
|
+
record[:fields] = fields
|
19
|
+
hash[:record] = record
|
20
|
+
hash.to_json
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloud_kit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Brooke-Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A gem which provides initial Ruby bindings for Apple's CloudKit
|
56
|
+
email: matt@futureworkshops.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/cloud_kit.rb
|
62
|
+
- lib/create_operation.rb
|
63
|
+
- lib/modify_operation.rb
|
64
|
+
homepage: http://rubygems.org/gems/cloud_kit
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.4.5.1
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: CloudKit Ruby bindings
|
88
|
+
test_files: []
|