Class: UEUser

Inherits:
Object show all
Defined in:
lib/models/UEUser.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri_or_key, secret = nil) ⇒ UEUser

URI: user://e9759590-54ef-4cd3-a01c-cb2241ddd812:1aee1a25-e0c4-4036-a8fd-4d41adc8611b@ COMB: key,secret Constructor

Parameters:

  • uri (String)

    the user uri string

  • key (String)

    the user key

  • secret (String) (defaults to: nil)

    the user secret



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/models/UEUser.rb', line 11

def initialize(uri_or_key, secret=nil)
    if secret then
        # key,secret format
        @user_key, @user_secret =  [uri_or_key, secret]
        @uri = "user://#{@user_key}:#{@user_secret}@"
    else
        # uri format
        @uri = uri_or_key
        @user_key, @user_secret =  uri_or_key.match(/user:\/\/(.+):(.+)@/).captures
    end
end

Instance Method Details

#add_connection(connection_name, service_scheme, service_access_token) ⇒ UEConnection

Adds a connection to the current user

/

Parameters:

  • connection_name (String)

    the connection identifier. Unique per connection

  • service_scheme (String)

    a string representing a connector service (service scheme)

  • service_access_token (String)

    service access token acquired from the provider (fb token, twitter token..etc)

Returns:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/models/UEUser.rb', line 46

def add_connection(connection_name, service_scheme, service_access_token) 

    response = UERequest.fetch "connection/add",{
        user: @user_key,
        pass: @user_secret,
        form: {
            uri: "#{service_scheme}://#{service_access_token}@#{service_scheme}.com",
            name: connection_name
        }
    }

    (response[:status] == 200) || response


end

#list_connectionsConnection

List connections for current user

Returns:

  • (Connection)

    } List of Connection objects representing the user connections



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/models/UEUser.rb', line 65

def list_connections() 

    response = UERequest.fetch "connection/list",{
        user: @user_key,
        pass: @user_secret,
    }

    if  !response[:connections]
        return []
    end

    connections = []
    response[:connections].each do |cname,v| 
       connections.push(UEConnection.new cname, response[:connections][cname.to_sym][:uri], self)
    end
    connections 

end

#remove_connection(connection_name) ⇒ Boolean

Removes a connection from a user

Parameters:

  • connection_name (String)

    the connection identifier

Returns:

  • (Boolean)

    Success/Fail



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/models/UEUser.rb', line 92

def remove_connection(connection_name) 
    response = UERequest.fetch "connection/remove",{
        user: @user_key,
        pass: @user_secret,
        form:{
            name: connection_name
        }
    }

    response[:status] == 200


end

#test_connection(service_uri) ⇒ Boolean

Tests a connection to a connector

Parameters:

Returns:

  • (Boolean)

    Success/Fail



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/models/UEUser.rb', line 113

def test_connection(service_uri) 
    response = UERequest.fetch "connection/test",{
        user: @user_key,
        pass: @user_secret,
        form:{
            uri: service_uri
        }
    }

    response[:Status][:""][:status] == 200 



end

#uriObject

Getters



25
26
27
# File 'lib/models/UEUser.rb', line 25

def uri
    @uri
end

#user_keyObject



29
30
31
# File 'lib/models/UEUser.rb', line 29

def user_key
    @user_key
end

#user_secretObject



33
34
35
# File 'lib/models/UEUser.rb', line 33

def user_secret
    @user_secret
end