Class: FuelSDK::Client
- Inherits:
-
Object
- Object
- FuelSDK::Client
- Defined in:
- lib/fuelsdk/client.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#id ⇒ Object
Returns the value of attribute id.
-
#internal_token ⇒ Object
Returns the value of attribute internal_token.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#signature ⇒ Object
Returns the value of attribute signature.
Attributes included from Targeting
Attributes included from Soap
Instance Method Summary collapse
- #AddSubscriberToList(email, ids, subscriber_key = nil) ⇒ Object
- #cache ⇒ Object
- #clear_client! ⇒ Object
- #CreateDataExtensions(definitions) ⇒ Object
- #decoded_jwt=(decoded_jwt) ⇒ Object
-
#initialize(params = {}, debug = false) ⇒ Client
constructor
A new instance of Client.
- #jwt=(encoded_jwt) ⇒ Object
- #refresh(force = false) ⇒ Object
- #refresh! ⇒ Object
- #request_token_data ⇒ Object
- #request_token_options(data) ⇒ Object
Methods included from Rest
#complete_url, #get_url_properties, #normalize_keys, #parse_properties, #rest_client, #rest_delete, #rest_get, #rest_patch, #rest_post
Methods included from Targeting
Methods included from Soap
#add_complex_filter_part, #add_simple_filter_part, #cache_editable, #cache_properties, #cache_retrievable, #cached_properties?, #create_action_message, #create_object_type_message, #create_objects_message, #describe, #describe_data_extension, #describe_dataextension_message, #describe_object_type_message, #editable_properties_cached?, #format_dataextension_cud_properties, #format_object_cud_properties, #get_all_object_properties, #get_dataextension_properties, #get_editable_properties, #get_retrievable_properties, #header, #is_a_dataextension?, #normalize_customer_key, #normalize_filter, #normalize_properties_for_cud, #normalize_properties_for_retrieve, #retrievable_properties_cached?, #soap_client, #soap_configure, #soap_delete, #soap_describe, #soap_get, #soap_perform, #soap_post, #soap_put
Constructor Details
#initialize(params = {}, debug = false) ⇒ Client
Returns a new instance of Client.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fuelsdk/client.rb', line 67 def initialize(params={}, debug=false) self.debug = debug client_config = params['client'] if client_config self.id = client_config["id"] self.secret = client_config["secret"] self.signature = client_config["signature"] end self.jwt = params['jwt'] if params['jwt'] self.refresh_token = params['refresh_token'] if params['refresh_token'] self.wsdl = params["defaultwsdl"] if params["defaultwsdl"] end |
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
41 42 43 |
# File 'lib/fuelsdk/client.rb', line 41 def auth_token @auth_token end |
#debug ⇒ Object
Returns the value of attribute debug.
41 42 43 |
# File 'lib/fuelsdk/client.rb', line 41 def debug @debug end |
#id ⇒ Object
Returns the value of attribute id.
41 42 43 |
# File 'lib/fuelsdk/client.rb', line 41 def id @id end |
#internal_token ⇒ Object
Returns the value of attribute internal_token.
41 42 43 |
# File 'lib/fuelsdk/client.rb', line 41 def internal_token @internal_token end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
41 42 43 |
# File 'lib/fuelsdk/client.rb', line 41 def refresh_token @refresh_token end |
#secret ⇒ Object
Returns the value of attribute secret.
41 42 43 |
# File 'lib/fuelsdk/client.rb', line 41 def secret @secret end |
#signature ⇒ Object
Returns the value of attribute signature.
41 42 43 |
# File 'lib/fuelsdk/client.rb', line 41 def signature @signature end |
Instance Method Details
#AddSubscriberToList(email, ids, subscriber_key = nil) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/fuelsdk/client.rb', line 122 def AddSubscriberToList(email, ids, subscriber_key = nil) s = FuelSDK::Subscriber.new s.client = self lists = ids.collect{|id| {'ID' => id}} s.properties = {"EmailAddress" => email, "Lists" => lists} s.propertiess['SubscriberKey'] = subscriber_key if subscriber_key # Try to add the subscriber if(rsp = s.post and rsp.results.first[:error_code] == '12014') # subscriber already exists we need to update. rsp = s.patch end rsp end |
#cache ⇒ Object
47 48 49 50 51 52 |
# File 'lib/fuelsdk/client.rb', line 47 def cache @cache ||= { :retrievable => {}, :editable => {} } end |
#clear_client! ⇒ Object
101 102 103 |
# File 'lib/fuelsdk/client.rb', line 101 def clear_client! @soap_client = nil end |
#CreateDataExtensions(definitions) ⇒ Object
137 138 139 140 141 142 |
# File 'lib/fuelsdk/client.rb', line 137 def CreateDataExtensions(definitions) de = FuelSDK::DataExtension.new de.client = self de.properties = definitions de.post end |
#decoded_jwt=(decoded_jwt) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/fuelsdk/client.rb', line 59 def decoded_jwt= decoded_jwt @decoded_jwt = decoded_jwt self.auth_token = decoded_jwt['request']['user']['oauthToken'] self.internal_token = decoded_jwt['request']['user']['internalOauthToken'] self.refresh_token = decoded_jwt['request']['user']['refreshToken'] #@authTokenExpiration = Time.new + decoded_jwt['request']['user']['expiresIn'] end |
#jwt=(encoded_jwt) ⇒ Object
54 55 56 57 |
# File 'lib/fuelsdk/client.rb', line 54 def jwt= encoded_jwt raise 'Require app signature to decode JWT' unless self.signature self.decoded_jwt=JWT.decode(encoded_jwt, self.signature, true) end |
#refresh(force = false) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fuelsdk/client.rb', line 105 def refresh force=false if (self.auth_token.nil? || force) clear_client! = (request_token_data) response = post("https://auth.exacttargetapis.com/v1/requestToken", ) raise "Unable to refresh token: #{response['message']}" unless response.has_key?('accessToken') self.auth_token = response['accessToken'] self.internal_token = response['legacyToken'] self.refresh_token = response['refreshToken'] if response.has_key?("refreshToken") end end |
#refresh! ⇒ Object
118 119 120 |
# File 'lib/fuelsdk/client.rb', line 118 def refresh! refresh true end |
#request_token_data ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fuelsdk/client.rb', line 82 def request_token_data raise 'Require Client Id and Client Secret to refresh tokens' unless (id && secret) { 'clientId' => id, 'clientSecret' => secret, 'accessType' => 'offline' }.tap do |h| h['refreshToken'] = refresh_token if refresh_token end end |
#request_token_options(data) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/fuelsdk/client.rb', line 93 def data { 'data' => data, 'content_type' => 'application/json', 'params' => {'legacy' => 1} } end |