bluevia 1.0
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.
- data/LICENSE.LGPLv3 +165 -0
- data/License_Bluevia.txt +22 -0
- data/README +172 -0
- data/lib/bluevia.rb +13 -0
- data/lib/bluevia/ad_response.rb +35 -0
- data/lib/bluevia/advertising.rb +108 -0
- data/lib/bluevia/base_client.rb +401 -0
- data/lib/bluevia/bluevia_client.rb +119 -0
- data/lib/bluevia/bluevia_logger.rb +30 -0
- data/lib/bluevia/directory.rb +81 -0
- data/lib/bluevia/errors.rb +13 -0
- data/lib/bluevia/errors/client_error.rb +6 -0
- data/lib/bluevia/errors/not_found_error.rb +5 -0
- data/lib/bluevia/errors/server_error.rb +6 -0
- data/lib/bluevia/ext/hash.rb +64 -0
- data/lib/bluevia/messaging.rb +96 -0
- data/lib/bluevia/oauth.rb +117 -0
- data/lib/bluevia/response.rb +48 -0
- data/lib/bluevia/schemas.rb +10 -0
- data/lib/bluevia/schemas/common_types.rb +166 -0
- data/lib/bluevia/schemas/directory_types.rb +491 -0
- data/lib/bluevia/schemas/sms_types.rb +256 -0
- data/lib/bluevia/sms.rb +91 -0
- data/lib/bluevia/utils.rb +110 -0
- data/lib/multipartable.rb +15 -0
- data/test/test_advertising.rb +67 -0
- data/test/test_config.rb +77 -0
- data/test/test_directory.rb +124 -0
- data/test/test_oauth.rb +72 -0
- data/test/test_sms.rb +112 -0
- data/test/test_sms_mo.rb +78 -0
- metadata +137 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
#require 'parts'
|
2
|
+
module Multipartable
|
3
|
+
DEFAULT_BOUNDARY = "-----------RubyMultipartPost"
|
4
|
+
def initialize(path, params, headers={}, boundary = DEFAULT_BOUNDARY)
|
5
|
+
super(path, headers)
|
6
|
+
parts = params.map {|k,v| Parts::Part.new(boundary, k, v)}
|
7
|
+
parts << Parts::EpiloguePart.new(boundary)
|
8
|
+
ios = parts.map{|p| p.to_io }
|
9
|
+
self.set_content_type("multipart/form-data", { "boundary" => boundary })
|
10
|
+
# smoking area
|
11
|
+
# content_length is invalid and it deletes 2 bytes per part in multipart
|
12
|
+
self.content_length = parts.inject(-2) {|sum,i| sum + (i.length + 2)}
|
13
|
+
self.body_stream = CompositeReadIO.new(*ios)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#
|
2
|
+
# BlueVia is a global iniciative of Telefonica delivered by Movistar and O2.
|
3
|
+
# Please, check out www.bluevia.com and if you need more information
|
4
|
+
# contact us at mailto:support@bluevia.com
|
5
|
+
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
7
|
+
|
8
|
+
require 'test/unit'
|
9
|
+
require 'bluevia'
|
10
|
+
require 'test_config'
|
11
|
+
|
12
|
+
class TestAdvertising < Test::Unit::TestCase
|
13
|
+
include TestConfig
|
14
|
+
def setup
|
15
|
+
create_client(false, :Advertising)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_get_ad
|
19
|
+
get_ad
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_get_ad_fails
|
23
|
+
get_ad_fails
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_get_ad_commercial
|
27
|
+
create_client(true, :Advertising)
|
28
|
+
get_ad
|
29
|
+
end
|
30
|
+
|
31
|
+
def t_test_get_ad_commercial_fails
|
32
|
+
create_client(true, :Advertising)
|
33
|
+
get_ad_fails
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def get_ad
|
39
|
+
params = {:user_agent => "Mozilla 5.0",
|
40
|
+
:ad_request_id => "a1x4zasg58",
|
41
|
+
:ad_space => "1200"
|
42
|
+
}
|
43
|
+
response = @service.request(params)
|
44
|
+
|
45
|
+
assert_equal response.instance_of?(Bluevia::AdResponse), true
|
46
|
+
|
47
|
+
response.each{|item|
|
48
|
+
%w[value type_name interaction type_id].each{|key|
|
49
|
+
assert_equal true, item.has_key?(key)
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
assert_equal response.image.instance_of?(Hash), true
|
54
|
+
|
55
|
+
assert_equal response.text.instance_of?(Hash), true
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_ad_fails
|
60
|
+
params = {:user_agent => "Mozilla 5.0",
|
61
|
+
:ad_request_id => "a1x4zasg58w"
|
62
|
+
}
|
63
|
+
assert_raise Bluevia::ClientError do
|
64
|
+
@service.request(params)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/test/test_config.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# BlueVia is a global iniciative of Telefonica delivered by Movistar and O2.
|
3
|
+
# Please, check out www.bluevia.com and if you need more information
|
4
|
+
# contact us at mailto:support@bluevia.com
|
5
|
+
|
6
|
+
module TestConfig
|
7
|
+
|
8
|
+
# Configuration for sandbox endpoint
|
9
|
+
module SandBox
|
10
|
+
|
11
|
+
# App Credentials
|
12
|
+
CONSUMER_KEY = "rtWB11108FG"
|
13
|
+
CONSUMER_SECRET = "1291943612105"
|
14
|
+
|
15
|
+
# User Credentials
|
16
|
+
TOKEN = "963139c903e26941d6801ce7702fed0a"
|
17
|
+
TOKEN_SECRET = "78a375c0a4b7c876a5f8160e919fb1cb"
|
18
|
+
|
19
|
+
# SMS MO
|
20
|
+
SMS_REGISTRATION_ID = "5210666"
|
21
|
+
SMS_SPECIAL_NUMBER = "5721100001"
|
22
|
+
SMS_SPECIAL_KEYWORD = "OTAFSMSSB"
|
23
|
+
|
24
|
+
# SYNC MESSAGING
|
25
|
+
SYNC_REGISTRATION_ID= "5210666"
|
26
|
+
SYNC_SPECIAL_NUMBER = "5721100001"
|
27
|
+
SYNC_SPECIAL_KEYWORD= "OTAFSYNCSB"
|
28
|
+
|
29
|
+
BASEURI = "https://api.bluevia.com"
|
30
|
+
|
31
|
+
AUTHORIZE_URI = "http://connect.bluevia.com/authorise/"
|
32
|
+
end
|
33
|
+
|
34
|
+
# Configuration for commercial endpoint
|
35
|
+
module Commercial
|
36
|
+
|
37
|
+
CONSUMER_KEY = "AnjI10920Xk"
|
38
|
+
CONSUMER_SECRET = "1290440360972"
|
39
|
+
TOKEN = "7807453c8c11a6d9cc90581de97642c5"
|
40
|
+
TOKEN_SECRET = "34a2a42c942cea85bc9e23a903f9624b"
|
41
|
+
|
42
|
+
BASEURI = "https://api.bluevia.com"
|
43
|
+
|
44
|
+
AUTHORIZE_URI = "http://connect.bluevia.com/authorise/"
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_client(commercial = false, service = nil)
|
48
|
+
if commercial
|
49
|
+
@bc = Bluevia::BlueviaClient.new(
|
50
|
+
{ :consumer_key => TestConfig::Commercial::CONSUMER_KEY,
|
51
|
+
:consumer_secret=> TestConfig::Commercial::CONSUMER_SECRET,
|
52
|
+
:token => TestConfig::Commercial::TOKEN,
|
53
|
+
:token_secret => TestConfig::Commercial::TOKEN_SECRET,
|
54
|
+
:uri => TestConfig::Commercial::BASEURI
|
55
|
+
})
|
56
|
+
@bc.set_commercial
|
57
|
+
else
|
58
|
+
@bc = Bluevia::BlueviaClient.new(
|
59
|
+
{ :consumer_key => TestConfig::SandBox::CONSUMER_KEY,
|
60
|
+
:consumer_secret=> TestConfig::SandBox::CONSUMER_SECRET,
|
61
|
+
:token => TestConfig::SandBox::TOKEN,
|
62
|
+
:token_secret => TestConfig::SandBox::TOKEN_SECRET,
|
63
|
+
:uri => TestConfig::SandBox::BASEURI
|
64
|
+
})
|
65
|
+
end
|
66
|
+
|
67
|
+
@bc.log_level = Logger::DEBUG
|
68
|
+
|
69
|
+
unless service.nil?
|
70
|
+
@service = @bc.get_service(service)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_correlator_id
|
75
|
+
(0...10).map{ ('a'..'z').to_a[rand(26)] }.join
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
#
|
2
|
+
# BlueVia is a global iniciative of Telefonica delivered by Movistar and O2.
|
3
|
+
# Please, check out www.bluevia.com and if you need more information
|
4
|
+
# contact us at mailto:support@bluevia.com
|
5
|
+
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
7
|
+
|
8
|
+
require 'test/unit'
|
9
|
+
require 'bluevia'
|
10
|
+
require 'test_config'
|
11
|
+
|
12
|
+
#
|
13
|
+
# (c) Bluevia (mailto:support@bluevia.com)
|
14
|
+
#
|
15
|
+
|
16
|
+
class TestDirectory < Test::Unit::TestCase
|
17
|
+
include Bluevia
|
18
|
+
include TestConfig
|
19
|
+
def setup
|
20
|
+
create_client(false, :Directory)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_get_terminal_info
|
24
|
+
get_terminal_info(TestConfig::SandBox::TOKEN)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_terminal_info_commercial
|
28
|
+
create_client(true, :Directory)
|
29
|
+
get_terminal_info(TestConfig::Commercial::TOKEN)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_get_access_info
|
33
|
+
get_access_info(TestConfig::SandBox::TOKEN)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_get_access_info_commercial
|
37
|
+
create_client(true, :Directory)
|
38
|
+
get_access_info(TestConfig::Commercial::TOKEN)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_get_profile
|
42
|
+
get_profile(TestConfig::SandBox::TOKEN)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_get_profile_commercial
|
46
|
+
create_client(true, :Directory)
|
47
|
+
get_profile(TestConfig::Commercial::TOKEN)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_get_two_values
|
51
|
+
get_profile_access_info(TestConfig::SandBox::TOKEN)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_get_two_values_commercial
|
55
|
+
create_client(true, :Directory)
|
56
|
+
get_profile_access_info(TestConfig::Commercial::TOKEN)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_get_all_info
|
60
|
+
get_all_info(TestConfig::SandBox::TOKEN)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_get_all_info_commercial
|
64
|
+
create_client(true, :Directory)
|
65
|
+
get_all_info(TestConfig::Commercial::TOKEN)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def get_terminal_info(acess_token)
|
71
|
+
response = @service.get_user_info(acess_token, Directory::USER_TERMINAL_INFO)
|
72
|
+
assert_equal response.size, 1
|
73
|
+
assert_equal response.include?("userTerminalInfo"), true
|
74
|
+
assert_equal response["userTerminalInfo"].size >= 1, true
|
75
|
+
assert_equal response["userTerminalInfo"].include?("version"), true
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_access_info(acess_token)
|
79
|
+
response = @service.get_user_info(acess_token, Directory::USER_ACCESS_INFO)
|
80
|
+
assert_equal response.size, 1
|
81
|
+
assert_equal response.include?("userAccessInfo"), true
|
82
|
+
assert_equal response["userAccessInfo"].size >= 1, true
|
83
|
+
%W[apn].each { |key|
|
84
|
+
assert_equal response["userAccessInfo"].include?(key), true
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_profile(acess_token)
|
89
|
+
response = @service.get_user_info(acess_token, Directory::USER_PROFILE)
|
90
|
+
assert_equal response.size, 1
|
91
|
+
assert_equal response.include?("userProfile"), true
|
92
|
+
%W[userType icb ocb parentalControl operatorId segment].each { |key|
|
93
|
+
assert_equal response["userProfile"].include?(key), true
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_profile_access_info(acess_token)
|
98
|
+
response = @service.get_user_info(acess_token, [Directory::USER_ACCESS_INFO, Directory::USER_PROFILE])
|
99
|
+
|
100
|
+
assert_equal response.size >= 1
|
101
|
+
|
102
|
+
%w[userAccessInfo].each{|key|
|
103
|
+
assert_equal true, response.has_key?(key)
|
104
|
+
}
|
105
|
+
|
106
|
+
%W[apn].each { |key|
|
107
|
+
assert_equal response["userAccessInfo"].include?(key), true
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
def get_all_info(acess_token)
|
112
|
+
response = @service.get_user_info(acess_token)
|
113
|
+
assert_equal response.size, 1
|
114
|
+
assert_equal response.include?("userInfo"), true
|
115
|
+
assert_equal response["userInfo"].size >= 2
|
116
|
+
|
117
|
+
[ "userAccessInfo",
|
118
|
+
"userProfile"].each {
|
119
|
+
|key|
|
120
|
+
assert_equal response["userInfo"].include?(key), true
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
data/test/test_oauth.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
#
|
2
|
+
# BlueVia is a global iniciative of Telefonica delivered by Movistar and O2.
|
3
|
+
# Please, check out www.bluevia.com and if you need more information
|
4
|
+
# contact us at mailto:support@bluevia.com
|
5
|
+
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
7
|
+
|
8
|
+
require 'test/unit'
|
9
|
+
require 'bluevia'
|
10
|
+
require 'test_config'
|
11
|
+
|
12
|
+
#
|
13
|
+
# (c) Bluevia (mailto:support@bluevia.com)
|
14
|
+
#
|
15
|
+
|
16
|
+
class TestOauth < Test::Unit::TestCase
|
17
|
+
include TestConfig
|
18
|
+
def setup
|
19
|
+
create_client(false, :oAuth)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_get_request_token_callback
|
23
|
+
token, secret, url = @service.get_request_token({:callback =>"http://foo.bar"})
|
24
|
+
p url
|
25
|
+
assert_not_nil token
|
26
|
+
assert_not_nil secret
|
27
|
+
assert_not_nil url
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_get_request_token_callback_uri
|
31
|
+
token, secret, url = @service.get_request_token({:callback =>"http://foo.bar", :uri => TestConfig::SandBox::AUTHORIZE_URI})
|
32
|
+
p url
|
33
|
+
assert_not_nil token
|
34
|
+
assert_not_nil secret
|
35
|
+
assert_not_nil url
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_get_request_token_nickname
|
39
|
+
token, secret, url = @service.get_request_token({:nickname =>"juansdp7"})
|
40
|
+
p token
|
41
|
+
p secret
|
42
|
+
p url
|
43
|
+
assert_not_nil token
|
44
|
+
assert_not_nil secret
|
45
|
+
assert_not_nil url
|
46
|
+
end
|
47
|
+
|
48
|
+
def ftest_get_request_token_invalid
|
49
|
+
assert_raise SyntaxError do
|
50
|
+
@service.get_request_token({:nicknam =>"juandebravo"})
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def ftest_get_request_token_commercial
|
55
|
+
create_client(true, :oAuth)
|
56
|
+
token, secret, url = @service.get_request_token("http://foo.bar")
|
57
|
+
p token
|
58
|
+
p secret
|
59
|
+
p url
|
60
|
+
end
|
61
|
+
|
62
|
+
def ftest_get_access_token
|
63
|
+
create_client(true, :oAuth)
|
64
|
+
|
65
|
+
token = "20100728102227000020"
|
66
|
+
secret = "f8e12e97c4ee785bab418ed0f68df623"
|
67
|
+
|
68
|
+
result1, result2 = @service.get_access_token(token, secret, "529fa27d6bbb8565add26600137294b7")
|
69
|
+
p result1
|
70
|
+
p result2
|
71
|
+
end
|
72
|
+
end
|
data/test/test_sms.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
#
|
2
|
+
# BlueVia is a global iniciative of Telefonica delivered by Movistar and O2.
|
3
|
+
# Please, check out www.bluevia.com and if you need more information
|
4
|
+
# contact us at mailto:support@bluevia.com
|
5
|
+
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
7
|
+
|
8
|
+
require 'test/unit'
|
9
|
+
require 'bluevia'
|
10
|
+
require 'bluevia/errors'
|
11
|
+
require 'test_config'
|
12
|
+
|
13
|
+
#
|
14
|
+
# (c) Bluevia (mailto:support@bluevia.com)
|
15
|
+
#
|
16
|
+
|
17
|
+
class TestSms < Test::Unit::TestCase
|
18
|
+
include TestConfig
|
19
|
+
include Bluevia
|
20
|
+
|
21
|
+
URL_DELIVERY_NOTIFICATION = "http://foo.bar"
|
22
|
+
|
23
|
+
def setup
|
24
|
+
create_client(false, :Sms)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_send_sms
|
28
|
+
send_sms(TestConfig::SandBox::TOKEN)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_send_sms_commercial
|
32
|
+
create_client(true, :Sms)
|
33
|
+
send_sms(TestConfig::Commercial::TOKEN)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_get_delivery_status
|
37
|
+
get_delivery_status(TestConfig::SandBox::TOKEN)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_get_delivery_status_commercial
|
41
|
+
create_client(true, :Sms)
|
42
|
+
get_delivery_status(TestConfig::Commercial::TOKEN)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_get_delivery_status_commercial_identifier
|
46
|
+
create_client(true, :Sms)
|
47
|
+
get_delivery_status(TestConfig::Commercial::TOKEN, "10001112090452109328")
|
48
|
+
end
|
49
|
+
|
50
|
+
def ftest_get_received_sms
|
51
|
+
get_received_sms
|
52
|
+
end
|
53
|
+
|
54
|
+
def ftest_get_received_sms_fails
|
55
|
+
get_received_sms_fails
|
56
|
+
end
|
57
|
+
|
58
|
+
def ftest_get_received_sms_commercial
|
59
|
+
create_client(true, :Sms)
|
60
|
+
get_received_sms(true)
|
61
|
+
end
|
62
|
+
|
63
|
+
def ftest_get_received_sms_commercial_fails
|
64
|
+
create_client(true, :Sms)
|
65
|
+
get_received_sms_fails
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def get_correlator_id
|
71
|
+
(0...10).map{ ('a'..'z').to_a[rand(26)] }.join
|
72
|
+
end
|
73
|
+
|
74
|
+
def send_sms(origin)
|
75
|
+
info = @service.send_sms(["11111", "33333"], origin, "Yet another SMS Text")
|
76
|
+
assert_not_nil info
|
77
|
+
assert_match(/^.*(deliverystatus)$/, info)
|
78
|
+
info
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_received_sms(commercial = false)
|
82
|
+
if commercial
|
83
|
+
registration_id = "4353432" # TODO: change this number
|
84
|
+
else
|
85
|
+
registration_id = "35234264"
|
86
|
+
end
|
87
|
+
info = @service.get_received_sms(registration_id)
|
88
|
+
assert_equal info.include?("receivedSMS"), true
|
89
|
+
p info
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_received_sms_fails
|
93
|
+
assert_raise RuntimeError do
|
94
|
+
@service.get_received_sms("352342641")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def get_delivery_status(origin, identifier = nil)
|
99
|
+
if identifier.nil?
|
100
|
+
info = send_sms(origin)
|
101
|
+
size = 2
|
102
|
+
identifier = info.split("/").last(2).first
|
103
|
+
else
|
104
|
+
size = 1
|
105
|
+
end
|
106
|
+
info = @service.get_delivery_status(identifier)
|
107
|
+
assert_equal info["smsDeliveryStatus"].size, size
|
108
|
+
assert_equal info["smsDeliveryStatus"][0].include?("address"), true
|
109
|
+
assert_equal info["smsDeliveryStatus"][0].include?("deliveryStatus"), true
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|