Class: Rhosync::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rhosync/client.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Client) initialize(params = {})

allow configuration, uri or environment variable initialization

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rhosync/client.rb', line 8

def initialize(params = {})
  uri = params[:uri] || Rhosync.configuration.uri || ENV['RHOSYNC_URL']
  raise ArgumentError.new("Please provide a :uri or set RHOSYNC_URL") unless uri
  uri = URI.parse(uri)
  
  @token = params[:token] || Rhosync.configuration.token || uri.user
  uri.user = nil; @uri = uri.to_s      
  raise ArgumentError.new("Please provide a :token or set it in uri") unless @token
  
  RestClient.proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
end

Instance Attribute Details

- (Object) token

Returns the value of attribute token



5
6
7
# File 'lib/rhosync/client.rb', line 5

def token
  @token
end

- (Object) uri

Returns the value of attribute uri



5
6
7
# File 'lib/rhosync/client.rb', line 5

def uri
  @uri
end

Instance Method Details

- (Object) create(source_name, partition, obj = {}) Also known as: update



20
21
22
# File 'lib/rhosync/client.rb', line 20

def create(source_name, partition, obj = {})
  send_objects(:push_objects, source_name, partition, obj)
end

- (Object) destroy(source_name, partition, obj = {})



24
25
26
# File 'lib/rhosync/client.rb', line 24

def destroy(source_name, partition, obj = {})
  send_objects(:push_deletes, source_name, partition, obj)
end

- (Object) set_auth_callback(callback)



31
32
33
# File 'lib/rhosync/client.rb', line 31

def set_auth_callback(callback)
  process(:post, "/api/set_auth_callback", { :callback => callback })
end

- (Object) set_query_callback(source_name, callback)



35
36
37
38
39
40
41
42
# File 'lib/rhosync/client.rb', line 35

def set_query_callback(source_name, callback)
  process(:post, "/api/set_query_callback", 
    { 
      :source_id => source_name,
      :callback => callback 
    }
  )
end