Class: HelloTxt::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(api_key, user_key) ⇒ Client

Returns a new instance of Client.



13
14
15
16
# File 'lib/hellotxt/client.rb', line 13

def initialize(api_key, user_key)
	@api_key = api_key
	@user_key = user_key
end

Instance Method Details

#post(body, title = '', group = 'inhome', image = '', debug = 0) ⇒ Object

Posts a message to the user’s social services Arguments: body = message body Optional arguments: title = title of the posted message, only used if the service supports it group = service group type; either ‘inhome’, ‘friend’, ‘collegue’ image = raw bytes of an image to post debug = set debug to 1 to avoid posting test data if successful returns:

{'status' => 'OK'}

if unsuccessful returns:

{'status' => 'FAIL', 'message' => 'message what went wrong'}


68
69
70
71
72
73
74
75
76
77
78
# File 'lib/hellotxt/client.rb', line 68

def post(body, title = '', group = 'inhome', image = '', debug = 0)
  response = get_response('user.post',
                          'body' => body, 'title' => title,
                          'group' => group, 'image' => image,
                          'debug' => debug)
	if response.elements['rsp'].attributes['status'] == 'OK'
		return status_ok
	else
		return status_fail(response)
	end
end

#user_servicesObject

if unsuccessful returns:

{'status' => 'FAIL', 'message' => 'message what went wrong'}


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/hellotxt/client.rb', line 37

def user_services
  response = get_response('user.services')
	if response.elements['rsp'].attributes['status'] == 'OK'
		services = status_ok()
		services['services'] = []
		response.elements.each('rsp/services/service') do |service|
			services['services'].push({'id' => service.attributes['id'],
										'name' => service.attributes['name'],
										'code' => service.elements['code'].text,
										'inhome' => service.elements['inhome'].text,
										'friend' => service.elements['friend'].text,
										'collegue' => service.elements['collegue'].text})
		end
		return services
	else
		return status_fail(response)
	end
end

#validateObject

Validates API key and USER key if successful returns:

{'status' => 'OK'}

if unsuccessful returns:

{'status' => 'FAIL', 'message' => 'message what went wrong'}


23
24
25
26
27
28
29
30
# File 'lib/hellotxt/client.rb', line 23

def validate
  response = get_response('user.validate')
	if response.elements['rsp'].attributes['status'] == 'OK'
		return status_ok
	else
		return status_fail(response)
	end
end