responsys-api 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0c3a10d995ca728b549d02f9de846a3b406f6425
4
- data.tar.gz: 63cf563d0cf8e44b6770dc62c4c896741bf12617
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDc0ODIyNWIxZDg5YzUyYWU3MzYwYmQ5MjVkNjhlZTU5NGJkYTA0Yg==
5
+ data.tar.gz: !binary |-
6
+ MWQ3NTEwZjgyYjU1YjZlYzZlNjY4ODBjNWMzYzMwYzE4NzVkZDg3Mw==
5
7
  SHA512:
6
- metadata.gz: 7f98ddbc040040aa8b0aac236032a106d5c3b0ec238fdedcfd73fab0ff4e3f2f1148d09f3bd38cef6d540d9a1388233a671769b50e275ca9dbf5302d5d83a0b2
7
- data.tar.gz: 35d99e84b5840eb90daee24d725fc0bf1aac3382efd750e6f93ae79a1e0aa083f3f2924bbc8cea45757e305ab3d3ccf68e7bd12e33f3e4b0463c0b92cee6744b
8
+ metadata.gz: !binary |-
9
+ OTIzNTlmODA2MGM5Zjc1YjMxNjg2YmRhM2I0ZWY5Y2ZmMzIxODA3ZDRjM2E2
10
+ NzA4ZjA1N2MxOGM0Y2I1ODJjNmFkODEzMWEyMmRjMzA3ZDNmZWI2YjQ2M2I1
11
+ NjhhNmUwNTRhYmU5ZWI3OWIxMjAyNThmMmExYWM5YTI1NzUxNjk=
12
+ data.tar.gz: !binary |-
13
+ Y2EyYTdiOGJkZDMzZTRhZjEzMTNiODMxYzI5YTA3MDhjMTU1NzE2NTIyMDVi
14
+ ZWZjYzM5ZjQ3MjkzYWQ0ZDA3ODM1MjViMTNkYmY0MWJmNTk1N2Y1MDhhZWNm
15
+ MjZmMjQ2ZTVjZTQ3YTMyYjAxZTVkNmNmYWJmZTYxZGVmNDA3MTA=
data/.gitignore CHANGED
@@ -18,3 +18,4 @@ tmp
18
18
  .DS_Store
19
19
  lib/.DS_Store
20
20
  lib/responsys/.DS_Store
21
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --tty
3
+ --format documentation
4
+ --drb
@@ -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
@@ -0,0 +1,7 @@
1
+ class ResponsysApi
2
+ module Helper
3
+ def self.format_response(response, action)
4
+ response.body[("#{action}_response").to_sym][:result]
5
+ end
6
+ end
7
+ 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(username, password, wsdl)
7
- @username = username
8
- @password = password
9
- @wsdl = wsdl
10
- @client = SavonApi.new(wsdl)
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", login_credentials)
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(method_name, message)
23
- client.run_with_credentials(method_name, message, jsession_id, header)
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
@@ -1 +1,4 @@
1
1
  require 'responsys/responsys_api'
2
+ require 'responsys/configuration'
3
+ require 'responsys/helper'
4
+ require 'savon/savon_api'
@@ -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
@@ -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.1"
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'
@@ -0,0 +1,4 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe ResponsysApi do
4
+ end
@@ -0,0 +1,4 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require './lib/responsys_api.rb'
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.1
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/client.rb
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.0.14
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
@@ -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