syncano 3.1.1.beta → 3.1.1.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +27 -5
- data/lib/syncano.rb +6 -3
- data/lib/syncano/clients/base.rb +15 -7
- data/lib/syncano/clients/rest.rb +12 -2
- data/lib/syncano/clients/sync.rb +26 -5
- data/lib/syncano/errors.rb +4 -0
- data/lib/syncano/packets/auth.rb +20 -0
- data/lib/syncano/packets/base.rb +6 -0
- data/lib/syncano/query_builder.rb +9 -1
- data/lib/syncano/resources/api_key.rb +64 -2
- data/lib/syncano/resources/collection.rb +54 -0
- data/lib/syncano/resources/folder.rb +54 -0
- data/lib/syncano/resources/project.rb +54 -0
- data/lib/syncano/resources/user.rb +18 -0
- data/lib/syncano/sync_connection.rb +9 -5
- data/lib/syncano/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac6af4d016919012111232a83c25611b78f7dfe5
|
4
|
+
data.tar.gz: c05ac4801c237b661c186a6bbfda7d0f835a65e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15fa18f3ad11ac370beeec7d0ebeccc73bae2e63ea0de668ac2055517229bafab40d66fa44b458daf8a05991d00bb968d3bccee226ef24968f67d92e1798b035
|
7
|
+
data.tar.gz: 2119169c94e58495816e98258ed551f937b44788bb673ab96a254da77c6659d563f9e2b3f08752b338875e1b0900992205d258159ed29ac7f9d7fadb579221b2
|
data/README.md
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# Syncano
|
2
2
|
|
3
|
-
Syncano ruby gem provides communication with Syncano ([www.syncano.com](www.syncano.com)) via HTTPS RESTful interface and TCP sockets.
|
3
|
+
Syncano ruby gem provides communication with Syncano ([www.syncano.com](http://www.syncano.com)) via HTTPS RESTful interface and TCP sockets.
|
4
4
|
|
5
5
|
The full source code can be found on [Github](https://github.com/Syncano/syncano-ruby) - feel free to browse or contribute.
|
6
6
|
|
7
|
-
Click here to learn more about [Syncano](www.syncano.com) or [create an account](https://login.syncano.com/sign_up)!
|
7
|
+
Click here to learn more about [Syncano](http://www.syncano.com) or [create an account](https://login.syncano.com/sign_up)!
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
13
|
-
gem 'syncano'
|
13
|
+
gem 'syncano', '~> 3.1.1.beta2'
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
@@ -18,7 +18,7 @@ And then execute:
|
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
$ gem install syncano
|
21
|
+
$ gem install syncano -v 3.1.1.beta2 --pre
|
22
22
|
|
23
23
|
At the end generate initializer with api key and api instance name:
|
24
24
|
|
@@ -56,6 +56,18 @@ client.disconnect
|
|
56
56
|
```
|
57
57
|
* managing callbacks for handling notifications (it is described later in this document)
|
58
58
|
|
59
|
+
#### User api key
|
60
|
+
|
61
|
+
If you want to use an user api key, you have to pass auth key or username and password to the client's constructor.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
client = Syncano.client(api_key: 'api key', instance_name: 'instance name', auth_key: 'auth key')
|
65
|
+
```
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
client = Syncano.client(api_key: 'api key', instance_name: 'instance name', username: 'username', password: 'password')
|
69
|
+
```
|
70
|
+
|
59
71
|
### Resources
|
60
72
|
|
61
73
|
Syncano gem utilizes an ActiveRecord pattern for managing resources. You can use it in similar way with both type of clients.
|
@@ -85,7 +97,9 @@ Below is a list of all implemented resources with information about what methods
|
|
85
97
|
|
86
98
|
#### Project
|
87
99
|
|
88
|
-
Implements all standard methods
|
100
|
+
Implements all standard methods and following custom:
|
101
|
+
|
102
|
+
* project.authorize(api_key_id, permission)
|
89
103
|
|
90
104
|
##### Examples
|
91
105
|
|
@@ -108,6 +122,12 @@ project[:description] = 'Lorem ipsum'
|
|
108
122
|
project.save
|
109
123
|
```
|
110
124
|
|
125
|
+
* Authorizing user api key with read permission
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
project.authorize(api_key_id, 'read_data')
|
129
|
+
```
|
130
|
+
|
111
131
|
#### Collection
|
112
132
|
|
113
133
|
Implements all standard methods and following custom:
|
@@ -117,6 +137,7 @@ Implements all standard methods and following custom:
|
|
117
137
|
* collection.deactivate
|
118
138
|
* collection.add_tag(tag, weight, remove_others)
|
119
139
|
* collection.delete_tag(tag)
|
140
|
+
* collection.authorize(api_key_id, permission)
|
120
141
|
|
121
142
|
##### Examples
|
122
143
|
|
@@ -150,6 +171,7 @@ collection2.add_tags('tag3', 1, true)
|
|
150
171
|
Implements all standard methods and following custom:
|
151
172
|
|
152
173
|
* folders.find_by_name(folder_name)
|
174
|
+
* folder.authorize(api_key_id, permission)
|
153
175
|
|
154
176
|
Find method uses folder name as a key.
|
155
177
|
|
data/lib/syncano.rb
CHANGED
@@ -7,7 +7,9 @@ class Syncano
|
|
7
7
|
# @return [Syncano::Clients::Rest] Syncano client.
|
8
8
|
def self.client(options = {})
|
9
9
|
auth_data = self.auth_data(options)
|
10
|
-
Syncano::Clients::Rest.new(auth_data[:instance_name], auth_data[:api_key])
|
10
|
+
client = Syncano::Clients::Rest.new(auth_data[:instance_name], auth_data[:api_key], auth_data[:auth_key])
|
11
|
+
client.login(options[:username], options[:password]) if client.auth_key.nil? && options[:username].present?
|
12
|
+
client
|
11
13
|
end
|
12
14
|
|
13
15
|
# Used for initializing Syncano Sync Client
|
@@ -15,7 +17,8 @@ class Syncano
|
|
15
17
|
# @return [Syncano::Clients::Rest] Syncano client.
|
16
18
|
def self.sync_client(options = {})
|
17
19
|
auth_data = self.auth_data(options)
|
18
|
-
client = Syncano::Clients::Sync.instance(auth_data[:instance_name], auth_data[:api_key])
|
20
|
+
client = Syncano::Clients::Sync.instance(auth_data[:instance_name], auth_data[:api_key], auth_data[:auth_key])
|
21
|
+
client.login(options[:username], options[:password]) if client.auth_key.nil? && options[:username].present?
|
19
22
|
client.connect
|
20
23
|
client
|
21
24
|
end
|
@@ -32,7 +35,7 @@ class Syncano
|
|
32
35
|
api_key = options[:api_key] || ::SYNCANO_API_KEY
|
33
36
|
raise 'Syncano api key cannot be blank!' if api_key.nil?
|
34
37
|
|
35
|
-
{ instance_name: instance_name, api_key: api_key }
|
38
|
+
{ instance_name: instance_name, api_key: api_key, auth_key: options[:auth_key] }
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
data/lib/syncano/clients/base.rb
CHANGED
@@ -3,16 +3,24 @@ class Syncano
|
|
3
3
|
module Clients
|
4
4
|
# Base class for representing clients
|
5
5
|
class Base
|
6
|
-
attr_reader :instance_name, :api_key
|
6
|
+
attr_reader :instance_name, :api_key, :auth_key
|
7
7
|
|
8
8
|
# Constructor for Syncano::Clients::Base object
|
9
9
|
# @param [String] instance_name
|
10
10
|
# @param [String] api_key
|
11
|
-
def initialize(instance_name, api_key)
|
11
|
+
def initialize(instance_name, api_key, auth_key)
|
12
12
|
super()
|
13
13
|
|
14
14
|
self.instance_name = instance_name
|
15
15
|
self.api_key = api_key
|
16
|
+
self.auth_key = auth_key if auth_key.present?
|
17
|
+
end
|
18
|
+
|
19
|
+
# Deletes saved auth_key
|
20
|
+
# @return [TrueClass, FalseClass]
|
21
|
+
def logout
|
22
|
+
self.auth_key = nil
|
23
|
+
self.auth_key.nil?
|
16
24
|
end
|
17
25
|
|
18
26
|
# Returns query builder for Syncano::Resources::Admin objects
|
@@ -66,8 +74,8 @@ class Syncano
|
|
66
74
|
# @param [Integer, String] project_id
|
67
75
|
# @param [Integer, String] collection_id
|
68
76
|
# @return [Syncano::QueryBuilder]
|
69
|
-
def users
|
70
|
-
::Syncano::QueryBuilder.new(self, ::Syncano::Resources::User
|
77
|
+
def users
|
78
|
+
::Syncano::QueryBuilder.new(self, ::Syncano::Resources::User)
|
71
79
|
end
|
72
80
|
|
73
81
|
# Performs request to Syncano api
|
@@ -91,7 +99,7 @@ class Syncano
|
|
91
99
|
|
92
100
|
private
|
93
101
|
|
94
|
-
attr_writer :instance_name, :api_key
|
102
|
+
attr_writer :instance_name, :api_key, :auth_key
|
95
103
|
|
96
104
|
# Parses Syncano api response and returns Syncano::Response object
|
97
105
|
# @param [String] response_key
|
@@ -101,8 +109,8 @@ class Syncano
|
|
101
109
|
status = raw_response.nil? || raw_response['result'] != 'NOK'
|
102
110
|
if raw_response.nil?
|
103
111
|
data = nil
|
104
|
-
elsif raw_response[response_key].present?
|
105
|
-
data = raw_response[response_key]
|
112
|
+
elsif raw_response[response_key.to_s].present?
|
113
|
+
data = raw_response[response_key.to_s]
|
106
114
|
else
|
107
115
|
data = raw_response['count']
|
108
116
|
end
|
data/lib/syncano/clients/rest.rb
CHANGED
@@ -7,11 +7,19 @@ class Syncano
|
|
7
7
|
# Constructor for Syncano::Clients::Rest object
|
8
8
|
# @param [String] instance_name
|
9
9
|
# @param [String] api_key
|
10
|
-
def initialize(instance_name, api_key)
|
11
|
-
super(instance_name, api_key)
|
10
|
+
def initialize(instance_name, api_key, auth_key = nil)
|
11
|
+
super(instance_name, api_key, auth_key)
|
12
12
|
self.client = ::Jimson::Client.new(json_rpc_url)
|
13
13
|
end
|
14
14
|
|
15
|
+
# Gets auth_key based on username and password
|
16
|
+
# @return [TrueClass, FalseClass]
|
17
|
+
def login(username, password)
|
18
|
+
logout
|
19
|
+
self.auth_key = users.login(username, password)
|
20
|
+
!self.auth_key.nil?
|
21
|
+
end
|
22
|
+
|
15
23
|
# Performs request to Syncano api
|
16
24
|
# @param [String] resource_name
|
17
25
|
# @param [String] method_name
|
@@ -19,6 +27,8 @@ class Syncano
|
|
19
27
|
# @param [String] response_key for cases when response from api is incompatible with the convention
|
20
28
|
# @return [Syncano::Response]
|
21
29
|
def make_request(resource_name, method_name, params = {}, response_key = nil)
|
30
|
+
params.merge!(auth_key: auth_key) if auth_key.present?
|
31
|
+
|
22
32
|
response_key ||= resource_name
|
23
33
|
response = client.send("#{resource_name}.#{method_name}", request_params.merge(params))
|
24
34
|
response = self.class.parse_response(response_key, response)
|
data/lib/syncano/clients/sync.rb
CHANGED
@@ -9,20 +9,21 @@ class Syncano
|
|
9
9
|
# Constructor for Syncano::Clients::Sync object
|
10
10
|
# @param [String] instance_name
|
11
11
|
# @param [String] api_key
|
12
|
-
def initialize(instance_name, api_key)
|
13
|
-
super(instance_name, api_key)
|
12
|
+
def initialize(instance_name, api_key, auth_key = nil)
|
13
|
+
super(instance_name, api_key, auth_key)
|
14
14
|
self.connection = nil
|
15
|
+
self.auth_key = auth_key if auth_key.present?
|
15
16
|
end
|
16
17
|
|
17
18
|
# Getter for Singleton instance
|
18
19
|
# @param [String] instance_name
|
19
20
|
# @param [String] api_key
|
20
21
|
# @return [Syncano::Clients::Base]
|
21
|
-
def self.instance(instance_name = nil, api_key = nil)
|
22
|
+
def self.instance(instance_name = nil, api_key = nil, auth_key = nil)
|
22
23
|
unless @singleton__instance__
|
23
24
|
@singleton__mutex__.synchronize do
|
24
25
|
return @singleton__instance__ if @singleton__instance__
|
25
|
-
@singleton__instance__ = new(instance_name, api_key)
|
26
|
+
@singleton__instance__ = new(instance_name, api_key, auth_key)
|
26
27
|
end
|
27
28
|
end
|
28
29
|
@singleton__instance__
|
@@ -53,6 +54,15 @@ class Syncano
|
|
53
54
|
end
|
54
55
|
|
55
56
|
raise ::Syncano::ConnectionError.new('Connection timeout') unless timeout > 0
|
57
|
+
|
58
|
+
timeout = 300
|
59
|
+
|
60
|
+
while (response = connection.get_response('auth')).blank? && timeout > 0
|
61
|
+
timeout -= 1
|
62
|
+
sleep 1.0/10.0
|
63
|
+
end
|
64
|
+
|
65
|
+
raise ::Syncano::ConnectionError.new(response.error) if response.status == 'NOK'
|
56
66
|
end
|
57
67
|
end
|
58
68
|
|
@@ -68,6 +78,15 @@ class Syncano
|
|
68
78
|
connect
|
69
79
|
end
|
70
80
|
|
81
|
+
# Gets auth_key based on username and password
|
82
|
+
# @return [TrueClass, FalseClass]
|
83
|
+
def login(username, password)
|
84
|
+
logout
|
85
|
+
rest_client = ::Syncano.client(api_key: api_key)
|
86
|
+
self.auth_key = rest_client.users.login(username, password)
|
87
|
+
!self.auth_key.nil?
|
88
|
+
end
|
89
|
+
|
71
90
|
# Returns query builder for Syncano::Resources::Subscription objects
|
72
91
|
# @return [Syncano::QueryBuilder]
|
73
92
|
def subscriptions
|
@@ -124,8 +143,10 @@ class Syncano
|
|
124
143
|
end
|
125
144
|
end
|
126
145
|
|
146
|
+
raise(::Syncano::ApiError.new('Request timeout error!')) if timer == 0
|
147
|
+
|
127
148
|
response = self.class.parse_response(response_key, response_packet.to_response)
|
128
|
-
response.errors.present? ? raise(Syncano::ApiError.new(response.errors)) : response
|
149
|
+
response.errors.present? ? raise(::Syncano::ApiError.new(response.errors)) : response
|
129
150
|
end
|
130
151
|
end
|
131
152
|
end
|
data/lib/syncano/errors.rb
CHANGED
data/lib/syncano/packets/auth.rb
CHANGED
@@ -2,6 +2,26 @@ class Syncano
|
|
2
2
|
module Packets
|
3
3
|
# Class representing auth packets used in communication with the Sync Server
|
4
4
|
class Auth < Syncano::Packets::Base
|
5
|
+
attr_reader :message_id, :status, :error
|
6
|
+
|
7
|
+
# Constructor for Syncano::Packets::Auth object
|
8
|
+
# @param [Hash] attributes
|
9
|
+
def initialize(attributes)
|
10
|
+
super(attributes)
|
11
|
+
self.message_id = 'auth'
|
12
|
+
self.status = attributes[:result]
|
13
|
+
self.error = attributes[:error]
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns true if is an auth packet
|
17
|
+
# @return [TrueClass, FalseClass]
|
18
|
+
def auth?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_writer :message_id, :status, :error
|
5
25
|
end
|
6
26
|
end
|
7
27
|
end
|
data/lib/syncano/packets/base.rb
CHANGED
@@ -51,7 +51,7 @@ class Syncano
|
|
51
51
|
# @param [Integer, String] key
|
52
52
|
# @param [Hash] conditions
|
53
53
|
# @return [Syncano::Resources::Base]
|
54
|
-
def find(key, conditions = {})
|
54
|
+
def find(key = nil, conditions = {})
|
55
55
|
resource_class.find(client, key, scope_parameters, conditions)
|
56
56
|
end
|
57
57
|
|
@@ -137,6 +137,14 @@ class Syncano
|
|
137
137
|
resource_class.batch_move(batch_client, scope_parameters, ids, conditions, new_folder, new_state)
|
138
138
|
end
|
139
139
|
|
140
|
+
# Proxy for calling "login" method on the resource object
|
141
|
+
# @param [String] username
|
142
|
+
# @param [String] password
|
143
|
+
# @return [Array] collection of Syncano::Resource objects
|
144
|
+
def login(username = nil, password = nil)
|
145
|
+
resource_class.login(client, username, password)
|
146
|
+
end
|
147
|
+
|
140
148
|
private
|
141
149
|
|
142
150
|
attr_accessor :client, :resource_class, :scope_parameters
|
@@ -8,14 +8,48 @@ class Syncano
|
|
8
8
|
def initialize(client, attributes = {})
|
9
9
|
super(client, attributes)
|
10
10
|
if @attributes[:role].is_a?(Hash)
|
11
|
-
@attributes[:role] = ::Syncano::Resources::Role.new(@attributes[:role])
|
11
|
+
@attributes[:role] = ::Syncano::Resources::Role.new(client, @attributes[:role])
|
12
12
|
end
|
13
13
|
|
14
14
|
if @saved_attributes[:role].is_a?(Hash)
|
15
|
-
@saved_attributes[:role] = ::Syncano::Resources::Role.new(@saved_attributes[:role])
|
15
|
+
@saved_attributes[:role] = ::Syncano::Resources::Role.new(client, @saved_attributes[:role])
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
# Wrapper for api "authorize" method
|
20
|
+
# @param [String] permission
|
21
|
+
# @return [Syncano::Resources::Base]
|
22
|
+
def authorize(permission)
|
23
|
+
perform_authorize(nil, permission: permission)
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
# Wrapper for api "authorize" method
|
28
|
+
# @param [Jimson::BatchClient] batch_client
|
29
|
+
# @param [String] permission
|
30
|
+
# @return [Syncano::Resources::Base]
|
31
|
+
def batch_authorize(batch_client, permission)
|
32
|
+
perform_authorize(batch_client, permission: permission)
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
# Wrapper for api "deauthorize" method
|
37
|
+
# @param [String] permission
|
38
|
+
# @return [Syncano::Resources::Base]
|
39
|
+
def deauthorize(permission)
|
40
|
+
perform_deauthorize(nil, permission: permission)
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
# Wrapper for api "deauthorize" method
|
45
|
+
# @param [Jimson::BatchClient] batch_client
|
46
|
+
# @param [String] permission
|
47
|
+
# @return [Syncano::Resources::Base]
|
48
|
+
def batch_deauthorize(batch_client, permission)
|
49
|
+
perform_deauthorize(batch_client, permission: permission)
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
19
53
|
private
|
20
54
|
|
21
55
|
# Prepares attributes to synchronizing with Syncano
|
@@ -34,6 +68,18 @@ class Syncano
|
|
34
68
|
:api_client_id
|
35
69
|
end
|
36
70
|
|
71
|
+
# Executes proper find request
|
72
|
+
# @param [Syncano::Clients::Base] client
|
73
|
+
# @param [Symbol, String] key_name
|
74
|
+
# @param [Integer, String] key
|
75
|
+
# @param [Hash] scope_parameters
|
76
|
+
# @param [Hash] conditions
|
77
|
+
# @return [Syncano::Response]
|
78
|
+
def self.perform_find(client, key_name, key, scope_parameters, conditions)
|
79
|
+
key_parameters = key.present? ? { key_name.to_sym => key } : {}
|
80
|
+
make_request(client, nil, :find, conditions.merge(scope_parameters.merge(key_parameters)))
|
81
|
+
end
|
82
|
+
|
37
83
|
# Executes proper update request
|
38
84
|
# @param [Jimson::BatchClient] batch_client
|
39
85
|
# @param [Hash] attributes
|
@@ -41,6 +87,22 @@ class Syncano
|
|
41
87
|
def perform_update(batch_client, attributes)
|
42
88
|
self.class.make_request(client, batch_client, :update_description, self.class.attributes_to_sync(attributes).merge(self.class.primary_key_name.to_sym => primary_key))
|
43
89
|
end
|
90
|
+
|
91
|
+
# Executes proper authorize request
|
92
|
+
# @param [Jimson::BatchClient] batch_client
|
93
|
+
# @param [Hash] parameters
|
94
|
+
# @return [Syncano::Response]
|
95
|
+
def perform_authorize(batch_client, parameters)
|
96
|
+
self.class.make_request(client, batch_client, :authorize, parameters.merge(self.class.primary_key_name.to_sym => primary_key))
|
97
|
+
end
|
98
|
+
|
99
|
+
# Executes proper deauthorize request
|
100
|
+
# @param [Jimson::BatchClient] batch_client
|
101
|
+
# @param [Hash] parameters
|
102
|
+
# @return [Syncano::Response]
|
103
|
+
def perform_deauthorize(batch_client, parameters)
|
104
|
+
self.class.make_request(client, batch_client, :deauthorize, parameters.merge(self.class.primary_key_name.to_sym => primary_key))
|
105
|
+
end
|
44
106
|
end
|
45
107
|
end
|
46
108
|
end
|
@@ -118,6 +118,44 @@ class Syncano
|
|
118
118
|
reload!
|
119
119
|
end
|
120
120
|
|
121
|
+
# Wrapper for api "authorize" method
|
122
|
+
# @param [Integer] api_client_id
|
123
|
+
# @param [String] permission
|
124
|
+
# @return [Syncano::Resources::Base]
|
125
|
+
def authorize(api_client_id, permission)
|
126
|
+
perform_authorize(nil, api_client_id: api_client_id, permission: permission)
|
127
|
+
self
|
128
|
+
end
|
129
|
+
|
130
|
+
# Wrapper for api "authorize" method
|
131
|
+
# @param [Jimson::BatchClient] batch_client
|
132
|
+
# @param [Integer] api_client_id
|
133
|
+
# @param [String] permission
|
134
|
+
# @return [Syncano::Resources::Base]
|
135
|
+
def batch_authorize(batch_client, api_client_id, permission)
|
136
|
+
perform_authorize(batch_client, api_client_id: api_client_id, permission: permission)
|
137
|
+
self
|
138
|
+
end
|
139
|
+
|
140
|
+
# Wrapper for api "deauthorize" method
|
141
|
+
# @param [Integer] api_client_id
|
142
|
+
# @param [String] permission
|
143
|
+
# @return [Syncano::Resources::Base]
|
144
|
+
def deauthorize(api_client_id, permission)
|
145
|
+
perform_deauthorize(nil, api_client_id: api_client_id, permission: permission)
|
146
|
+
self
|
147
|
+
end
|
148
|
+
|
149
|
+
# Wrapper for api "deauthorize" method
|
150
|
+
# @param [Jimson::BatchClient] batch_client
|
151
|
+
# @param [Integer] api_client_id
|
152
|
+
# @param [String] permission
|
153
|
+
# @return [Syncano::Resources::Base]
|
154
|
+
def batch_deauthorize(batch_client, api_client_id, permission)
|
155
|
+
perform_deauthorize(batch_client, api_client_id: api_client_id, permission: permission)
|
156
|
+
self
|
157
|
+
end
|
158
|
+
|
121
159
|
private
|
122
160
|
|
123
161
|
self.scope_parameters = [:project_id]
|
@@ -181,6 +219,22 @@ class Syncano
|
|
181
219
|
check_if_sync_client!
|
182
220
|
client.make_request(:subscription, :unsubscribe_collection, scope_parameters.merge(collection_id: id))
|
183
221
|
end
|
222
|
+
|
223
|
+
# Executes proper authorize request
|
224
|
+
# @param [Jimson::BatchClient] batch_client
|
225
|
+
# @param [Hash] parameters
|
226
|
+
# @return [Syncano::Response]
|
227
|
+
def perform_authorize(batch_client, parameters)
|
228
|
+
self.class.make_request(client, batch_client, :authorize, scope_parameters.merge(parameters.merge(self.class.primary_key_name.to_sym => primary_key)))
|
229
|
+
end
|
230
|
+
|
231
|
+
# Executes proper deauthorize request
|
232
|
+
# @param [Jimson::BatchClient] batch_client
|
233
|
+
# @param [Hash] parameters
|
234
|
+
# @return [Syncano::Response]
|
235
|
+
def perform_deauthorize(batch_client, parameters)
|
236
|
+
self.class.make_request(client, batch_client, :deauthorize, scope_parameters.merge(parameters.merge(self.class.primary_key_name.to_sym => primary_key)))
|
237
|
+
end
|
184
238
|
end
|
185
239
|
end
|
186
240
|
end
|
@@ -18,6 +18,44 @@ class Syncano
|
|
18
18
|
find(client, name, scope_parameters, conditions)
|
19
19
|
end
|
20
20
|
|
21
|
+
# Wrapper for api "authorize" method
|
22
|
+
# @param [Integer] api_client_id
|
23
|
+
# @param [String] permission
|
24
|
+
# @return [Syncano::Resources::Base]
|
25
|
+
def authorize(api_client_id, permission)
|
26
|
+
perform_authorize(nil, api_client_id: api_client_id, permission: permission)
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
# Wrapper for api "authorize" method
|
31
|
+
# @param [Jimson::BatchClient] batch_client
|
32
|
+
# @param [Integer] api_client_id
|
33
|
+
# @param [String] permission
|
34
|
+
# @return [Syncano::Resources::Base]
|
35
|
+
def batch_authorize(batch_client, api_client_id, permission)
|
36
|
+
perform_authorize(batch_client, api_client_id: api_client_id, permission: permission)
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
# Wrapper for api "deauthorize" method
|
41
|
+
# @param [Integer] api_client_id
|
42
|
+
# @param [String] permission
|
43
|
+
# @return [Syncano::Resources::Base]
|
44
|
+
def deauthorize(api_client_id, permission)
|
45
|
+
perform_deauthorize(nil, api_client_id: api_client_id, permission: permission)
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
# Wrapper for api "deauthorize" method
|
50
|
+
# @param [Jimson::BatchClient] batch_client
|
51
|
+
# @param [Integer] api_client_id
|
52
|
+
# @param [String] permission
|
53
|
+
# @return [Syncano::Resources::Base]
|
54
|
+
def batch_deauthorize(batch_client, api_client_id, permission)
|
55
|
+
perform_deauthorize(batch_client, api_client_id: api_client_id, permission: permission)
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
21
59
|
private
|
22
60
|
|
23
61
|
self.primary_key = :name
|
@@ -29,6 +67,22 @@ class Syncano
|
|
29
67
|
def perform_destroy(batch_client)
|
30
68
|
self.class.make_request(client, batch_client, :destroy, scope_parameters.merge(name: primary_key))
|
31
69
|
end
|
70
|
+
|
71
|
+
# Executes proper authorize request
|
72
|
+
# @param [Jimson::BatchClient] batch_client
|
73
|
+
# @param [Hash] parameters
|
74
|
+
# @return [Syncano::Response]
|
75
|
+
def perform_authorize(batch_client, parameters)
|
76
|
+
self.class.make_request(client, batch_client, :authorize, scope_parameters.merge(parameters.merge(self.class.primary_key_name.to_sym => primary_key)))
|
77
|
+
end
|
78
|
+
|
79
|
+
# Executes proper deauthorize request
|
80
|
+
# @param [Jimson::BatchClient] batch_client
|
81
|
+
# @param [Hash] parameters
|
82
|
+
# @return [Syncano::Response]
|
83
|
+
def perform_deauthorize(batch_client, parameters)
|
84
|
+
self.class.make_request(client, batch_client, :deauthorize, scope_parameters.merge(parameters.merge(self.class.primary_key_name.to_sym => primary_key)))
|
85
|
+
end
|
32
86
|
end
|
33
87
|
end
|
34
88
|
end
|
@@ -22,6 +22,44 @@ class Syncano
|
|
22
22
|
reload!
|
23
23
|
end
|
24
24
|
|
25
|
+
# Wrapper for api "authorize" method
|
26
|
+
# @param [Integer] api_client_id
|
27
|
+
# @param [String] permission
|
28
|
+
# @return [Syncano::Resources::Base]
|
29
|
+
def authorize(api_client_id, permission)
|
30
|
+
perform_authorize(nil, api_client_id: api_client_id, permission: permission)
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
# Wrapper for api "authorize" method
|
35
|
+
# @param [Jimson::BatchClient] batch_client
|
36
|
+
# @param [Integer] api_client_id
|
37
|
+
# @param [String] permission
|
38
|
+
# @return [Syncano::Resources::Base]
|
39
|
+
def batch_authorize(batch_client, api_client_id, permission)
|
40
|
+
perform_authorize(batch_client, api_client_id: api_client_id, permission: permission)
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
# Wrapper for api "deauthorize" method
|
45
|
+
# @param [Integer] api_client_id
|
46
|
+
# @param [String] permission
|
47
|
+
# @return [Syncano::Resources::Base]
|
48
|
+
def deauthorize(api_client_id, permission)
|
49
|
+
perform_deauthorize(nil, api_client_id: api_client_id, permission: permission)
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
# Wrapper for api "deauthorize" method
|
54
|
+
# @param [Jimson::BatchClient] batch_client
|
55
|
+
# @param [Integer] api_client_id
|
56
|
+
# @param [String] permission
|
57
|
+
# @return [Syncano::Resources::Base]
|
58
|
+
def batch_deauthorize(batch_client, api_client_id, permission)
|
59
|
+
perform_deauthorize(batch_client, api_client_id: api_client_id, permission: permission)
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
25
63
|
private
|
26
64
|
|
27
65
|
# Executes proper subscribe request
|
@@ -37,6 +75,22 @@ class Syncano
|
|
37
75
|
check_if_sync_client!
|
38
76
|
client.make_request(:subscription, :unsubscribe_project, { project_id: id })
|
39
77
|
end
|
78
|
+
|
79
|
+
# Executes proper authorize request
|
80
|
+
# @param [Jimson::BatchClient] batch_client
|
81
|
+
# @param [Hash] parameters
|
82
|
+
# @return [Syncano::Response]
|
83
|
+
def perform_authorize(batch_client, parameters)
|
84
|
+
self.class.make_request(client, batch_client, :authorize, parameters.merge(self.class.primary_key_name.to_sym => primary_key))
|
85
|
+
end
|
86
|
+
|
87
|
+
# Executes proper deauthorize request
|
88
|
+
# @param [Jimson::BatchClient] batch_client
|
89
|
+
# @param [Hash] parameters
|
90
|
+
# @return [Syncano::Response]
|
91
|
+
def perform_deauthorize(batch_client, parameters)
|
92
|
+
self.class.make_request(client, batch_client, :deauthorize, parameters.merge(self.class.primary_key_name.to_sym => primary_key))
|
93
|
+
end
|
40
94
|
end
|
41
95
|
end
|
42
96
|
end
|
@@ -12,6 +12,16 @@ class Syncano
|
|
12
12
|
response.data if response.status
|
13
13
|
end
|
14
14
|
|
15
|
+
# Wrapper for api "login" method
|
16
|
+
# @param [Syncano::Clients::Base] client
|
17
|
+
# @param [String] username
|
18
|
+
# @param [String] password
|
19
|
+
# @return [Integer]
|
20
|
+
def self.login(client, username, password)
|
21
|
+
response = perform_login(client, user_name: username, password: password)
|
22
|
+
response.data
|
23
|
+
end
|
24
|
+
|
15
25
|
private
|
16
26
|
|
17
27
|
self.scope_parameters = [:project_id, :collection_id]
|
@@ -42,6 +52,14 @@ class Syncano
|
|
42
52
|
def self.perform_count(client, scope_parameters, conditions)
|
43
53
|
make_request(client, nil, :count, conditions.merge(scope_parameters))
|
44
54
|
end
|
55
|
+
|
56
|
+
# Executes proper login request
|
57
|
+
# @param [Syncano::Clients::Base] client
|
58
|
+
# @param [Hash] parameters
|
59
|
+
# @return [Syncano::Response]
|
60
|
+
def self.perform_login(client, parameters = {})
|
61
|
+
make_request(client, nil, :login, parameters, :auth_key)
|
62
|
+
end
|
45
63
|
end
|
46
64
|
end
|
47
65
|
end
|
@@ -21,13 +21,15 @@ class Syncano
|
|
21
21
|
start_tls
|
22
22
|
end
|
23
23
|
|
24
|
-
# Eventmachine callback invoked completing ssl handshake
|
24
|
+
# Eventmachine callback invoked after completing ssl handshake
|
25
25
|
def ssl_handshake_completed
|
26
26
|
auth_data = {
|
27
27
|
api_key: client.api_key,
|
28
28
|
instance: client.instance_name
|
29
29
|
}
|
30
30
|
|
31
|
+
auth_data[:auth_key] = client.auth_key if client.auth_key.present?
|
32
|
+
|
31
33
|
client.connection = self
|
32
34
|
|
33
35
|
send_data "#{auth_data.to_json}\n"
|
@@ -47,6 +49,8 @@ class Syncano
|
|
47
49
|
end
|
48
50
|
elsif packet.call_response?
|
49
51
|
queue_response(packet)
|
52
|
+
elsif packet.auth?
|
53
|
+
queue_response(packet)
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
@@ -77,7 +81,7 @@ class Syncano
|
|
77
81
|
# @param [Integer, String] message_id
|
78
82
|
# @return [Syncano::Packets::CallResponse]
|
79
83
|
def get_response(message_id)
|
80
|
-
responses.delete(message_id)
|
84
|
+
responses.delete(message_id.to_s)
|
81
85
|
end
|
82
86
|
|
83
87
|
private
|
@@ -88,9 +92,9 @@ class Syncano
|
|
88
92
|
# @param [Syncano::Packets::CallResponse] packet
|
89
93
|
def queue_response(packet)
|
90
94
|
prune_responses_queue
|
91
|
-
message_id = packet.message_id.
|
95
|
+
message_id = packet.message_id.to_s
|
92
96
|
responses[message_id] = packet
|
93
|
-
responses_queue << message_id
|
97
|
+
responses_queue << message_id.to_s
|
94
98
|
end
|
95
99
|
|
96
100
|
# Removes old call response packets from the responses queue
|
@@ -98,7 +102,7 @@ class Syncano
|
|
98
102
|
while !responses_queue.empty?
|
99
103
|
message_id = responses_queue.first
|
100
104
|
|
101
|
-
if
|
105
|
+
if responses[message_id].nil? || Time.now - responses[message_id].timestamp.to_time > 2.minutes
|
102
106
|
responses_queue.shift
|
103
107
|
responses.delete(message_id)
|
104
108
|
else
|
data/lib/syncano/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syncano
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.1.
|
4
|
+
version: 3.1.1.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Zadrożny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jimson-client
|