Class: CloudRailSi::Services::Twitter

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudrail_si/services/Twitter.rb

Constant Summary collapse

SERVICE_CODE =
{
  
    "Authenticating:login" => [
      [ "callFunc", "checkAuthentication", "$P0"]
      
    ],
  
    "Authenticating:logout" => [
      [ "delete", "$S0.oauthToken"],
      [ "delete", "$S0.oauthTokenSecret"],
      [ "set", "$P0.userInfo", nil]
      
    ],
  
    "Social:postUpdate" => [
      [ "if==than", "$P1", nil, 2],
      [ "create", "$L0", "Error", "The status is not allowed to be null.", "IllegalArgument"],
      [ "throwError", "$L0"],
      [ "size", "$L0", "$P1"],
      [ "if>than", "$L0", 140, 2],
      [ "create", "$L0", "Error", "The status is not allowed to contain more than 140 characters.", "IllegalArgument"],
      [ "throwError", "$L0"],
      [ "callFunc", "checkAuthentication", "$P0"],
      [ "callFunc", "post", "$P0", "$P1"]
      
    ],
  
    "Social:postImage" => [
      [ "if==than", "$P1", nil, 2],
      [ "create", "$L0", "Error", "The message is not allowed to be null", "IllegalArgument"],
      [ "throwError", "$L0"],
      [ "if==than", "$P2", nil, 2],
      [ "create", "$L0", "Error", "The image is not allowed to be null", "IllegalArgument"],
      [ "throwError", "$L0"],
      [ "callFunc", "checkAuthentication", "$P0"],
      [ "create", "$L0", "Object"],
      [ "set", "$L0.method", "POST"],
      [ "set", "$L0.url", "https://upload.twitter.com/1.1/media/upload.json"],
      [ "create", "$L1", "Array"],
      [ "push", "$L1", "oauth_consumer_key"],
      [ "push", "$L1", "oauth_nonce"],
      [ "push", "$L1", "oauth_signature_method"],
      [ "push", "$L1", "oauth_timestamp"],
      [ "push", "$L1", "oauth_token"],
      [ "push", "$L1", "oauth_version"],
      [ "callFunc", "oAuth1:signRequest", "$P0", "$L0", "$L1"],
      [ "create", "$L2", "String", "AaB03xh3u2hfiugiuhuo34gwhoughugheruighui34giuwrgh"],
      [ "string.concat", "$L0.requestHeaders.Content-Type", "multipart/form-data; boundary=", "$L2"],
      [ "string.concat", "$L3", "--", "$L2", "\r\n"],
      [ "string.concat", "$L3", "$L3", "Content-Disposition: form-data; name=\"media\"\r\n"],
      [ "string.concat", "$L3", "$L3", "Content-Type: application/octet-stream\r\n\r\n"],
      [ "stream.stringToStream", "$L3", "$L3"],
      [ "string.concat", "$L4", "\r\n--", "$L2", "--"],
      [ "stream.stringToStream", "$L4", "$L4"],
      [ "stream.makeJoinedStream", "$L0.requestBody", "$L3", "$P2", "$L4"],
      [ "http.requestCall", "$L5", "$L0"],
      [ "callFunc", "validateResponse", "$P0", "$L5"],
      [ "json.parse", "$L6", "$L5.responseBody"],
      [ "set", "$L7", "$L6.media_id_string"],
      [ "callFunc", "post", "$P0", "$P1", "$L7"]
      
    ],
  
    "Social:postVideo" => [
      [ "if==than", "$P1", nil, 2],
      [ "create", "$L0", "Error", "The message is not allowed to be null", "IllegalArgument"],
      [ "throwError", "$L0"],
      [ "if==than", "$P2", nil, 2],
      [ "create", "$L0", "Error", "The image is not allowed to be null", "IllegalArgument"],
      [ "throwError", "$L0"],
      [ "callFunc", "checkAuthentication", "$P0"],
      [ "callFunc", "initUpload", "$P0", "$L0", "$P3", "$P4"],
      [ "callFunc", "performUpload", "$P0", "$L0", "$P2", "$P3"],
      [ "callFunc", "finishUpload", "$P0", "$L0"],
      [ "callFunc", "post", "$P0", "$P1", "$L0"]
      
    ],
  
    "Social:getConnections" => [
      [ "callFunc", "checkAuthentication", "$P0"],
      [ "create", "$L0", "Object"],
      [ "set", "$L0.method", "GET"],
      [ "set", "$L0.url", "https://api.twitter.com/1.1/friends/ids.json"],
      [ "create", "$L1", "Array"],
      [ "push", "$L1", "count"],
      [ "push", "$L1", "oauth_consumer_key"],
      [ "push", "$L1", "oauth_nonce"],
      [ "push", "$L1", "oauth_signature_method"],
      [ "push", "$L1", "oauth_timestamp"],
      [ "push", "$L1", "oauth_token"],
      [ "push", "$L1", "oauth_version"],
      [ "push", "$L1", "stringify_ids"],
      [ "create", "$L3", "Object"],
      [ "set", "$L3.count", "5000"],
      [ "set", "$L3.stringify_ids", "true"],
      [ "callFunc", "oAuth1:signRequest", "$P0", "$L0", "$L1", "$L3"],
      [ "string.concat", "$L0.url", "$L0.url", "?count=5000&stringify_ids=true"],
      [ "http.requestCall", "$L1", "$L0"],
      [ "json.parse", "$L2", "$L1.responseBody"],
      [ "callFunc", "validateResponse", "$P0", "$L1"],
      [ "set", "$L3", "$L2.ids"],
      [ "create", "$P1", "Array"],
      [ "create", "$L4", "Number", 0],
      [ "size", "$L5", "$L3"],
      [ "if<than", "$L4", "$L5", 5],
      [ "get", "$L6", "$L3", "$L4"],
      [ "string.concat", "$L6", "twitter-", "$L6"],
      [ "push", "$P1", "$L6"],
      [ "math.add", "$L4", "$L4", 1],
      [ "jumpRel", -6]
      
    ],
  
    "Profile:getIdentifier" => [
      [ "callFunc", "User:getInfo", "$P0"],
      [ "string.concat", "$P1", "twitter-", "$P0.userInfo.id"]
      
    ],
  
    "Profile:getFullName" => [
      [ "callFunc", "User:getInfo", "$P0"],
      [ "set", "$P1", "$P0.userInfo.name"]
      
    ],
  
    "Profile:getEmail" => [
      [ "callFunc", "User:getInfo", "$P0"],
      [ "set", "$P1", "$P0.userInfo.email"]
      
    ],
  
    "Profile:getGender" => [
      [ "callFunc", "User:getInfo", "$P0"],
      [ "set", "$P1", "$P0.userInfo.gender"]
      
    ],
  
    "Profile:getDescription" => [
      [ "callFunc", "User:getInfo", "$P0"],
      [ "set", "$P1", "$P0.userInfo.description"]
      
    ],
  
    "Profile:getDateOfBirth" => [
      [ "callFunc", "User:getInfo", "$P0"],
      [ "set", "$P1", "$P0.userInfo.dateOfBirth"]
      
    ],
  
    "Profile:getLocale" => [
      [ "callFunc", "User:getInfo", "$P0"],
      [ "set", "$P1", "$P0.userInfo.locale"]
      
    ],
  
    "Profile:getPictureURL" => [
      [ "callFunc", "User:getInfo", "$P0"],
      [ "set", "$P1", "$P0.userInfo.pictureURL"]
      
    ],
  
    "User:getInfo" => [
      [ "if!=than", "$P0.userInfo", nil, 4],
      [ "create", "$L0", "Date"],
      [ "math.add", "$L0", "$L0.Time", -10000],
      [ "if>than", "$P0.userInfo.lastUpdate", "$L0", 1],
      [ "return"],
      [ "callFunc", "User:sendInfoRequest", "$P0"]
      
    ],
  
    "User:sendInfoRequest" => [
      [ "callFunc", "checkAuthentication", "$P0"],
      [ "create", "$L0", "Object"],
      [ "set", "$L0.method", "GET"],
      [ "set", "$L0.url", "https://api.twitter.com/1.1/account/verify_credentials.json"],
      [ "create", "$L1", "Array"],
      [ "push", "$L1", "oauth_consumer_key"],
      [ "push", "$L1", "oauth_nonce"],
      [ "push", "$L1", "oauth_signature_method"],
      [ "push", "$L1", "oauth_timestamp"],
      [ "push", "$L1", "oauth_token"],
      [ "push", "$L1", "oauth_version"],
      [ "callFunc", "oAuth1:signRequest", "$P0", "$L0", "$L1"],
      [ "http.requestCall", "$L1", "$L0"],
      [ "json.parse", "$L2", "$L1.responseBody"],
      [ "callFunc", "validateResponse", "$P0", "$L1"],
      [ "create", "$P0.userInfo", "Object"],
      [ "create", "$L3", "Date"],
      [ "set", "$P0.userInfo.lastUpdate", "$L3.Time"],
      [ "set", "$P0.userInfo.id", "$L2.id_str"],
      [ "set", "$P0.userInfo.name", "$L2.name"],
      [ "set", "$P0.userInfo.email", nil],
      [ "set", "$P0.userInfo.gender", nil],
      [ "set", "$P0.userInfo.description", "$L2.description"],
      [ "create", "$P0.userInfo.dateOfBirth", "DateOfBirth"],
      [ "set", "$P0.userInfo.locale", "$L2.lang"],
      [ "set", "$P0.userInfo.pictureURL", "$L2.profile_image_url"]
      
    ],
  
    "initUpload" => [
      [ "create", "$L0", "Object"],
      [ "set", "$L0.method", "POST"],
      [ "string.concat", "$L0.url", "https://upload.twitter.com/1.1/media/upload.json"],
      [ "create", "$L1", "Array"],
      [ "push", "$L1", "command"],
      [ "push", "$L1", "media_type"],
      [ "push", "$L1", "oauth_consumer_key"],
      [ "push", "$L1", "oauth_nonce"],
      [ "push", "$L1", "oauth_signature_method"],
      [ "push", "$L1", "oauth_timestamp"],
      [ "push", "$L1", "oauth_token"],
      [ "push", "$L1", "oauth_version"],
      [ "push", "$L1", "total_bytes"],
      [ "create", "$L2", "Object"],
      [ "set", "$L2.command", "INIT"],
      [ "set", "$L2.media_type", "$P3"],
      [ "string.concat", "$L2.total_bytes", "$P2", ""],
      [ "callFunc", "oAuth1:signRequest", "$P0", "$L0", "$L1", "$L2"],
      [ "string.urlEncode", "$L3", "$P3"],
      [ "string.concat", "$L3", "command=INIT&media_type=", "$L3", "&total_bytes=", "$P2"],
      [ "stream.stringToStream", "$L0.requestBody", "$L3"],
      [ "set", "$L0.requestHeaders.Content-Type", "application/x-www-form-urlencoded"],
      [ "http.requestCall", "$L4", "$L0"],
      [ "callFunc", "validateResponse", "$P0", "$L4"],
      [ "json.parse", "$L5", "$L4.responseBody"],
      [ "set", "$P1", "$L5.media_id_string"]
      
    ],
  
    "performUpload" => [
      [ "create", "$L20", "Number", 2097152],
      [ "create", "$L21", "Number", 0],
      [ "create", "$L22", "Number", 1],
      [ "if<than", "$L22", "$P3", 35],
      [ "create", "$L0", "Object"],
      [ "set", "$L0.method", "POST"],
      [ "string.concat", "$L0.url", "https://upload.twitter.com/1.1/media/upload.json"],
      [ "create", "$L1", "Array"],
      [ "push", "$L1", "oauth_consumer_key"],
      [ "push", "$L1", "oauth_nonce"],
      [ "push", "$L1", "oauth_signature_method"],
      [ "push", "$L1", "oauth_timestamp"],
      [ "push", "$L1", "oauth_token"],
      [ "push", "$L1", "oauth_version"],
      [ "callFunc", "oAuth1:signRequest", "$P0", "$L0", "$L1"],
      [ "create", "$L2", "String", "AaB03xh3u2hfiugiuhuo34gwhoughugheruighui34giuwrgh"],
      [ "string.concat", "$L3", "--", "$L2", "\r\n"],
      [ "string.concat", "$L3", "$L3", "Content-Disposition: form-data; name=\"command\"\r\n\r\n"],
      [ "string.concat", "$L3", "$L3", "APPEND\r\n"],
      [ "string.concat", "$L3", "$L3", "--", "$L2", "\r\n"],
      [ "string.concat", "$L3", "$L3", "Content-Disposition: form-data; name=\"media_id\"\r\n\r\n"],
      [ "string.concat", "$L3", "$L3", "$P1", "\r\n"],
      [ "string.concat", "$L3", "$L3", "--", "$L2", "\r\n"],
      [ "string.concat", "$L3", "$L3", "Content-Disposition: form-data; name=\"segment_index\"\r\n\r\n"],
      [ "string.concat", "$L3", "$L3", "$L21", "\r\n"],
      [ "string.concat", "$L3", "$L3", "--", "$L2", "\r\n"],
      [ "string.concat", "$L3", "$L3", "Content-Disposition: form-data; name=\"media\"\r\n"],
      [ "string.concat", "$L3", "$L3", "Content-Type: application/octet-stream\r\n\r\n"],
      [ "stream.stringToStream", "$L3", "$L3"],
      [ "stream.makeLimitedStream", "$L23", "$P2", "$L20"],
      [ "string.concat", "$L4", "\r\n--", "$L2", "--"],
      [ "stream.stringToStream", "$L4", "$L4"],
      [ "stream.makeJoinedStream", "$L0.requestBody", "$L3", "$L23", "$L4"],
      [ "string.concat", "$L0.requestHeaders.Content-Type", "multipart/form-data; boundary=", "$L2"],
      [ "http.requestCall", "$L5", "$L0"],
      [ "callFunc", "validateResponse", "$P0", "$L5"],
      [ "math.add", "$L22", "$L22", "$L20"],
      [ "math.add", "$L21", "$L21", 1],
      [ "jumpRel", -36]
      
    ],
  
    "finishUpload" => [
      [ "create", "$L0", "Object"],
      [ "set", "$L0.method", "POST"],
      [ "string.concat", "$L0.url", "https://upload.twitter.com/1.1/media/upload.json"],
      [ "create", "$L1", "Array"],
      [ "push", "$L1", "command"],
      [ "push", "$L1", "media_id"],
      [ "push", "$L1", "oauth_consumer_key"],
      [ "push", "$L1", "oauth_nonce"],
      [ "push", "$L1", "oauth_signature_method"],
      [ "push", "$L1", "oauth_timestamp"],
      [ "push", "$L1", "oauth_token"],
      [ "push", "$L1", "oauth_version"],
      [ "create", "$L2", "Object"],
      [ "set", "$L2.command", "FINALIZE"],
      [ "set", "$L2.media_id", "$P1"],
      [ "callFunc", "oAuth1:signRequest", "$P0", "$L0", "$L1", "$L2"],
      [ "string.concat", "$L3", "command=FINALIZE&media_id=", "$P1"],
      [ "stream.stringToStream", "$L0.requestBody", "$L3"],
      [ "set", "$L0.requestHeaders.Content-Type", "application/x-www-form-urlencoded"],
      [ "http.requestCall", "$L4", "$L0"],
      [ "callFunc", "validateResponse", "$P0", "$L4"]
      
    ],
  
    "post" => [
      [ "string.urlEncode", "$L3", "$P1"],
      [ "callFunc", "urlEncode", "$P0", "$L5", "$L3"],
      [ "create", "$L0", "Object"],
      [ "set", "$L0.method", "POST"],
      [ "string.concat", "$L0.url", "https://api.twitter.com/1.1/statuses/update.json"],
      [ "create", "$L1", "Array"],
      [ "if!=than", "$P2", nil, 1],
      [ "push", "$L1", "media_ids"],
      [ "push", "$L1", "oauth_consumer_key"],
      [ "push", "$L1", "oauth_nonce"],
      [ "push", "$L1", "oauth_signature_method"],
      [ "push", "$L1", "oauth_timestamp"],
      [ "push", "$L1", "oauth_token"],
      [ "push", "$L1", "oauth_version"],
      [ "push", "$L1", "status"],
      [ "create", "$L4", "Object"],
      [ "set", "$L4.status", "$P1"],
      [ "if!=than", "$P2", nil, 1],
      [ "set", "$L4.media_ids", "$P2"],
      [ "callFunc", "oAuth1:signRequest", "$P0", "$L0", "$L1", "$L4"],
      [ "string.concat", "$L21", "status=", "$L5"],
      [ "if!=than", "$P2", nil, 1],
      [ "string.concat", "$L21", "$L21", "&media_ids=", "$P2"],
      [ "stream.stringToStream", "$L0.requestBody", "$L21"],
      [ "set", "$L0.requestHeaders.Content-Type", "application/x-www-form-urlencoded"],
      [ "http.requestCall", "$L1", "$L0"],
      [ "callFunc", "validateResponse", "$P0", "$L1"]
      
    ],
  
    "AdvancedRequestSupporter:advancedRequest" => [
      [ "create", "$L0", "Object"],
      [ "create", "$L0.url", "String"],
      [ "if!=than", "$P2.appendBaseUrl", 0, 1],
      [ "set", "$L0.url", "https://api.twitter.com/1.1"],
      [ "string.concat", "$L0.url", "$L0.url", "$P2.url"],
      [ "set", "$L0.requestHeaders", "$P2.headers"],
      [ "set", "$L0.method", "$P2.method"],
      [ "if==than", "$P2.headers.Content-Type", "application/x-www-form-urlencoded", 3],
      [ "stream.streamToString", "$L10", "$P2.body"],
      [ "stream.stringToStream", "$L0.requestBody", "$L10"],
      [ "jumpRel", 1],
      [ "set", "$L0.requestBody", "$P2.body"],
      [ "if!=than", "$P2.appendAuthorization", 0, 21],
      [ "callFunc", "checkAuthentication", "$P0"],
      [ "string.split", "$L2", "$P2.url", "\\?", 2],
      [ "size", "$L3", "$L2"],
      [ "create", "$L4", "String"],
      [ "if==than", "$L3", 2, 1],
      [ "get", "$L4", "$L2", 1],
      [ "if==than", "$P2.headers.Content-Type", "application/x-www-form-urlencoded", 4],
      [ "size", "$L6", "$L4"],
      [ "if>than", "$L6", 0, 1],
      [ "string.concat", "$L4", "$L4", "&"],
      [ "string.concat", "$L4", "$L4", "$L10"],
      [ "callFunc", "extractParameters", "$P0", "$L6", "$L4"],
      [ "object.getKeyArray", "$L5", "$L6"],
      [ "push", "$L5", "oauth_consumer_key"],
      [ "push", "$L5", "oauth_nonce"],
      [ "push", "$L5", "oauth_signature_method"],
      [ "push", "$L5", "oauth_timestamp"],
      [ "push", "$L5", "oauth_token"],
      [ "push", "$L5", "oauth_version"],
      [ "array.sort", "$L5", "$L5"],
      [ "callFunc", "oAuth1:signRequest", "$P0", "$L0", "$L5", "$L6"],
      [ "http.requestCall", "$L1", "$L0"],
      [ "if!=than", "$P2.checkErrors", 0, 1],
      [ "callFunc", "validateResponse", "$P0", "$L1"],
      [ "create", "$P1", "AdvancedRequestResponse"],
      [ "set", "$P1.status", "$L1.code"],
      [ "set", "$P1.headers", "$L1.responseHeaders"],
      [ "set", "$P1.body", "$L1.responseBody"]
      
    ],
  
    "extractParameters" => [
      [ "create", "$P1", "Object"],
      [ "size", "$L0", "$P2"],
      [ "if==than", "$L0", 0, 1],
      [ "return"],
      [ "string.split", "$L1", "$P2", "&"],
      [ "size", "$L2", "$L1"],
      [ "set", "$L3", 0],
      [ "if<than", "$L3", "$L2", 7],
      [ "get", "$L4", "$L1", "$L3"],
      [ "string.split", "$L5", "$L4", "=", 2],
      [ "get", "$L6", "$L5", 0],
      [ "get", "$L7", "$L5", 1],
      [ "set", "$P1", "$L7", "$L6"],
      [ "math.add", "$L3", "$L3", 1],
      [ "jumpRel", -8]
      
    ],
  
    "oAuth1:signRequest" => [
      [ "if==than", "$P1.requestHeaders", nil, 1],
      [ "create", "$P1.requestHeaders", "Object"],
      [ "create", "$L0", "Object"],
      [ "set", "$L0.oauth_consumer_key", "$P0.clientID"],
      [ "callFunc", "oAuth1:generateNonce", "$L0.oauth_nonce"],
      [ "set", "$L0.oauth_signature_method", "HMAC-SHA1"],
      [ "create", "$L1", "Date"],
      [ "math.multiply", "$L1", "$L1.Time", 0.001],
      [ "math.floor", "$L1", "$L1"],
      [ "string.format", "$L0.oauth_timestamp", "%d", "$L1"],
      [ "set", "$L0.oauth_token", "$S0.oauthToken"],
      [ "set", "$L0.oauth_version", "1.0"],
      [ "string.split", "$L2", "$P1.url", "\\?", 2],
      [ "get", "$L2", "$L2", 0],
      [ "string.urlEncode", "$L2", "$L2"],
      [ "string.concat", "$L1", "$P1.method", "&", "$L2", "&"],
      [ "set", "$L2", ""],
      [ "set", "$L3", 0],
      [ "size", "$L4", "$P2"],
      [ "if<than", "$L3", "$L4", 15],
      [ "get", "$L5", "$P2", "$L3"],
      [ "if==than", "$L5", "oauth_callback", 1],
      [ "set", "$L0.oauth_callback", "$P0.redirectUri"],
      [ "get", "$L6", "$L0", "$L5"],
      [ "if>than", "$L3", 0, 1],
      [ "string.concat", "$L2", "$L2", "&"],
      [ "if==than", "$L6", nil, 1],
      [ "get", "$L6", "$P3", "$L5"],
      [ "string.urlEncode", "$L6", "$L6"],
      [ "if==than", "$L5", "status", 2],
      [ "callFunc", "urlEncode", "$P0", "$L20", "$L6"],
      [ "set", "$L6", "$L20"],
      [ "string.concat", "$L2", "$L2", "$L5", "=", "$L6"],
      [ "math.add", "$L3", "$L3", 1],
      [ "jumpRel", -16],
      [ "string.urlEncode", "$L2", "$L2"],
      [ "string.concat", "$L1", "$L1", "$L2"],
      [ "set", "$L2", "$S0.oauthTokenSecret"],
      [ "if==than", "$L2", nil, 1],
      [ "set", "$L2", ""],
      [ "string.concat", "$L2", "$P0.clientSecret", "&", "$L2"],
      [ "crypt.hmac.sha1", "$L2", "$L2", "$L1"],
      [ "array.uint8ToBase64", "$L2", "$L2"],
      [ "string.urlEncode", "$L2", "$L2"],
      [ "set", "$L0.oauth_signature", "$L2"],
      [ "set", "$L2", "OAuth "],
      [ "if!=than", "$L0.oauth_callback", nil, 2],
      [ "string.urlEncode", "$L3", "$L0.oauth_callback"],
      [ "string.concat", "$L2", "$L2", "oauth_callback", "=\"", "$L3", "\"", ", "],
      [ "string.concat", "$L2", "$L2", "oauth_consumer_key", "=\"", "$L0.oauth_consumer_key", "\""],
      [ "string.concat", "$L2", "$L2", ", ", "oauth_nonce", "=\"", "$L0.oauth_nonce", "\""],
      [ "string.concat", "$L2", "$L2", ", ", "oauth_signature", "=\"", "$L0.oauth_signature", "\""],
      [ "string.concat", "$L2", "$L2", ", ", "oauth_signature_method", "=\"", "$L0.oauth_signature_method", "\""],
      [ "string.concat", "$L2", "$L2", ", ", "oauth_timestamp", "=\"", "$L0.oauth_timestamp", "\""],
      [ "if!=than", "$L0.oauth_token", nil, 1],
      [ "string.concat", "$L2", "$L2", ", ", "oauth_token", "=\"", "$L0.oauth_token", "\""],
      [ "string.concat", "$L2", "$L2", ", ", "oauth_version", "=\"", "$L0.oauth_version", "\""],
      [ "set", "$P1.requestHeaders.Authorization", "$L2"]
      
    ],
  
    "oAuth1:generateNonce" => [
      [ "create", "$L0", "Date"],
      [ "string.format", "$L0", "%d", "$L0.Time"],
      [ "hash.md5", "$L0", "$L0"],
      [ "size", "$L1", "$L0"],
      [ "set", "$L2", 0],
      [ "set", "$P0", ""],
      [ "get", "$L3", "$L0", "$L2"],
      [ "string.format", "$L4", "%02x", "$L3"],
      [ "string.concat", "$P0", "$P0", "$L4"],
      [ "math.add", "$L2", "$L2", 1],
      [ "if>=than", "$L2", "$L1", -5]
      
    ],
  
    "urlEncode" => [
      [ "string.split", "$L0", "$P2", "\\+"],
      [ "size", "$L1", "$L0"],
      [ "create", "$L2", "Number"],
      [ "set", "$L2", 0],
      [ "create", "$L4", "String"],
      [ "if<than", "$L2", "$L1", 7],
      [ "get", "$L5", "$L0", "$L2"],
      [ "if==than", "$L2", 0, 2],
      [ "set", "$L4", "$L5"],
      [ "jumpRel", 1],
      [ "string.concat", "$L4", "$L4", "%20", "$L5"],
      [ "math.add", "$L2", "$L2", 1],
      [ "jumpRel", -8],
      [ "set", "$P1", "$L4"]
      
    ],
  
    "checkAuthentication" => [
      [ "if!=than", "$S0.oauthToken", nil, 2],
      [ "if!=than", "$S0.oauthTokenSecret", nil, 1],
      [ "return"],
      [ "callFunc", "authenticate", "$P0"]
      
    ],
  
    "authenticate" => [
      [ "create", "$L0", "Object"],
      [ "set", "$L0.method", "POST"],
      [ "set", "$L0.url", "https://api.twitter.com/oauth/request_token"],
      [ "create", "$L1", "Array"],
      [ "push", "$L1", "oauth_callback"],
      [ "push", "$L1", "oauth_consumer_key"],
      [ "push", "$L1", "oauth_nonce"],
      [ "push", "$L1", "oauth_signature_method"],
      [ "push", "$L1", "oauth_timestamp"],
      [ "push", "$L1", "oauth_version"],
      [ "callFunc", "oAuth1:signRequest", "$P0", "$L0", "$L1"],
      [ "http.requestCall", "$L1", "$L0"],
      [ "if!=than", "$L1.code", 200, 3],
      [ "stream.streamToString", "$L2", "$L1.responseBody"],
      [ "create", "$L3", "Error", "$L2", "Authentication"],
      [ "throwError", "$L3"],
      [ "stream.streamToString", "$L2", "$L1.responseBody"],
      [ "string.split", "$L2", "$L2", "&"],
      [ "set", "$L3", 0],
      [ "size", "$L4", "$L2"],
      [ "create", "$L0", "Object"],
      [ "if<than", "$L3", "$L4", 8],
      [ "get", "$L5", "$L2", "$L3"],
      [ "string.split", "$L6", "$L5", "=", 2],
      [ "get", "$L7", "$L6", 0],
      [ "get", "$L8", "$L6", 1],
      [ "string.urlDecode", "$L8", "$L8"],
      [ "set", "$L0", "$L8", "$L7"],
      [ "math.add", "$L3", "$L3", 1],
      [ "jumpRel", -9],
      [ "string.concat", "$L3", "https://api.twitter.com/oauth/authenticate?oauth_token=", "$L0.oauth_token"],
      [ "awaitCodeRedirect", "$L3", "$L3", "oauth_token", "oauth_verifier"],
      [ "set", "$S0.oauthToken", "$L3.oauth_token"],
      [ "create", "$L4", "Object"],
      [ "set", "$L4.method", "POST"],
      [ "set", "$L4.url", "https://api.twitter.com/oauth/access_token"],
      [ "create", "$L4.requestHeaders", "Object"],
      [ "set", "$L4.requestHeaders.Content-Type", "application/x-www-form-urlencoded"],
      [ "string.urlEncode", "$L5", "$L3.oauth_verifier"],
      [ "string.concat", "$L5", "oauth_verifier=", "$L5"],
      [ "stream.stringToStream", "$L4.requestBody", "$L5"],
      [ "create", "$L6", "Object"],
      [ "set", "$L6.oauth_verifier", "$L3.oauth_verifier"],
      [ "create", "$L7", "Array"],
      [ "push", "$L7", "oauth_callback"],
      [ "push", "$L7", "oauth_consumer_key"],
      [ "push", "$L7", "oauth_nonce"],
      [ "push", "$L7", "oauth_signature_method"],
      [ "push", "$L7", "oauth_timestamp"],
      [ "push", "$L7", "oauth_verifier"],
      [ "push", "$L7", "oauth_version"],
      [ "callFunc", "oAuth1:signRequest", "$P0", "$L4", "$L7", "$L6"],
      [ "http.requestCall", "$L9", "$L4"],
      [ "if!=than", "$L9.code", 200, 3],
      [ "stream.streamToString", "$L10", "$L9.responseBody"],
      [ "create", "$L11", "Error", "$L10", "Authentication"],
      [ "throwError", "$L11"],
      [ "stream.streamToString", "$L10", "$L9.responseBody"],
      [ "string.split", "$L10", "$L10", "&"],
      [ "set", "$L11", 0],
      [ "size", "$L12", "$L10"],
      [ "create", "$L13", "Object"],
      [ "if<than", "$L11", "$L12", 8],
      [ "get", "$L14", "$L10", "$L11"],
      [ "string.split", "$L15", "$L14", "=", 2],
      [ "get", "$L16", "$L15", 0],
      [ "get", "$L17", "$L15", 1],
      [ "string.urlDecode", "$L17", "$L17"],
      [ "set", "$L13", "$L17", "$L16"],
      [ "math.add", "$L11", "$L11", 1],
      [ "jumpRel", -9],
      [ "string.urlDecode", "$S0.oauthToken", "$L13.oauth_token"],
      [ "string.urlDecode", "$S0.oauthTokenSecret", "$L13.oauth_token_secret"]
      
    ],
  
    "validateResponse" => [
      [ "if>=than", "$P1.code", 400, 3],
      [ "stream.streamToString", "$L2", "$P1.responseBody"],
      [ "create", "$L3", "Error", "$L2", "Http"],
      [ "throwError", "$L3"]
      
    ]
  
}

Instance Method Summary collapse

Constructor Details

#initialize(redirect_receiver, client_id, client_secret, redirect_uri) ⇒ Twitter

Returns a new instance of Twitter.



595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/cloudrail_si/services/Twitter.rb', line 595

def initialize(redirect_receiver, client_id, client_secret, redirect_uri)
    @interpreter_storage = {}
    @persistent_storage = [{}]
    @instance_dependency_storage = {
        redirect_receiver: redirect_receiver
    }

    ServiceCode::InitSelfTest.init_test('Twitter')

    @interpreter_storage['clientID'] = client_id
    @interpreter_storage['clientSecret'] = client_secret
    @interpreter_storage['redirectUri'] = redirect_uri
    

    

    # call init servicecode function
    ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
    # check and call the initialization function if is available

    ip.call_function_sync('init', @interpreter_storage) if (SERVICE_CODE['init'])
end

Instance Method Details

#advanced_request(specification) ⇒ Object



729
730
731
732
733
734
735
736
# File 'lib/cloudrail_si/services/Twitter.rb', line 729

def advanced_request(specification)
  ServiceCode::Statistics.add_call('Twitter', 'advanced_request')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('AdvancedRequestSupporter:advancedRequest', @interpreter_storage, nil, specification)

  check_for_error(ip.sandbox.thrown_error)
  return nil || ip.get_parameter(1)
end

#check_for_error(error) ⇒ Object



618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
# File 'lib/cloudrail_si/services/Twitter.rb', line 618

def check_for_error(error)
  if (error)
    ServiceCode::Statistics.add_error('Twitter', '')
    case (error.type)
    when 'IllegalArgument'
      raise Errors::IllegalArgumentError.new(error.message)
    when 'Authentication'
      raise Errors::AuthenticationError.new(error.message)
    when 'NotFound'
      raise Errors::NotFoundError.new(error.message)
    when 'Http'
      raise Errors::HttpError.new(error.message)
    when 'ServiceUnavailable'
      raise Errors::ServiceUnavailableError.new(error.message)
    else
      raise Errors::StandardError.new(error.message)
    end
  end
end

#get_connectionsObject



765
766
767
768
769
770
771
772
# File 'lib/cloudrail_si/services/Twitter.rb', line 765

def get_connections()
  ServiceCode::Statistics.add_call('Twitter', 'get_connections')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Social:getConnections', @interpreter_storage, nil)

  check_for_error(ip.sandbox.thrown_error)
  return nil || ip.get_parameter(1)
end

#get_date_of_birthObject



684
685
686
687
688
689
690
691
# File 'lib/cloudrail_si/services/Twitter.rb', line 684

def get_date_of_birth()
  ServiceCode::Statistics.add_call('Twitter', 'get_date_of_birth')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Profile:getDateOfBirth', @interpreter_storage, nil)

  check_for_error(ip.sandbox.thrown_error)
  return nil || ip.get_parameter(1)
end

#get_descriptionObject



675
676
677
678
679
680
681
682
# File 'lib/cloudrail_si/services/Twitter.rb', line 675

def get_description()
  ServiceCode::Statistics.add_call('Twitter', 'get_description')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Profile:getDescription', @interpreter_storage, nil)

  check_for_error(ip.sandbox.thrown_error)
  return nil || ip.get_parameter(1)
end

#get_emailObject



657
658
659
660
661
662
663
664
# File 'lib/cloudrail_si/services/Twitter.rb', line 657

def get_email()
  ServiceCode::Statistics.add_call('Twitter', 'get_email')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Profile:getEmail', @interpreter_storage, nil)

  check_for_error(ip.sandbox.thrown_error)
  return nil || ip.get_parameter(1)
end

#get_full_nameObject



648
649
650
651
652
653
654
655
# File 'lib/cloudrail_si/services/Twitter.rb', line 648

def get_full_name()
  ServiceCode::Statistics.add_call('Twitter', 'get_full_name')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Profile:getFullName', @interpreter_storage, nil)

  check_for_error(ip.sandbox.thrown_error)
  return nil || ip.get_parameter(1)
end

#get_genderObject



666
667
668
669
670
671
672
673
# File 'lib/cloudrail_si/services/Twitter.rb', line 666

def get_gender()
  ServiceCode::Statistics.add_call('Twitter', 'get_gender')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Profile:getGender', @interpreter_storage, nil)

  check_for_error(ip.sandbox.thrown_error)
  return nil || ip.get_parameter(1)
end

#get_identifierObject



639
640
641
642
643
644
645
646
# File 'lib/cloudrail_si/services/Twitter.rb', line 639

def get_identifier()
  ServiceCode::Statistics.add_call('Twitter', 'get_identifier')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Profile:getIdentifier', @interpreter_storage, nil)

  check_for_error(ip.sandbox.thrown_error)
  return nil || ip.get_parameter(1)
end

#get_localeObject



693
694
695
696
697
698
699
700
# File 'lib/cloudrail_si/services/Twitter.rb', line 693

def get_locale()
  ServiceCode::Statistics.add_call('Twitter', 'get_locale')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Profile:getLocale', @interpreter_storage, nil)

  check_for_error(ip.sandbox.thrown_error)
  return nil || ip.get_parameter(1)
end

#get_picture_urlObject



702
703
704
705
706
707
708
709
# File 'lib/cloudrail_si/services/Twitter.rb', line 702

def get_picture_url()
  ServiceCode::Statistics.add_call('Twitter', 'get_picture_url')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Profile:getPictureURL', @interpreter_storage, nil)

  check_for_error(ip.sandbox.thrown_error)
  return nil || ip.get_parameter(1)
end

#load_as_string(saved_state) ⇒ Object



780
781
782
783
784
785
# File 'lib/cloudrail_si/services/Twitter.rb', line 780

def load_as_string(saved_state)
	sandbox = ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)
	ip = ServiceCode::Interpreter.new(sandbox)
	ip.load_as_string(saved_state)
	@persistent_storage = sandbox.persistent_storage
end

#loginObject



711
712
713
714
715
716
717
718
# File 'lib/cloudrail_si/services/Twitter.rb', line 711

def ()
  ServiceCode::Statistics.add_call('Twitter', 'login')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Authenticating:login', @interpreter_storage)

  check_for_error(ip.sandbox.thrown_error)
  return nil
end

#logoutObject



720
721
722
723
724
725
726
727
# File 'lib/cloudrail_si/services/Twitter.rb', line 720

def logout()
  ServiceCode::Statistics.add_call('Twitter', 'logout')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Authenticating:logout', @interpreter_storage)

  check_for_error(ip.sandbox.thrown_error)
  return nil
end

#post_image(message, image) ⇒ Object



747
748
749
750
751
752
753
754
# File 'lib/cloudrail_si/services/Twitter.rb', line 747

def post_image(message, image)
  ServiceCode::Statistics.add_call('Twitter', 'post_image')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Social:postImage', @interpreter_storage, message, image)

  check_for_error(ip.sandbox.thrown_error)
  return nil
end

#post_update(content) ⇒ Object



738
739
740
741
742
743
744
745
# File 'lib/cloudrail_si/services/Twitter.rb', line 738

def post_update(content)
  ServiceCode::Statistics.add_call('Twitter', 'post_update')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Social:postUpdate', @interpreter_storage, content)

  check_for_error(ip.sandbox.thrown_error)
  return nil
end

#post_video(message, video, size, mime_type) ⇒ Object



756
757
758
759
760
761
762
763
# File 'lib/cloudrail_si/services/Twitter.rb', line 756

def post_video(message, video, size, mime_type)
  ServiceCode::Statistics.add_call('Twitter', 'post_video')
  ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
  ip.call_function('Social:postVideo', @interpreter_storage, message, video, size, mime_type)

  check_for_error(ip.sandbox.thrown_error)
  return nil
end

#resume_login(execution_state, callback) ⇒ Object



787
788
789
790
791
792
# File 'lib/cloudrail_si/services/Twitter.rb', line 787

def (execution_state, callback)
  sandbox = ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)
  sandbox.load_state_from_string(execution_state)
  ip = ServiceCode::Interpreter.new(sandbox)
  ip.resume_function('Authenticating:login', @interpreter_storage, callback)
end

#save_as_stringObject



775
776
777
778
# File 'lib/cloudrail_si/services/Twitter.rb', line 775

def save_as_string
	ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
	return ip.save_as_string()
end