Class: ET::Client
- Inherits:
-
CreateWSDL
- Object
- CreateWSDL
- ET::Client
- Defined in:
- lib/exact-target-api/client.rb
Instance Attribute Summary collapse
-
#appsignature ⇒ Object
readonly
Returns the value of attribute appsignature.
-
#auth ⇒ Object
Returns the value of attribute auth.
-
#authObj ⇒ Object
readonly
Returns the value of attribute authObj.
-
#authToken ⇒ Object
Returns the value of attribute authToken.
-
#authTokenExpiration ⇒ Object
readonly
Returns the value of attribute authTokenExpiration.
-
#clientId ⇒ Object
readonly
Returns the value of attribute clientId.
-
#clientSecret ⇒ Object
readonly
Returns the value of attribute clientSecret.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#internalAuthToken ⇒ Object
readonly
Returns the value of attribute internalAuthToken.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#ready ⇒ Object
Returns the value of attribute ready.
-
#refreshKey ⇒ Object
readonly
Returns the value of attribute refreshKey.
-
#soapHeader ⇒ Object
readonly
Returns the value of attribute soapHeader.
-
#stackID ⇒ Object
readonly
Returns the value of attribute stackID.
-
#status ⇒ Object
Returns the value of attribute status.
-
#wsdlLoc ⇒ Object
readonly
Returns the value of attribute wsdlLoc.
Instance Method Summary collapse
-
#initialize(config, options = {}) ⇒ Client
constructor
A new instance of Client.
- #list ⇒ Object
- #refresh_token(force = nil) ⇒ Object (also: #refreshToken)
- #subscriber ⇒ Object
Methods inherited from CreateWSDL
#stringify_keys!, #symbolize_keys!, #wsdl_file
Constructor Details
#initialize(config, options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/exact-target-api/client.rb', line 8 def initialize(config, = {}) load_config(config) symbolize_keys!() get_wsdl = .has_key?(:wsdl) ? [:wsdl] : true @debug = [:debug] @path = Dir.tmpdir begin if get_wsdl super(@path) end if [:jwt] jwt = JWT.decode([:jwt], @appsignature, true) @authToken = jwt['request']['user']['oauthToken'] @authTokenExpiration = [Time.at(jwt['exp']), Time.now + jwt['request']['user']['expiresIn']].min @internalAuthToken = jwt['request']['user']['internalOauthToken'] @refreshKey = jwt['request']['user']['refreshToken'] self.determine_stack @authObj = {'oAuth' => {'oAuthToken' => @internalAuthToken}} @authObj[:attributes!] = { 'oAuth' => { 'xmlns' => 'http://exacttarget.com' }} @auth = Savon.client(soap_header: @authObj, wsdl: File.read(wsdl_file(@path)), endpoint: @endpoint, wsse_auth: ["*", "*"], raise_errors: false, log: @debug, open_timeout: 180, read_timeout: 180) end refresh_token rescue raise end @ready = @auth.operations.length > 0 && @status >= 200 && @status <= 400 end |
Instance Attribute Details
#appsignature ⇒ Object (readonly)
Returns the value of attribute appsignature.
6 7 8 |
# File 'lib/exact-target-api/client.rb', line 6 def appsignature @appsignature end |
#auth ⇒ Object
Returns the value of attribute auth.
5 6 7 |
# File 'lib/exact-target-api/client.rb', line 5 def auth @auth end |
#authObj ⇒ Object (readonly)
Returns the value of attribute authObj.
6 7 8 |
# File 'lib/exact-target-api/client.rb', line 6 def authObj @authObj end |
#authToken ⇒ Object
Returns the value of attribute authToken.
5 6 7 |
# File 'lib/exact-target-api/client.rb', line 5 def authToken @authToken end |
#authTokenExpiration ⇒ Object (readonly)
Returns the value of attribute authTokenExpiration.
6 7 8 |
# File 'lib/exact-target-api/client.rb', line 6 def authTokenExpiration @authTokenExpiration end |
#clientId ⇒ Object (readonly)
Returns the value of attribute clientId.
6 7 8 |
# File 'lib/exact-target-api/client.rb', line 6 def clientId @clientId end |
#clientSecret ⇒ Object (readonly)
Returns the value of attribute clientSecret.
6 7 8 |
# File 'lib/exact-target-api/client.rb', line 6 def clientSecret @clientSecret end |
#debug ⇒ Object
Returns the value of attribute debug.
5 6 7 |
# File 'lib/exact-target-api/client.rb', line 5 def debug @debug end |
#internalAuthToken ⇒ Object (readonly)
Returns the value of attribute internalAuthToken.
6 7 8 |
# File 'lib/exact-target-api/client.rb', line 6 def internalAuthToken @internalAuthToken end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/exact-target-api/client.rb', line 6 def path @path end |
#ready ⇒ Object
Returns the value of attribute ready.
5 6 7 |
# File 'lib/exact-target-api/client.rb', line 5 def ready @ready end |
#refreshKey ⇒ Object (readonly)
Returns the value of attribute refreshKey.
6 7 8 |
# File 'lib/exact-target-api/client.rb', line 6 def refreshKey @refreshKey end |
#soapHeader ⇒ Object (readonly)
Returns the value of attribute soapHeader.
6 7 8 |
# File 'lib/exact-target-api/client.rb', line 6 def soapHeader @soapHeader end |
#stackID ⇒ Object (readonly)
Returns the value of attribute stackID.
6 7 8 |
# File 'lib/exact-target-api/client.rb', line 6 def stackID @stackID end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/exact-target-api/client.rb', line 5 def status @status end |
#wsdlLoc ⇒ Object (readonly)
Returns the value of attribute wsdlLoc.
6 7 8 |
# File 'lib/exact-target-api/client.rb', line 6 def wsdlLoc @wsdlLoc end |
Instance Method Details
#list ⇒ Object
103 104 105 |
# File 'lib/exact-target-api/client.rb', line 103 def list ET::List.new(self) end |
#refresh_token(force = nil) ⇒ Object Also known as: refreshToken
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/exact-target-api/client.rb', line 52 def refresh_token(force = nil) #If we don't already have a token or the token expires within 5 min(300 seconds), get one if force || @authToken.nil? || Time.now + 300 > @authTokenExpiration begin uri = URI.parse("https://auth.exacttargetapis.com/v1/requestToken?legacy=1") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri) jsonPayload = {clientId: @clientId, clientSecret: @clientSecret, accessType: 'offline'} # Pass in the refreshKey if we have it if @refreshKey jsonPayload[:refreshToken] = @refreshKey jsonPayload[:scope] = "cas:#{@internalAuthToken}" end request.body = jsonPayload.to_json request.add_field "Content-Type", "application/json" tokenResponse = JSON.parse(http.request(request).body) if tokenResponse['accessToken'].nil? raise 'Unable to validate App Keys(ClientID/ClientSecret) provided: ' + http.request(request).body end @authToken = tokenResponse['accessToken'] @authTokenExpiration = Time.new + tokenResponse['expiresIn'] @internalAuthToken = tokenResponse['legacyToken'] if tokenResponse["refreshToken"] @refreshKey = tokenResponse['refreshToken'] end self.determine_stack if @endpoint.nil? @authObj = {'oAuth' => {'oAuthToken' => @internalAuthToken}} @authObj[:attributes!] = {'oAuth' => {'xmlns' => 'http://exacttarget.com' }} @auth = Savon.client(soap_header: @authObj, wsdl: File.read(wsdl_file(@path)), endpoint: @endpoint, wsse_auth: ["*", "*"], raise_errors: false, log: @debug) rescue Exception => e raise 'Unable to validate App Keys(ClientID/ClientSecret) provided: ' + e. end end end |
#subscriber ⇒ Object
107 108 109 |
# File 'lib/exact-target-api/client.rb', line 107 def subscriber ET::Subscriber.new(self) end |