cloudrail_si 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +3 -0
- data/examples/README.md +3 -0
- data/examples/simple/index.rb +11 -0
- data/lib/cloudrail_si.rb +41 -0
- data/lib/cloudrail_si/RedirectReceivers.rb +40 -0
- data/lib/cloudrail_si/Settings.rb +12 -0
- data/lib/cloudrail_si/errors/DetailErrors.rb +13 -0
- data/lib/cloudrail_si/errors/InternalError.rb +10 -0
- data/lib/cloudrail_si/errors/UserError.rb +11 -0
- data/lib/cloudrail_si/helpers/Helper.rb +151 -0
- data/lib/cloudrail_si/helpers/LimitedReadableStream.rb +55 -0
- data/lib/cloudrail_si/helpers/SequenceReadableStream.rb +59 -0
- data/lib/cloudrail_si/servicecode/InitSelfTest.rb +92 -0
- data/lib/cloudrail_si/servicecode/Interpreter.rb +213 -0
- data/lib/cloudrail_si/servicecode/Sandbox.rb +361 -0
- data/lib/cloudrail_si/servicecode/VarAddress.rb +11 -0
- data/lib/cloudrail_si/servicecode/commands/AwaitCodeRedirect.rb +48 -0
- data/lib/cloudrail_si/servicecode/commands/Break.rb +16 -0
- data/lib/cloudrail_si/servicecode/commands/CallFunc.rb +26 -0
- data/lib/cloudrail_si/servicecode/commands/Clone.rb +18 -0
- data/lib/cloudrail_si/servicecode/commands/Concat.rb +22 -0
- data/lib/cloudrail_si/servicecode/commands/Conditional.rb +27 -0
- data/lib/cloudrail_si/servicecode/commands/Create.rb +56 -0
- data/lib/cloudrail_si/servicecode/commands/Delete.rb +21 -0
- data/lib/cloudrail_si/servicecode/commands/Get.rb +25 -0
- data/lib/cloudrail_si/servicecode/commands/GetMimeType.rb +1005 -0
- data/lib/cloudrail_si/servicecode/commands/JumpRel.rb +18 -0
- data/lib/cloudrail_si/servicecode/commands/Pull.rb +34 -0
- data/lib/cloudrail_si/servicecode/commands/Push.rb +32 -0
- data/lib/cloudrail_si/servicecode/commands/Return.rb +16 -0
- data/lib/cloudrail_si/servicecode/commands/Set.rb +23 -0
- data/lib/cloudrail_si/servicecode/commands/Size.rb +26 -0
- data/lib/cloudrail_si/servicecode/commands/ThrowError.rb +17 -0
- data/lib/cloudrail_si/servicecode/commands/array/Uint8ToBase64.rb +25 -0
- data/lib/cloudrail_si/servicecode/commands/debug/Out.rb +24 -0
- data/lib/cloudrail_si/servicecode/commands/hash/md5.rb +29 -0
- data/lib/cloudrail_si/servicecode/commands/hash/sha1.rb +30 -0
- data/lib/cloudrail_si/servicecode/commands/http/RequestCall.rb +51 -0
- data/lib/cloudrail_si/servicecode/commands/json/Parse.rb +40 -0
- data/lib/cloudrail_si/servicecode/commands/json/Stringify.rb +21 -0
- data/lib/cloudrail_si/servicecode/commands/math/Floor.rb +27 -0
- data/lib/cloudrail_si/servicecode/commands/math/MathCombine.rb +35 -0
- data/lib/cloudrail_si/servicecode/commands/object/GetKeyArray.rb +21 -0
- data/lib/cloudrail_si/servicecode/commands/object/GetKeyValueArrays.rb +29 -0
- data/lib/cloudrail_si/servicecode/commands/stream/MakeJoinedStream.rb +38 -0
- data/lib/cloudrail_si/servicecode/commands/stream/MakeLimitedStream.rb +23 -0
- data/lib/cloudrail_si/servicecode/commands/stream/StreamToString.rb +25 -0
- data/lib/cloudrail_si/servicecode/commands/stream/StringToStream.rb +20 -0
- data/lib/cloudrail_si/servicecode/commands/string/Base64Encode.rb +42 -0
- data/lib/cloudrail_si/servicecode/commands/string/Format.rb +43 -0
- data/lib/cloudrail_si/servicecode/commands/string/IndexOf.rb +29 -0
- data/lib/cloudrail_si/servicecode/commands/string/LastIndexOf.rb +29 -0
- data/lib/cloudrail_si/servicecode/commands/string/Split.rb +29 -0
- data/lib/cloudrail_si/servicecode/commands/string/StringTransform.rb +29 -0
- data/lib/cloudrail_si/servicecode/commands/string/Substr.rb +30 -0
- data/lib/cloudrail_si/servicecode/commands/string/Substring.rb +30 -0
- data/lib/cloudrail_si/services/Facebook.rb +528 -0
- data/lib/cloudrail_si/services/FacebookPage.rb +310 -0
- data/lib/cloudrail_si/services/Foursquare.rb +314 -0
- data/lib/cloudrail_si/services/GitHub.rb +354 -0
- data/lib/cloudrail_si/services/GooglePlaces.rb +309 -0
- data/lib/cloudrail_si/services/GooglePlus.rb +367 -0
- data/lib/cloudrail_si/services/Instagram.rb +342 -0
- data/lib/cloudrail_si/services/LinkedIn.rb +363 -0
- data/lib/cloudrail_si/services/MicrosoftLive.rb +346 -0
- data/lib/cloudrail_si/services/Nexmo.rb +173 -0
- data/lib/cloudrail_si/services/Slack.rb +318 -0
- data/lib/cloudrail_si/services/Twilio.rb +173 -0
- data/lib/cloudrail_si/services/Twitter.rb +795 -0
- data/lib/cloudrail_si/services/Yahoo.rb +408 -0
- data/lib/cloudrail_si/services/Yelp.rb +389 -0
- data/lib/cloudrail_si/statistics/Statistics.rb +125 -0
- data/lib/cloudrail_si/types/Address.rb +9 -0
- data/lib/cloudrail_si/types/Charge.rb +33 -0
- data/lib/cloudrail_si/types/CloudMetaData.rb +19 -0
- data/lib/cloudrail_si/types/CreditCard.rb +76 -0
- data/lib/cloudrail_si/types/Date.rb +49 -0
- data/lib/cloudrail_si/types/DateOfBirth.rb +16 -0
- data/lib/cloudrail_si/types/Error.rb +21 -0
- data/lib/cloudrail_si/types/Location.rb +8 -0
- data/lib/cloudrail_si/types/POI.rb +17 -0
- data/lib/cloudrail_si/types/Refund.rb +25 -0
- data/lib/cloudrail_si/types/SandboxObject.rb +20 -0
- data/lib/cloudrail_si/types/SpaceAllocation.rb +13 -0
- data/lib/cloudrail_si/types/Subscription.rb +27 -0
- data/lib/cloudrail_si/types/SubscriptionPlan.rb +26 -0
- data/lib/cloudrail_si/types/Types.rb +43 -0
- data/lib/cloudrail_si/version.rb +3 -0
- metadata +205 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7bc47e8e893f702a961fedea634f5f71126d4e3a
|
4
|
+
data.tar.gz: 17ebb9379cedb2c25db68549f55fa0fa7efe32df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a4765e3fc399f9334f1a45aa1a48a9cb029d19ebbbb21c0429321bdba1e6f2c17beb0a635ac2b77dafe05ac08fc79e1ccebd3b148c49c6fafc1e20231043150
|
7
|
+
data.tar.gz: 2e3489fd1d312cb567a1d7485d50b03d8b69377d9f9df391cc314dcf6220295c7ceb94b2d0c7d9645744bc403bb3a25ce31bbd685936d38d7eb56955fb71e2b3
|
data/LICENSE.txt
ADDED
data/examples/README.md
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
This folder contains examples on how to use the CloudRail SI node.js library
|
2
|
+
|
3
|
+
* The "simple" folder contains a very basic example of how to use a service where the redirectReceiver parameter to the service constructor can be null (interfaces Payment, Email, SMS, Point of Interest)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'cloudrail_si'
|
2
|
+
|
3
|
+
CloudRailSi::Settings.license_key = '[Your CloudRail license key]'
|
4
|
+
|
5
|
+
service = CloudRailSi::Services::GooglePlaces.new(nil, 'xxx') # replace "xxx" with a valid API key
|
6
|
+
#service = cloudrail.Services.Foursquare.new(nil, "[clientId]", "[clientSecret]")
|
7
|
+
#service = cloudrail.Services.Yelp.new(nil, "[consumerKey]", "[consumerSecret]", "[token]", "[tokenSecret]")
|
8
|
+
|
9
|
+
pois = service.get_nearby_pois(49.4557091, 8.5279138, 3000, "sparkasse", ["bank"])
|
10
|
+
|
11
|
+
print "Amount of locations called 'sparkasse' in a 3km radius around the given coordinates, tagged with category 'bank': #{pois.length}\n"
|
data/lib/cloudrail_si.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'cloudrail_si/Version'
|
2
|
+
|
3
|
+
#require 'cloudrail_si/services/AmazonS3'
|
4
|
+
#require 'cloudrail_si/services/Backblaze'
|
5
|
+
#require 'cloudrail_si/services/Box'
|
6
|
+
#require 'cloudrail_si/services/Dropbox'
|
7
|
+
#require 'cloudrail_si/services/Egnyte'
|
8
|
+
require 'cloudrail_si/services/Facebook'
|
9
|
+
require 'cloudrail_si/services/FacebookPage'
|
10
|
+
require 'cloudrail_si/services/Foursquare'
|
11
|
+
require 'cloudrail_si/services/GitHub'
|
12
|
+
#require 'cloudrail_si/services/GoogleCloudPlatform'
|
13
|
+
#require 'cloudrail_si/services/GoogleDrive'
|
14
|
+
require 'cloudrail_si/services/GooglePlaces'
|
15
|
+
require 'cloudrail_si/services/GooglePlus'
|
16
|
+
#require 'cloudrail_si/services/Heroku'
|
17
|
+
require 'cloudrail_si/services/Instagram'
|
18
|
+
require 'cloudrail_si/services/LinkedIn'
|
19
|
+
#require 'cloudrail_si/services/MailJet'
|
20
|
+
#require 'cloudrail_si/services/MicrosoftAzure'
|
21
|
+
require 'cloudrail_si/services/MicrosoftLive'
|
22
|
+
require 'cloudrail_si/services/Nexmo'
|
23
|
+
#require 'cloudrail_si/services/OneDrive'
|
24
|
+
#require 'cloudrail_si/services/OneDriveBusiness'
|
25
|
+
#require 'cloudrail_si/services/PayPal'
|
26
|
+
#require 'cloudrail_si/services/Rackspace'
|
27
|
+
#require 'cloudrail_si/services/SendGrid'
|
28
|
+
require 'cloudrail_si/services/Slack'
|
29
|
+
#require 'cloudrail_si/services/Stripe'
|
30
|
+
require 'cloudrail_si/services/Twilio'
|
31
|
+
require 'cloudrail_si/services/Twitter'
|
32
|
+
require 'cloudrail_si/services/Yahoo'
|
33
|
+
require 'cloudrail_si/services/Yelp'
|
34
|
+
|
35
|
+
require 'cloudrail_si/Settings'
|
36
|
+
|
37
|
+
require 'cloudrail_si/RedirectReceivers'
|
38
|
+
|
39
|
+
module CloudRailSi
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'launchy'
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
module CloudRailSi
|
5
|
+
class RedirectReceivers
|
6
|
+
@@default_html = '<h2>Authentication successful, you can close this window now</h2>'
|
7
|
+
|
8
|
+
# Adapted from http://practicingruby.com/articles/implementing-an-http-file-server
|
9
|
+
def self.get_local_authenticator(port=12345, resp_html=@@default_html)
|
10
|
+
return lambda { |url, state|
|
11
|
+
Launchy.open(url)
|
12
|
+
|
13
|
+
server = TCPServer.new('localhost', port)
|
14
|
+
loop do
|
15
|
+
begin
|
16
|
+
socket = server.accept
|
17
|
+
request = socket.gets
|
18
|
+
|
19
|
+
STDERR.puts request
|
20
|
+
|
21
|
+
socket.print "HTTP/1.1 200 OK\r\n" +
|
22
|
+
"Content-Type: text/html\r\n" +
|
23
|
+
"Content-Length: #{resp_html.bytesize}\r\n" +
|
24
|
+
"Connection: close\r\n"
|
25
|
+
|
26
|
+
socket.print "\r\n"
|
27
|
+
|
28
|
+
socket.print resp_html
|
29
|
+
socket.close
|
30
|
+
return request.split(' ')[1]
|
31
|
+
rescue => ex
|
32
|
+
socket.close
|
33
|
+
raise ex
|
34
|
+
break
|
35
|
+
end
|
36
|
+
end
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module CloudRailSi
|
2
|
+
module Errors
|
3
|
+
class AuthenticationError < StandardError; end
|
4
|
+
|
5
|
+
class HttpError < StandardError; end
|
6
|
+
|
7
|
+
class NotFoundError < StandardError; end
|
8
|
+
|
9
|
+
class ServiceUnavailableError < StandardError; end
|
10
|
+
|
11
|
+
class IllegalArgumentError < StandardError; end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module CloudRailSi
|
2
|
+
module Errors
|
3
|
+
class InternalError < StandardError
|
4
|
+
def initialize(message)
|
5
|
+
updated_message = message.nil? ? nil : message.gsub('null', 'nil')
|
6
|
+
super("An internal error has occurred which you probably cannot fix. We'd very much appreciate it if you would report it to the CloudRail team. The error message is:\n #{updated_message}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module CloudRailSi
|
2
|
+
module Errors
|
3
|
+
class UserError < StandardError
|
4
|
+
def initialize(message)
|
5
|
+
updated_message = message.nil? ? nil : message.gsub('null', 'nil')
|
6
|
+
|
7
|
+
super("An error occurred that you should be able to fix. The error message is:\n#{updated_message}")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require_relative '../errors/InternalError'
|
2
|
+
|
3
|
+
#require 'faraday'
|
4
|
+
require 'stringio'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
module CloudRailSi
|
8
|
+
module ServiceCode
|
9
|
+
class Helper
|
10
|
+
class << self
|
11
|
+
def add_all(target, source)
|
12
|
+
target.concat(source)
|
13
|
+
end
|
14
|
+
def put_all(target, source)
|
15
|
+
source.each do |key|
|
16
|
+
target[key] = source[key]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
def clear(target)
|
20
|
+
target.each do |key|
|
21
|
+
delete target[key]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
def remove(target, element)
|
25
|
+
target.delete(element)
|
26
|
+
end
|
27
|
+
def is_string(object)
|
28
|
+
object.is_a? String
|
29
|
+
end
|
30
|
+
def is_object(object)
|
31
|
+
(!is_string(object)) && (!is_sandbox(object)) && object.is_a?(Object) && !object.nil?
|
32
|
+
end
|
33
|
+
def is_sandbox(object)
|
34
|
+
object.instance_variable_get(:@is_sandbox)
|
35
|
+
end
|
36
|
+
def is_number(object)
|
37
|
+
object.is_a? Numeric
|
38
|
+
end
|
39
|
+
def is_boolean(object)
|
40
|
+
(object == true) || (object == false)
|
41
|
+
end
|
42
|
+
def is_var_address(object)
|
43
|
+
!object.instance_variable_get(:@address_string).nil?
|
44
|
+
end
|
45
|
+
def is_number_string(obj)
|
46
|
+
Float obj rescue nil # http://stackoverflow.com/questions/1235863/test-if-a-string-is-basically-an-integer-in-quotes-using-ruby
|
47
|
+
end
|
48
|
+
def is_stream(obj)
|
49
|
+
return obj.class.to_s == 'StringIO'
|
50
|
+
end
|
51
|
+
|
52
|
+
# Only print if allowed by env
|
53
|
+
def log(str)
|
54
|
+
print str if (ENV['cloudrail_ruby_print']==='true')
|
55
|
+
end
|
56
|
+
|
57
|
+
# Only debug if allowed by env
|
58
|
+
def debug
|
59
|
+
byebug if (ENV['cloudrail_ruby_debug']==='true')
|
60
|
+
end
|
61
|
+
|
62
|
+
def assert(expression)
|
63
|
+
debug if !expression
|
64
|
+
raise Errors::InternalError.new("Assertion failed") if (!expression)
|
65
|
+
end
|
66
|
+
def resolve(environment, value, check_existence=true)
|
67
|
+
check_existence = true if (check_existence === 0)
|
68
|
+
if is_var_address(value)
|
69
|
+
return environment.get_variable(value, -1, !check_existence)
|
70
|
+
else
|
71
|
+
return value
|
72
|
+
end
|
73
|
+
end
|
74
|
+
def compare(a_obj, b_obj)
|
75
|
+
result = (a_obj <=> b_obj)
|
76
|
+
raise Errors::InternalError.new("Compare compares incomparable values") if result.nil?
|
77
|
+
|
78
|
+
return result
|
79
|
+
end
|
80
|
+
def dump_stream(stream, target_encoding=nil)
|
81
|
+
contents = stream.string
|
82
|
+
contents = contents.force_encoding(target_encoding) unless target_encoding.nil?
|
83
|
+
return contents
|
84
|
+
end
|
85
|
+
def streamify_string(str, source_encoding)
|
86
|
+
res_stream = StringIO.new
|
87
|
+
res_stream.set_encoding(source_encoding) unless source_encoding.nil?
|
88
|
+
res_stream.write(str)
|
89
|
+
res_stream.write(nil)
|
90
|
+
|
91
|
+
return res_stream
|
92
|
+
end
|
93
|
+
|
94
|
+
# TODO: add stream support
|
95
|
+
# TODO: add faraday support
|
96
|
+
def make_request(url_string, headers, body, method)
|
97
|
+
Helper.log "\nmake_request_headers #{headers}\n" if headers
|
98
|
+
Helper.log "\nmake_request_url: #{url_string}\n"
|
99
|
+
uri = URI.parse(url_string)
|
100
|
+
use_ssl = uri.scheme == 'https'
|
101
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl, open_timeout: 30, read_timeout: 30) do |http|
|
102
|
+
if (method.downcase == 'get')
|
103
|
+
req = Net::HTTP::Get.new uri, headers
|
104
|
+
elsif (method.downcase == 'post')
|
105
|
+
req = Net::HTTP::Post.new uri, headers
|
106
|
+
elsif (method.downcase == 'delete')
|
107
|
+
req = Net::HTTP::Delete.new uri, headers
|
108
|
+
elsif (method.downcase == 'put')
|
109
|
+
req = Net::HTTP::Put.new uri, headers
|
110
|
+
elsif (method.downcase == 'patch')
|
111
|
+
req = Net::HTTP::Patch.new uri, headers
|
112
|
+
else
|
113
|
+
raise Errors::InternalError.new("Unexpected method for make_request: #{method}.")
|
114
|
+
end
|
115
|
+
|
116
|
+
req.body = body
|
117
|
+
|
118
|
+
req.body = dump_stream(req.body) if is_stream(req.body)
|
119
|
+
Helper.log "make_request_body: #{req.body}\n"
|
120
|
+
|
121
|
+
response = http.request(req)
|
122
|
+
|
123
|
+
return response
|
124
|
+
end
|
125
|
+
|
126
|
+
#TODO: support redirects
|
127
|
+
end
|
128
|
+
|
129
|
+
def lower_case_first_letter(str)
|
130
|
+
return str[0].downcase + str[1..-1]
|
131
|
+
end
|
132
|
+
def upper_case_first_letter(str)
|
133
|
+
return str[0].upcase + str[1..-1]
|
134
|
+
end
|
135
|
+
def is_array(object)
|
136
|
+
object.is_a?(Array)
|
137
|
+
end
|
138
|
+
|
139
|
+
# via http://stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby
|
140
|
+
def to_snake_case(str)
|
141
|
+
str.gsub(/::/, '/').
|
142
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
143
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
144
|
+
tr("-", "_").
|
145
|
+
downcase
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module CloudRailSi
|
2
|
+
module ServiceCode
|
3
|
+
class LimitedReadableStream
|
4
|
+
@CHUNK_SIZE = 8 * 1024
|
5
|
+
|
6
|
+
def initialize(source, limit)
|
7
|
+
super()
|
8
|
+
|
9
|
+
@source = source
|
10
|
+
@limit = limit
|
11
|
+
@should_push = false
|
12
|
+
@sourceReadable = source.readable
|
13
|
+
|
14
|
+
|
15
|
+
#TODO: translate this
|
16
|
+
=begin
|
17
|
+
source.on("readable", function () {
|
18
|
+
_this.sourceReadable = true;
|
19
|
+
_this.process();
|
20
|
+
})
|
21
|
+
source.on("end", function () {
|
22
|
+
_this.push(null);
|
23
|
+
})
|
24
|
+
source.on("error", function (err) {
|
25
|
+
_this.emit("error", err);
|
26
|
+
})
|
27
|
+
=end
|
28
|
+
end
|
29
|
+
|
30
|
+
def _read
|
31
|
+
@shouldPush = true
|
32
|
+
@process.call
|
33
|
+
end
|
34
|
+
|
35
|
+
def _process
|
36
|
+
if (@should_push && this.source_readable)
|
37
|
+
chunk = source.read(min(@limit, CHUNK_SIZE))
|
38
|
+
while (!chunk.nil?)
|
39
|
+
@limit -= chunk.length
|
40
|
+
if (@limit === 0)
|
41
|
+
@push.call(chunk)
|
42
|
+
@push.call(null)
|
43
|
+
return
|
44
|
+
end
|
45
|
+
if (!this.push(chunk))
|
46
|
+
this.shouldPush = false
|
47
|
+
return
|
48
|
+
end
|
49
|
+
chunk = source.read(min(@limit, CHUNK_SIZE))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module CloudRailSi
|
2
|
+
module ServiceCode
|
3
|
+
class SequenceReadableStream
|
4
|
+
=begin #TODO
|
5
|
+
def initialize(stream1, stream2)
|
6
|
+
@stream1 = stream1;
|
7
|
+
@stream2 = stream2;
|
8
|
+
@first = true;
|
9
|
+
@shouldPush = false;
|
10
|
+
@info1 = {
|
11
|
+
readable: stream1.readable
|
12
|
+
};
|
13
|
+
@info2 = {
|
14
|
+
readable: stream2.readable
|
15
|
+
};
|
16
|
+
stream1.on("readable", function () {
|
17
|
+
@info1.readable = true;
|
18
|
+
process();
|
19
|
+
});
|
20
|
+
stream1.on("end", function () {
|
21
|
+
@first = false;
|
22
|
+
process();
|
23
|
+
});
|
24
|
+
stream1.on("error", function (err) {
|
25
|
+
@emit("error", err);
|
26
|
+
});
|
27
|
+
stream2.on("readable", function () {
|
28
|
+
@info2.readable = true;
|
29
|
+
process();
|
30
|
+
});
|
31
|
+
stream2.on("end", function () {
|
32
|
+
@push(null);
|
33
|
+
});
|
34
|
+
stream2.on("error", function (err) {
|
35
|
+
@emit("error", err);
|
36
|
+
});
|
37
|
+
end
|
38
|
+
def _read
|
39
|
+
@should_push = true;
|
40
|
+
process();
|
41
|
+
end
|
42
|
+
def process
|
43
|
+
info = @first ? @info1 : @info2
|
44
|
+
if (@should_push && info.readable)
|
45
|
+
source = @first ? @stream1 : @stream2
|
46
|
+
chunk = 0
|
47
|
+
while ((chunk = source.read()).present?)
|
48
|
+
if (!@push(chunk))
|
49
|
+
@should_push = false
|
50
|
+
return
|
51
|
+
end
|
52
|
+
end
|
53
|
+
info.readable = false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
=end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require_relative './Interpreter'
|
2
|
+
require_relative './Sandbox'
|
3
|
+
require_relative '../Version'
|
4
|
+
|
5
|
+
module CloudRailSi
|
6
|
+
module ServiceCode
|
7
|
+
class InitSelfTest
|
8
|
+
class << self
|
9
|
+
def init_test(service_name)
|
10
|
+
return true unless @@tested_services.index(service_name).nil?
|
11
|
+
test_res = execute(service_name)
|
12
|
+
@@tested_services.push(service_name) unless !test_res || @@tested_services.index(service_name).nil?
|
13
|
+
test_res
|
14
|
+
end
|
15
|
+
def execute(servicename)
|
16
|
+
test_state = true
|
17
|
+
service_code = {
|
18
|
+
'selfTest' => [
|
19
|
+
['create', '$L0', 'Object'],
|
20
|
+
['create', '$L1', 'Object'],
|
21
|
+
['create', '$L1.client', 'Object'],
|
22
|
+
['create', '$L1.app', 'Object'],
|
23
|
+
['set', '$L1.client.mac', '$P1'],
|
24
|
+
['set', '$L1.client.platform', '$P0.platform'],
|
25
|
+
['set', '$L1.client.os', '$P0.os'],
|
26
|
+
['set', '$L1.app.name', '$P2'],
|
27
|
+
['set', '$L1.app.version', '$P3'],
|
28
|
+
['json.stringify', '$L3', '$L1.client'],
|
29
|
+
['callFunc', 'hashString', '$L4', '$L3'],
|
30
|
+
['json.stringify', '$L5', '$L1.app'],
|
31
|
+
['callFunc', 'hashString', '$L6', '$L5'],
|
32
|
+
['delete', '$L1.client.mac'],
|
33
|
+
['create', '$L8', 'Object'],
|
34
|
+
['set', '$L8.method', 'GET'],
|
35
|
+
['string.concat', '$L8.url', 'https://stat-si.cloudrail.com/current_version?service=', '$P0.serviceName', '&client=', '$L4', '&app=', '$L6'],
|
36
|
+
['create', '$L8.requestHeaders', 'Object'],
|
37
|
+
['json.stringify', '$L8.requestHeaders.clientdata', '$L1.client'],
|
38
|
+
['json.stringify', '$L8.requestHeaders.appdata', '$L1.app'],
|
39
|
+
['http.requestCall', '$L9', '$L8']
|
40
|
+
],
|
41
|
+
'hashString' => [
|
42
|
+
['hash.md5', '$L0', '$P1'],
|
43
|
+
['size', '$L1', '$L0'],
|
44
|
+
['set', '$L2', 0],
|
45
|
+
['set', '$P0', ''],
|
46
|
+
['get', '$L3', '$L0', '$L2'],
|
47
|
+
['string.format', '$L4', '%02X', '$L3'],
|
48
|
+
['string.concat', '$P0', '$P0', '$L4'],
|
49
|
+
['math.add', '$L2', '$L2', 1],
|
50
|
+
['if>=than', '$L2', '$L1', -5]
|
51
|
+
]
|
52
|
+
};
|
53
|
+
interpreter_storage = {
|
54
|
+
'serviceName' => servicename,
|
55
|
+
'platform' => 'Ruby',
|
56
|
+
'os' => get_os
|
57
|
+
}
|
58
|
+
mac = get_mac
|
59
|
+
nv = get_name_version
|
60
|
+
interpreter = Interpreter.new(Sandbox.new(service_code, [], {}))
|
61
|
+
interpreter.call_function('selfTest', interpreter_storage, mac, nv['name'], nv['version'])
|
62
|
+
test_state
|
63
|
+
end
|
64
|
+
|
65
|
+
# from http://stackoverflow.com/questions/8761878/how-to-get-my-mac-address-programmatically-with-ruby
|
66
|
+
def get_mac
|
67
|
+
platform = RUBY_PLATFORM.downcase
|
68
|
+
output = `#{(platform =~ /win32/) ? 'ipconfig /all' : 'ifconfig'}`
|
69
|
+
case platform
|
70
|
+
when /darwin/
|
71
|
+
$1 if output =~ /en1.*?(([A-F0-9]{2}:){5}[A-F0-9]{2})/im
|
72
|
+
when /win32/
|
73
|
+
$1 if output =~ /Physical Address.*?(([A-F0-9]{2}-){5}[A-F0-9]{2})/im
|
74
|
+
# Cases for other platforms...
|
75
|
+
else nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_name_version
|
80
|
+
return {
|
81
|
+
'name' => 'CloudRailSi',
|
82
|
+
'version' => CloudRailSi::VERSION
|
83
|
+
}
|
84
|
+
end
|
85
|
+
def get_os
|
86
|
+
"#{RbConfig::CONFIG['arch']}, #{RbConfig::CONFIG['target_os']}, #{RbConfig::CONFIG['host_os']}"
|
87
|
+
end
|
88
|
+
@@tested_services = []
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|