Class: BtSync::Directory
Instance Attribute Summary collapse
#opts
Instance Method Summary
collapse
#auth, #cookies, #generate_secret, #get, #password, #path, #port, #protocol, #request_token, #root_url, #starter, #token, #token_path, #uri, #user
Constructor Details
#initialize(name, secret, btsync) ⇒ Directory
Returns a new instance of Directory.
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/btsync/directory.rb', line 8
def initialize(name, secret, btsync)
@name = name
@secret = secret
@opts = btsync.opts
find_or_create
@errors = []
end
|
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
7
8
9
|
# File 'lib/btsync/directory.rb', line 7
def errors
@errors
end
|
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/btsync/directory.rb', line 7
def name
@name
end
|
#secret ⇒ Object
Returns the value of attribute secret.
7
8
9
|
# File 'lib/btsync/directory.rb', line 7
def secret
@secret
end
|
Instance Method Details
#add_host(host, port) ⇒ Object
58
59
60
61
62
|
# File 'lib/btsync/directory.rb', line 58
def add_host(host, port)
query = { name: name, secret: secret, addr: host, port: port }
get(path('addknownhosts'), query: query)
true
end
|
#delete_to_trash=(opt) ⇒ Object
122
123
124
|
# File 'lib/btsync/directory.rb', line 122
def delete_to_trash=(opt)
set_pref('deletetotrash', opt)
end
|
#delete_to_trash? ⇒ Boolean
126
127
128
|
# File 'lib/btsync/directory.rb', line 126
def delete_to_trash?
bool(preferences['deletetotrash'])
end
|
#destroy ⇒ Object
19
20
21
22
|
# File 'lib/btsync/directory.rb', line 19
def destroy
get(path('removefolder'), query: { name: name, secret: secret })
self.instance_variables.each { |v| v = nil }
end
|
#folders ⇒ Object
39
40
41
42
|
# File 'lib/btsync/directory.rb', line 39
def folders
res = get(path('getdir'), query: { dir: @name })
res.parsed_response['folders']
end
|
#is_writable? ⇒ Boolean
130
131
132
|
# File 'lib/btsync/directory.rb', line 130
def is_writable?
bool(preferences['iswritable'])
end
|
#known_hosts ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/btsync/directory.rb', line 50
def known_hosts
query = { name: name, secret: secret }
res = get(path('getknownhosts'), query: query)
hosts = {}
res['hosts'].map { |h| hosts[h['index']] = h['peer'] }
hosts
end
|
#peers ⇒ Object
44
45
46
47
48
|
# File 'lib/btsync/directory.rb', line 44
def peers
res = get(path('getsyncfolders'))
r = res.parsed_response['folders'].select { |f| f['name'] == name }.first
r['peers']
end
|
#preferences ⇒ Object
134
135
136
137
|
# File 'lib/btsync/directory.rb', line 134
def preferences
res = get(path('getfolderpref'), query: { name: @name, secret: @secret })
res.parsed_response['folderpref']
end
|
#read_only_secret ⇒ Object
139
140
141
|
# File 'lib/btsync/directory.rb', line 139
def read_only_secret
preferences['readonlysecret']
end
|
#remove_host(index) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/btsync/directory.rb', line 64
def remove_host(index)
host_name = known_hosts.select { |id, host| id == index }
query = { name: name, secret: secret, index: index }
get(path('removeknownhosts'), query: query) unless host_name.nil? || host_name.empty?
known_hosts.select { |id, host| host == host_name }.empty?
end
|
#remove_host_by_ip(ip, port = nil) ⇒ Object
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/btsync/directory.rb', line 71
def remove_host_by_ip(ip, port = nil)
known_hosts.each do |id, host|
host = host.split(':')
if ip == host[0]
next if port != host[1] unless port.nil?
remove_host(id)
end
end
end
|
#search_dht=(opt) ⇒ Object
106
107
108
|
# File 'lib/btsync/directory.rb', line 106
def search_dht=(opt)
set_pref('searchdht', opt)
end
|
#search_dht? ⇒ Boolean
110
111
112
|
# File 'lib/btsync/directory.rb', line 110
def search_dht?
bool(preferences['searchdht'])
end
|
#search_lan=(opt) ⇒ Object
98
99
100
|
# File 'lib/btsync/directory.rb', line 98
def search_lan=(opt)
set_pref('searchlan', opt)
end
|
#search_lan? ⇒ Boolean
102
103
104
|
# File 'lib/btsync/directory.rb', line 102
def search_lan?
bool(preferences['searchlan'])
end
|
#update_secret(new_secret = generate_secret) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/btsync/directory.rb', line 24
def update_secret(new_secret = generate_secret)
query = secret_params(new_secret)
res = get(path('updatesecret'), query: query)
p = res.parsed_response
if p != {}
@secret = new_secret
true
else
if p == {}
@errors << "Invalid Secret"
end
false
end
end
|
#use_hosts=(opt) ⇒ Object
90
91
92
|
# File 'lib/btsync/directory.rb', line 90
def use_hosts=(opt)
set_pref('usehosts', opt)
end
|
#use_hosts? ⇒ Boolean
94
95
96
|
# File 'lib/btsync/directory.rb', line 94
def use_hosts?
bool(preferences['usehosts'])
end
|
#use_relay=(opt) ⇒ Object
114
115
116
|
# File 'lib/btsync/directory.rb', line 114
def use_relay=(opt)
set_pref('relay', opt)
end
|
#use_relay? ⇒ Boolean
118
119
120
|
# File 'lib/btsync/directory.rb', line 118
def use_relay?
bool(preferences['relay'])
end
|
#use_tracker=(opt) ⇒ Object
82
83
84
|
# File 'lib/btsync/directory.rb', line 82
def use_tracker=(opt)
set_pref('usetracker', opt)
end
|
#use_tracker? ⇒ Boolean
86
87
88
|
# File 'lib/btsync/directory.rb', line 86
def use_tracker?
bool(preferences['usetracker'])
end
|