responsys-api 0.0.1 → 0.0.2
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.
- checksums.yaml +13 -5
- data/.gitignore +1 -0
- data/.rspec +4 -0
- data/lib/responsys/configuration.rb +26 -0
- data/lib/responsys/helper.rb +7 -0
- data/lib/responsys/responsys_api.rb +13 -11
- data/lib/responsys_api.rb +3 -0
- data/lib/savon/savon_api.rb +22 -0
- data/responsys-api.gemspec +1 -1
- data/spec/responsys_api_spec.rb +4 -0
- data/spec/spec_helper.rb +4 -0
- metadata +15 -8
- data/lib/responsys/client.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDc0ODIyNWIxZDg5YzUyYWU3MzYwYmQ5MjVkNjhlZTU5NGJkYTA0Yg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MWQ3NTEwZjgyYjU1YjZlYzZlNjY4ODBjNWMzYzMwYzE4NzVkZDg3Mw==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTIzNTlmODA2MGM5Zjc1YjMxNjg2YmRhM2I0ZWY5Y2ZmMzIxODA3ZDRjM2E2
|
10
|
+
NzA4ZjA1N2MxOGM0Y2I1ODJjNmFkODEzMWEyMmRjMzA3ZDNmZWI2YjQ2M2I1
|
11
|
+
NjhhNmUwNTRhYmU5ZWI3OWIxMjAyNThmMmExYWM5YTI1NzUxNjk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Y2EyYTdiOGJkZDMzZTRhZjEzMTNiODMxYzI5YTA3MDhjMTU1NzE2NTIyMDVi
|
14
|
+
ZWZjYzM5ZjQ3MjkzYWQ0ZDA3ODM1MjViMTNkYmY0MWJmNTk1N2Y1MDhhZWNm
|
15
|
+
MjZmMjQ2ZTVjZTQ3YTMyYjAxZTVkNmNmYWJmZTYxZGVmNDA3MTA=
|
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
class ResponsysApi
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :settings
|
4
|
+
# Put all these constants into a configurable setting hash
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@settings = {
|
8
|
+
username: nil,
|
9
|
+
password: nil,
|
10
|
+
wsdl: ""
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :configuration
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configuration
|
20
|
+
@configuration ||= Configuration.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.configure
|
24
|
+
yield(configuration)
|
25
|
+
end
|
26
|
+
end
|
@@ -1,26 +1,28 @@
|
|
1
1
|
require 'savon'
|
2
2
|
|
3
3
|
class ResponsysApi
|
4
|
-
attr_accessor :client, :session_id, :jsession_id, :header
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
|
8
|
-
@
|
9
|
-
|
10
|
-
|
4
|
+
attr_accessor :credentials, :client, :session_id, :jsession_id, :header
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
settings = ResponsysApi.configuration.settings
|
8
|
+
@credentials = {
|
9
|
+
"tns:username" => settings[:username],
|
10
|
+
"tns:password" => settings[:password]
|
11
|
+
}
|
12
|
+
@client = SavonApi.new(settings[:wsdl])
|
11
13
|
login
|
12
14
|
end
|
13
15
|
|
14
16
|
def login
|
15
|
-
response = client.run("login",
|
17
|
+
response = client.run("login", credentials)
|
16
18
|
establish_session_id(response)
|
17
19
|
establish_jsession_id(response)
|
18
20
|
set_session_credentials
|
19
|
-
response
|
20
21
|
end
|
21
22
|
|
22
|
-
def api_method(
|
23
|
-
client.run_with_credentials(
|
23
|
+
def api_method(action, message = nil)
|
24
|
+
response = client.run_with_credentials(action, message, jsession_id, header)
|
25
|
+
ResponsysApi::Helper.format_response(response, action)
|
24
26
|
end
|
25
27
|
|
26
28
|
private
|
data/lib/responsys_api.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
class SavonApi
|
2
|
+
attr_accessor :client
|
3
|
+
|
4
|
+
def initialize(wsdl)
|
5
|
+
# @client = Savon.client(log_level: :debug, log: false, pretty_print_xml: true, wsdl: wsdl)
|
6
|
+
|
7
|
+
# should use this, the call above is only to help debug
|
8
|
+
@client = Savon.client(wsdl: wsdl)
|
9
|
+
end
|
10
|
+
|
11
|
+
def run(method, message)
|
12
|
+
@client.call(method.to_sym, message: message)
|
13
|
+
end
|
14
|
+
|
15
|
+
def run_with_credentials(method, message, cookie, header)
|
16
|
+
@client.call(method.to_sym, message: message, cookies: cookie, soap_header: header)
|
17
|
+
end
|
18
|
+
|
19
|
+
def available_operations
|
20
|
+
@client.operations
|
21
|
+
end
|
22
|
+
end
|
data/responsys-api.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "responsys-api"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.2"
|
8
8
|
spec.authors = ["Dan DeMeyere", "Florian Lorrain", "Morgan Griggs", "Mike Rocco"]
|
9
9
|
spec.email = ["dan@thredup.com", "florain.lorrain@thredup.com", "morgan@thredup.com", "michael.rocco@thredup.com"]
|
10
10
|
spec.description = 'A gem to integrate with the Responsys SOAP API'
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: responsys-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan DeMeyere
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
name: rake
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
|
-
- - '>='
|
48
|
+
- - ! '>='
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '0'
|
51
51
|
type: :development
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
|
-
- - '>='
|
55
|
+
- - ! '>='
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
58
|
- !ruby/object:Gem::Dependency
|
@@ -80,14 +80,19 @@ extensions: []
|
|
80
80
|
extra_rdoc_files: []
|
81
81
|
files:
|
82
82
|
- .gitignore
|
83
|
+
- .rspec
|
83
84
|
- Gemfile
|
84
85
|
- LICENSE.txt
|
85
86
|
- README.md
|
86
87
|
- Rakefile
|
87
|
-
- lib/responsys/
|
88
|
+
- lib/responsys/configuration.rb
|
89
|
+
- lib/responsys/helper.rb
|
88
90
|
- lib/responsys/responsys_api.rb
|
89
91
|
- lib/responsys_api.rb
|
92
|
+
- lib/savon/savon_api.rb
|
90
93
|
- responsys-api.gemspec
|
94
|
+
- spec/responsys_api_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
91
96
|
homepage: https://github.com/dandemeyere/responsys-api
|
92
97
|
licenses:
|
93
98
|
- MIT
|
@@ -98,18 +103,20 @@ require_paths:
|
|
98
103
|
- lib
|
99
104
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
105
|
requirements:
|
101
|
-
- - '>='
|
106
|
+
- - ! '>='
|
102
107
|
- !ruby/object:Gem::Version
|
103
108
|
version: '0'
|
104
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
110
|
requirements:
|
106
|
-
- - '>='
|
111
|
+
- - ! '>='
|
107
112
|
- !ruby/object:Gem::Version
|
108
113
|
version: '0'
|
109
114
|
requirements: []
|
110
115
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
116
|
+
rubygems_version: 2.2.2
|
112
117
|
signing_key:
|
113
118
|
specification_version: 4
|
114
119
|
summary: Write a proper summary
|
115
|
-
test_files:
|
120
|
+
test_files:
|
121
|
+
- spec/responsys_api_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
data/lib/responsys/client.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'version'
|
2
|
-
require 'responsys_helper'
|
3
|
-
require 'savon'
|
4
|
-
|
5
|
-
module ResponsysApi
|
6
|
-
class Client
|
7
|
-
###### Initialization/Session mgmt ######
|
8
|
-
def initialize(wsdl=nil, username=nil, password=nil)
|
9
|
-
#Get the settings
|
10
|
-
@wsdl = wsdl || ResponsysApi.wsdl || raise(ArgumentError, "You must provide a WSDL or call ResponsysApi.settings() first")
|
11
|
-
@username = username || ResponsysApi.username || raise(ArgumentError, "You must provide a username or call ResponsysApi.settings() first")
|
12
|
-
@password = password || ResponsysApi.password || raise(ArgumentError, "You must provide a password or call ResponsysApi.settings() first")
|
13
|
-
|
14
|
-
#Connection to the API with the credentials
|
15
|
-
@client = connect
|
16
|
-
end
|
17
|
-
|
18
|
-
#Set up the @client object used to call the api
|
19
|
-
def connect
|
20
|
-
sessionIds = login
|
21
|
-
@client = Savon.client(
|
22
|
-
wsdl: @wsdl,
|
23
|
-
soap_header: { "sessionHeader" => { "sessionId" => sessionIds["sessionId"] } },
|
24
|
-
headers: { "Cookie" => "JSESSIONID=#{sessionIds['jSessionId']}" },
|
25
|
-
element_form_default: :qualified
|
26
|
-
)
|
27
|
-
end
|
28
|
-
|
29
|
-
#Return the session ids required to identify the client
|
30
|
-
def login
|
31
|
-
temp_connection = Savon.client(wsdl: @wsdl,element_form_default: :qualified)
|
32
|
-
|
33
|
-
response = temp_connection.call(:login, message: { "username"=>@username,"password"=>@password })
|
34
|
-
|
35
|
-
result = ResponsysApi::Helper::get_result(response, 'login')
|
36
|
-
|
37
|
-
#Keep the Soap SessionId which is to be used in each soap header requests
|
38
|
-
sessionId = result[:session_id]
|
39
|
-
|
40
|
-
#Keep the JSESSIONID which is to be inserted in each HTTP header of soap requests
|
41
|
-
jSessionId = response.http.headers["set-cookie"][0].split(';')[0].partition('=')[2]
|
42
|
-
|
43
|
-
{"sessionId" => sessionId, "jSessionId" => jSessionId}
|
44
|
-
end
|
45
|
-
|
46
|
-
def logout
|
47
|
-
@client.call(:logout)
|
48
|
-
@client=nil
|
49
|
-
end
|
50
|
-
|
51
|
-
def connected?
|
52
|
-
!@client.nil?
|
53
|
-
end
|
54
|
-
###### End Initialization/Session mgmt ######
|
55
|
-
|
56
|
-
###### Folders ######
|
57
|
-
def listFolders
|
58
|
-
response = @client.call(:list_folders)
|
59
|
-
|
60
|
-
ResponsysApi::Helper::get_result(response, 'list_folders')
|
61
|
-
end
|
62
|
-
###### End Folders ######
|
63
|
-
end
|
64
|
-
end
|